Salome HOME
fix bug 11943 TC: Wrong nodal connectivity of hexahedrons imported from UNV format...
[modules/smesh.git] / src / DriverUNV / DriverUNV_R_SMDS_Mesh.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/
19 //
20 #include "DriverUNV_R_SMDS_Mesh.h"
21 #include "SMDS_Mesh.hxx"
22
23 #include "utilities.h"
24
25 #include "UNV2411_Structure.hxx"
26 #include "UNV2412_Structure.hxx"
27 #include "UNV_Utilities.hxx"
28
29 using namespace std;
30
31
32 #ifdef _DEBUG_
33 static int MYDEBUG = 0;
34 #else
35 static int MYDEBUG = 0;
36 #endif
37
38
39 Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform()
40 {
41   Status aResult = DRS_OK;
42   std::ifstream in_stream(myFile.c_str());
43   try{
44     {
45       using namespace UNV2411;
46       TDataSet aDataSet2411;
47       UNV2411::Read(in_stream,aDataSet2411);
48       if(MYDEBUG) MESSAGE("Perform - aDataSet2411.size() = "<<aDataSet2411.size());
49       TDataSet::const_iterator anIter = aDataSet2411.begin();
50       for(; anIter != aDataSet2411.end(); anIter++){
51         const TNodeLab& aLabel = anIter->first;
52         const TRecord& aRec = anIter->second;
53         myMesh->AddNodeWithID(aRec.coord[0],aRec.coord[1],aRec.coord[2],aLabel);
54       }
55     }
56     {
57       using namespace UNV2412;
58       in_stream.seekg(0);
59       TDataSet aDataSet2412;
60       UNV2412::Read(in_stream,aDataSet2412);
61       TDataSet::const_iterator anIter = aDataSet2412.begin();
62       if(MYDEBUG) MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
63       for(; anIter != aDataSet2412.end(); anIter++){
64         SMDS_MeshElement* anElement = NULL;
65         const TElementLab& aLabel = anIter->first;
66         const TRecord& aRec = anIter->second;
67         if(IsBeam(aRec.fe_descriptor_id)) {
68           if(aRec.fe_descriptor_id == 11) {
69             // edge with two nodes
70             anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
71                                               aRec.node_labels[1],
72                                               aLabel);
73           }
74           else {
75             // quadratic edge (with 3 nodes)
76             anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
77                                               aRec.node_labels[1],
78                                               aRec.node_labels[2],
79                                               aLabel);
80           }
81         }
82         else if(IsFace(aRec.fe_descriptor_id)) {
83           switch(aRec.fe_descriptor_id){
84           case 71: // TRI3
85           case 72:
86           case 74:
87             
88           case 41: // Plane Stress Linear Triangle - TRI3
89           case 91: // Thin Shell Linear Triangle - TRI3
90             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
91                                               aRec.node_labels[1],
92                                               aRec.node_labels[2],
93                                               aLabel);
94             break;
95             
96           case 42: // Plane Stress Quadratic Triangle - TRI6
97           case 92: // Thin Shell Quadratic Triangle - TRI6
98             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
99                                               aRec.node_labels[1],
100                                               aRec.node_labels[2],
101                                               aRec.node_labels[3],
102                                               aRec.node_labels[4],
103                                               aRec.node_labels[5],
104                                               aLabel);
105             break;
106             
107           case 44: // Plane Stress Linear Quadrilateral - QUAD4
108           case 94: // Thin Shell   Linear Quadrilateral -  QUAD4
109             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
110                                               aRec.node_labels[1],
111                                               aRec.node_labels[2],
112                                               aRec.node_labels[3],
113                                               aLabel);
114             break;
115             
116           case 45: // Plane Stress Quadratic Quadrilateral - QUAD8
117           case 95: // Thin Shell   Quadratic Quadrilateral - QUAD8
118             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
119                                               aRec.node_labels[1],
120                                               aRec.node_labels[2],
121                                               aRec.node_labels[3],
122                                               aRec.node_labels[4],
123                                               aRec.node_labels[5],
124                                               aRec.node_labels[6],
125                                               aRec.node_labels[7],
126                                               aLabel);
127             break;
128           }
129         }
130         else if(IsVolume(aRec.fe_descriptor_id)){
131           switch(aRec.fe_descriptor_id){
132             
133           case 111: // Solid Linear Tetrahedron - TET4
134             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
135                                                 aRec.node_labels[2],
136                                                 aRec.node_labels[1],
137                                                 aRec.node_labels[3],
138                                                 aLabel);
139             break;
140
141           case 118: // Solid Quadratic Tetrahedron - TET10
142             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
143                                                 aRec.node_labels[2],
144                                                 aRec.node_labels[1],
145                                                 aRec.node_labels[3],
146                                                 aRec.node_labels[6],
147                                                 aRec.node_labels[5],
148                                                 aRec.node_labels[4],
149                                                 aRec.node_labels[7],
150                                                 aRec.node_labels[9],
151                                                 aRec.node_labels[8],
152                                                 aLabel);
153             break;
154             
155           case 112: // Solid Linear Prism - PRISM6
156             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
157                                                 aRec.node_labels[2],
158                                                 aRec.node_labels[1],
159                                                 aRec.node_labels[3],
160                                                 aRec.node_labels[5],
161                                                 aRec.node_labels[4],
162                                                 aLabel);
163             break;
164             
165           case 113: // Solid Quadratic Prism - PRISM15
166             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
167                                                 aRec.node_labels[2],
168                                                 aRec.node_labels[1],
169                                                 aRec.node_labels[3],
170                                                 aRec.node_labels[5],
171                                                 aRec.node_labels[4],
172                                                 aRec.node_labels[8],
173                                                 aRec.node_labels[7],
174                                                 aRec.node_labels[6],
175                                                 aRec.node_labels[11],
176                                                 aRec.node_labels[10],
177                                                 aRec.node_labels[9],
178                                                 aRec.node_labels[12],
179                                                 aRec.node_labels[14],
180                                                 aRec.node_labels[13],
181                                                 aLabel);
182             break;
183             
184           case 115: // Solid Linear Brick - HEX8
185             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
186                                                 aRec.node_labels[3],
187                                                 aRec.node_labels[2],
188                                                 aRec.node_labels[1],
189                                                 aRec.node_labels[4],
190                                                 aRec.node_labels[7],
191                                                 aRec.node_labels[6],
192                                                 aRec.node_labels[5],
193                                                 aLabel);
194             break;
195
196           case 116: // Solid Quadratic Brick - HEX20
197             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
198                                                 aRec.node_labels[6],
199                                                 aRec.node_labels[4],
200                                                 aRec.node_labels[2],
201
202                                                 aRec.node_labels[12],
203                                                 aRec.node_labels[18],
204                                                 aRec.node_labels[16],
205                                                 aRec.node_labels[14],
206
207                                                 aRec.node_labels[7],
208                                                 aRec.node_labels[5],
209                                                 aRec.node_labels[3],
210                                                 aRec.node_labels[1],
211
212                                                 aRec.node_labels[19],
213                                                 aRec.node_labels[17],
214                                                 aRec.node_labels[15],
215                                                 aRec.node_labels[13],
216
217                                                 aRec.node_labels[8],
218                                                 aRec.node_labels[11],
219                                                 aRec.node_labels[10],
220                                                 aRec.node_labels[9],
221                                                 aLabel);
222             break;
223
224           case 114: // pyramid of 13 nodes (quadratic) - PIRA13
225             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
226                                                 aRec.node_labels[3],
227                                                 aRec.node_labels[2],
228                                                 aRec.node_labels[1],
229                                                 aRec.node_labels[4],
230                                                 aRec.node_labels[8],
231                                                 aRec.node_labels[7],
232                                                 aRec.node_labels[6],
233                                                 aRec.node_labels[5],
234                                                 aRec.node_labels[9],
235                                                 aRec.node_labels[12],
236                                                 aRec.node_labels[11],
237                                                 aRec.node_labels[10],
238                                                 aLabel);
239             break;
240
241           }
242         }
243         if(!anElement)
244           MESSAGE("DriverUNV_R_SMDS_Mesh::Perform - can not add element with ID = "<<aLabel<<" and type = "<<aRec.fe_descriptor_id);
245       }
246     }
247   }
248   catch(const std::exception& exc){
249     INFOS("Follow exception was cought:\n\t"<<exc.what());
250   }
251   catch(...){
252     INFOS("Unknown exception was cought !!!");
253   }
254   return aResult;
255 }