Salome HOME
Fix bug 12796: Warning missed for the bad file 'test18.med'
[modules/smesh.git] / src / DriverUNV / UNV2412_Structure.cxx
1 //  Copyright (C) 2003  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/ or email : webmaster.salome@opencascade.com
19
20 #include <fstream>      
21 #include <iomanip>
22
23 #include "UNV2412_Structure.hxx"
24 #include "UNV_Utilities.hxx"
25
26 using namespace std;
27 using namespace UNV;
28 using namespace UNV2412;
29
30 #ifdef _DEBUG_
31 static int MYDEBUG = 1;
32 #else
33 static int MYDEBUG = 0;
34 #endif
35
36 static string _label_dataset = "2412";
37
38 UNV2412::TRecord::TRecord():
39   phys_prop_tab_num(2),
40   mat_prop_tab_num(1),
41   color(7),
42   beam_orientation(0),
43   beam_fore_end(0),
44   beam_aft_end(0)
45 {}
46
47 void UNV2412::Read(std::ifstream& in_stream, TDataSet& theDataSet)
48 {
49   if(!in_stream.good())
50     EXCEPTION(runtime_error,"ERROR: Input file not good.");
51
52   /*
53    * adjust the \p istream to our
54    * position
55    */
56   if(!beginning_of_dataset(in_stream,_label_dataset))
57     EXCEPTION(runtime_error,"ERROR: Could not find "<<_label_dataset<<" dataset!");
58
59   TElementLab aLabel;
60   for(; !in_stream.eof();){
61     in_stream >> aLabel ;
62     if(aLabel == -1){
63       // end of dataset is reached
64       break;
65     }
66     
67     int n_nodes;
68     TRecord aRec;
69     in_stream>>aRec.fe_descriptor_id;
70     in_stream>>aRec.phys_prop_tab_num;
71     in_stream>>aRec.mat_prop_tab_num;
72     in_stream>>aRec.color;
73     in_stream>>n_nodes;
74
75     if(IsBeam(aRec.fe_descriptor_id)){
76       in_stream>>aRec.beam_orientation;
77       in_stream>>aRec.beam_fore_end;
78       in_stream>>aRec.beam_aft_end;
79     }
80
81     aRec.node_labels.resize(n_nodes);
82     for(int j=0; j < n_nodes; j++){
83       // read node labels
84       in_stream>>aRec.node_labels[j];             
85     }
86
87     theDataSet.insert(TDataSet::value_type(aLabel,aRec));
88   }
89
90 }
91
92
93 void UNV2412::Write(std::ofstream& out_stream, const TDataSet& theDataSet)
94 {
95   if(!out_stream.good())
96     EXCEPTION(runtime_error,"ERROR: Output file not good.");
97   
98   /*
99    * Write beginning of dataset
100    */
101   out_stream<<"    -1\n";
102   out_stream<<"  "<<_label_dataset<<"\n";
103
104   TDataSet::const_iterator anIter = theDataSet.begin();
105   for(; anIter != theDataSet.end(); anIter++){
106     const TElementLab& aLabel = anIter->first;
107     const TRecord& aRec = anIter->second;
108     out_stream<<std::setw(10)<<aLabel;  /* element ID */
109     out_stream<<std::setw(10)<<aRec.fe_descriptor_id;  /* type of element */
110     out_stream<<std::setw(10)<<aRec.phys_prop_tab_num;
111     out_stream<<std::setw(10)<<aRec.mat_prop_tab_num;
112     out_stream<<std::setw(10)<<aRec.color;
113     out_stream<<std::setw(10)<<aRec.node_labels.size()<<std::endl;  /* No. of nodes per element */
114
115     if(IsBeam(aRec.fe_descriptor_id)){
116       out_stream<<std::setw(10)<<aRec.beam_orientation;
117       out_stream<<std::setw(10)<<aRec.beam_fore_end;
118       out_stream<<std::setw(10)<<aRec.beam_aft_end<<std::endl;
119     }
120
121     int n_nodes = aRec.node_labels.size();
122     int iEnd = (n_nodes-1)/8 + 1;
123     for(int i = 0, k = 0; i < iEnd; i++){
124       int jEnd = n_nodes - 8*(i+1);
125       if(jEnd < 0) 
126         jEnd = 8 + jEnd;
127       else
128         jEnd = 8;
129       for(int j = 0; j < jEnd ; k++, j++){
130         out_stream<<std::setw(10)<<aRec.node_labels[k];
131       }
132       out_stream<<std::endl;
133     }
134   }
135
136   /*
137    * Write end of dataset
138    */
139   out_stream<<"    -1\n";
140 }
141
142
143 bool UNV2412::IsBeam(int theFeDescriptorId){
144   switch (theFeDescriptorId){
145   case 11: // edge with 2 nodes
146   case 21: 
147   case 22: // edge with 3 nodes
148   case 23: // curved beam
149   case 24:
150   case 25:
151     return true;
152   }
153   return false;
154 }
155
156
157 bool UNV2412::IsFace(int theFeDescriptorId){
158   switch (theFeDescriptorId){
159     
160   case 71: // TRI3
161   case 72:
162   case 74:
163
164   case 41: // Plane Stress Linear Triangle - TRI3
165   case 91: // Thin Shell Linear Triangle - TRI3
166
167   case 42: // Plane Stress Quadratic Triangle - TRI6
168   case 92: // Thin Shell Quadratic Triangle - TRI6
169
170   case 43: // Plane Stress Cubic Triangle
171
172   case 44: // Plane Stress Linear Quadrilateral - QUAD4
173   case 94: // Thin Shell   Linear Quadrilateral -  QUAD4
174
175   case 45: // Plane Stress Quadratic Quadrilateral - QUAD8
176   case 95: // Thin Shell   Quadratic Quadrilateral - QUAD8
177
178   case 46: // Plane Stress Cubic Quadrilateral
179
180     return true;
181   }
182   return false;
183 }
184
185
186 bool UNV2412::IsVolume(int theFeDescriptorId){
187   //if(!IsBeam(theFeDescriptorId) && !IsFace(theFeDescriptorId))
188   //  return true;
189   switch (theFeDescriptorId){
190
191   case 111: // Solid Linear Tetrahedron - TET4
192   case 118: // Solid Quadratic Tetrahedron - TET10
193
194   case 112: // Solid Linear Prism - PRISM6
195   case 113: // Solid Quadratic Prism - PRISM15
196
197   case 115: // Solid Linear Brick - HEX8
198   case 116: // Solid Quadratic Brick - HEX20
199
200   case 117: // Solid Cubic Brick
201
202   case 114: // pyramid of 13 nodes (quadratic)
203     return true;
204   }
205   return false;
206 }