1 // Copyright (C) 2007-2010 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 = 0;
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 myMesh->AddNodeWithID(aRec.coord[0],aRec.coord[1],aRec.coord[2],aLabel);
72 using namespace UNV2412;
74 TDataSet aDataSet2412;
75 UNV2412::Read(in_stream,aDataSet2412);
76 TDataSet::const_iterator anIter = aDataSet2412.begin();
77 if(MYDEBUG) MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
78 for(; anIter != aDataSet2412.end(); anIter++){
79 SMDS_MeshElement* anElement = NULL;
80 const TElementLab& aLabel = anIter->first;
81 const TRecord& aRec = anIter->second;
82 if(IsBeam(aRec.fe_descriptor_id)) {
83 switch ( aRec.node_labels.size() ) {
84 case 2: // edge with two nodes
85 anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
89 case 3: // quadratic edge (with 3 nodes)
90 anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
96 else if(IsFace(aRec.fe_descriptor_id)) {
97 switch(aRec.fe_descriptor_id){
102 case 41: // Plane Stress Linear Triangle - TRI3
103 case 91: // Thin Shell Linear Triangle - TRI3
104 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
110 case 42: // Plane Stress Quadratic Triangle - TRI6
111 case 92: // Thin Shell Quadratic Triangle - TRI6
112 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
121 case 44: // Plane Stress Linear Quadrilateral - QUAD4
122 case 94: // Thin Shell Linear Quadrilateral - QUAD4
123 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
130 case 45: // Plane Stress Quadratic Quadrilateral - QUAD8
131 case 95: // Thin Shell Quadratic Quadrilateral - QUAD8
132 anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
144 else if(IsVolume(aRec.fe_descriptor_id)){
145 switch(aRec.fe_descriptor_id){
147 case 111: // Solid Linear Tetrahedron - TET4
148 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
155 case 118: // Solid Quadratic Tetrahedron - TET10
156 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
172 case 112: // Solid Linear Prism - PRISM6
173 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
182 case 113: // Solid Quadratic Prism - PRISM15
183 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
188 aRec.node_labels[13],
189 aRec.node_labels[11],
195 aRec.node_labels[14],
196 aRec.node_labels[12],
197 aRec.node_labels[10],
205 case 115: // Solid Linear Brick - HEX8
206 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
217 case 116: // Solid Quadratic Brick - HEX20
218 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
223 aRec.node_labels[12],
224 aRec.node_labels[18],
225 aRec.node_labels[16],
226 aRec.node_labels[14],
233 aRec.node_labels[19],
234 aRec.node_labels[17],
235 aRec.node_labels[15],
236 aRec.node_labels[13],
239 aRec.node_labels[11],
240 aRec.node_labels[10],
245 case 114: // pyramid of 13 nodes (quadratic) - PIRA13
246 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
256 aRec.node_labels[11],
257 aRec.node_labels[10],
259 aRec.node_labels[12],
266 // MESSAGE("DriverUNV_R_SMDS_Mesh::Perform - can not add element with ID = "<<aLabel<<" and type = "<<aRec.fe_descriptor_id);
270 using namespace UNV2417;
272 TDataSet aDataSet2417;
273 UNV2417::Read(in_stream,aDataSet2417);
274 if(MYDEBUG) MESSAGE("Perform - aDataSet2417.size() = "<<aDataSet2417.size());
275 if (aDataSet2417.size() > 0) {
276 myGroup = new SMDS_MeshGroup(myMesh);
277 TDataSet::const_iterator anIter = aDataSet2417.begin();
278 for(; anIter != aDataSet2417.end(); anIter++){
279 const TGroupId& aLabel = anIter->first;
280 const TRecord& aRec = anIter->second;
282 int aNodesNb = aRec.NodeList.size();
283 int aElementsNb = aRec.ElementList.size();
285 bool useSuffix = ((aNodesNb > 0) && (aElementsNb > 0));
288 SMDS_MeshGroup* aNodesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Node);
289 std::string aGrName = (useSuffix) ? aRec.GroupName + "_Nodes" : aRec.GroupName;
290 int i = aGrName.find( "\r" );
292 aGrName.erase (i, 2);
293 myGroupNames.insert(TGroupNamesMap::value_type(aNodesGroup, aGrName));
294 myGroupId.insert(TGroupIdMap::value_type(aNodesGroup, aLabel));
296 for (i = 0; i < aNodesNb; i++) {
297 const SMDS_MeshNode* aNode = myMesh->FindNode(aRec.NodeList[i]);
299 aNodesGroup->Add(aNode);
302 if (aElementsNb > 0){
303 SMDS_MeshGroup* aEdgesGroup = 0;
304 SMDS_MeshGroup* aFacesGroup = 0;
305 SMDS_MeshGroup* aVolumeGroup = 0;
306 bool createdGroup = false;
308 for (i = 0; i < aElementsNb; i++) {
309 const SMDS_MeshElement* aElement = myMesh->FindElement(aRec.ElementList[i]);
311 switch (aElement->GetType()) {
314 aEdgesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Edge);
315 if (!useSuffix && createdGroup) useSuffix = true;
316 std::string aEdgesGrName = (useSuffix) ? aRec.GroupName + "_Edges" : aRec.GroupName;
317 int i = aEdgesGrName.find( "\r" );
319 aEdgesGrName.erase (i, 2);
320 myGroupNames.insert(TGroupNamesMap::value_type(aEdgesGroup, aEdgesGrName));
321 myGroupId.insert(TGroupIdMap::value_type(aEdgesGroup, aLabel));
324 aEdgesGroup->Add(aElement);
328 aFacesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Face);
329 if (!useSuffix && createdGroup) useSuffix = true;
330 std::string aFacesGrName = (useSuffix) ? aRec.GroupName + "_Faces" : aRec.GroupName;
331 int i = aFacesGrName.find( "\r" );
333 aFacesGrName.erase (i, 2);
334 myGroupNames.insert(TGroupNamesMap::value_type(aFacesGroup, aFacesGrName));
335 myGroupId.insert(TGroupIdMap::value_type(aFacesGroup, aLabel));
338 aFacesGroup->Add(aElement);
342 aVolumeGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Volume);
343 if (!useSuffix && createdGroup) useSuffix = true;
344 std::string aVolumeGrName = (useSuffix) ? aRec.GroupName + "_Volumes" : aRec.GroupName;
345 int i = aVolumeGrName.find( "\r" );
347 aVolumeGrName.erase (i, 2);
348 myGroupNames.insert(TGroupNamesMap::value_type(aVolumeGroup, aVolumeGrName));
349 myGroupId.insert(TGroupIdMap::value_type(aVolumeGroup, aLabel));
352 aVolumeGroup->Add(aElement);
362 catch(const std::exception& exc){
363 INFOS("Follow exception was cought:\n\t"<<exc.what());
366 INFOS("Unknown exception was cought !!!");