1 // Copyright (C) 2007-2011 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.
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 "UNV2411_Structure.hxx"
30 #include "UNV2412_Structure.hxx"
31 #include "UNV2417_Structure.hxx"
32 #include "UNV_Utilities.hxx"
34 #include <Basics_Utils.hxx>
40 static int MYDEBUG = 1;
42 static int MYDEBUG = 0;
46 DriverUNV_R_SMDS_Mesh::~DriverUNV_R_SMDS_Mesh()
53 Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform()
55 Kernel_Utils::Localizer loc;
56 Status aResult = DRS_OK;
57 std::ifstream in_stream(myFile.c_str());
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 //MESSAGE("AddNodeWithID " << aLabel << " " << aRec.coord[0] << " " << aRec.coord[1] << " " << aRec.coord[2]);
69 myMesh->AddNodeWithID(aRec.coord[0],aRec.coord[1],aRec.coord[2],aLabel);
73 using namespace UNV2412;
75 TDataSet aDataSet2412;
76 UNV2412::Read(in_stream,aDataSet2412);
77 TDataSet::const_iterator anIter = aDataSet2412.begin();
78 if(MYDEBUG) MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
79 for(; anIter != aDataSet2412.end(); anIter++){
80 SMDS_MeshElement* anElement = NULL;
81 const TElementLab& aLabel = anIter->first;
82 const TRecord& aRec = anIter->second;
83 if(IsBeam(aRec.fe_descriptor_id)) {
84 switch ( aRec.node_labels.size() ) {
85 case 2: // edge with two nodes
86 //MESSAGE("add edge " << aLabel << " " << aRec.node_labels[0] << " " << aRec.node_labels[1]);
87 anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
91 case 3: // quadratic edge (with 3 nodes)
92 //MESSAGE("add edge " << aLabel << " " << aRec.node_labels[0] << " " << aRec.node_labels[1] << " " << aRec.node_labels[2]);
93 anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
99 else if(IsFace(aRec.fe_descriptor_id)) {
100 //MESSAGE("add face " << aLabel);
101 switch(aRec.fe_descriptor_id){
102 case 41: // Plane Stress Linear Triangle
103 case 51: // Plane Strain Linear Triangle
104 case 61: // Plate Linear Triangle
105 case 74: // Membrane Linear Triangle
106 case 81: // Axisymetric Solid Linear Triangle
107 case 91: // Thin Shell Linear Triangle
108 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
114 case 42: // Plane Stress Parabolic Triangle
115 case 52: // Plane Strain Parabolic Triangle
116 case 62: // Plate Parabolic Triangle
117 case 72: // Membrane Parabolic Triangle
118 case 82: // Axisymetric Solid Parabolic Triangle
119 case 92: // Thin Shell Parabolic Triangle
120 //MESSAGE("add face " << aLabel << " " << aRec.node_labels[0] << " " << aRec.node_labels[1] << " " << aRec.node_labels[2] << " " << aRec.node_labels[3] << " " << aRec.node_labels[4] << " " << aRec.node_labels[5]);
121 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
130 case 44: // Plane Stress Linear Quadrilateral
131 case 54: // Plane Strain Linear Quadrilateral
132 case 64: // Plate Linear Quadrilateral
133 case 71: // Membrane Linear Quadrilateral
134 case 84: // Axisymetric Solid Linear Quadrilateral
135 case 94: // Thin Shell Linear Quadrilateral
136 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
143 case 45: // Plane Stress Parabolic Quadrilateral
144 case 55: // Plane Strain Parabolic Quadrilateral
145 case 65: // Plate Parabolic Quadrilateral
146 case 75: // Membrane Parabolic Quadrilateral
147 case 85: // Axisymetric Solid Parabolic Quadrilateral
148 case 95: // Thin Shell Parabolic Quadrilateral
149 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
161 else if(IsVolume(aRec.fe_descriptor_id)){
162 //MESSAGE("add volume " << aLabel);
163 switch(aRec.fe_descriptor_id){
165 case 111: // Solid Linear Tetrahedron - TET4
166 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
173 case 118: // Solid Quadratic Tetrahedron - TET10
174 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
190 case 112: // Solid Linear Prism - PRISM6
191 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
200 case 113: // Solid Quadratic Prism - PRISM15
201 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
206 aRec.node_labels[13],
207 aRec.node_labels[11],
213 aRec.node_labels[14],
214 aRec.node_labels[12],
215 aRec.node_labels[10],
223 case 115: // Solid Linear Brick - HEX8
224 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
235 case 116: // Solid Quadratic Brick - HEX20
236 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
241 aRec.node_labels[12],
242 aRec.node_labels[18],
243 aRec.node_labels[16],
244 aRec.node_labels[14],
251 aRec.node_labels[19],
252 aRec.node_labels[17],
253 aRec.node_labels[15],
254 aRec.node_labels[13],
257 aRec.node_labels[11],
258 aRec.node_labels[10],
263 case 114: // pyramid of 13 nodes (quadratic) - PIRA13
264 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
274 aRec.node_labels[11],
275 aRec.node_labels[10],
277 aRec.node_labels[12],
284 MESSAGE("DriverUNV_R_SMDS_Mesh::Perform - can not add element with ID = "<<aLabel<<" and type = "<<aRec.fe_descriptor_id);
288 using namespace UNV2417;
290 TDataSet aDataSet2417;
291 UNV2417::Read(in_stream,aDataSet2417);
292 if(MYDEBUG) MESSAGE("Perform - aDataSet2417.size() = "<<aDataSet2417.size());
293 if (aDataSet2417.size() > 0) {
294 myGroup = new SMDS_MeshGroup(myMesh);
295 TDataSet::const_iterator anIter = aDataSet2417.begin();
296 for(; anIter != aDataSet2417.end(); anIter++){
297 const TGroupId& aLabel = anIter->first;
298 const TRecord& aRec = anIter->second;
300 int aNodesNb = aRec.NodeList.size();
301 int aElementsNb = aRec.ElementList.size();
303 bool useSuffix = ((aNodesNb > 0) && (aElementsNb > 0));
306 SMDS_MeshGroup* aNodesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Node);
307 std::string aGrName = (useSuffix) ? aRec.GroupName + "_Nodes" : aRec.GroupName;
308 int i = aGrName.find( "\r" );
310 aGrName.erase (i, 2);
311 myGroupNames.insert(TGroupNamesMap::value_type(aNodesGroup, aGrName));
312 myGroupId.insert(TGroupIdMap::value_type(aNodesGroup, aLabel));
314 for (i = 0; i < aNodesNb; i++) {
315 const SMDS_MeshNode* aNode = myMesh->FindNode(aRec.NodeList[i]);
317 aNodesGroup->Add(aNode);
320 if (aElementsNb > 0){
321 SMDS_MeshGroup* aEdgesGroup = 0;
322 SMDS_MeshGroup* aFacesGroup = 0;
323 SMDS_MeshGroup* aVolumeGroup = 0;
324 bool createdGroup = false;
326 for (i = 0; i < aElementsNb; i++) {
327 const SMDS_MeshElement* aElement = myMesh->FindElement(aRec.ElementList[i]);
329 switch (aElement->GetType()) {
332 aEdgesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Edge);
333 if (!useSuffix && createdGroup) useSuffix = true;
334 std::string aEdgesGrName = (useSuffix) ? aRec.GroupName + "_Edges" : aRec.GroupName;
335 int i = aEdgesGrName.find( "\r" );
337 aEdgesGrName.erase (i, 2);
338 myGroupNames.insert(TGroupNamesMap::value_type(aEdgesGroup, aEdgesGrName));
339 myGroupId.insert(TGroupIdMap::value_type(aEdgesGroup, aLabel));
342 aEdgesGroup->Add(aElement);
346 aFacesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Face);
347 if (!useSuffix && createdGroup) useSuffix = true;
348 std::string aFacesGrName = (useSuffix) ? aRec.GroupName + "_Faces" : aRec.GroupName;
349 int i = aFacesGrName.find( "\r" );
351 aFacesGrName.erase (i, 2);
352 myGroupNames.insert(TGroupNamesMap::value_type(aFacesGroup, aFacesGrName));
353 myGroupId.insert(TGroupIdMap::value_type(aFacesGroup, aLabel));
356 aFacesGroup->Add(aElement);
360 aVolumeGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Volume);
361 if (!useSuffix && createdGroup) useSuffix = true;
362 std::string aVolumeGrName = (useSuffix) ? aRec.GroupName + "_Volumes" : aRec.GroupName;
363 int i = aVolumeGrName.find( "\r" );
365 aVolumeGrName.erase (i, 2);
366 myGroupNames.insert(TGroupNamesMap::value_type(aVolumeGroup, aVolumeGrName));
367 myGroupId.insert(TGroupIdMap::value_type(aVolumeGroup, aLabel));
370 aVolumeGroup->Add(aElement);
380 catch(const std::exception& exc){
381 INFOS("Follow exception was cought:\n\t"<<exc.what());
384 INFOS("Unknown exception was cought !!!");
387 myMesh->compactMesh();