Salome HOME
c438fa334639dc62cffd0ff3696250611e8b10b5
[modules/smesh.git] / src / DriverUNV / DriverUNV_R_SMDS_Mesh.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "DriverUNV_R_SMDS_Mesh.h"
23 #include "SMDS_Mesh.hxx"
24 #include "SMDS_MeshGroup.hxx"
25
26 #include "utilities.h"
27
28 #include "UNV2411_Structure.hxx"
29 #include "UNV2412_Structure.hxx"
30 #include "UNV2417_Structure.hxx"
31 #include "UNV_Utilities.hxx"
32
33 using namespace std;
34
35
36 #ifdef _DEBUG_
37 static int MYDEBUG = 0;
38 #else
39 static int MYDEBUG = 0;
40 #endif
41
42
43 DriverUNV_R_SMDS_Mesh::~DriverUNV_R_SMDS_Mesh()
44 {
45   if (myGroup != 0) 
46     delete myGroup;
47 }
48
49
50 Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform()
51 {
52   Status aResult = DRS_OK;
53   std::ifstream in_stream(myFile.c_str());
54   try{
55     {
56       using namespace UNV2411;
57       TDataSet aDataSet2411;
58       UNV2411::Read(in_stream,aDataSet2411);
59       if(MYDEBUG) MESSAGE("Perform - aDataSet2411.size() = "<<aDataSet2411.size());
60       TDataSet::const_iterator anIter = aDataSet2411.begin();
61       for(; anIter != aDataSet2411.end(); anIter++){
62         const TNodeLab& aLabel = anIter->first;
63         const TRecord& aRec = anIter->second;
64         myMesh->AddNodeWithID(aRec.coord[0],aRec.coord[1],aRec.coord[2],aLabel);
65       }
66     }
67     {
68       using namespace UNV2412;
69       in_stream.seekg(0);
70       TDataSet aDataSet2412;
71       UNV2412::Read(in_stream,aDataSet2412);
72       TDataSet::const_iterator anIter = aDataSet2412.begin();
73       if(MYDEBUG) MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
74       for(; anIter != aDataSet2412.end(); anIter++){
75         SMDS_MeshElement* anElement = NULL;
76         const TElementLab& aLabel = anIter->first;
77         const TRecord& aRec = anIter->second;
78         if(IsBeam(aRec.fe_descriptor_id)) {
79           switch ( aRec.node_labels.size() ) {
80           case 2: // edge with two nodes
81             anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
82                                               aRec.node_labels[1],
83                                               aLabel);
84             break;
85           case 3: // quadratic edge (with 3 nodes)
86             anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
87                                               aRec.node_labels[2],
88                                               aRec.node_labels[1],
89                                               aLabel);
90           }
91         }
92         else if(IsFace(aRec.fe_descriptor_id)) {
93           switch(aRec.fe_descriptor_id){
94           case 71: // TRI3
95           case 72:
96           case 74:
97             
98           case 41: // Plane Stress Linear Triangle - TRI3
99           case 91: // Thin Shell Linear Triangle - TRI3
100             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
101                                               aRec.node_labels[1],
102                                               aRec.node_labels[2],
103                                               aLabel);
104             break;
105             
106           case 42: // Plane Stress Quadratic Triangle - TRI6
107           case 92: // Thin Shell Quadratic Triangle - TRI6
108             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
109                                               aRec.node_labels[2],
110                                               aRec.node_labels[4],
111                                               aRec.node_labels[1],
112                                               aRec.node_labels[3],
113                                               aRec.node_labels[5],
114                                               aLabel);
115             break;
116             
117           case 44: // Plane Stress Linear Quadrilateral - QUAD4
118           case 94: // Thin Shell   Linear Quadrilateral -  QUAD4
119             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
120                                               aRec.node_labels[1],
121                                               aRec.node_labels[2],
122                                               aRec.node_labels[3],
123                                               aLabel);
124             break;
125             
126           case 45: // Plane Stress Quadratic Quadrilateral - QUAD8
127           case 95: // Thin Shell   Quadratic Quadrilateral - QUAD8
128             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
129                                               aRec.node_labels[2],
130                                               aRec.node_labels[4],
131                                               aRec.node_labels[6],
132                                               aRec.node_labels[1],
133                                               aRec.node_labels[3],
134                                               aRec.node_labels[5],
135                                               aRec.node_labels[7],
136                                               aLabel);
137             break;
138           }
139         }
140         else if(IsVolume(aRec.fe_descriptor_id)){
141           switch(aRec.fe_descriptor_id){
142             
143           case 111: // Solid Linear Tetrahedron - TET4
144             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
145                                                 aRec.node_labels[2],
146                                                 aRec.node_labels[1],
147                                                 aRec.node_labels[3],
148                                                 aLabel);
149             break;
150
151           case 118: // Solid Quadratic Tetrahedron - TET10
152             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
153                                                 aRec.node_labels[4],
154                                                 aRec.node_labels[2],
155
156                                                 aRec.node_labels[9],
157
158                                                 aRec.node_labels[5],
159                                                 aRec.node_labels[3],
160                                                 aRec.node_labels[1],
161
162                                                 aRec.node_labels[6],
163                                                 aRec.node_labels[8],
164                                                 aRec.node_labels[7],
165                                                 aLabel);
166             break;
167             
168           case 112: // Solid Linear Prism - PRISM6
169             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
170                                                 aRec.node_labels[2],
171                                                 aRec.node_labels[1],
172                                                 aRec.node_labels[3],
173                                                 aRec.node_labels[5],
174                                                 aRec.node_labels[4],
175                                                 aLabel);
176             break;
177             
178           case 113: // Solid Quadratic Prism - PRISM15
179             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
180                                                 aRec.node_labels[4],
181                                                 aRec.node_labels[2],
182
183                                                 aRec.node_labels[9],
184                                                 aRec.node_labels[13],
185                                                 aRec.node_labels[11],
186
187                                                 aRec.node_labels[5],
188                                                 aRec.node_labels[3],
189                                                 aRec.node_labels[1],
190
191                                                 aRec.node_labels[14],
192                                                 aRec.node_labels[12],
193                                                 aRec.node_labels[10],
194
195                                                 aRec.node_labels[6],
196                                                 aRec.node_labels[8],
197                                                 aRec.node_labels[7],
198                                                 aLabel);
199             break;
200             
201           case 115: // Solid Linear Brick - HEX8
202             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
203                                                 aRec.node_labels[3],
204                                                 aRec.node_labels[2],
205                                                 aRec.node_labels[1],
206                                                 aRec.node_labels[4],
207                                                 aRec.node_labels[7],
208                                                 aRec.node_labels[6],
209                                                 aRec.node_labels[5],
210                                                 aLabel);
211             break;
212
213           case 116: // Solid Quadratic Brick - HEX20
214             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
215                                                 aRec.node_labels[6],
216                                                 aRec.node_labels[4],
217                                                 aRec.node_labels[2],
218
219                                                 aRec.node_labels[12],
220                                                 aRec.node_labels[18],
221                                                 aRec.node_labels[16],
222                                                 aRec.node_labels[14],
223
224                                                 aRec.node_labels[7],
225                                                 aRec.node_labels[5],
226                                                 aRec.node_labels[3],
227                                                 aRec.node_labels[1],
228
229                                                 aRec.node_labels[19],
230                                                 aRec.node_labels[17],
231                                                 aRec.node_labels[15],
232                                                 aRec.node_labels[13],
233
234                                                 aRec.node_labels[8],
235                                                 aRec.node_labels[11],
236                                                 aRec.node_labels[10],
237                                                 aRec.node_labels[9],
238                                                 aLabel);
239             break;
240
241           case 114: // pyramid of 13 nodes (quadratic) - PIRA13
242             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
243                                                 aRec.node_labels[6],
244                                                 aRec.node_labels[4],
245                                                 aRec.node_labels[2],
246                                                 aRec.node_labels[7],
247                                                 aRec.node_labels[5],
248                                                 aRec.node_labels[3],
249                                                 aRec.node_labels[1],
250
251                                                 aRec.node_labels[8],
252                                                 aRec.node_labels[11],
253                                                 aRec.node_labels[10],
254                                                 aRec.node_labels[9],
255                                                 aRec.node_labels[12],
256                                                 aLabel);
257             break;
258
259           }
260         }
261         //      if(!anElement)
262         //        MESSAGE("DriverUNV_R_SMDS_Mesh::Perform - can not add element with ID = "<<aLabel<<" and type = "<<aRec.fe_descriptor_id);
263       }
264     }
265     {
266       using namespace UNV2417;      
267       in_stream.seekg(0);
268       TDataSet aDataSet2417;
269       UNV2417::Read(in_stream,aDataSet2417);
270       if(MYDEBUG) MESSAGE("Perform - aDataSet2417.size() = "<<aDataSet2417.size());
271       if  (aDataSet2417.size() > 0) {
272         myGroup = new SMDS_MeshGroup(myMesh);
273         TDataSet::const_iterator anIter = aDataSet2417.begin();
274         for(; anIter != aDataSet2417.end(); anIter++){
275           const TGroupId& aLabel = anIter->first;
276           const TRecord& aRec = anIter->second;
277
278           int aNodesNb = aRec.NodeList.size();
279           int aElementsNb = aRec.ElementList.size();
280
281           bool useSuffix = ((aNodesNb > 0) && (aElementsNb > 0));
282           int i;
283           if (aNodesNb > 0) {
284             SMDS_MeshGroup* aNodesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Node);
285             std::string aGrName = (useSuffix) ? aRec.GroupName + "_Nodes" : aRec.GroupName;
286             int i = aGrName.find( "\r" );
287             if (i > 0)
288               aGrName.erase (i, 2);
289             myGroupNames.insert(TGroupNamesMap::value_type(aNodesGroup, aGrName));
290             myGroupId.insert(TGroupIdMap::value_type(aNodesGroup, aLabel));
291
292             for (i = 0; i < aNodesNb; i++) {
293               const SMDS_MeshNode* aNode = myMesh->FindNode(aRec.NodeList[i]);
294               if (aNode)
295                 aNodesGroup->Add(aNode);
296             }
297           }
298           if (aElementsNb > 0){
299             SMDS_MeshGroup* aEdgesGroup = 0;
300             SMDS_MeshGroup* aFacesGroup = 0;
301             SMDS_MeshGroup* aVolumeGroup = 0;
302             bool createdGroup = false;
303
304             for (i = 0; i < aElementsNb; i++) {
305               const SMDS_MeshElement* aElement = myMesh->FindElement(aRec.ElementList[i]);
306               if (aElement) {
307                 switch (aElement->GetType()) {
308                 case SMDSAbs_Edge:
309                   if (!aEdgesGroup) {
310                     aEdgesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Edge);
311                     if (!useSuffix && createdGroup) useSuffix = true;
312                     std::string aEdgesGrName = (useSuffix) ? aRec.GroupName + "_Edges" : aRec.GroupName;
313                     int i = aEdgesGrName.find( "\r" );
314                     if (i > 0)
315                       aEdgesGrName.erase (i, 2);
316                     myGroupNames.insert(TGroupNamesMap::value_type(aEdgesGroup, aEdgesGrName));
317                     myGroupId.insert(TGroupIdMap::value_type(aEdgesGroup, aLabel));
318                     createdGroup = true;
319                   }
320                   aEdgesGroup->Add(aElement);
321                   break;
322                 case SMDSAbs_Face:
323                   if (!aFacesGroup) {
324                     aFacesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Face);
325                     if (!useSuffix && createdGroup) useSuffix = true;
326                     std::string aFacesGrName = (useSuffix) ? aRec.GroupName + "_Faces" : aRec.GroupName;
327                     int i = aFacesGrName.find( "\r" );
328                     if (i > 0)
329                       aFacesGrName.erase (i, 2);
330                     myGroupNames.insert(TGroupNamesMap::value_type(aFacesGroup, aFacesGrName));
331                     myGroupId.insert(TGroupIdMap::value_type(aFacesGroup, aLabel));
332                     createdGroup = true;
333                   }
334                   aFacesGroup->Add(aElement);
335                   break;
336                 case SMDSAbs_Volume:
337                   if (!aVolumeGroup) {
338                     aVolumeGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Volume);
339                     if (!useSuffix && createdGroup) useSuffix = true;
340                     std::string aVolumeGrName = (useSuffix) ? aRec.GroupName + "_Volumes" : aRec.GroupName;
341                     int i = aVolumeGrName.find( "\r" );
342                     if (i > 0)
343                       aVolumeGrName.erase (i, 2);
344                     myGroupNames.insert(TGroupNamesMap::value_type(aVolumeGroup, aVolumeGrName));
345                     myGroupId.insert(TGroupIdMap::value_type(aVolumeGroup, aLabel));
346                     createdGroup = true;
347                   }
348                   aVolumeGroup->Add(aElement);
349                   break;
350                 }
351               } 
352             }
353           }
354         }
355       }
356     } 
357   }
358   catch(const std::exception& exc){
359     INFOS("Follow exception was cought:\n\t"<<exc.what());
360   }
361   catch(...){
362     INFOS("Unknown exception was cought !!!");
363   }
364   return aResult;
365 }