Salome HOME
Element 21 is a simple linear edge
[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 "UNV2417_Structure.hxx"
28 #include "UNV_Utilities.hxx"
29
30 using namespace std;
31
32
33 #ifdef _DEBUG_
34 static int MYDEBUG = 0;
35 #else
36 static int MYDEBUG = 0;
37 #endif
38
39
40 Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform()
41 {
42   Status aResult = DRS_OK;
43   std::ifstream in_stream(myFile.c_str());
44   try{
45     {
46       using namespace UNV2411;
47       TDataSet aDataSet2411;
48       UNV2411::Read(in_stream,aDataSet2411);
49       if(MYDEBUG) MESSAGE("Perform - aDataSet2411.size() = "<<aDataSet2411.size());
50       TDataSet::const_iterator anIter = aDataSet2411.begin();
51       for(; anIter != aDataSet2411.end(); anIter++){
52         const TNodeLab& aLabel = anIter->first;
53         const TRecord& aRec = anIter->second;
54         myMesh->AddNodeWithID(aRec.coord[0],aRec.coord[1],aRec.coord[2],aLabel);
55       }
56     }
57     {
58       using namespace UNV2412;
59       in_stream.seekg(0);
60       TDataSet aDataSet2412;
61       UNV2412::Read(in_stream,aDataSet2412);
62       TDataSet::const_iterator anIter = aDataSet2412.begin();
63       if(MYDEBUG) MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
64       for(; anIter != aDataSet2412.end(); anIter++){
65         SMDS_MeshElement* anElement = NULL;
66         const TElementLab& aLabel = anIter->first;
67         const TRecord& aRec = anIter->second;
68         if(IsBeam(aRec.fe_descriptor_id)) {
69           if((aRec.fe_descriptor_id == 11) || (aRec.fe_descriptor_id == 21)) {
70             // edge with two nodes
71             anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
72                                               aRec.node_labels[1],
73                                               aLabel);
74           }
75           else {
76             cout<<"### Id of element = "<<aRec.fe_descriptor_id<<endl;
77             // quadratic edge (with 3 nodes)
78             anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
79                                               aRec.node_labels[1],
80                                               aRec.node_labels[2],
81                                               aLabel);
82           }
83         }
84         else if(IsFace(aRec.fe_descriptor_id)) {
85           switch(aRec.fe_descriptor_id){
86           case 71: // TRI3
87           case 72:
88           case 74:
89             
90           case 41: // Plane Stress Linear Triangle - TRI3
91           case 91: // Thin Shell Linear Triangle - TRI3
92             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
93                                               aRec.node_labels[1],
94                                               aRec.node_labels[2],
95                                               aLabel);
96             break;
97             
98           case 42: // Plane Stress Quadratic Triangle - TRI6
99           case 92: // Thin Shell Quadratic Triangle - TRI6
100             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
101                                               aRec.node_labels[1],
102                                               aRec.node_labels[2],
103                                               aRec.node_labels[3],
104                                               aRec.node_labels[4],
105                                               aRec.node_labels[5],
106                                               aLabel);
107             break;
108             
109           case 44: // Plane Stress Linear Quadrilateral - QUAD4
110           case 94: // Thin Shell   Linear Quadrilateral -  QUAD4
111             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
112                                               aRec.node_labels[1],
113                                               aRec.node_labels[2],
114                                               aRec.node_labels[3],
115                                               aLabel);
116             break;
117             
118           case 45: // Plane Stress Quadratic Quadrilateral - QUAD8
119           case 95: // Thin Shell   Quadratic Quadrilateral - QUAD8
120             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
121                                               aRec.node_labels[1],
122                                               aRec.node_labels[2],
123                                               aRec.node_labels[3],
124                                               aRec.node_labels[4],
125                                               aRec.node_labels[5],
126                                               aRec.node_labels[6],
127                                               aRec.node_labels[7],
128                                               aLabel);
129             break;
130           }
131         }
132         else if(IsVolume(aRec.fe_descriptor_id)){
133           switch(aRec.fe_descriptor_id){
134             
135           case 111: // Solid Linear Tetrahedron - TET4
136             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
137                                                 aRec.node_labels[2],
138                                                 aRec.node_labels[1],
139                                                 aRec.node_labels[3],
140                                                 aLabel);
141             break;
142
143           case 118: // Solid Quadratic Tetrahedron - TET10
144             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
145                                                 aRec.node_labels[2],
146                                                 aRec.node_labels[1],
147                                                 aRec.node_labels[3],
148                                                 aRec.node_labels[6],
149                                                 aRec.node_labels[5],
150                                                 aRec.node_labels[4],
151                                                 aRec.node_labels[7],
152                                                 aRec.node_labels[9],
153                                                 aRec.node_labels[8],
154                                                 aLabel);
155             break;
156             
157           case 112: // Solid Linear Prism - PRISM6
158             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
159                                                 aRec.node_labels[2],
160                                                 aRec.node_labels[1],
161                                                 aRec.node_labels[3],
162                                                 aRec.node_labels[5],
163                                                 aRec.node_labels[4],
164                                                 aLabel);
165             break;
166             
167           case 113: // Solid Quadratic Prism - PRISM15
168             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
169                                                 aRec.node_labels[2],
170                                                 aRec.node_labels[1],
171                                                 aRec.node_labels[3],
172                                                 aRec.node_labels[5],
173                                                 aRec.node_labels[4],
174                                                 aRec.node_labels[8],
175                                                 aRec.node_labels[7],
176                                                 aRec.node_labels[6],
177                                                 aRec.node_labels[11],
178                                                 aRec.node_labels[10],
179                                                 aRec.node_labels[9],
180                                                 aRec.node_labels[12],
181                                                 aRec.node_labels[14],
182                                                 aRec.node_labels[13],
183                                                 aLabel);
184             break;
185             
186           case 115: // Solid Linear Brick - HEX8
187             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
188                                                 aRec.node_labels[3],
189                                                 aRec.node_labels[2],
190                                                 aRec.node_labels[1],
191                                                 aRec.node_labels[4],
192                                                 aRec.node_labels[7],
193                                                 aRec.node_labels[6],
194                                                 aRec.node_labels[5],
195                                                 aLabel);
196             break;
197
198           case 116: // Solid Quadratic Brick - HEX20
199             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
200                                                 aRec.node_labels[6],
201                                                 aRec.node_labels[4],
202                                                 aRec.node_labels[2],
203
204                                                 aRec.node_labels[12],
205                                                 aRec.node_labels[18],
206                                                 aRec.node_labels[16],
207                                                 aRec.node_labels[14],
208
209                                                 aRec.node_labels[7],
210                                                 aRec.node_labels[5],
211                                                 aRec.node_labels[3],
212                                                 aRec.node_labels[1],
213
214                                                 aRec.node_labels[19],
215                                                 aRec.node_labels[17],
216                                                 aRec.node_labels[15],
217                                                 aRec.node_labels[13],
218
219                                                 aRec.node_labels[8],
220                                                 aRec.node_labels[11],
221                                                 aRec.node_labels[10],
222                                                 aRec.node_labels[9],
223                                                 aLabel);
224             break;
225
226           case 114: // pyramid of 13 nodes (quadratic) - PIRA13
227             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
228                                                 aRec.node_labels[3],
229                                                 aRec.node_labels[2],
230                                                 aRec.node_labels[1],
231                                                 aRec.node_labels[4],
232                                                 aRec.node_labels[8],
233                                                 aRec.node_labels[7],
234                                                 aRec.node_labels[6],
235                                                 aRec.node_labels[5],
236                                                 aRec.node_labels[9],
237                                                 aRec.node_labels[12],
238                                                 aRec.node_labels[11],
239                                                 aRec.node_labels[10],
240                                                 aLabel);
241             break;
242
243           }
244         }
245         //      if(!anElement)
246         //        MESSAGE("DriverUNV_R_SMDS_Mesh::Perform - can not add element with ID = "<<aLabel<<" and type = "<<aRec.fe_descriptor_id);
247       }
248     }
249     {
250       using namespace UNV2417;      
251       TDataSet aDataSet2417;
252       UNV2417::Read(in_stream,aDataSet2417);
253     }
254   }
255   catch(const std::exception& exc){
256     INFOS("Follow exception was cought:\n\t"<<exc.what());
257   }
258   catch(...){
259     INFOS("Unknown exception was cought !!!");
260   }
261   return aResult;
262 }