1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "DriverUNV_R_SMDS_Mesh.h"
21 #include "SMDS_Mesh.hxx"
22 #include "SMDS_MeshGroup.hxx"
24 #include "utilities.h"
26 #include "UNV2411_Structure.hxx"
27 #include "UNV2412_Structure.hxx"
28 #include "UNV2417_Structure.hxx"
29 #include "UNV_Utilities.hxx"
35 static int MYDEBUG = 0;
37 static int MYDEBUG = 0;
41 DriverUNV_R_SMDS_Mesh::~DriverUNV_R_SMDS_Mesh()
48 Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform()
50 Status aResult = DRS_OK;
51 std::ifstream in_stream(myFile.c_str());
54 using namespace UNV2411;
55 TDataSet aDataSet2411;
56 UNV2411::Read(in_stream,aDataSet2411);
57 if(MYDEBUG) MESSAGE("Perform - aDataSet2411.size() = "<<aDataSet2411.size());
58 TDataSet::const_iterator anIter = aDataSet2411.begin();
59 for(; anIter != aDataSet2411.end(); anIter++){
60 const TNodeLab& aLabel = anIter->first;
61 const TRecord& aRec = anIter->second;
62 myMesh->AddNodeWithID(aRec.coord[0],aRec.coord[1],aRec.coord[2],aLabel);
66 using namespace UNV2412;
68 TDataSet aDataSet2412;
69 UNV2412::Read(in_stream,aDataSet2412);
70 TDataSet::const_iterator anIter = aDataSet2412.begin();
71 if(MYDEBUG) MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
72 for(; anIter != aDataSet2412.end(); anIter++){
73 SMDS_MeshElement* anElement = NULL;
74 const TElementLab& aLabel = anIter->first;
75 const TRecord& aRec = anIter->second;
76 if(IsBeam(aRec.fe_descriptor_id)) {
77 switch ( aRec.node_labels.size() ) {
78 case 2: // edge with two nodes
79 anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
83 case 3: // quadratic edge (with 3 nodes)
84 anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
90 else if(IsFace(aRec.fe_descriptor_id)) {
91 switch(aRec.fe_descriptor_id){
96 case 41: // Plane Stress Linear Triangle - TRI3
97 case 91: // Thin Shell Linear Triangle - TRI3
98 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
104 case 42: // Plane Stress Quadratic Triangle - TRI6
105 case 92: // Thin Shell Quadratic Triangle - TRI6
106 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
115 case 44: // Plane Stress Linear Quadrilateral - QUAD4
116 case 94: // Thin Shell Linear Quadrilateral - QUAD4
117 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
124 case 45: // Plane Stress Quadratic Quadrilateral - QUAD8
125 case 95: // Thin Shell Quadratic Quadrilateral - QUAD8
126 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
138 else if(IsVolume(aRec.fe_descriptor_id)){
139 switch(aRec.fe_descriptor_id){
141 case 111: // Solid Linear Tetrahedron - TET4
142 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
149 case 118: // Solid Quadratic Tetrahedron - TET10
150 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
166 case 112: // Solid Linear Prism - PRISM6
167 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
176 case 113: // Solid Quadratic Prism - PRISM15
177 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
182 aRec.node_labels[13],
183 aRec.node_labels[11],
189 aRec.node_labels[14],
190 aRec.node_labels[12],
191 aRec.node_labels[10],
199 case 115: // Solid Linear Brick - HEX8
200 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
211 case 116: // Solid Quadratic Brick - HEX20
212 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
217 aRec.node_labels[12],
218 aRec.node_labels[18],
219 aRec.node_labels[16],
220 aRec.node_labels[14],
227 aRec.node_labels[19],
228 aRec.node_labels[17],
229 aRec.node_labels[15],
230 aRec.node_labels[13],
233 aRec.node_labels[11],
234 aRec.node_labels[10],
239 case 114: // pyramid of 13 nodes (quadratic) - PIRA13
240 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
250 aRec.node_labels[11],
251 aRec.node_labels[10],
253 aRec.node_labels[12],
260 // MESSAGE("DriverUNV_R_SMDS_Mesh::Perform - can not add element with ID = "<<aLabel<<" and type = "<<aRec.fe_descriptor_id);
264 using namespace UNV2417;
266 TDataSet aDataSet2417;
267 UNV2417::Read(in_stream,aDataSet2417);
268 if(MYDEBUG) MESSAGE("Perform - aDataSet2417.size() = "<<aDataSet2417.size());
269 if (aDataSet2417.size() > 0) {
270 myGroup = new SMDS_MeshGroup(myMesh);
271 TDataSet::const_iterator anIter = aDataSet2417.begin();
272 for(; anIter != aDataSet2417.end(); anIter++){
273 const TGroupId& aLabel = anIter->first;
274 const TRecord& aRec = anIter->second;
276 int aNodesNb = aRec.NodeList.size();
277 int aElementsNb = aRec.ElementList.size();
279 bool useSuffix = ((aNodesNb > 0) && (aElementsNb > 0));
282 SMDS_MeshGroup* aNodesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Node);
283 std::string aGrName = (useSuffix) ? aRec.GroupName + "_Nodes" : aRec.GroupName;
284 myGroupNames.insert(TGroupNamesMap::value_type(aNodesGroup, aGrName));
285 myGroupId.insert(TGroupIdMap::value_type(aNodesGroup, aLabel));
287 for (i = 0; i < aNodesNb; i++) {
288 const SMDS_MeshNode* aNode = myMesh->FindNode(aRec.NodeList[i]);
290 aNodesGroup->Add(aNode);
293 if (aElementsNb > 0){
294 SMDS_MeshGroup* aEdgesGroup = 0;
295 SMDS_MeshGroup* aFacesGroup = 0;
296 SMDS_MeshGroup* aVolumeGroup = 0;
297 bool createdGroup = false;
299 for (i = 0; i < aElementsNb; i++) {
300 const SMDS_MeshElement* aElement = myMesh->FindElement(aRec.ElementList[i]);
302 switch (aElement->GetType()) {
305 aEdgesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Edge);
306 if (!useSuffix && createdGroup) useSuffix = true;
307 std::string aEdgesGrName = (useSuffix) ? aRec.GroupName + "_Edges" : aRec.GroupName;
308 myGroupNames.insert(TGroupNamesMap::value_type(aEdgesGroup, aEdgesGrName));
309 myGroupId.insert(TGroupIdMap::value_type(aEdgesGroup, aLabel));
312 aEdgesGroup->Add(aElement);
316 aFacesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Face);
317 if (!useSuffix && createdGroup) useSuffix = true;
318 std::string aFacesGrName = (useSuffix) ? aRec.GroupName + "_Faces" : aRec.GroupName;
319 myGroupNames.insert(TGroupNamesMap::value_type(aFacesGroup, aFacesGrName));
320 myGroupId.insert(TGroupIdMap::value_type(aFacesGroup, aLabel));
323 aFacesGroup->Add(aElement);
327 aVolumeGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Volume);
328 if (!useSuffix && createdGroup) useSuffix = true;
329 std::string aVolumeGrName = (useSuffix) ? aRec.GroupName + "_Volumes" : aRec.GroupName;
330 myGroupNames.insert(TGroupNamesMap::value_type(aVolumeGroup, aVolumeGrName));
331 myGroupId.insert(TGroupIdMap::value_type(aVolumeGroup, aLabel));
334 aVolumeGroup->Add(aElement);
344 catch(const std::exception& exc){
345 INFOS("Follow exception was cought:\n\t"<<exc.what());
348 INFOS("Unknown exception was cought !!!");