Salome HOME
70a91360248cc54fde75d3738d2f141f4bd0752e
[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           if((aRec.fe_descriptor_id == 11) || (aRec.fe_descriptor_id == 21)) {
78             // edge with two nodes
79             anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
80                                               aRec.node_labels[1],
81                                               aLabel);
82           }
83           else {
84             // quadratic edge (with 3 nodes)
85             anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
86                                               aRec.node_labels[1],
87                                               aRec.node_labels[2],
88                                               aLabel);
89           }
90         }
91         else if(IsFace(aRec.fe_descriptor_id)) {
92           switch(aRec.fe_descriptor_id){
93           case 71: // TRI3
94           case 72:
95           case 74:
96             
97           case 41: // Plane Stress Linear Triangle - TRI3
98           case 91: // Thin Shell Linear Triangle - TRI3
99             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
100                                               aRec.node_labels[1],
101                                               aRec.node_labels[2],
102                                               aLabel);
103             break;
104             
105           case 42: // Plane Stress Quadratic Triangle - TRI6
106           case 92: // Thin Shell Quadratic Triangle - TRI6
107             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
108                                               aRec.node_labels[1],
109                                               aRec.node_labels[2],
110                                               aRec.node_labels[3],
111                                               aRec.node_labels[4],
112                                               aRec.node_labels[5],
113                                               aLabel);
114             break;
115             
116           case 44: // Plane Stress Linear Quadrilateral - QUAD4
117           case 94: // Thin Shell   Linear Quadrilateral -  QUAD4
118             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
119                                               aRec.node_labels[1],
120                                               aRec.node_labels[2],
121                                               aRec.node_labels[3],
122                                               aLabel);
123             break;
124             
125           case 45: // Plane Stress Quadratic Quadrilateral - QUAD8
126           case 95: // Thin Shell   Quadratic Quadrilateral - QUAD8
127             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
128                                               aRec.node_labels[1],
129                                               aRec.node_labels[2],
130                                               aRec.node_labels[3],
131                                               aRec.node_labels[4],
132                                               aRec.node_labels[5],
133                                               aRec.node_labels[6],
134                                               aRec.node_labels[7],
135                                               aLabel);
136             break;
137           }
138         }
139         else if(IsVolume(aRec.fe_descriptor_id)){
140           switch(aRec.fe_descriptor_id){
141             
142           case 111: // Solid Linear Tetrahedron - TET4
143             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
144                                                 aRec.node_labels[2],
145                                                 aRec.node_labels[1],
146                                                 aRec.node_labels[3],
147                                                 aLabel);
148             break;
149
150           case 118: // Solid Quadratic Tetrahedron - TET10
151             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
152                                                 aRec.node_labels[2],
153                                                 aRec.node_labels[1],
154                                                 aRec.node_labels[3],
155                                                 aRec.node_labels[6],
156                                                 aRec.node_labels[5],
157                                                 aRec.node_labels[4],
158                                                 aRec.node_labels[7],
159                                                 aRec.node_labels[9],
160                                                 aRec.node_labels[8],
161                                                 aLabel);
162             break;
163             
164           case 112: // Solid Linear Prism - PRISM6
165             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
166                                                 aRec.node_labels[2],
167                                                 aRec.node_labels[1],
168                                                 aRec.node_labels[3],
169                                                 aRec.node_labels[5],
170                                                 aRec.node_labels[4],
171                                                 aLabel);
172             break;
173             
174           case 113: // Solid Quadratic Prism - PRISM15
175             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
176                                                 aRec.node_labels[2],
177                                                 aRec.node_labels[1],
178                                                 aRec.node_labels[3],
179                                                 aRec.node_labels[5],
180                                                 aRec.node_labels[4],
181                                                 aRec.node_labels[8],
182                                                 aRec.node_labels[7],
183                                                 aRec.node_labels[6],
184                                                 aRec.node_labels[11],
185                                                 aRec.node_labels[10],
186                                                 aRec.node_labels[9],
187                                                 aRec.node_labels[12],
188                                                 aRec.node_labels[14],
189                                                 aRec.node_labels[13],
190                                                 aLabel);
191             break;
192             
193           case 115: // Solid Linear Brick - HEX8
194             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
195                                                 aRec.node_labels[3],
196                                                 aRec.node_labels[2],
197                                                 aRec.node_labels[1],
198                                                 aRec.node_labels[4],
199                                                 aRec.node_labels[7],
200                                                 aRec.node_labels[6],
201                                                 aRec.node_labels[5],
202                                                 aLabel);
203             break;
204
205           case 116: // Solid Quadratic Brick - HEX20
206             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
207                                                 aRec.node_labels[6],
208                                                 aRec.node_labels[4],
209                                                 aRec.node_labels[2],
210
211                                                 aRec.node_labels[12],
212                                                 aRec.node_labels[18],
213                                                 aRec.node_labels[16],
214                                                 aRec.node_labels[14],
215
216                                                 aRec.node_labels[7],
217                                                 aRec.node_labels[5],
218                                                 aRec.node_labels[3],
219                                                 aRec.node_labels[1],
220
221                                                 aRec.node_labels[19],
222                                                 aRec.node_labels[17],
223                                                 aRec.node_labels[15],
224                                                 aRec.node_labels[13],
225
226                                                 aRec.node_labels[8],
227                                                 aRec.node_labels[11],
228                                                 aRec.node_labels[10],
229                                                 aRec.node_labels[9],
230                                                 aLabel);
231             break;
232
233           case 114: // pyramid of 13 nodes (quadratic) - PIRA13
234             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
235                                                 aRec.node_labels[3],
236                                                 aRec.node_labels[2],
237                                                 aRec.node_labels[1],
238                                                 aRec.node_labels[4],
239                                                 aRec.node_labels[8],
240                                                 aRec.node_labels[7],
241                                                 aRec.node_labels[6],
242                                                 aRec.node_labels[5],
243                                                 aRec.node_labels[9],
244                                                 aRec.node_labels[12],
245                                                 aRec.node_labels[11],
246                                                 aRec.node_labels[10],
247                                                 aLabel);
248             break;
249
250           }
251         }
252         //      if(!anElement)
253         //        MESSAGE("DriverUNV_R_SMDS_Mesh::Perform - can not add element with ID = "<<aLabel<<" and type = "<<aRec.fe_descriptor_id);
254       }
255     }
256     {
257       using namespace UNV2417;      
258       in_stream.seekg(0);
259       TDataSet aDataSet2417;
260       UNV2417::Read(in_stream,aDataSet2417);
261       if(MYDEBUG) MESSAGE("Perform - aDataSet2417.size() = "<<aDataSet2417.size());
262       if  (aDataSet2417.size() > 0) {
263         myGroup = new SMDS_MeshGroup(myMesh);
264         TDataSet::const_iterator anIter = aDataSet2417.begin();
265         for(; anIter != aDataSet2417.end(); anIter++){
266           const TGroupId& aLabel = anIter->first;
267           const TRecord& aRec = anIter->second;
268           //SMDS_MeshGroup* aNewGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Edge);
269           //myGroupNames.insert(TGroupNamesMap::value_type(aNewGroup, aRec.GroupName));
270           //myGroupId.insert(TGroupIdMap::value_type(aNewGroup, aLabel));
271
272           int aNodesNb = aRec.NodeList.size();
273           int i;
274           if (aNodesNb > 0) {
275             SMDS_MeshGroup* aNodesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Node);
276             std::string aGrName = aRec.GroupName + "_Nodes";
277             myGroupNames.insert(TGroupNamesMap::value_type(aNodesGroup, aGrName));
278             myGroupId.insert(TGroupIdMap::value_type(aNodesGroup, aLabel));
279
280             for (i = 0; i < aNodesNb; i++) {
281               const SMDS_MeshNode* aNode = myMesh->FindNode(aRec.NodeList[i]);
282               if (aNode)
283                 aNodesGroup->Add(aNode);
284             }
285           }
286           int aElementsNb = aRec.ElementList.size();
287           if (aElementsNb > 0){
288             SMDS_MeshGroup* aEdgesGroup = 0;
289             SMDS_MeshGroup* aFacesGroup = 0;
290
291             for (i = 0; i < aElementsNb; i++) {
292               const SMDS_MeshElement* aElement = myMesh->FindElement(aRec.ElementList[i]);
293               if (aElement) {
294                 switch (aElement->GetType()) {
295                 case SMDSAbs_Edge:
296                   if (!aEdgesGroup) {
297                     aEdgesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Edge);
298                     std::string aEdgesGrName = aRec.GroupName + "_Edges";
299                     myGroupNames.insert(TGroupNamesMap::value_type(aEdgesGroup, aEdgesGrName));
300                     myGroupId.insert(TGroupIdMap::value_type(aEdgesGroup, aLabel));
301                   }
302                   aEdgesGroup->Add(aElement);
303                   break;
304                 case SMDSAbs_Face:
305                   if (!aFacesGroup) {
306                     aFacesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Face);
307                     std::string aFacesGrName = aRec.GroupName + "_Faces";
308                     myGroupNames.insert(TGroupNamesMap::value_type(aFacesGroup, aFacesGrName));
309                     myGroupId.insert(TGroupIdMap::value_type(aFacesGroup, aLabel));
310                   }
311                   aFacesGroup->Add(aElement);
312                   break;
313                 }
314               }
315             }
316           }
317         }
318       }
319     }
320   }
321   catch(const std::exception& exc){
322     INFOS("Follow exception was cought:\n\t"<<exc.what());
323   }
324   catch(...){
325     INFOS("Unknown exception was cought !!!");
326   }
327   return aResult;
328 }