Salome HOME
Final version of the V2_2_0 in the main trunk of the CVS tree.
[modules/med.git] / src / MEDMEM / tests / testUCellModel.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 //
21 //
22 //  File   : testUCellModel.cxx
23 //  Module : MED
24
25 #include <set>
26 #include <cstdlib> 
27 #include "utilities.h"
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 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( "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( "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( "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( "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                 int dim2=dimension - dim;
164                 cout << "Nb d elements de dimension " << dim << " : ";
165
166                 try
167                 {
168                         cout << tous[i].getNumberOfConstituents(dim)<< endl;
169                 }
170                 catch ( const std::exception &e )
171                 {
172                         cout << "------------------------------------" << endl;
173                         cout << "  Pb au getNumberOfConstituents()   " << endl;
174                         cout << "------------------------------------" << endl;
175                         MESSAGE( "catched exception : " << e.what() ) ;
176                         return EXIT_FAILURE ;
177                 }
178                 catch (...)
179                 {
180                         cout << "------------------------------------" << endl;
181                         cout << "  Pb au getNumberOfConstituents()   " << endl;
182                         cout << "------------------------------------" << endl;
183                         return EXIT_FAILURE ;
184                 };
185         }
186 /*
187
188                 try
189                 {
190                         int** v1=tous[i].getConstituents(dim2);
191                         if ( v1.size() != tous[i].getNumberOfConstituents(dim2) )
192                         {
193                                 cout << "----------------------------" << endl;
194                                 cout << "  Pb au getConstituents()   " << endl;
195                                 cout << "----------------------------" << endl;
196                         }
197                 }
198                 catch ( const std::exception &e )
199                 {
200                         cout << "-------------------------------" << endl;
201                         cout << "  Pb au getConstituents()   " << endl;
202                         cout << "-------------------------------" << endl;
203                         MESSAGE( "catched exception : " << e.what() ) ;
204                         return EXIT_FAILURE ;
205                 }
206                 catch (...)
207                 {
208                         cout << "----------------------------" << endl;
209                         cout << "  Pb au getConstituents()   " << endl;
210                         cout << "----------------------------" << endl;
211                         return EXIT_FAILURE ;
212                 };
213
214                 cout << "Types de ces elements " << endl; 
215
216                 set <medGeometryElement> setGeomElt;
217                 medGeometryElement * vt;
218                 int taille;
219                 try
220                 {
221                         vt=tous[i].getConstituentsType(dim2); 
222                         taille=tous[i].getNumberOfConstituents(dim2);
223                 }
224                 catch ( const std::exception &e )
225                 {
226                         cout << "-------------------------------" << endl;
227                         cout << "  Pb au getConstituentsType()   " << endl;
228                         cout << "-------------------------------" << endl;
229                         MESSAGE( "catched exception : " << e.what() ) ;
230                         return EXIT_FAILURE ;
231                 }
232                 catch (...)
233                 {
234                         cout << "--------------------------------" << endl;
235                         cout << "  Pb au getConstituentsType()   " << endl;
236                         cout << "--------------------------------" << endl;
237                         return EXIT_FAILURE ;
238                 };
239                 for (int k=0; k<taille;k++)
240                 {
241                         try
242                         {
243                                 medGeometryElement me=tous[i].getConstituentType(dim2,k+1);
244                                 if  ( vt[k] != me )
245                                 {
246                                         cout << "-------------------------------" << endl;
247                                         cout << "  Pb au getConstituentType()   " << endl;
248                                         cout << "-------------------------------" << endl;
249                                 }
250                                 setGeomElt.insert(me);
251                         }
252                         catch ( const std::exception &e )
253                         {
254                                 cout << "-------------------------------" << endl;
255                                 cout << "  Pb au getConstituentType()   " << endl;
256                                 cout << "-------------------------------" << endl;
257                                 MESSAGE( "catched exception : " << e.what() ) ;
258                                 return EXIT_FAILURE ;
259                         }
260                         catch (...)
261                         {
262                                 cout << "--------------------------------" << endl;
263                                 cout << "  Pb au getConstituentsType()   " << endl;
264                                 cout << "--------------------------------" << endl;
265                                 return EXIT_FAILURE ;
266                         }
267                 }
268 */
269 /*
270                 set <medGeometryElement>::iterator iter_s;
271                 for (iter_s=setGeomElt.begin() ;iter_s!=setGeomElt.end();iter_s++)
272                 {
273                         cout << geoNames[(*iter_s)] << endl;    
274                 }
275                 
276                 cout << "Impression des coordonnées du 1er Element de ce type" << endl;
277                 try
278                 {
279                         vector<int> v2=tous[i].getNodesConstituent(dim2,1); 
280                         for (int  k=0; k<v2.size();k++)
281                         {
282                                 cout << v2[k] << " ";
283                                 try
284                                 {
285                                         int verif=tous[i].getNodeConstituent(dim2,1,k+1);
286                                         if ( v2[k] != verif)
287                                         {
288                                                 cout << "-------------------------------" << endl;
289                                                 cout << "  Pb au getNodeConstituent()   " << endl;
290                                                 cout << "-------------------------------" << endl;
291                                         }
292                                 }
293                                 catch ( const std::exception &e )
294                                 {
295                                         cout << "-------------------------------" << endl;
296                                         cout << "  Pb au getNodeConstituent()   " << endl;
297                                         cout << "-------------------------------" << endl;
298                                         MESSAGE( "catched exception : " << e.what() ) ;
299                                         return EXIT_FAILURE ;
300                                 }
301                                 catch (...)
302                                 {
303                                         cout << "-------------------------------" << endl;
304                                         cout << "  Pb au getNodeConstituent()   " << endl;
305                                         cout << "-------------------------------" << endl;
306                                         return EXIT_FAILURE ;
307                                 }
308                         }
309                         cout << endl;
310                 }
311                 catch ( const std::exception &e )
312                 {
313                         cout << "-------------------------------" << endl;
314                         cout << "  Pb au getNodeConstituent()    " << endl;
315                         cout << "-------------------------------" << endl;
316                         MESSAGE( "catched exception : " << e.what() ) ;
317                         return EXIT_FAILURE ;
318                 }
319                 catch (...)
320                 {
321                         cout << "--------------------------------" << endl;
322                         cout << "  Pb au getNodeConstituent()    " << endl;
323                         cout << "--------------------------------" << endl;
324                         return EXIT_FAILURE ;
325                 }
326 */
327
328         cout << endl;
329 /*
330         if ( dimension > 1 )
331         {
332                 try
333                 {
334                         cout << "Informations particulieres -  dimension " << dimension - 1 << endl;
335                         set <medGeometryElement>::iterator iter_s;
336                         for (iter_s=tous[i].getAllConstituentsType().begin() ;
337                         iter_s!=tous[i].getAllConstituentsType().end();iter_s++)
338                         {
339                                 cout << geoNames[*iter_s] << endl;      
340                         }
341                 }
342                 catch ( const std::exception &e )
343                 {
344                         cout << "-------------------------------" << endl;
345                         cout << "  Pb au getAllConstituentsType()    " << endl;
346                         cout << "-------------------------------" << endl;
347                         MESSAGE( "catched exception : " << e.what() ) ;
348                         return EXIT_FAILURE ;
349                 }
350                 catch (...)
351                 {
352                         cout << "------------------------------------" << endl;
353                         cout << "  Pb au getAllConstituentsType()    " << endl;
354                         cout << "------------------------------------" << endl;
355                         return EXIT_FAILURE ;
356                 }
357         }
358 */
359
360   }
361
362   delete[] tous ;
363
364   return EXIT_SUCCESS ;
365 /*
366 Reste a Tester
367   // Return number of constituents foreach type (which dimension is _dimension-1).
368   map <medGeometryElement,int>  getNumberOfConstituentsForeachType() const; 
369 */
370 }