Salome HOME
Merge from V6_main 01/04/2013
[modules/med.git] / src / MEDMEMBinTest / tests / testUCellModel.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  File   : testUCellModel.cxx
21 //  Module : MED
22 //
23 #include <set>
24 #include <cstdlib> 
25 #include "MEDMEM_Utilities.hxx"
26
27 #include "MEDMEM_CellModel.hxx"
28 #include "MEDMEM_define.hxx"
29 #include "MEDMEM_DriversDef.hxx"
30
31 using namespace std;
32 using namespace MEDMEM;
33 using namespace MED_EN;
34
35 #define MED_NBR_GEOMETRIE_MAILLE 15
36
37 static void usage(char * name)
38 {
39   cout << "    " << name << endl;
40 }
41
42 int main (int argc, char ** argv)
43 {
44
45   if (argc < 1) usage(argv[0]);
46
47
48   cout << "CELLMODEL Test" << endl ;
49   cout << "--------------" << endl;
50
51   /*    -----------------------------------------------------
52         Construction de tous les types de cellmodel possibles
53         -----------------------------------------------------
54   */
55
56   CELLMODEL * tous  =new CELLMODEL[MED_NBR_GEOMETRIE_MAILLE ];
57   const medGeometryElement  allCellType[MED_NBR_GEOMETRIE_MAILLE ]=
58     {MED_POINT1, MED_SEG2,    MED_SEG3,   MED_TRIA3,
59      MED_QUAD4,  MED_TRIA6,   MED_QUAD8,  MED_TETRA4,
60      MED_PYRA5,  MED_PENTA6,  MED_HEXA8,  MED_TETRA10,
61      MED_PYRA13, MED_PENTA15, MED_HEXA20 };
62
63   for (int i=0; i<MED_NBR_GEOMETRIE_MAILLE ; i++)
64     {
65       tous[i]=CELLMODEL(allCellType[i]);
66     }
67
68   /*    -----------------------------------------------------
69         Boucle sur  tous les types de cellmodel possibles
70         - Chaque Méthode de cellmodel est appelee
71         -----------------------------------------------------
72   */
73   for (int i=0; i<MED_NBR_GEOMETRIE_MAILLE ; i++)
74     {
75       cout << endl;
76       cout << geoNames[tous[i].getType()] << endl;
77       cout << "__________________"  << endl;
78
79       try 
80         {
81           cout << "CellModel de Nom : " << tous[i].getName() << endl;
82         }
83       catch ( const std::exception &e )
84         {
85           cout << "-------------------------------" << endl;
86           cout << "     Pb au getName()         " << endl;
87           cout << "-------------------------------" << endl;
88           MESSAGE_MED( "catched exception : " << e.what() ) ;
89           return EXIT_FAILURE ;
90         }
91       catch (...)
92         {
93           cout << "-------------------------------" << endl;
94           cout << "     Pb au getName()         " << endl;
95           cout << "-------------------------------" << endl;
96           return EXIT_FAILURE ;
97         };
98
99       try 
100         {
101           cout << "Nb de Vertexes   : " << tous[i].getNumberOfVertexes() << endl;
102         }
103       catch ( const std::exception &e )
104         {
105           cout << "-------------------------------" << endl;
106           cout << "     Pb au getNumberOfVertexes()     " << endl;
107           cout << "-------------------------------" << endl;
108           MESSAGE_MED( "catched exception : " << e.what() ) ;
109           return EXIT_FAILURE ;
110         }
111       catch (...)
112         {
113           cout << "---------------------------------------" << endl;
114           cout << "     Pb au getNumberOfVertexes()     " << endl;
115           cout << "---------------------------------------" << endl;
116           return EXIT_FAILURE ;
117         };
118
119       try 
120         {
121           cout << "Nb de Noeuds     : " << tous[i].getNumberOfNodes() << endl;
122         }
123       catch ( const std::exception &e )
124         {
125           cout << "-------------------------------" << endl;
126           cout << "     Pb au getNumberOfNodes()  " << endl;
127           cout << "-------------------------------" << endl;
128           MESSAGE_MED( "catched exception : " << e.what() ) ;
129           return EXIT_FAILURE ;
130         }
131       catch (...)
132         {
133           cout << "---------------------------------" << endl;
134           cout << "     Pb au getNumberOfNodes()  " << endl;
135           cout << "---------------------------------" << endl;
136           return EXIT_FAILURE ;
137         };
138
139       int dimension;
140       try 
141         {
142           dimension=tous[i].getDimension();
143           cout << "Dimension        : " << dimension << endl;   
144         }
145       catch ( const std::exception &e )
146         {
147           cout << "-------------------------------" << endl;
148           cout << "     Pb au getDimension()    " << endl;
149           cout << "-------------------------------" << endl;
150           MESSAGE_MED( "catched exception : " << e.what() ) ;
151           return EXIT_FAILURE ;
152         }
153       catch (...)
154         {
155           cout << "-------------------------------" << endl;
156           cout << "     Pb au getDimension()    " << endl;
157           cout << "-------------------------------" << endl;
158           return EXIT_FAILURE ;
159         }
160
161       for (int dim=1; dim< dimension; dim++)
162         {
163           cout << "Nb d elements de dimension " << dim << " : ";
164
165           try
166             {
167               cout << tous[i].getNumberOfConstituents(dim)<< endl;
168             }
169           catch ( const std::exception &e )
170             {
171               cout << "------------------------------------" << endl;
172               cout << "  Pb au getNumberOfConstituents()   " << endl;
173               cout << "------------------------------------" << endl;
174               MESSAGE_MED( "catched exception : " << e.what() ) ;
175               return EXIT_FAILURE ;
176             }
177           catch (...)
178             {
179               cout << "------------------------------------" << endl;
180               cout << "  Pb au getNumberOfConstituents()   " << endl;
181               cout << "------------------------------------" << endl;
182               return EXIT_FAILURE ;
183             };
184         }
185 /*
186
187                 try
188                 {
189                         int** v1=tous[i].getConstituents(dim2);
190                         if ( v1.size() != tous[i].getNumberOfConstituents(dim2) )
191                         {
192                                 cout << "----------------------------" << endl;
193                                 cout << "  Pb au getConstituents()   " << endl;
194                                 cout << "----------------------------" << endl;
195                         }
196                 }
197                 catch ( const std::exception &e )
198                 {
199                         cout << "-------------------------------" << endl;
200                         cout << "  Pb au getConstituents()   " << endl;
201                         cout << "-------------------------------" << endl;
202                         MESSAGE_MED( "catched exception : " << e.what() ) ;
203                         return EXIT_FAILURE ;
204                 }
205                 catch (...)
206                 {
207                         cout << "----------------------------" << endl;
208                         cout << "  Pb au getConstituents()   " << endl;
209                         cout << "----------------------------" << endl;
210                         return EXIT_FAILURE ;
211                 };
212
213                 cout << "Types de ces elements " << endl; 
214
215                 set <medGeometryElement> setGeomElt;
216                 medGeometryElement * vt;
217                 int taille;
218                 try
219                 {
220                         vt=tous[i].getConstituentsType(dim2); 
221                         taille=tous[i].getNumberOfConstituents(dim2);
222                 }
223                 catch ( const std::exception &e )
224                 {
225                         cout << "-------------------------------" << endl;
226                         cout << "  Pb au getConstituentsType()   " << endl;
227                         cout << "-------------------------------" << endl;
228                         MESSAGE_MED( "catched exception : " << e.what() ) ;
229                         return EXIT_FAILURE ;
230                 }
231                 catch (...)
232                 {
233                         cout << "--------------------------------" << endl;
234                         cout << "  Pb au getConstituentsType()   " << endl;
235                         cout << "--------------------------------" << endl;
236                         return EXIT_FAILURE ;
237                 };
238                 for (int k=0; k<taille;k++)
239                 {
240                         try
241                         {
242                                 medGeometryElement me=tous[i].getConstituentType(dim2,k+1);
243                                 if  ( vt[k] != me )
244                                 {
245                                         cout << "-------------------------------" << endl;
246                                         cout << "  Pb au getConstituentType()   " << endl;
247                                         cout << "-------------------------------" << endl;
248                                 }
249                                 setGeomElt.insert(me);
250                         }
251                         catch ( const std::exception &e )
252                         {
253                                 cout << "-------------------------------" << endl;
254                                 cout << "  Pb au getConstituentType()   " << endl;
255                                 cout << "-------------------------------" << endl;
256                                 MESSAGE_MED( "catched exception : " << e.what() ) ;
257                                 return EXIT_FAILURE ;
258                         }
259                         catch (...)
260                         {
261                                 cout << "--------------------------------" << endl;
262                                 cout << "  Pb au getConstituentsType()   " << endl;
263                                 cout << "--------------------------------" << endl;
264                                 return EXIT_FAILURE ;
265                         }
266                 }
267 */
268 /*
269                 set <medGeometryElement>::iterator iter_s;
270                 for (iter_s=setGeomElt.begin() ;iter_s!=setGeomElt.end();iter_s++)
271                 {
272                         cout << geoNames[(*iter_s)] << endl;    
273                 }
274                 
275                 cout << "Impression des coordonnées du 1er Element de ce type" << endl;
276                 try
277                 {
278                         vector<int> v2=tous[i].getNodesConstituent(dim2,1); 
279                         for (int  k=0; k<v2.size();k++)
280                         {
281                                 cout << v2[k] << " ";
282                                 try
283                                 {
284                                         int verif=tous[i].getNodeConstituent(dim2,1,k+1);
285                                         if ( v2[k] != verif)
286                                         {
287                                                 cout << "-------------------------------" << endl;
288                                                 cout << "  Pb au getNodeConstituent()   " << endl;
289                                                 cout << "-------------------------------" << endl;
290                                         }
291                                 }
292                                 catch ( const std::exception &e )
293                                 {
294                                         cout << "-------------------------------" << endl;
295                                         cout << "  Pb au getNodeConstituent()   " << endl;
296                                         cout << "-------------------------------" << endl;
297                                         MESSAGE_MED( "catched exception : " << e.what() ) ;
298                                         return EXIT_FAILURE ;
299                                 }
300                                 catch (...)
301                                 {
302                                         cout << "-------------------------------" << endl;
303                                         cout << "  Pb au getNodeConstituent()   " << endl;
304                                         cout << "-------------------------------" << endl;
305                                         return EXIT_FAILURE ;
306                                 }
307                         }
308                         cout << endl;
309                 }
310                 catch ( const std::exception &e )
311                 {
312                         cout << "-------------------------------" << endl;
313                         cout << "  Pb au getNodeConstituent()    " << endl;
314                         cout << "-------------------------------" << endl;
315                         MESSAGE_MED( "catched exception : " << e.what() ) ;
316                         return EXIT_FAILURE ;
317                 }
318                 catch (...)
319                 {
320                         cout << "--------------------------------" << endl;
321                         cout << "  Pb au getNodeConstituent()    " << endl;
322                         cout << "--------------------------------" << endl;
323                         return EXIT_FAILURE ;
324                 }
325 */
326
327       cout << endl;
328 /*
329         if ( dimension > 1 )
330         {
331                 try
332                 {
333                         cout << "Informations particulieres -  dimension " << dimension - 1 << endl;
334                         set <medGeometryElement>::iterator iter_s;
335                         for (iter_s=tous[i].getAllConstituentsType().begin() ;
336                         iter_s!=tous[i].getAllConstituentsType().end();iter_s++)
337                         {
338                                 cout << geoNames[*iter_s] << endl;      
339                         }
340                 }
341                 catch ( const std::exception &e )
342                 {
343                         cout << "-------------------------------" << endl;
344                         cout << "  Pb au getAllConstituentsType()    " << endl;
345                         cout << "-------------------------------" << endl;
346                         MESSAGE_MED( "catched exception : " << e.what() ) ;
347                         return EXIT_FAILURE ;
348                 }
349                 catch (...)
350                 {
351                         cout << "------------------------------------" << endl;
352                         cout << "  Pb au getAllConstituentsType()    " << endl;
353                         cout << "------------------------------------" << endl;
354                         return EXIT_FAILURE ;
355                 }
356         }
357 */
358
359     }
360
361   delete[] tous ;
362
363   return EXIT_SUCCESS ;
364 /*
365   Reste a Tester
366   // Return number of constituents foreach type (which dimension is _dimension-1).
367   map <medGeometryElement,int>  getNumberOfConstituentsForeachType() const; 
368 */
369 }