Salome HOME
24150eeda41d13b8ceef0f078128ef4db97c508a
[modules/smesh.git] / src / DriverUNV / DriverUNV_R_SMDS_Mesh.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "DriverUNV_R_SMDS_Mesh.h"
24 #include "SMDS_Mesh.hxx"
25 #include "SMDS_MeshGroup.hxx"
26
27 #include "utilities.h"
28
29 #include "UNV2411_Structure.hxx"
30 #include "UNV2412_Structure.hxx"
31 #include "UNV2417_Structure.hxx"
32 #include "UNV_Utilities.hxx"
33
34 #include <Basics_Utils.hxx>
35
36 using namespace std;
37
38
39 #ifdef _DEBUG_
40 static int MYDEBUG = 0;
41 #else
42 static int MYDEBUG = 0;
43 #endif
44
45
46 DriverUNV_R_SMDS_Mesh::~DriverUNV_R_SMDS_Mesh()
47 {
48   if (myGroup != 0) 
49     delete myGroup;
50 }
51
52
53 Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform()
54 {
55   Kernel_Utils::Localizer loc;
56   Status aResult = DRS_OK;
57   std::ifstream in_stream(myFile.c_str());
58   try{
59     {
60       using namespace UNV2411;
61       TDataSet aDataSet2411;
62       UNV2411::Read(in_stream,aDataSet2411);
63       if(MYDEBUG) MESSAGE("Perform - aDataSet2411.size() = "<<aDataSet2411.size());
64       TDataSet::const_iterator anIter = aDataSet2411.begin();
65       for(; anIter != aDataSet2411.end(); anIter++){
66         const TNodeLab& aLabel = anIter->first;
67         const TRecord& aRec = anIter->second;
68         myMesh->AddNodeWithID(aRec.coord[0],aRec.coord[1],aRec.coord[2],aLabel);
69       }
70     }
71     {
72       using namespace UNV2412;
73       in_stream.seekg(0);
74       TDataSet aDataSet2412;
75       UNV2412::Read(in_stream,aDataSet2412);
76       TDataSet::const_iterator anIter = aDataSet2412.begin();
77       if(MYDEBUG) MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
78       for(; anIter != aDataSet2412.end(); anIter++){
79         SMDS_MeshElement* anElement = NULL;
80         const TElementLab& aLabel = anIter->first;
81         const TRecord& aRec = anIter->second;
82         if(IsBeam(aRec.fe_descriptor_id)) {
83           switch ( aRec.node_labels.size() ) {
84           case 2: // edge with two nodes
85             anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
86                                               aRec.node_labels[1],
87                                               aLabel);
88             break;
89           case 3: // quadratic edge (with 3 nodes)
90             anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
91                                               aRec.node_labels[2],
92                                               aRec.node_labels[1],
93                                               aLabel);
94           }
95         }
96         else if(IsFace(aRec.fe_descriptor_id)) {
97           switch(aRec.fe_descriptor_id){
98           case 41: // Plane Stress Linear Triangle      
99           case 51: // Plane Strain Linear Triangle      
100           case 61: // Plate Linear Triangle             
101           case 74: // Membrane Linear Triangle          
102           case 81: // Axisymetric Solid Linear Triangle 
103           case 91: // Thin Shell Linear Triangle        
104             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
105                                               aRec.node_labels[1],
106                                               aRec.node_labels[2],
107                                               aLabel);
108             break;
109             
110           case 42: //  Plane Stress Parabolic Triangle       
111           case 52: //  Plane Strain Parabolic Triangle       
112           case 62: //  Plate Parabolic Triangle              
113           case 72: //  Membrane Parabolic Triangle           
114           case 82: //  Axisymetric Solid Parabolic Triangle  
115           case 92: //  Thin Shell Parabolic Triangle         
116             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
117                                               aRec.node_labels[2],
118                                               aRec.node_labels[4],
119                                               aRec.node_labels[1],
120                                               aRec.node_labels[3],
121                                               aRec.node_labels[5],
122                                               aLabel);
123             break;
124             
125           case 44: // Plane Stress Linear Quadrilateral     
126           case 54: // Plane Strain Linear Quadrilateral     
127           case 64: // Plate Linear Quadrilateral            
128           case 71: // Membrane Linear Quadrilateral         
129           case 84: // Axisymetric Solid Linear Quadrilateral
130           case 94: // Thin Shell Linear Quadrilateral       
131             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
132                                               aRec.node_labels[1],
133                                               aRec.node_labels[2],
134                                               aRec.node_labels[3],
135                                               aLabel);
136             break;
137             
138           case 45: // Plane Stress Parabolic Quadrilateral      
139           case 55: // Plane Strain Parabolic Quadrilateral      
140           case 65: // Plate Parabolic Quadrilateral             
141           case 75: // Membrane Parabolic Quadrilateral          
142           case 85: // Axisymetric Solid Parabolic Quadrilateral 
143           case 95: // Thin Shell Parabolic Quadrilateral        
144             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
145                                               aRec.node_labels[2],
146                                               aRec.node_labels[4],
147                                               aRec.node_labels[6],
148                                               aRec.node_labels[1],
149                                               aRec.node_labels[3],
150                                               aRec.node_labels[5],
151                                               aRec.node_labels[7],
152                                               aLabel);
153             break;
154           }
155         }
156         else if(IsVolume(aRec.fe_descriptor_id)){
157           switch(aRec.fe_descriptor_id){
158             
159           case 111: // Solid Linear Tetrahedron - TET4
160             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
161                                                 aRec.node_labels[2],
162                                                 aRec.node_labels[1],
163                                                 aRec.node_labels[3],
164                                                 aLabel);
165             break;
166
167           case 118: // Solid Quadratic Tetrahedron - TET10
168             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
169                                                 aRec.node_labels[4],
170                                                 aRec.node_labels[2],
171
172                                                 aRec.node_labels[9],
173
174                                                 aRec.node_labels[5],
175                                                 aRec.node_labels[3],
176                                                 aRec.node_labels[1],
177
178                                                 aRec.node_labels[6],
179                                                 aRec.node_labels[8],
180                                                 aRec.node_labels[7],
181                                                 aLabel);
182             break;
183             
184           case 112: // Solid Linear Prism - PRISM6
185             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
186                                                 aRec.node_labels[2],
187                                                 aRec.node_labels[1],
188                                                 aRec.node_labels[3],
189                                                 aRec.node_labels[5],
190                                                 aRec.node_labels[4],
191                                                 aLabel);
192             break;
193             
194           case 113: // Solid Quadratic Prism - PRISM15
195             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
196                                                 aRec.node_labels[4],
197                                                 aRec.node_labels[2],
198
199                                                 aRec.node_labels[9],
200                                                 aRec.node_labels[13],
201                                                 aRec.node_labels[11],
202
203                                                 aRec.node_labels[5],
204                                                 aRec.node_labels[3],
205                                                 aRec.node_labels[1],
206
207                                                 aRec.node_labels[14],
208                                                 aRec.node_labels[12],
209                                                 aRec.node_labels[10],
210
211                                                 aRec.node_labels[6],
212                                                 aRec.node_labels[8],
213                                                 aRec.node_labels[7],
214                                                 aLabel);
215             break;
216             
217           case 115: // Solid Linear Brick - HEX8
218             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
219                                                 aRec.node_labels[3],
220                                                 aRec.node_labels[2],
221                                                 aRec.node_labels[1],
222                                                 aRec.node_labels[4],
223                                                 aRec.node_labels[7],
224                                                 aRec.node_labels[6],
225                                                 aRec.node_labels[5],
226                                                 aLabel);
227             break;
228
229           case 116: // Solid Quadratic Brick - HEX20
230             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
231                                                 aRec.node_labels[6],
232                                                 aRec.node_labels[4],
233                                                 aRec.node_labels[2],
234
235                                                 aRec.node_labels[12],
236                                                 aRec.node_labels[18],
237                                                 aRec.node_labels[16],
238                                                 aRec.node_labels[14],
239
240                                                 aRec.node_labels[7],
241                                                 aRec.node_labels[5],
242                                                 aRec.node_labels[3],
243                                                 aRec.node_labels[1],
244
245                                                 aRec.node_labels[19],
246                                                 aRec.node_labels[17],
247                                                 aRec.node_labels[15],
248                                                 aRec.node_labels[13],
249
250                                                 aRec.node_labels[8],
251                                                 aRec.node_labels[11],
252                                                 aRec.node_labels[10],
253                                                 aRec.node_labels[9],
254                                                 aLabel);
255             break;
256
257           case 114: // pyramid of 13 nodes (quadratic) - PIRA13
258             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
259                                                 aRec.node_labels[6],
260                                                 aRec.node_labels[4],
261                                                 aRec.node_labels[2],
262                                                 aRec.node_labels[7],
263                                                 aRec.node_labels[5],
264                                                 aRec.node_labels[3],
265                                                 aRec.node_labels[1],
266
267                                                 aRec.node_labels[8],
268                                                 aRec.node_labels[11],
269                                                 aRec.node_labels[10],
270                                                 aRec.node_labels[9],
271                                                 aRec.node_labels[12],
272                                                 aLabel);
273             break;
274
275           }
276         }
277         //      if(!anElement)
278         //        MESSAGE("DriverUNV_R_SMDS_Mesh::Perform - can not add element with ID = "<<aLabel<<" and type = "<<aRec.fe_descriptor_id);
279       }
280     }
281     {
282       using namespace UNV2417;      
283       in_stream.seekg(0);
284       TDataSet aDataSet2417;
285       UNV2417::Read(in_stream,aDataSet2417);
286       if(MYDEBUG) MESSAGE("Perform - aDataSet2417.size() = "<<aDataSet2417.size());
287       if  (aDataSet2417.size() > 0) {
288         myGroup = new SMDS_MeshGroup(myMesh);
289         TDataSet::const_iterator anIter = aDataSet2417.begin();
290         for(; anIter != aDataSet2417.end(); anIter++){
291           const TGroupId& aLabel = anIter->first;
292           const TRecord& aRec = anIter->second;
293
294           int aNodesNb = aRec.NodeList.size();
295           int aElementsNb = aRec.ElementList.size();
296
297           bool useSuffix = ((aNodesNb > 0) && (aElementsNb > 0));
298           int i;
299           if (aNodesNb > 0) {
300             SMDS_MeshGroup* aNodesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Node);
301             std::string aGrName = (useSuffix) ? aRec.GroupName + "_Nodes" : aRec.GroupName;
302             int i = aGrName.find( "\r" );
303             if (i > 0)
304               aGrName.erase (i, 2);
305             myGroupNames.insert(TGroupNamesMap::value_type(aNodesGroup, aGrName));
306             myGroupId.insert(TGroupIdMap::value_type(aNodesGroup, aLabel));
307
308             for (i = 0; i < aNodesNb; i++) {
309               const SMDS_MeshNode* aNode = myMesh->FindNode(aRec.NodeList[i]);
310               if (aNode)
311                 aNodesGroup->Add(aNode);
312             }
313           }
314           if (aElementsNb > 0){
315             SMDS_MeshGroup* aEdgesGroup = 0;
316             SMDS_MeshGroup* aFacesGroup = 0;
317             SMDS_MeshGroup* aVolumeGroup = 0;
318             bool createdGroup = false;
319
320             for (i = 0; i < aElementsNb; i++) {
321               const SMDS_MeshElement* aElement = myMesh->FindElement(aRec.ElementList[i]);
322               if (aElement) {
323                 switch (aElement->GetType()) {
324                 case SMDSAbs_Edge:
325                   if (!aEdgesGroup) {
326                     aEdgesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Edge);
327                     if (!useSuffix && createdGroup) useSuffix = true;
328                     std::string aEdgesGrName = (useSuffix) ? aRec.GroupName + "_Edges" : aRec.GroupName;
329                     int i = aEdgesGrName.find( "\r" );
330                     if (i > 0)
331                       aEdgesGrName.erase (i, 2);
332                     myGroupNames.insert(TGroupNamesMap::value_type(aEdgesGroup, aEdgesGrName));
333                     myGroupId.insert(TGroupIdMap::value_type(aEdgesGroup, aLabel));
334                     createdGroup = true;
335                   }
336                   aEdgesGroup->Add(aElement);
337                   break;
338                 case SMDSAbs_Face:
339                   if (!aFacesGroup) {
340                     aFacesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Face);
341                     if (!useSuffix && createdGroup) useSuffix = true;
342                     std::string aFacesGrName = (useSuffix) ? aRec.GroupName + "_Faces" : aRec.GroupName;
343                     int i = aFacesGrName.find( "\r" );
344                     if (i > 0)
345                       aFacesGrName.erase (i, 2);
346                     myGroupNames.insert(TGroupNamesMap::value_type(aFacesGroup, aFacesGrName));
347                     myGroupId.insert(TGroupIdMap::value_type(aFacesGroup, aLabel));
348                     createdGroup = true;
349                   }
350                   aFacesGroup->Add(aElement);
351                   break;
352                 case SMDSAbs_Volume:
353                   if (!aVolumeGroup) {
354                     aVolumeGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Volume);
355                     if (!useSuffix && createdGroup) useSuffix = true;
356                     std::string aVolumeGrName = (useSuffix) ? aRec.GroupName + "_Volumes" : aRec.GroupName;
357                     int i = aVolumeGrName.find( "\r" );
358                     if (i > 0)
359                       aVolumeGrName.erase (i, 2);
360                     myGroupNames.insert(TGroupNamesMap::value_type(aVolumeGroup, aVolumeGrName));
361                     myGroupId.insert(TGroupIdMap::value_type(aVolumeGroup, aLabel));
362                     createdGroup = true;
363                   }
364                   aVolumeGroup->Add(aElement);
365                   break;
366                 }
367               } 
368             }
369           }
370         }
371       }
372     } 
373   }
374   catch(const std::exception& exc){
375     INFOS("Follow exception was cought:\n\t"<<exc.what());
376   }
377   catch(...){
378     INFOS("Unknown exception was cought !!!");
379   }
380   return aResult;
381 }