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