Salome HOME
Merge with version on tag OCC-V2_1_0d
[modules/smesh.git] / src / DriverUNV / DriverUNV_R_SMDS_Mesh.cxx
1 #include "DriverUNV_R_SMDS_Mesh.h"
2 #include "SMDS_Mesh.hxx"
3
4 #include "utilities.h"
5
6 #include "UNV2411_Structure.hxx"
7 #include "UNV2412_Structure.hxx"
8 #include "UNV_Utilities.hxx"
9
10 using namespace std;
11
12
13 #ifdef _DEBUG_
14 static int MYDEBUG = 0;
15 #else
16 static int MYDEBUG = 0;
17 #endif
18
19
20 static const SMDS_MeshNode* 
21 FindNode(const SMDS_Mesh* theMesh, int theId){
22   const SMDS_MeshNode* aNode = theMesh->FindNode(theId);
23   if(aNode) return aNode;
24   EXCEPTION(runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<<theId);
25 }
26
27
28 Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform()
29 {
30   Status aResult = DRS_OK;
31   std::ifstream in_stream(myFile.c_str());
32   try{
33     {
34       using namespace UNV2411;
35       TDataSet aDataSet2411;
36       UNV2411::Read(in_stream,aDataSet2411);
37       if(MYDEBUG) MESSAGE("Perform - aDataSet2411.size() = "<<aDataSet2411.size());
38       TDataSet::const_iterator anIter = aDataSet2411.begin();
39       for(; anIter != aDataSet2411.end(); anIter++){
40         const TNodeLab& aLabel = anIter->first;
41         const TRecord& aRec = anIter->second;
42         const SMDS_MeshNode* aNode = 
43           myMesh->AddNodeWithID(aRec.coord[0],aRec.coord[1],aRec.coord[2],aLabel);
44       }
45     }
46     {
47       using namespace UNV2412;
48       in_stream.seekg(0);
49       TDataSet aDataSet2412;
50       UNV2412::Read(in_stream,aDataSet2412);
51       TDataSet::const_iterator anIter = aDataSet2412.begin();
52       if(MYDEBUG) MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
53       for(; anIter != aDataSet2412.end(); anIter++){
54         SMDS_MeshElement* anElement = NULL;
55         const TElementLab& aLabel = anIter->first;
56         const TRecord& aRec = anIter->second;
57         int aNbNodes = aRec.node_labels.size();
58         if(IsBeam(aRec.fe_descriptor_id)){
59           anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
60                                             aRec.node_labels[1],
61                                             aLabel);
62         }else if(IsFace(aRec.fe_descriptor_id)){
63           switch(aRec.fe_descriptor_id){
64           case 71: // TRI3
65           case 72:
66           case 74:
67             
68           case 41: // Plane Stress Linear Triangle - TRI3
69           case 91: // Thin Shell Linear Triangle - TRI3
70             
71           case 42: // Plane Stress Quadratic Triangle - TRI6
72           case 92: // Thin Shell Quadratic Triangle - TRI6
73             
74             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
75                                               aRec.node_labels[1],
76                                               aRec.node_labels[2],
77                                               aLabel);
78             break;
79             
80           case 44: // Plane Stress Linear Quadrilateral - QUAD4
81           case 94: // Thin Shell   Linear Quadrilateral -  QUAD4
82             
83           case 45: // Plane Stress Quadratic Quadrilateral - QUAD8
84           case 95: // Thin Shell   Quadratic Quadrilateral - QUAD8
85             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
86                                               aRec.node_labels[1],
87                                               aRec.node_labels[2],
88                                               aRec.node_labels[3],
89                                               aLabel);
90             break;
91           }
92         }else if(IsVolume(aRec.fe_descriptor_id)){
93           switch(aRec.fe_descriptor_id){
94             
95           case 111: // Solid Linear Tetrahedron - TET4
96           case 118: // Solid Quadratic Tetrahedron - TET10
97             
98             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
99                                                 aRec.node_labels[1],
100                                                 aRec.node_labels[2],
101                                                 aRec.node_labels[3],
102                                                 aLabel);
103             break;
104             
105           case 112: // Solid Linear Prism - PRISM6
106             
107             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
108                                                 aRec.node_labels[2],
109                                                 aRec.node_labels[1],
110                                                 aRec.node_labels[3],
111                                                 aRec.node_labels[5],
112                                                 aRec.node_labels[4],
113                                                 aLabel);
114             break;
115             
116           case 113: // Solid Quadratic Prism - PRISM15
117             
118             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
119                                                 aRec.node_labels[4],
120                                                 aRec.node_labels[2],
121                                                 aRec.node_labels[9],
122                                                 aRec.node_labels[13],
123                                                 aRec.node_labels[11],
124                                                 aLabel);
125             break;
126             
127           case 115: // Solid Linear Brick - HEX8
128             
129             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
130                                                 aRec.node_labels[1],
131                                                 aRec.node_labels[2],
132                                                 aRec.node_labels[3],
133                                                 aRec.node_labels[4],
134                                                 aRec.node_labels[5],
135                                                 aRec.node_labels[6],
136                                                 aRec.node_labels[7],
137                                                 aLabel);
138             break;
139
140           case 116: // Solid Quadratic Brick - HEX20
141             
142             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
143                                                 aRec.node_labels[2],
144                                                 aRec.node_labels[4],
145                                                 aRec.node_labels[6],
146                                                 aRec.node_labels[12],
147                                                 aRec.node_labels[14],
148                                                 aRec.node_labels[16],
149                                                 aRec.node_labels[18],
150                                                 aLabel);
151             break;
152           }
153         }
154         if(!anElement)
155           MESSAGE("DriverUNV_R_SMDS_Mesh::Perform - can not add element with ID = "<<aLabel<<" and type = "<<aRec.fe_descriptor_id);
156       }
157     }
158   }catch(const std::exception& exc){
159     INFOS("Follow exception was cought:\n\t"<<exc.what());
160   }catch(...){
161     INFOS("Unknown exception was cought !!!");
162   }
163   return aResult;
164 }