1 // Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "DriverUNV_R_SMDS_Mesh.h"
24 #include "SMDS_Mesh.hxx"
25 #include "SMDS_MeshGroup.hxx"
27 #include "utilities.h"
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"
36 #include <Basics_Utils.hxx>
42 static int MYDEBUG = 0;
44 static int MYDEBUG = 0;
50 * \brief Move node coordinates to the global Cartesian CS
52 void transformNodes( UNV2411::TDataSet::const_iterator fromNode,
53 UNV2411::TDataSet::const_iterator endNode,
54 const UNV2420::TRecord & csRecord )
56 const int csLabel = fromNode->exp_coord_sys_num;
58 UNV2411::TDataSet::const_iterator nodeIt;
60 // apply Transformation Matrix
61 if ( !csRecord.isIdentityMatrix() )
63 for ( nodeIt = fromNode; nodeIt != endNode; ++nodeIt )
65 const UNV2411::TRecord& nodeRec = *nodeIt;
66 if ( nodeRec.exp_coord_sys_num == csLabel )
67 csRecord.ApplyMatrix( (double*) nodeRec.coord );
71 // transform from Cylindrical CS
72 if ( csRecord.coord_sys_type == UNV2420::Cylindrical )
74 for ( nodeIt = fromNode; nodeIt != endNode; ++nodeIt )
76 const UNV2411::TRecord& nodeRec = *nodeIt;
77 if ( nodeRec.exp_coord_sys_num == csLabel )
78 csRecord.FromCylindricalCS( (double*) nodeRec.coord );
81 // transform from Spherical CS
82 else if ( csRecord.coord_sys_type == UNV2420::Spherical )
84 for ( nodeIt = fromNode; nodeIt != endNode; ++nodeIt )
86 const UNV2411::TRecord& nodeRec = *nodeIt;
87 if ( nodeRec.exp_coord_sys_num == csLabel )
88 csRecord.FromSphericalCS( (double*) nodeRec.coord );
94 DriverUNV_R_SMDS_Mesh::~DriverUNV_R_SMDS_Mesh()
96 TGroupNamesMap::iterator grp2name = myGroupNames.begin();
97 for ( ; grp2name != myGroupNames.end(); ++grp2name )
98 delete grp2name->first;
101 Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform()
103 Kernel_Utils::Localizer loc;
104 Status aResult = DRS_OK;
105 #if defined(WIN32) && defined(UNICODE)
106 std::wstring aFile = Kernel_Utils::utf8_decode_s(myFile);
107 std::ifstream in_stream(aFile.c_str());
109 std::ifstream in_stream(myFile.c_str());
115 UNV164::TRecord aUnitsRecord;
116 UNV164::Read( in_stream, aUnitsRecord );
118 // Read Coordinate systems
119 UNV2420::TDataSet aCoordSysDataSet;
120 UNV2420::Read(in_stream, myMeshName, aCoordSysDataSet);
123 using namespace UNV2411;
124 TDataSet aDataSet2411;
125 UNV2411::Read(in_stream,aDataSet2411);
126 if(MYDEBUG) MESSAGE("Perform - aDataSet2411.size() = "<<aDataSet2411.size());
128 // Move nodes in a global CS
129 if ( !aCoordSysDataSet.empty() )
131 UNV2420::TDataSet::const_iterator csIter = aCoordSysDataSet.begin();
132 for ( ; csIter != aCoordSysDataSet.end(); ++csIter )
134 // find any node in this CS
135 TDataSet::const_iterator nodeIter = aDataSet2411.begin();
136 for (; nodeIter != aDataSet2411.end(); nodeIter++)
137 if ( nodeIter->exp_coord_sys_num == csIter->coord_sys_label )
139 transformNodes( nodeIter, aDataSet2411.end(), *csIter );
144 // Move nodes to SI unit system
145 const double lenFactor = aUnitsRecord.factors[ UNV164::LENGTH_FACTOR ];
146 if ( lenFactor != 1. )
148 TDataSet::iterator nodeIter = aDataSet2411.begin(), nodeEnd;
149 for ( nodeEnd = aDataSet2411.end(); nodeIter != nodeEnd; nodeIter++)
151 UNV2411::TRecord& nodeRec = *nodeIter;
152 nodeRec.coord[0] *= lenFactor;
153 nodeRec.coord[1] *= lenFactor;
154 nodeRec.coord[2] *= lenFactor;
158 // Create nodes in the mesh
159 TDataSet::const_iterator anIter = aDataSet2411.begin();
160 for(; anIter != aDataSet2411.end(); anIter++)
162 const TRecord& aRec = *anIter;
163 myMesh->AddNodeWithID(aRec.coord[0],aRec.coord[1],aRec.coord[2],aRec.label);
167 using namespace UNV2412;
168 TDataSet aDataSet2412;
169 UNV2412::Read(in_stream,aDataSet2412);
170 TDataSet::const_iterator anIter = aDataSet2412.begin();
171 if(MYDEBUG) MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
172 for(; anIter != aDataSet2412.end(); anIter++)
174 SMDS_MeshElement* anElement = NULL;
175 const TRecord& aRec = *anIter;
176 if(IsBeam(aRec.fe_descriptor_id)) {
177 switch ( aRec.node_labels.size() ) {
178 case 2: // edge with two nodes
179 //MESSAGE("add edge " << aLabel << " " << aRec.node_labels[0] << " " << aRec.node_labels[1]);
180 anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
184 case 3: // quadratic edge (with 3 nodes)
185 //MESSAGE("add edge " << aRec.label << " " << aRec.node_labels[0] << " " << aRec.node_labels[1] << " " << aRec.node_labels[2]);
186 anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
192 else if(IsFace(aRec.fe_descriptor_id)) {
193 //MESSAGE("add face " << aRec.label);
194 switch(aRec.fe_descriptor_id){
195 case 41: // Plane Stress Linear Triangle
196 case 51: // Plane Strain Linear Triangle
197 case 61: // Plate Linear Triangle
198 case 74: // Membrane Linear Triangle
199 case 81: // Axisymmetric Solid Linear Triangle
200 case 91: // Thin Shell Linear Triangle
201 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
207 case 42: // Plane Stress Parabolic Triangle
208 case 52: // Plane Strain Parabolic Triangle
209 case 62: // Plate Parabolic Triangle
210 case 72: // Membrane Parabolic Triangle
211 case 82: // Axisymmetric Solid Parabolic Triangle
212 case 92: // Thin Shell Parabolic Triangle
213 if ( aRec.node_labels.size() == 7 )
214 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
223 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
232 case 44: // Plane Stress Linear Quadrilateral
233 case 54: // Plane Strain Linear Quadrilateral
234 case 64: // Plate Linear Quadrilateral
235 case 71: // Membrane Linear Quadrilateral
236 case 84: // Axisymmetric Solid Linear Quadrilateral
237 case 94: // Thin Shell Linear Quadrilateral
238 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
245 case 45: // Plane Stress Parabolic Quadrilateral
246 case 55: // Plane Strain Parabolic Quadrilateral
247 case 65: // Plate Parabolic Quadrilateral
248 case 75: // Membrane Parabolic Quadrilateral
249 case 85: // Axisymmetric Solid Parabolic Quadrilateral
250 case 95: // Thin Shell Parabolic Quadrilateral
251 if ( aRec.node_labels.size() == 9 )
252 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
263 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
275 else if(IsVolume(aRec.fe_descriptor_id)){
276 //MESSAGE("add volume " << aRec.label);
277 switch(aRec.fe_descriptor_id){
279 case 111: // Solid Linear Tetrahedron - TET4
280 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
287 case 118: // Solid Quadratic Tetrahedron - TET10
288 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
304 case 112: // Solid Linear Prism - PRISM6
305 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
314 case 113: // Solid Quadratic Prism - PRISM15
315 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
320 aRec.node_labels[13],
321 aRec.node_labels[11],
327 aRec.node_labels[14],
328 aRec.node_labels[12],
329 aRec.node_labels[10],
337 case 115: // Solid Linear Brick - HEX8
338 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
349 case 116: // Solid Quadratic Brick - HEX20
350 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
355 aRec.node_labels[12],
356 aRec.node_labels[18],
357 aRec.node_labels[16],
358 aRec.node_labels[14],
365 aRec.node_labels[19],
366 aRec.node_labels[17],
367 aRec.node_labels[15],
368 aRec.node_labels[13],
371 aRec.node_labels[11],
372 aRec.node_labels[10],
377 case 114: // pyramid of 13 nodes (quadratic) - PIRA13
378 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
383 aRec.node_labels[12],
391 aRec.node_labels[11],
392 aRec.node_labels[10],
400 MESSAGE("DriverUNV_R_SMDS_Mesh::Perform - can not add element with ID = "<<aRec.label<<" and type = "<<aRec.fe_descriptor_id);
404 using namespace UNV2417;
405 TDataSet aDataSet2417;
406 UNV2417::Read(in_stream,aDataSet2417);
407 if(MYDEBUG) MESSAGE("Perform - aDataSet2417.size() = "<<aDataSet2417.size());
408 if (aDataSet2417.size() > 0)
410 TDataSet::const_iterator anIter = aDataSet2417.begin();
411 for ( ; anIter != aDataSet2417.end(); anIter++ )
413 const TRecord& aRec = anIter->second;
414 int aNodesNb = aRec.NodeList.size();
415 int aElementsNb = aRec.ElementList.size();
417 bool useSuffix = ((aNodesNb > 0) && (aElementsNb > 0));
420 SMDS_MeshGroup* aNodesGroup = new SMDS_MeshGroup( myMesh );
421 std::string aGrName = (useSuffix) ? aRec.GroupName + "_Nodes" : aRec.GroupName;
422 int i = aGrName.find( "\r" );
424 aGrName.erase (i, 2);
425 myGroupNames.insert( std::make_pair( aNodesGroup, aGrName ));
427 for ( int i = 0; i < aNodesNb; i++ )
428 if ( const SMDS_MeshNode* aNode = myMesh->FindNode( aRec.NodeList[i] ))
429 aNodesGroup->Add( aNode );
431 if ( aElementsNb > 0 )
433 std::vector< SMDS_MeshGroup* > aGroupVec( SMDSAbs_NbElementTypes, (SMDS_MeshGroup*)0 );
434 const char* aSuffix[] = { "", "", "_Edges", "_Faces", "_Volumes", "_0D", "_Balls" };
435 bool createdGroup = false;
436 for ( int i = 0; i < aElementsNb; i++)
438 const SMDS_MeshElement* aElement = myMesh->FindElement( aRec.ElementList[i] );
439 if ( !aElement ) continue;
441 SMDS_MeshGroup * & aGroup = aGroupVec[ aElement->GetType() ];
444 aGroup = new SMDS_MeshGroup( myMesh );
445 if (!useSuffix && createdGroup) useSuffix = true;
446 std::string aGrName = aRec.GroupName;
447 int i = aGrName.find( "\r" );
449 aGrName.erase (i, 2);
451 aGrName += aSuffix[ aElement->GetType() ];
452 myGroupNames.insert( std::make_pair( aGroup, aGrName ));
455 aGroup->Add(aElement);
462 catch(const std::exception& exc){
463 INFOS("Follow exception was cought:\n\t"<<exc.what());
466 INFOS("Unknown exception was cought !!!");
471 myMesh->CompactMesh();