1 // Copyright (C) 2007-2016 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 = 1;
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()
101 Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform()
103 Kernel_Utils::Localizer loc;
104 Status aResult = DRS_OK;
105 std::ifstream in_stream(myFile.c_str());
110 UNV164::TRecord aUnitsRecord;
111 UNV164::Read( in_stream, aUnitsRecord );
113 // Read Coordinate systems
114 UNV2420::TDataSet aCoordSysDataSet;
115 UNV2420::Read(in_stream, myMeshName, aCoordSysDataSet);
118 using namespace UNV2411;
119 TDataSet aDataSet2411;
120 UNV2411::Read(in_stream,aDataSet2411);
121 if(MYDEBUG) MESSAGE("Perform - aDataSet2411.size() = "<<aDataSet2411.size());
123 // Move nodes in a global CS
124 if ( !aCoordSysDataSet.empty() )
126 UNV2420::TDataSet::const_iterator csIter = aCoordSysDataSet.begin();
127 for ( ; csIter != aCoordSysDataSet.end(); ++csIter )
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 )
134 transformNodes( nodeIter, aDataSet2411.end(), *csIter );
139 // Move nodes to SI unit system
140 const double lenFactor = aUnitsRecord.factors[ UNV164::LENGTH_FACTOR ];
141 if ( lenFactor != 1. )
143 TDataSet::iterator nodeIter = aDataSet2411.begin(), nodeEnd;
144 for ( nodeEnd = aDataSet2411.end(); nodeIter != nodeEnd; nodeIter++)
146 UNV2411::TRecord& nodeRec = *nodeIter;
147 nodeRec.coord[0] *= lenFactor;
148 nodeRec.coord[1] *= lenFactor;
149 nodeRec.coord[2] *= lenFactor;
153 // Create nodes in the mesh
154 TDataSet::const_iterator anIter = aDataSet2411.begin();
155 for(; anIter != aDataSet2411.end(); anIter++)
157 const TRecord& aRec = *anIter;
158 myMesh->AddNodeWithID(aRec.coord[0],aRec.coord[1],aRec.coord[2],aRec.label);
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++)
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],
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],
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],
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],
218 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
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],
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],
258 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
270 else if(IsVolume(aRec.fe_descriptor_id)){
271 //MESSAGE("add volume " << aRec.label);
272 switch(aRec.fe_descriptor_id){
274 case 111: // Solid Linear Tetrahedron - TET4
275 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
282 case 118: // Solid Quadratic Tetrahedron - TET10
283 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
299 case 112: // Solid Linear Prism - PRISM6
300 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
309 case 113: // Solid Quadratic Prism - PRISM15
310 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
315 aRec.node_labels[13],
316 aRec.node_labels[11],
322 aRec.node_labels[14],
323 aRec.node_labels[12],
324 aRec.node_labels[10],
332 case 115: // Solid Linear Brick - HEX8
333 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
344 case 116: // Solid Quadratic Brick - HEX20
345 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
350 aRec.node_labels[12],
351 aRec.node_labels[18],
352 aRec.node_labels[16],
353 aRec.node_labels[14],
360 aRec.node_labels[19],
361 aRec.node_labels[17],
362 aRec.node_labels[15],
363 aRec.node_labels[13],
366 aRec.node_labels[11],
367 aRec.node_labels[10],
372 case 114: // pyramid of 13 nodes (quadratic) - PIRA13
373 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
383 aRec.node_labels[11],
384 aRec.node_labels[10],
386 aRec.node_labels[12],
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 if(MYDEBUG) MESSAGE("Perform - aDataSet2417.size() = "<<aDataSet2417.size());
401 if (aDataSet2417.size() > 0) {
402 myGroup = new SMDS_MeshGroup(myMesh);
403 TDataSet::const_iterator anIter = aDataSet2417.begin();
404 for(; anIter != aDataSet2417.end(); anIter++){
405 const TGroupId& aLabel = anIter->first;
406 const TRecord& aRec = anIter->second;
408 int aNodesNb = aRec.NodeList.size();
409 int aElementsNb = aRec.ElementList.size();
411 bool useSuffix = ((aNodesNb > 0) && (aElementsNb > 0));
414 SMDS_MeshGroup* aNodesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Node);
415 std::string aGrName = (useSuffix) ? aRec.GroupName + "_Nodes" : aRec.GroupName;
416 int i = aGrName.find( "\r" );
418 aGrName.erase (i, 2);
419 myGroupNames.insert(TGroupNamesMap::value_type(aNodesGroup, aGrName));
420 myGroupId.insert(TGroupIdMap::value_type(aNodesGroup, aLabel));
422 for (i = 0; i < aNodesNb; i++) {
423 const SMDS_MeshNode* aNode = myMesh->FindNode(aRec.NodeList[i]);
425 aNodesGroup->Add(aNode);
428 if (aElementsNb > 0){
429 SMDS_MeshGroup* aEdgesGroup = 0;
430 SMDS_MeshGroup* aFacesGroup = 0;
431 SMDS_MeshGroup* aVolumeGroup = 0;
432 bool createdGroup = false;
434 for (i = 0; i < aElementsNb; i++) {
435 const SMDS_MeshElement* aElement = myMesh->FindElement(aRec.ElementList[i]);
437 switch (aElement->GetType()) {
441 aEdgesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Edge);
442 if (!useSuffix && createdGroup) useSuffix = true;
443 std::string aEdgesGrName = (useSuffix) ? aRec.GroupName + "_Edges" : aRec.GroupName;
444 int i = aEdgesGrName.find( "\r" );
446 aEdgesGrName.erase (i, 2);
447 myGroupNames.insert(TGroupNamesMap::value_type(aEdgesGroup, aEdgesGrName));
448 myGroupId.insert(TGroupIdMap::value_type(aEdgesGroup, aLabel));
451 aEdgesGroup->Add(aElement);
456 aFacesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Face);
457 if (!useSuffix && createdGroup) useSuffix = true;
458 std::string aFacesGrName = (useSuffix) ? aRec.GroupName + "_Faces" : aRec.GroupName;
459 int i = aFacesGrName.find( "\r" );
461 aFacesGrName.erase (i, 2);
462 myGroupNames.insert(TGroupNamesMap::value_type(aFacesGroup, aFacesGrName));
463 myGroupId.insert(TGroupIdMap::value_type(aFacesGroup, aLabel));
466 aFacesGroup->Add(aElement);
471 aVolumeGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Volume);
472 if (!useSuffix && createdGroup) useSuffix = true;
473 std::string aVolumeGrName = (useSuffix) ? aRec.GroupName + "_Volumes" : aRec.GroupName;
474 int i = aVolumeGrName.find( "\r" );
476 aVolumeGrName.erase (i, 2);
477 myGroupNames.insert(TGroupNamesMap::value_type(aVolumeGroup, aVolumeGrName));
478 myGroupId.insert(TGroupIdMap::value_type(aVolumeGroup, aLabel));
481 aVolumeGroup->Add(aElement);
493 catch(const std::exception& exc){
494 INFOS("Follow exception was cought:\n\t"<<exc.what());
497 INFOS("Unknown exception was cought !!!");
500 myMesh->compactMesh();