Salome HOME
Merge with version on tag OCC-V2_1_0d
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
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:
146   case 21:
147   case 22:
148   case 24:
149   case 25:
150     return true;
151   }
152   return false;
153 }
154
155
156 bool UNV2412::IsFace(int theFeDescriptorId){
157   switch (theFeDescriptorId){
158     
159   case 71: // TRI3
160   case 72:
161   case 74:
162
163   case 41: // Plane Stress Linear Triangle - TRI3
164   case 91: // Thin Shell Linear Triangle - TRI3
165
166   case 42: // Plane Stress Quadratic Triangle - TRI6
167   case 92: // Thin Shell Quadratic Triangle - TRI6
168
169   case 43: // Plane Stress Cubic Triangle
170
171   case 44: // Plane Stress Linear Quadrilateral - QUAD4
172   case 94: // Thin Shell   Linear Quadrilateral -  QUAD4
173
174   case 45: // Plane Stress Quadratic Quadrilateral - QUAD8
175   case 95: // Thin Shell   Quadratic Quadrilateral - QUAD8
176
177   case 46: // Plane Stress Cubic Quadrilateral
178
179     return true;
180   }
181   return false;
182 }
183
184
185 bool UNV2412::IsVolume(int theFeDescriptorId){
186   //if(!IsBeam(theFeDescriptorId) && !IsFace(theFeDescriptorId))
187   //  return true;
188   switch (theFeDescriptorId){
189
190   case 111: // Solid Linear Tetrahedron - TET4
191   case 118: // Solid Quadratic Tetrahedron - TET10
192
193   case 112: // Solid Linear Prism - PRISM6
194   case 113: // Solid Quadratic Prism - PRISM15
195
196   case 115: // Solid Linear Brick - HEX8
197   case 116: // Solid Quadratic Brick - HEX20
198
199   case 117: // Solid Cubic Brick
200     return true;
201   }
202   return false;
203 }