Salome HOME
Merge from V6_3_BR 06/06/2011
[modules/smesh.git] / src / DriverUNV / UNV2412_Structure.cxx
1 // Copyright (C) 2007-2011  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
23 #include <fstream>      
24 #include <iomanip>
25
26 #include "UNV2412_Structure.hxx"
27 #include "UNV_Utilities.hxx"
28
29 using namespace std;
30 using namespace UNV;
31 using namespace UNV2412;
32
33 // Universal Dataset Number 2412
34
35 // Name:   Elements
36 // Status: Current
37 // Owner:  Simulation
38 // Revision Date: 14-AUG-1992
39 // -----------------------------------------------------------------------
40  
41 // Record 1:        FORMAT(6I10)
42 //                  Field 1       -- element label
43 //                  Field 2       -- fe descriptor id
44 //                  Field 3       -- physical property table number
45 //                  Field 4       -- material property table number
46 //                  Field 5       -- color
47 //                  Field 6       -- number of nodes on element
48  
49 // Record 2:  *** FOR NON-BEAM ELEMENTS ***
50 //                  FORMAT(8I10)
51 //                  Fields 1-n    -- node labels defining element
52  
53 // Record 2:  *** FOR BEAM ELEMENTS ONLY ***
54 //                  FORMAT(3I10)
55 //                  Field 1       -- beam orientation node number
56 //                  Field 2       -- beam fore-end cross section number
57 //                  Field 3       -- beam  aft-end cross section number
58  
59 // Record 3:  *** FOR BEAM ELEMENTS ONLY ***
60 //                  FORMAT(8I10)
61 //                  Fields 1-n    -- node labels defining element
62  
63 // Records 1 and 2 are repeated for each non-beam element in the model.
64 // Records 1 - 3 are repeated for each beam element in the model.
65  
66 // Example:
67  
68 //     -1
69 //   2412
70 //          1        11         1      5380         7         2
71 //          0         1         1
72 //          1         2
73 //          2        21         2      5380         7         2
74 //          0         1         1
75 //          3         4
76 //          3        22         3      5380         7         2
77 //          0         1         2
78 //          5         6
79 //          6        91         6      5380         7         3
80 //         11        18        12
81 //          9        95         6      5380         7         8
82 //         22        25        29        30        31        26        24        23
83 //         14       136         8         0         7         2
84 //         53        54
85 //         36       116        16      5380         7        20
86 //        152       159       168       167       166       158       150       151
87 //        154       170       169       153       157       161       173       172
88 //        171       160       155       156
89 //     -1
90
91 // FE Descriptor Id definitions
92 // ____________________________
93
94 //    11  Rod
95 //    21  Linear beam
96 //    22  Tapered beam
97 //    23  Curved beam
98 //    24  Parabolic beam
99 //    31  Straight pipe
100 //    32  Curved pipe
101 //    41  Plane Stress Linear Triangle
102 //    42  Plane Stress Parabolic Triangle
103 //    43  Plane Stress Cubic Triangle
104 //    44  Plane Stress Linear Quadrilateral
105 //    45  Plane Stress Parabolic Quadrilateral
106 //    46  Plane Strain Cubic Quadrilateral
107 //    51  Plane Strain Linear Triangle
108 //    52  Plane Strain Parabolic Triangle
109 //    53  Plane Strain Cubic Triangle
110 //    54  Plane Strain Linear Quadrilateral
111 //    55  Plane Strain Parabolic Quadrilateral
112 //    56  Plane Strain Cubic Quadrilateral
113 //    61  Plate Linear Triangle
114 //    62  Plate Parabolic Triangle
115 //    63  Plate Cubic Triangle
116 //    64  Plate Linear Quadrilateral
117 //    65  Plate Parabolic Quadrilateral
118 //    66  Plate Cubic Quadrilateral
119 //    71  Membrane Linear Quadrilateral
120 //    72  Membrane Parabolic Triangle
121 //    73  Membrane Cubic Triangle
122 //    74  Membrane Linear Triangle
123 //    75  Membrane Parabolic Quadrilateral
124 //    76  Membrane Cubic Quadrilateral
125 //    81  Axisymetric Solid Linear Triangle
126 //    82  Axisymetric Solid Parabolic Triangle
127 //    84  Axisymetric Solid Linear Quadrilateral
128 //    85  Axisymetric Solid Parabolic Quadrilateral
129 //    91  Thin Shell Linear Triangle
130 //    92  Thin Shell Parabolic Triangle
131 //    93  Thin Shell Cubic Triangle
132 //    94  Thin Shell Linear Quadrilateral
133 //    95  Thin Shell Parabolic Quadrilateral
134 //    96  Thin Shell Cubic Quadrilateral
135 //    101 Thick Shell Linear Wedge
136 //    102 Thick Shell Parabolic Wedge
137 //    103 Thick Shell Cubic Wedge
138 //    104 Thick Shell Linear Brick
139 //    105 Thick Shell Parabolic Brick
140 //    106 Thick Shell Cubic Brick
141 //    111 Solid Linear Tetrahedron
142 //    112 Solid Linear Wedge
143 //    113 Solid Parabolic Wedge
144 //    114 Solid Cubic Wedge
145 //    115 Solid Linear Brick
146 //    116 Solid Parabolic Brick
147 //    117 Solid Cubic Brick
148 //    118 Solid Parabolic Tetrahedron
149 //    121 Rigid Bar
150 //    122 Rigid Element
151 //    136 Node To Node Translational Spring
152 //    137 Node To Node Rotational Spring
153 //    138 Node To Ground Translational Spring
154 //    139 Node To Ground Rotational Spring
155 //    141 Node To Node Damper
156 //    142 Node To Gound Damper
157 //    151 Node To Node Gap
158 //    152 Node To Ground Gap
159 //    161 Lumped Mass
160 //    171 Axisymetric Linear Shell
161 //    172 Axisymetric Parabolic Shell
162 //    181 Constraint
163 //    191 Plastic Cold Runner
164 //    192 Plastic Hot Runner
165 //    193 Plastic Water Line
166 //    194 Plastic Fountain
167 //    195 Plastic Baffle
168 //    196 Plastic Rod Heater
169 //    201 Linear node-to-node interface
170 //    202 Linear edge-to-edge interface
171 //    203 Parabolic edge-to-edge interface
172 //    204 Linear face-to-face interface
173 //    208 Parabolic face-to-face interface
174 //    212 Linear axisymmetric interface
175 //    213 Parabolic axisymmetric interface
176 //    221 Linear rigid surface
177 //    222 Parabolic rigin surface
178 //    231 Axisymetric linear rigid surface
179 //    232 Axisymentric parabolic rigid surface
180
181
182
183 static string _label_dataset = "2412";
184
185 UNV2412::TRecord::TRecord():
186   phys_prop_tab_num(2),
187   mat_prop_tab_num(1),
188   color(7),
189   beam_orientation(0),
190   beam_fore_end(0),
191   beam_aft_end(0)
192 {}
193
194 void UNV2412::Read(std::ifstream& in_stream, TDataSet& theDataSet)
195 {
196   if(!in_stream.good())
197     EXCEPTION(runtime_error,"ERROR: Input file not good.");
198
199   /*
200    * adjust the \p istream to our
201    * position
202    */
203   if(!beginning_of_dataset(in_stream,_label_dataset))
204     EXCEPTION(runtime_error,"ERROR: Could not find "<<_label_dataset<<" dataset!");
205
206   TElementLab aLabel;
207   for(; !in_stream.eof();){
208     in_stream >> aLabel ;
209     if(aLabel == -1){
210       // end of dataset is reached
211       break;
212     }
213     
214     int n_nodes;
215     TRecord aRec;
216     in_stream>>aRec.fe_descriptor_id;
217     in_stream>>aRec.phys_prop_tab_num;
218     in_stream>>aRec.mat_prop_tab_num;
219     in_stream>>aRec.color;
220     in_stream>>n_nodes;
221
222     if(IsBeam(aRec.fe_descriptor_id)){
223       in_stream>>aRec.beam_orientation;
224       in_stream>>aRec.beam_fore_end;
225       in_stream>>aRec.beam_aft_end;
226     }
227
228     aRec.node_labels.resize(n_nodes);
229     for(int j=0; j < n_nodes; j++){
230       // read node labels
231       in_stream>>aRec.node_labels[j];             
232     }
233
234     theDataSet.insert(TDataSet::value_type(aLabel,aRec));
235   }
236
237 }
238
239
240 void UNV2412::Write(std::ofstream& out_stream, const TDataSet& theDataSet)
241 {
242   if(!out_stream.good())
243     EXCEPTION(runtime_error,"ERROR: Output file not good.");
244   
245   /*
246    * Write beginning of dataset
247    */
248   out_stream<<"    -1\n";
249   out_stream<<"  "<<_label_dataset<<"\n";
250
251   TDataSet::const_iterator anIter = theDataSet.begin();
252   for(; anIter != theDataSet.end(); anIter++){
253     const TElementLab& aLabel = anIter->first;
254     const TRecord& aRec = anIter->second;
255     out_stream<<std::setw(10)<<aLabel;  /* element ID */
256     out_stream<<std::setw(10)<<aRec.fe_descriptor_id;  /* type of element */
257     out_stream<<std::setw(10)<<aRec.phys_prop_tab_num;
258     out_stream<<std::setw(10)<<aRec.mat_prop_tab_num;
259     out_stream<<std::setw(10)<<aRec.color;
260     out_stream<<std::setw(10)<<aRec.node_labels.size()<<std::endl;  /* No. of nodes per element */
261
262     if(IsBeam(aRec.fe_descriptor_id)){
263       out_stream<<std::setw(10)<<aRec.beam_orientation;
264       out_stream<<std::setw(10)<<aRec.beam_fore_end;
265       out_stream<<std::setw(10)<<aRec.beam_aft_end<<std::endl;
266     }
267
268     int n_nodes = aRec.node_labels.size();
269     int iEnd = (n_nodes-1)/8 + 1;
270     for(int i = 0, k = 0; i < iEnd; i++){
271       int jEnd = n_nodes - 8*(i+1);
272       if(jEnd < 0) 
273         jEnd = 8 + jEnd;
274       else
275         jEnd = 8;
276       for(int j = 0; j < jEnd ; k++, j++){
277         out_stream<<std::setw(10)<<aRec.node_labels[k];
278       }
279       out_stream<<std::endl;
280     }
281   }
282
283   /*
284    * Write end of dataset
285    */
286   out_stream<<"    -1\n";
287 }
288
289
290 bool UNV2412::IsBeam(int theFeDescriptorId){
291   switch (theFeDescriptorId){
292   case 11: // edge with 2 nodes
293   case 21: 
294   case 22: // edge with 3 nodes
295   case 23: // curved beam
296   case 24:
297   case 25:
298     return true;
299   }
300   return false;
301 }
302
303
304 bool UNV2412::IsFace(int theFeDescriptorId){
305   return ( 41 <= theFeDescriptorId && theFeDescriptorId <= 96 );
306 //   switch (theFeDescriptorId){
307     
308 //   case 71: // TRI3
309 //   case 72:
310 //   case 74:
311
312 //   case 41: // Plane Stress Linear Triangle - TRI3
313 //   case 51: // Plane Strain Linear Triangle
314 //   case 91: // Thin Shell Linear Triangle - TRI3
315
316 //   case 42: // Plane Stress Quadratic Triangle - TRI6
317 //   case 52: // Plane Strain Parabolic Triangle
318 //   case 92: // Thin Shell Quadratic Triangle - TRI6
319
320 //   case 43: // Plane Stress Cubic Triangle
321
322 //   case 44: // Plane Stress Linear Quadrilateral - QUAD4
323 //   case 94: // Thin Shell   Linear Quadrilateral -  QUAD4
324
325 //   case 45: // Plane Stress Quadratic Quadrilateral - QUAD8
326 //   case 95: // Thin Shell   Quadratic Quadrilateral - QUAD8
327
328 //   case 46: // Plane Stress Cubic Quadrilateral
329
330 //     return true;
331 //   }
332 //  return false;
333 }
334
335
336 bool UNV2412::IsVolume(int theFeDescriptorId){
337   //if(!IsBeam(theFeDescriptorId) && !IsFace(theFeDescriptorId))
338   //  return true;
339   switch (theFeDescriptorId){
340
341   case 111: // Solid Linear Tetrahedron - TET4
342   case 118: // Solid Quadratic Tetrahedron - TET10
343
344   case 112: // Solid Linear Prism - PRISM6
345   case 113: // Solid Quadratic Prism - PRISM15
346
347   case 115: // Solid Linear Brick - HEX8
348   case 116: // Solid Quadratic Brick - HEX20
349
350   case 117: // Solid Cubic Brick
351
352   case 114: // pyramid of 13 nodes (quadratic)
353     return true;
354   }
355   return false;
356 }