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