]> SALOME platform Git repositories - modules/smesh.git/blob - src/DriverUNV/DriverUNV_R_SMDS_Mesh.cxx
Salome HOME
IPAL54104: Wrong prismatic mesh
[modules/smesh.git] / src / DriverUNV / DriverUNV_R_SMDS_Mesh.cxx
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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 "UNV164_Structure.hxx"
30 #include "UNV2411_Structure.hxx"
31 #include "UNV2412_Structure.hxx"
32 #include "UNV2417_Structure.hxx"
33 #include "UNV2420_Structure.hxx"
34 #include "UNV_Utilities.hxx"
35
36 #include <Basics_Utils.hxx>
37
38 using namespace std;
39
40
41 #ifdef _DEBUG_
42 static int MYDEBUG = 0;
43 #else
44 static int MYDEBUG = 0;
45 #endif
46
47 namespace
48 {
49   /*!
50    * \brief Move node coordinates to the global Cartesian CS
51    */
52   void transformNodes( UNV2411::TDataSet::const_iterator fromNode,
53                        UNV2411::TDataSet::const_iterator endNode,
54                        const UNV2420::TRecord &          csRecord )
55   {
56     const int csLabel = fromNode->exp_coord_sys_num;
57
58     UNV2411::TDataSet::const_iterator nodeIt;
59
60     // apply Transformation Matrix
61     if ( !csRecord.isIdentityMatrix() )
62     {
63       for ( nodeIt = fromNode; nodeIt != endNode; ++nodeIt )
64       {
65         const UNV2411::TRecord& nodeRec = *nodeIt;
66         if ( nodeRec.exp_coord_sys_num == csLabel )
67           csRecord.ApplyMatrix( (double*) nodeRec.coord );
68       }
69     }
70
71     // transform from Cylindrical CS
72     if ( csRecord.coord_sys_type == UNV2420::Cylindrical )
73     {
74       for ( nodeIt = fromNode; nodeIt != endNode; ++nodeIt )
75       {
76         const UNV2411::TRecord& nodeRec = *nodeIt;
77         if ( nodeRec.exp_coord_sys_num == csLabel )
78           csRecord.FromCylindricalCS( (double*) nodeRec.coord );
79       }
80     }
81     // transform from Spherical CS
82     else if ( csRecord.coord_sys_type == UNV2420::Spherical )
83     {
84       for ( nodeIt = fromNode; nodeIt != endNode; ++nodeIt )
85       {
86         const UNV2411::TRecord& nodeRec = *nodeIt;
87         if ( nodeRec.exp_coord_sys_num == csLabel )
88           csRecord.FromSphericalCS( (double*) nodeRec.coord );
89       }
90     }
91   }
92 }
93
94 DriverUNV_R_SMDS_Mesh::~DriverUNV_R_SMDS_Mesh()
95 {
96   if (myGroup != 0) 
97     delete myGroup;
98 }
99
100
101 Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform()
102 {
103   Kernel_Utils::Localizer loc;
104   Status aResult = DRS_OK;
105   std::ifstream in_stream(myFile.c_str());
106   try
107   {
108     {
109       // Read Units
110       UNV164::TRecord aUnitsRecord;
111       UNV164::Read( in_stream, aUnitsRecord );
112
113       // Read Coordinate systems
114       UNV2420::TDataSet aCoordSysDataSet;
115       UNV2420::Read(in_stream, myMeshName, aCoordSysDataSet);
116
117       // Read nodes
118       using namespace UNV2411;
119       TDataSet aDataSet2411;
120       UNV2411::Read(in_stream,aDataSet2411);
121       if(MYDEBUG) MESSAGE("Perform - aDataSet2411.size() = "<<aDataSet2411.size());
122
123       // Move nodes in a global CS
124       if ( !aCoordSysDataSet.empty() )
125       {
126         UNV2420::TDataSet::const_iterator csIter = aCoordSysDataSet.begin();
127         for ( ; csIter != aCoordSysDataSet.end(); ++csIter )
128         {
129           // find any node in this CS
130           TDataSet::const_iterator nodeIter = aDataSet2411.begin();
131           for (; nodeIter != aDataSet2411.end(); nodeIter++)
132             if ( nodeIter->exp_coord_sys_num == csIter->coord_sys_label )
133             {
134               transformNodes( nodeIter, aDataSet2411.end(), *csIter );
135               break;
136             }
137         }
138       }
139       // Move nodes to SI unit system
140       const double lenFactor = aUnitsRecord.factors[ UNV164::LENGTH_FACTOR ]; 
141       if ( lenFactor != 1. )
142       {
143         TDataSet::iterator nodeIter = aDataSet2411.begin(), nodeEnd;
144         for ( nodeEnd = aDataSet2411.end(); nodeIter != nodeEnd; nodeIter++)
145         {
146           UNV2411::TRecord& nodeRec = *nodeIter;
147           nodeRec.coord[0] *= lenFactor;
148           nodeRec.coord[1] *= lenFactor;
149           nodeRec.coord[2] *= lenFactor;
150         }
151       }
152
153       // Create nodes in the mesh
154       TDataSet::const_iterator anIter = aDataSet2411.begin();
155       for(; anIter != aDataSet2411.end(); anIter++)
156       {
157         const TRecord& aRec = *anIter;
158         myMesh->AddNodeWithID(aRec.coord[0],aRec.coord[1],aRec.coord[2],aRec.label);
159       }
160     }
161     {
162       using namespace UNV2412;
163       TDataSet aDataSet2412;
164       UNV2412::Read(in_stream,aDataSet2412);
165       TDataSet::const_iterator anIter = aDataSet2412.begin();
166       if(MYDEBUG) MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
167       for(; anIter != aDataSet2412.end(); anIter++)
168       {
169         SMDS_MeshElement* anElement = NULL;
170         const TRecord& aRec = *anIter;
171         if(IsBeam(aRec.fe_descriptor_id)) {
172           switch ( aRec.node_labels.size() ) {
173           case 2: // edge with two nodes
174             //MESSAGE("add edge " << aLabel << " " << aRec.node_labels[0] << " " << aRec.node_labels[1]);
175             anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
176                                               aRec.node_labels[1],
177                                               aRec.label);
178             break;
179           case 3: // quadratic edge (with 3 nodes)
180             //MESSAGE("add edge " << aRec.label << " " << aRec.node_labels[0] << " " << aRec.node_labels[1] << " " << aRec.node_labels[2]);
181             anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
182                                               aRec.node_labels[2],
183                                               aRec.node_labels[1],
184                                               aRec.label);
185           }
186         }
187         else if(IsFace(aRec.fe_descriptor_id)) {
188           //MESSAGE("add face " << aRec.label);
189           switch(aRec.fe_descriptor_id){
190           case 41: // Plane Stress Linear Triangle      
191           case 51: // Plane Strain Linear Triangle      
192           case 61: // Plate Linear Triangle             
193           case 74: // Membrane Linear Triangle          
194           case 81: // Axisymetric Solid Linear Triangle 
195           case 91: // Thin Shell Linear Triangle        
196             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
197                                               aRec.node_labels[1],
198                                               aRec.node_labels[2],
199                                               aRec.label);
200             break;
201
202           case 42: //  Plane Stress Parabolic Triangle       
203           case 52: //  Plane Strain Parabolic Triangle       
204           case 62: //  Plate Parabolic Triangle              
205           case 72: //  Membrane Parabolic Triangle           
206           case 82: //  Axisymetric Solid Parabolic Triangle  
207           case 92: //  Thin Shell Parabolic Triangle
208             if ( aRec.node_labels.size() == 7 )
209               anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
210                                                 aRec.node_labels[2],
211                                                 aRec.node_labels[4],
212                                                 aRec.node_labels[1],
213                                                 aRec.node_labels[3],
214                                                 aRec.node_labels[5],
215                                                 aRec.node_labels[6],
216                                                 aRec.label);
217             else
218               anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
219                                                 aRec.node_labels[2],
220                                                 aRec.node_labels[4],
221                                                 aRec.node_labels[1],
222                                                 aRec.node_labels[3],
223                                                 aRec.node_labels[5],
224                                                 aRec.label);
225             break;
226
227           case 44: // Plane Stress Linear Quadrilateral     
228           case 54: // Plane Strain Linear Quadrilateral     
229           case 64: // Plate Linear Quadrilateral            
230           case 71: // Membrane Linear Quadrilateral         
231           case 84: // Axisymetric Solid Linear Quadrilateral
232           case 94: // Thin Shell Linear Quadrilateral       
233             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
234                                               aRec.node_labels[1],
235                                               aRec.node_labels[2],
236                                               aRec.node_labels[3],
237                                               aRec.label);
238             break;
239
240           case 45: // Plane Stress Parabolic Quadrilateral      
241           case 55: // Plane Strain Parabolic Quadrilateral      
242           case 65: // Plate Parabolic Quadrilateral             
243           case 75: // Membrane Parabolic Quadrilateral          
244           case 85: // Axisymetric Solid Parabolic Quadrilateral 
245           case 95: // Thin Shell Parabolic Quadrilateral        
246             if ( aRec.node_labels.size() == 9 )
247               anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
248                                                 aRec.node_labels[2],
249                                                 aRec.node_labels[4],
250                                                 aRec.node_labels[6],
251                                                 aRec.node_labels[1],
252                                                 aRec.node_labels[3],
253                                                 aRec.node_labels[5],
254                                                 aRec.node_labels[7],
255                                                 aRec.node_labels[8],
256                                                 aRec.label);
257             else
258               anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
259                                                 aRec.node_labels[2],
260                                                 aRec.node_labels[4],
261                                                 aRec.node_labels[6],
262                                                 aRec.node_labels[1],
263                                                 aRec.node_labels[3],
264                                                 aRec.node_labels[5],
265                                                 aRec.node_labels[7],
266                                                 aRec.label);
267             break;
268           }
269         }
270         else if(IsVolume(aRec.fe_descriptor_id)){
271           //MESSAGE("add volume " << aRec.label);
272           switch(aRec.fe_descriptor_id){
273
274           case 111: // Solid Linear Tetrahedron - TET4
275             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
276                                                 aRec.node_labels[2],
277                                                 aRec.node_labels[1],
278                                                 aRec.node_labels[3],
279                                                 aRec.label);
280             break;
281
282           case 118: // Solid Quadratic Tetrahedron - TET10
283             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
284                                                 aRec.node_labels[4],
285                                                 aRec.node_labels[2],
286
287                                                 aRec.node_labels[9],
288
289                                                 aRec.node_labels[5],
290                                                 aRec.node_labels[3],
291                                                 aRec.node_labels[1],
292
293                                                 aRec.node_labels[6],
294                                                 aRec.node_labels[8],
295                                                 aRec.node_labels[7],
296                                                 aRec.label);
297             break;
298             
299           case 112: // Solid Linear Prism - PRISM6
300             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
301                                                 aRec.node_labels[2],
302                                                 aRec.node_labels[1],
303                                                 aRec.node_labels[3],
304                                                 aRec.node_labels[5],
305                                                 aRec.node_labels[4],
306                                                 aRec.label);
307             break;
308             
309           case 113: // Solid Quadratic Prism - PRISM15
310             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
311                                                 aRec.node_labels[4],
312                                                 aRec.node_labels[2],
313
314                                                 aRec.node_labels[9],
315                                                 aRec.node_labels[13],
316                                                 aRec.node_labels[11],
317
318                                                 aRec.node_labels[5],
319                                                 aRec.node_labels[3],
320                                                 aRec.node_labels[1],
321
322                                                 aRec.node_labels[14],
323                                                 aRec.node_labels[12],
324                                                 aRec.node_labels[10],
325
326                                                 aRec.node_labels[6],
327                                                 aRec.node_labels[8],
328                                                 aRec.node_labels[7],
329                                                 aRec.label);
330             break;
331             
332           case 115: // Solid Linear Brick - HEX8
333             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
334                                                 aRec.node_labels[3],
335                                                 aRec.node_labels[2],
336                                                 aRec.node_labels[1],
337                                                 aRec.node_labels[4],
338                                                 aRec.node_labels[7],
339                                                 aRec.node_labels[6],
340                                                 aRec.node_labels[5],
341                                                 aRec.label);
342             break;
343
344           case 116: // Solid Quadratic Brick - HEX20
345             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
346                                                 aRec.node_labels[6],
347                                                 aRec.node_labels[4],
348                                                 aRec.node_labels[2],
349
350                                                 aRec.node_labels[12],
351                                                 aRec.node_labels[18],
352                                                 aRec.node_labels[16],
353                                                 aRec.node_labels[14],
354
355                                                 aRec.node_labels[7],
356                                                 aRec.node_labels[5],
357                                                 aRec.node_labels[3],
358                                                 aRec.node_labels[1],
359
360                                                 aRec.node_labels[19],
361                                                 aRec.node_labels[17],
362                                                 aRec.node_labels[15],
363                                                 aRec.node_labels[13],
364
365                                                 aRec.node_labels[8],
366                                                 aRec.node_labels[11],
367                                                 aRec.node_labels[10],
368                                                 aRec.node_labels[9],
369                                                 aRec.label);
370             break;
371
372           case 114: // pyramid of 13 nodes (quadratic) - PIRA13
373             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
374                                                 aRec.node_labels[6],
375                                                 aRec.node_labels[4],
376                                                 aRec.node_labels[2],
377
378                                                 aRec.node_labels[12],
379
380                                                 aRec.node_labels[7],
381                                                 aRec.node_labels[5],
382                                                 aRec.node_labels[3],
383                                                 aRec.node_labels[1],
384
385                                                 aRec.node_labels[8],
386                                                 aRec.node_labels[11],
387                                                 aRec.node_labels[10],
388                                                 aRec.node_labels[9],
389                                                 aRec.label);
390             break;
391
392           }
393         }
394         if(!anElement)
395           MESSAGE("DriverUNV_R_SMDS_Mesh::Perform - can not add element with ID = "<<aRec.label<<" and type = "<<aRec.fe_descriptor_id);
396       }
397     }
398     {
399       using namespace UNV2417;      
400       TDataSet aDataSet2417;
401       UNV2417::Read(in_stream,aDataSet2417);
402       if(MYDEBUG) MESSAGE("Perform - aDataSet2417.size() = "<<aDataSet2417.size());
403       if  (aDataSet2417.size() > 0) {
404         myGroup = new SMDS_MeshGroup(myMesh);
405         TDataSet::const_iterator anIter = aDataSet2417.begin();
406         for(; anIter != aDataSet2417.end(); anIter++){
407           const TGroupId& aLabel = anIter->first;
408           const TRecord& aRec = anIter->second;
409
410           int aNodesNb = aRec.NodeList.size();
411           int aElementsNb = aRec.ElementList.size();
412
413           bool useSuffix = ((aNodesNb > 0) && (aElementsNb > 0));
414           int i;
415           if (aNodesNb > 0) {
416             SMDS_MeshGroup* aNodesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Node);
417             std::string aGrName = (useSuffix) ? aRec.GroupName + "_Nodes" : aRec.GroupName;
418             int i = aGrName.find( "\r" );
419             if (i > 0)
420               aGrName.erase (i, 2);
421             myGroupNames.insert(TGroupNamesMap::value_type(aNodesGroup, aGrName));
422             myGroupId.insert(TGroupIdMap::value_type(aNodesGroup, aLabel));
423
424             for (i = 0; i < aNodesNb; i++) {
425               const SMDS_MeshNode* aNode = myMesh->FindNode(aRec.NodeList[i]);
426               if (aNode)
427                 aNodesGroup->Add(aNode);
428             }
429           }
430           if (aElementsNb > 0){
431             SMDS_MeshGroup* aEdgesGroup = 0;
432             SMDS_MeshGroup* aFacesGroup = 0;
433             SMDS_MeshGroup* aVolumeGroup = 0;
434             bool createdGroup = false;
435
436             for (i = 0; i < aElementsNb; i++) {
437               const SMDS_MeshElement* aElement = myMesh->FindElement(aRec.ElementList[i]);
438               if (aElement) {
439                 switch (aElement->GetType()) {
440
441                 case SMDSAbs_Edge:
442                   if (!aEdgesGroup) {
443                     aEdgesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Edge);
444                     if (!useSuffix && createdGroup) useSuffix = true;
445                     std::string aEdgesGrName = (useSuffix) ? aRec.GroupName + "_Edges" : aRec.GroupName;
446                     int i = aEdgesGrName.find( "\r" );
447                     if (i > 0)
448                       aEdgesGrName.erase (i, 2);
449                     myGroupNames.insert(TGroupNamesMap::value_type(aEdgesGroup, aEdgesGrName));
450                     myGroupId.insert(TGroupIdMap::value_type(aEdgesGroup, aLabel));
451                     createdGroup = true;
452                   }
453                   aEdgesGroup->Add(aElement);
454                   break;
455
456                 case SMDSAbs_Face:
457                   if (!aFacesGroup) {
458                     aFacesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Face);
459                     if (!useSuffix && createdGroup) useSuffix = true;
460                     std::string aFacesGrName = (useSuffix) ? aRec.GroupName + "_Faces" : aRec.GroupName;
461                     int i = aFacesGrName.find( "\r" );
462                     if (i > 0)
463                       aFacesGrName.erase (i, 2);
464                     myGroupNames.insert(TGroupNamesMap::value_type(aFacesGroup, aFacesGrName));
465                     myGroupId.insert(TGroupIdMap::value_type(aFacesGroup, aLabel));
466                     createdGroup = true;
467                   }
468                   aFacesGroup->Add(aElement);
469                   break;
470
471                 case SMDSAbs_Volume:
472                   if (!aVolumeGroup) {
473                     aVolumeGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Volume);
474                     if (!useSuffix && createdGroup) useSuffix = true;
475                     std::string aVolumeGrName = (useSuffix) ? aRec.GroupName + "_Volumes" : aRec.GroupName;
476                     int i = aVolumeGrName.find( "\r" );
477                     if (i > 0)
478                       aVolumeGrName.erase (i, 2);
479                     myGroupNames.insert(TGroupNamesMap::value_type(aVolumeGroup, aVolumeGrName));
480                     myGroupId.insert(TGroupIdMap::value_type(aVolumeGroup, aLabel));
481                     createdGroup = true;
482                   }
483                   aVolumeGroup->Add(aElement);
484                   break;
485
486                 default:;
487                 }
488               } 
489             }
490           }
491         }
492       }
493     } 
494   }
495   catch(const std::exception& exc){
496     INFOS("Follow exception was cought:\n\t"<<exc.what());
497   }
498   catch(...){
499     INFOS("Unknown exception was cought !!!");
500   }
501   if (myMesh)
502     myMesh->compactMesh();
503   return aResult;
504 }