1 // Copyright (C) 2007-2023 CEA, EDF, 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>
43 * \brief Move node coordinates to the global Cartesian CS
45 void transformNodes( UNV2411::TDataSet::const_iterator fromNode,
46 UNV2411::TDataSet::const_iterator endNode,
47 const UNV2420::TRecord & csRecord )
49 const int csLabel = fromNode->exp_coord_sys_num;
51 UNV2411::TDataSet::const_iterator nodeIt;
53 // apply Transformation Matrix
54 if ( !csRecord.isIdentityMatrix() )
56 for ( nodeIt = fromNode; nodeIt != endNode; ++nodeIt )
58 const UNV2411::TRecord& nodeRec = *nodeIt;
59 if ( nodeRec.exp_coord_sys_num == csLabel )
60 csRecord.ApplyMatrix( (double*) nodeRec.coord );
64 // transform from Cylindrical CS
65 if ( csRecord.coord_sys_type == UNV2420::Cylindrical )
67 for ( nodeIt = fromNode; nodeIt != endNode; ++nodeIt )
69 const UNV2411::TRecord& nodeRec = *nodeIt;
70 if ( nodeRec.exp_coord_sys_num == csLabel )
71 csRecord.FromCylindricalCS( (double*) nodeRec.coord );
74 // transform from Spherical CS
75 else if ( csRecord.coord_sys_type == UNV2420::Spherical )
77 for ( nodeIt = fromNode; nodeIt != endNode; ++nodeIt )
79 const UNV2411::TRecord& nodeRec = *nodeIt;
80 if ( nodeRec.exp_coord_sys_num == csLabel )
81 csRecord.FromSphericalCS( (double*) nodeRec.coord );
87 DriverUNV_R_SMDS_Mesh::~DriverUNV_R_SMDS_Mesh()
89 TGroupNamesMap::iterator grp2name = myGroupNames.begin();
90 for ( ; grp2name != myGroupNames.end(); ++grp2name )
91 delete grp2name->first;
94 Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform()
96 Kernel_Utils::Localizer loc;
97 Status aResult = DRS_OK;
98 #if defined(WIN32) && defined(UNICODE)
99 std::wstring aFile = Kernel_Utils::utf8_decode_s(myFile);
100 std::ifstream in_stream(aFile.c_str());
102 std::ifstream in_stream(myFile.c_str());
108 UNV164::TRecord aUnitsRecord;
109 UNV164::Read( in_stream, aUnitsRecord );
111 // Read Coordinate systems
112 UNV2420::TDataSet aCoordSysDataSet;
113 UNV2420::Read(in_stream, myMeshName, aCoordSysDataSet);
116 using namespace UNV2411;
117 TDataSet aDataSet2411;
118 UNV2411::Read(in_stream,aDataSet2411);
119 MESSAGE("Perform - aDataSet2411.size() = "<<aDataSet2411.size());
121 // Move nodes in a global CS
122 if ( !aCoordSysDataSet.empty() )
124 UNV2420::TDataSet::const_iterator csIter = aCoordSysDataSet.begin();
125 for ( ; csIter != aCoordSysDataSet.end(); ++csIter )
127 // find any node in this CS
128 TDataSet::const_iterator nodeIter = aDataSet2411.begin();
129 for (; nodeIter != aDataSet2411.end(); nodeIter++)
130 if ( nodeIter->exp_coord_sys_num == csIter->coord_sys_label )
132 transformNodes( nodeIter, aDataSet2411.end(), *csIter );
137 // Move nodes to SI unit system
138 const double lenFactor = aUnitsRecord.factors[ UNV164::LENGTH_FACTOR ];
139 if ( lenFactor != 1. )
141 TDataSet::iterator nodeIter = aDataSet2411.begin(), nodeEnd;
142 for ( nodeEnd = aDataSet2411.end(); nodeIter != nodeEnd; nodeIter++)
144 UNV2411::TRecord& nodeRec = *nodeIter;
145 nodeRec.coord[0] *= lenFactor;
146 nodeRec.coord[1] *= lenFactor;
147 nodeRec.coord[2] *= lenFactor;
151 // Create nodes in the mesh
152 TDataSet::const_iterator anIter = aDataSet2411.begin();
153 for(; anIter != aDataSet2411.end(); anIter++)
155 const TRecord& aRec = *anIter;
156 myMesh->AddNodeWithID(aRec.coord[0],aRec.coord[1],aRec.coord[2],aRec.label);
160 using namespace UNV2412;
161 TDataSet aDataSet2412;
162 UNV2412::Read(in_stream,aDataSet2412);
163 TDataSet::const_iterator anIter = aDataSet2412.begin();
164 MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
165 for(; anIter != aDataSet2412.end(); anIter++)
167 SMDS_MeshElement* anElement = NULL;
168 const TRecord& aRec = *anIter;
169 if(IsBeam(aRec.fe_descriptor_id)) {
170 switch ( aRec.node_labels.size() ) {
171 case 2: // edge with two nodes
172 //MESSAGE("add edge " << aLabel << " " << aRec.node_labels[0] << " " << aRec.node_labels[1]);
173 anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
177 case 3: // quadratic edge (with 3 nodes)
178 //MESSAGE("add edge " << aRec.label << " " << aRec.node_labels[0] << " " << aRec.node_labels[1] << " " << aRec.node_labels[2]);
179 anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
185 else if(IsFace(aRec.fe_descriptor_id)) {
186 //MESSAGE("add face " << aRec.label);
187 switch(aRec.fe_descriptor_id){
188 case 41: // Plane Stress Linear Triangle
189 case 51: // Plane Strain Linear Triangle
190 case 61: // Plate Linear Triangle
191 case 74: // Membrane Linear Triangle
192 case 81: // Axisymmetric Solid Linear Triangle
193 case 91: // Thin Shell Linear Triangle
194 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
200 case 42: // Plane Stress Parabolic Triangle
201 case 52: // Plane Strain Parabolic Triangle
202 case 62: // Plate Parabolic Triangle
203 case 72: // Membrane Parabolic Triangle
204 case 82: // Axisymmetric Solid Parabolic Triangle
205 case 92: // Thin Shell Parabolic Triangle
206 if ( aRec.node_labels.size() == 7 )
207 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
216 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
225 case 44: // Plane Stress Linear Quadrilateral
226 case 54: // Plane Strain Linear Quadrilateral
227 case 64: // Plate Linear Quadrilateral
228 case 71: // Membrane Linear Quadrilateral
229 case 84: // Axisymmetric Solid Linear Quadrilateral
230 case 94: // Thin Shell Linear Quadrilateral
231 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
238 case 45: // Plane Stress Parabolic Quadrilateral
239 case 55: // Plane Strain Parabolic Quadrilateral
240 case 65: // Plate Parabolic Quadrilateral
241 case 75: // Membrane Parabolic Quadrilateral
242 case 85: // Axisymmetric Solid Parabolic Quadrilateral
243 case 95: // Thin Shell Parabolic Quadrilateral
244 if ( aRec.node_labels.size() == 9 )
245 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
256 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
268 else if(IsVolume(aRec.fe_descriptor_id)){
269 //MESSAGE("add volume " << aRec.label);
270 switch(aRec.fe_descriptor_id){
272 case 111: // Solid Linear Tetrahedron - TET4
273 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
280 case 118: // Solid Quadratic Tetrahedron - TET10
281 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
297 case 112: // Solid Linear Prism - PRISM6
298 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
307 case 113: // Solid Quadratic Prism - PRISM15
308 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
313 aRec.node_labels[13],
314 aRec.node_labels[11],
320 aRec.node_labels[14],
321 aRec.node_labels[12],
322 aRec.node_labels[10],
330 case 115: // Solid Linear Brick - HEX8
331 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
342 case 116: // Solid Quadratic Brick - HEX20
343 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
348 aRec.node_labels[12],
349 aRec.node_labels[18],
350 aRec.node_labels[16],
351 aRec.node_labels[14],
358 aRec.node_labels[19],
359 aRec.node_labels[17],
360 aRec.node_labels[15],
361 aRec.node_labels[13],
364 aRec.node_labels[11],
365 aRec.node_labels[10],
370 case 114: // pyramid of 13 nodes (quadratic) - PIRA13
371 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
376 aRec.node_labels[12],
384 aRec.node_labels[11],
385 aRec.node_labels[10],
393 MESSAGE("DriverUNV_R_SMDS_Mesh::Perform - can not add element with ID = "<<aRec.label<<" and type = "<<aRec.fe_descriptor_id);
397 using namespace UNV2417;
398 TDataSet aDataSet2417;
399 UNV2417::Read(in_stream,aDataSet2417);
400 MESSAGE("Perform - aDataSet2417.size() = "<<aDataSet2417.size());
401 if (aDataSet2417.size() > 0)
403 TDataSet::const_iterator anIter = aDataSet2417.begin();
404 for ( ; anIter != aDataSet2417.end(); anIter++ )
406 const TRecord& aRec = anIter->second;
407 int aNodesNb = aRec.NodeList.size();
408 int aElementsNb = aRec.ElementList.size();
410 bool useSuffix = ((aNodesNb > 0) && (aElementsNb > 0));
413 SMDS_MeshGroup* aNodesGroup = new SMDS_MeshGroup( myMesh );
414 std::string aGrName = (useSuffix) ? aRec.GroupName + "_Nodes" : aRec.GroupName;
415 int i = aGrName.find( "\r" );
417 aGrName.erase (i, 2);
418 myGroupNames.insert( std::make_pair( aNodesGroup, aGrName ));
420 for ( int i = 0; i < aNodesNb; i++ )
421 if ( const SMDS_MeshNode* aNode = myMesh->FindNode( aRec.NodeList[i] ))
422 aNodesGroup->Add( aNode );
424 if ( aElementsNb > 0 )
426 std::vector< SMDS_MeshGroup* > aGroupVec( SMDSAbs_NbElementTypes, (SMDS_MeshGroup*)0 );
427 const char* aSuffix[] = { "", "", "_Edges", "_Faces", "_Volumes", "_0D", "_Balls" };
428 bool createdGroup = false;
429 for ( int i = 0; i < aElementsNb; i++)
431 const SMDS_MeshElement* aElement = myMesh->FindElement( aRec.ElementList[i] );
432 if ( !aElement ) continue;
434 SMDS_MeshGroup * & aGroup = aGroupVec[ aElement->GetType() ];
437 aGroup = new SMDS_MeshGroup( myMesh );
438 if (!useSuffix && createdGroup) useSuffix = true;
439 std::string aGrName = aRec.GroupName;
440 int i = aGrName.find( "\r" );
442 aGrName.erase (i, 2);
444 aGrName += aSuffix[ aElement->GetType() ];
445 myGroupNames.insert( std::make_pair( aGroup, aGrName ));
448 aGroup->Add(aElement);
455 catch(const std::exception& exc){
456 INFOS("Follow exception was cought:\n\t"<<exc.what());
459 INFOS("Unknown exception was cought !!!");
464 myMesh->CompactMesh();