Salome HOME
Copyrights update
[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
23 #include "utilities.h"
24
25 #include "UNV2411_Structure.hxx"
26 #include "UNV2412_Structure.hxx"
27 #include "UNV_Utilities.hxx"
28
29 using namespace std;
30
31
32 #ifdef _DEBUG_
33 static int MYDEBUG = 0;
34 #else
35 static int MYDEBUG = 0;
36 #endif
37
38
39 Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform()
40 {
41   Status aResult = DRS_OK;
42   std::ifstream in_stream(myFile.c_str());
43   try{
44     {
45       using namespace UNV2411;
46       TDataSet aDataSet2411;
47       UNV2411::Read(in_stream,aDataSet2411);
48       if(MYDEBUG) MESSAGE("Perform - aDataSet2411.size() = "<<aDataSet2411.size());
49       TDataSet::const_iterator anIter = aDataSet2411.begin();
50       for(; anIter != aDataSet2411.end(); anIter++){
51         const TNodeLab& aLabel = anIter->first;
52         const TRecord& aRec = anIter->second;
53         myMesh->AddNodeWithID(aRec.coord[0],aRec.coord[1],aRec.coord[2],aLabel);
54       }
55     }
56     {
57       using namespace UNV2412;
58       in_stream.seekg(0);
59       TDataSet aDataSet2412;
60       UNV2412::Read(in_stream,aDataSet2412);
61       TDataSet::const_iterator anIter = aDataSet2412.begin();
62       if(MYDEBUG) MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
63       for(; anIter != aDataSet2412.end(); anIter++){
64         SMDS_MeshElement* anElement = NULL;
65         const TElementLab& aLabel = anIter->first;
66         const TRecord& aRec = anIter->second;
67         if(IsBeam(aRec.fe_descriptor_id)){
68           anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
69                                             aRec.node_labels[1],
70                                             aLabel);
71         }else if(IsFace(aRec.fe_descriptor_id)){
72           switch(aRec.fe_descriptor_id){
73           case 71: // TRI3
74           case 72:
75           case 74:
76             
77           case 41: // Plane Stress Linear Triangle - TRI3
78           case 91: // Thin Shell Linear Triangle - TRI3
79             
80           case 42: // Plane Stress Quadratic Triangle - TRI6
81           case 92: // Thin Shell Quadratic Triangle - TRI6
82             
83             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
84                                               aRec.node_labels[1],
85                                               aRec.node_labels[2],
86                                               aLabel);
87             break;
88             
89           case 44: // Plane Stress Linear Quadrilateral - QUAD4
90           case 94: // Thin Shell   Linear Quadrilateral -  QUAD4
91             
92           case 45: // Plane Stress Quadratic Quadrilateral - QUAD8
93           case 95: // Thin Shell   Quadratic Quadrilateral - QUAD8
94             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
95                                               aRec.node_labels[1],
96                                               aRec.node_labels[2],
97                                               aRec.node_labels[3],
98                                               aLabel);
99             break;
100           }
101         }else if(IsVolume(aRec.fe_descriptor_id)){
102           switch(aRec.fe_descriptor_id){
103             
104           case 111: // Solid Linear Tetrahedron - TET4
105           case 118: // Solid Quadratic Tetrahedron - TET10
106             
107             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
108                                                 aRec.node_labels[2],
109                                                 aRec.node_labels[1],
110                                                 aRec.node_labels[3],
111                                                 aLabel);
112             break;
113             
114           case 112: // Solid Linear Prism - PRISM6
115             
116             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
117                                                 aRec.node_labels[2],
118                                                 aRec.node_labels[1],
119                                                 aRec.node_labels[3],
120                                                 aRec.node_labels[5],
121                                                 aRec.node_labels[4],
122                                                 aLabel);
123             break;
124             
125           case 113: // Solid Quadratic Prism - PRISM15
126             
127             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
128                                                 aRec.node_labels[4],
129                                                 aRec.node_labels[2],
130                                                 aRec.node_labels[9],
131                                                 aRec.node_labels[13],
132                                                 aRec.node_labels[11],
133                                                 aLabel);
134             break;
135             
136           case 115: // Solid Linear Brick - HEX8
137             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
138                                                 aRec.node_labels[3],
139                                                 aRec.node_labels[2],
140                                                 aRec.node_labels[1],
141                                                 aRec.node_labels[4],
142                                                 aRec.node_labels[7],
143                                                 aRec.node_labels[6],
144                                                 aRec.node_labels[5],
145                                                 aLabel);
146             break;
147
148           case 116: // Solid Quadratic Brick - HEX20
149             
150             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
151                                                 aRec.node_labels[6],
152                                                 aRec.node_labels[4],
153                                                 aRec.node_labels[2],
154                                                 aRec.node_labels[12],
155                                                 aRec.node_labels[18],
156                                                 aRec.node_labels[16],
157                                                 aRec.node_labels[14],
158                                                 aLabel);
159             break;
160           }
161         }
162         if(!anElement)
163           MESSAGE("DriverUNV_R_SMDS_Mesh::Perform - can not add element with ID = "<<aLabel<<" and type = "<<aRec.fe_descriptor_id);
164       }
165     }
166   }catch(const std::exception& exc){
167     INFOS("Follow exception was cought:\n\t"<<exc.what());
168   }catch(...){
169     INFOS("Unknown exception was cought !!!");
170   }
171   return aResult;
172 }