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