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