Salome HOME
Update copyrights 2014.
[modules/smesh.git] / src / DriverUNV / UNV2412_Structure.cxx
1 // Copyright (C) 2007-2014  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, or (at your option) any later version.
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   label(-1),
187   fe_descriptor_id(-1),
188   phys_prop_tab_num(2),
189   mat_prop_tab_num(1),
190   color(7),
191   beam_orientation(0),
192   beam_fore_end(1), // default values
193   beam_aft_end(1) // default values
194 {}
195
196 void UNV2412::Read(std::ifstream& in_stream, TDataSet& theDataSet)
197 {
198   if(!in_stream.good())
199     EXCEPTION(runtime_error,"ERROR: Input file not good.");
200
201   /*
202    * adjust the \p istream to our
203    * position
204    */
205   if(!beginning_of_dataset(in_stream,_label_dataset))
206     EXCEPTION(runtime_error,"ERROR: Could not find "<<_label_dataset<<" dataset!");
207
208   TRecord aRec;
209   while( !in_stream.eof())
210   {
211     in_stream >> aRec.label ;
212     if (aRec.label == -1)
213       // end of dataset is reached
214       break;
215     
216     int n_nodes;
217     in_stream>>aRec.fe_descriptor_id;
218     in_stream>>aRec.phys_prop_tab_num;
219     in_stream>>aRec.mat_prop_tab_num;
220     in_stream>>aRec.color;
221     in_stream>>n_nodes;
222
223     if(IsBeam(aRec.fe_descriptor_id)){
224       in_stream>>aRec.beam_orientation;
225       in_stream>>aRec.beam_fore_end;
226       in_stream>>aRec.beam_aft_end;
227     }
228
229     aRec.node_labels.resize(n_nodes);
230     for(int j=0; j < n_nodes; j++)
231       // read node labels
232       in_stream>>aRec.node_labels[j];             
233
234     theDataSet.push_back(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   {
254     const TRecord& aRec = *anIter;
255     out_stream<<std::setw(10)<<aRec.label;  /* 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     {
264       out_stream<<std::setw(10)<<aRec.beam_orientation;
265       out_stream<<std::setw(10)<<aRec.beam_fore_end;
266       out_stream<<std::setw(10)<<aRec.beam_aft_end<<std::endl;
267     }
268
269     int n_nodes = aRec.node_labels.size();
270     int iEnd = (n_nodes-1)/8 + 1;
271     for(int i = 0, k = 0; i < iEnd; i++){
272       int jEnd = n_nodes - 8*(i+1);
273       if(jEnd < 0) 
274         jEnd = 8 + jEnd;
275       else
276         jEnd = 8;
277       for(int j = 0; j < jEnd ; k++, j++){
278         out_stream<<std::setw(10)<<aRec.node_labels[k];
279       }
280       out_stream<<std::endl;
281     }
282   }
283
284   /*
285    * Write end of dataset
286    */
287   out_stream<<"    -1\n";
288 }
289
290
291 bool UNV2412::IsBeam(int theFeDescriptorId){
292   switch (theFeDescriptorId){
293   case 11: // edge with 2 nodes
294   case 21: 
295   case 22: // edge with 3 nodes
296   case 23: // curved beam
297   case 24:
298   case 25:
299     return true;
300   }
301   return false;
302 }
303
304
305 bool UNV2412::IsFace(int theFeDescriptorId){
306   return ( 41 <= theFeDescriptorId && theFeDescriptorId <= 96 );
307 //   switch (theFeDescriptorId){
308     
309 //   case 71: // TRI3
310 //   case 72:
311 //   case 74:
312
313 //   case 41: // Plane Stress Linear Triangle - TRI3
314 //   case 51: // Plane Strain Linear Triangle
315 //   case 91: // Thin Shell Linear Triangle - TRI3
316
317 //   case 42: // Plane Stress Quadratic Triangle - TRI6
318 //   case 52: // Plane Strain Parabolic Triangle
319 //   case 92: // Thin Shell Quadratic Triangle - TRI6
320
321 //   case 43: // Plane Stress Cubic Triangle
322
323 //   case 44: // Plane Stress Linear Quadrilateral - QUAD4
324 //   case 94: // Thin Shell   Linear Quadrilateral -  QUAD4
325
326 //   case 45: // Plane Stress Quadratic Quadrilateral - QUAD8
327 //   case 95: // Thin Shell   Quadratic Quadrilateral - QUAD8
328
329 //   case 46: // Plane Stress Cubic Quadrilateral
330
331 //     return true;
332 //   }
333 //  return false;
334 }
335
336
337 bool UNV2412::IsVolume(int theFeDescriptorId){
338   //if(!IsBeam(theFeDescriptorId) && !IsFace(theFeDescriptorId))
339   //  return true;
340   switch (theFeDescriptorId){
341
342   case 111: // Solid Linear Tetrahedron - TET4
343   case 118: // Solid Quadratic Tetrahedron - TET10
344
345   case 112: // Solid Linear Prism - PRISM6
346   case 113: // Solid Quadratic Prism - PRISM15
347
348   case 115: // Solid Linear Brick - HEX8
349   case 116: // Solid Quadratic Brick - HEX20
350
351   case 117: // Solid Cubic Brick
352
353   case 114: // pyramid of 13 nodes (quadratic)
354     return true;
355   }
356   return false;
357 }