Salome HOME
Merging with the MAN_SALOME2 branch
[modules/med.git] / src / MEDMEM / tests / testUCoordinate.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   : testUCoordinate.cxx
23 //  Module : MED
24
25 using namespace std;
26 #include <cstdlib>
27 #include <cmath>
28 #include "utilities.h"
29
30 #include "MEDMEM_define.hxx"
31 #include "MEDMEM_Array.hxx"
32 #include "MEDMEM_Coordinate.hxx"
33 #include <string> 
34 using namespace MEDMEM;
35
36 void usage(char * name)
37 {
38   cout << "    " << name << endl;
39 }
40
41 int main (int argc, char ** argv)
42 {
43  
44
45   if (argc < 1) usage(argv[0]);
46
47   const double pouieme = 0.009; 
48
49   cout << "COORDINATE Test" << endl;
50   cout << "---------------" << endl;
51
52   int SpaceDim = 3;
53   int NbOfNodes = 5;
54
55   string * noms = new string[3];
56   noms[0]=" X ";
57   noms[1]=" Y ";
58   noms[2]=" Z ";
59
60   string  units[3];
61   units[0]=" m ";
62   units[1]=" m ";
63   units[2]=" m ";
64
65   int * numbers=new int[5];
66   for (int i=0; i< 5; i++) numbers[i] =10+i;
67
68   MED_EN::medModeSwitch ModeFull=MED_EN::MED_FULL_INTERLACE;
69   MED_EN::medModeSwitch ModeNo=MED_EN::MED_NO_INTERLACE;
70   double coor[15] = {0,0,0,0,0,1,0,1,0,1,0,0,0.5,0.5,0.5} ;
71   ASSERT(SpaceDim*NbOfNodes == 15);
72
73
74   cout << "      - mode : MED_FULL_INTERLACE"  << endl;
75   cout << "      - dimension de l espace : " << SpaceDim << endl;
76   cout << "      - nombre de noeuds : " << NbOfNodes << endl;
77   
78   double * coor1 = new  double[SpaceDim*NbOfNodes];
79   for( int k=0 ; k<SpaceDim*NbOfNodes ; k++ ) 
80         coor1[k] = coor[k] ;
81
82   MEDARRAY<double>* CoordinateArray = new MEDARRAY<double>(coor1,SpaceDim,NbOfNodes,ModeFull);
83   COORDINATE mycoo;
84   try
85   {
86         mycoo.setCoordinates(CoordinateArray);
87   }
88   catch ( const std::exception &e )
89   {
90         cout << "-------------------------------" << endl;
91         cout << "pb avec setCoordinates" << endl;
92         cout << "-------------------------------" << endl;
93         MESSAGE( "catched exception : " << e.what() ) ;
94         return EXIT_FAILURE ;
95   }
96   catch (...)
97   {
98         cout << "-------------------------------" << endl;
99         cout << "pb avec setCoordinates" << endl;
100         cout << "-------------------------------" << endl;
101         return EXIT_FAILURE ;
102   };
103
104   //--------------------------------------------------------------------//
105   //                    Tests des methodes                              //
106   //                                                                    //
107   // - setCoordinatesNames                                              //
108   // - setCoordinatesUnits                                              //
109   // - setCoordinatesSystem                                             //
110   // - setNodesNumbers                                                  //
111   //                                                                    //
112   //--------------------------------------------------------------------//
113   try
114   {
115         mycoo.setCoordinatesNames(noms);
116   }
117   catch ( const std::exception &e )
118   {
119         cout << "-------------------------------" << endl;
120         cout << "pb avec setCoordinatesNames" << endl;
121         cout << "-------------------------------" << endl;
122         MESSAGE( "catched exception : " << e.what() ) ;
123         return EXIT_FAILURE ;
124   }
125   catch (...)
126   {
127         cout << "-------------------------------" << endl;
128         cout << "pb avec setCoordinatesNames" << endl;
129         cout << "-------------------------------" << endl;
130         return EXIT_FAILURE ;
131   };
132
133   try
134   {
135         mycoo.setCoordinatesUnits(units);
136   }
137   catch ( const std::exception &e )
138   {
139         cout << "-------------------------------" << endl;
140         cout << "pb avec setCoordinatesUnits" << endl;
141         cout << "-------------------------------" << endl;
142         MESSAGE( "catched exception : " << e.what() ) ;
143         return EXIT_FAILURE ;
144   }
145   catch (...)
146   {
147         cout << "-------------------------------" << endl;
148         cout << "pb avec setCoordinatesUnits" << endl;
149         cout << "-------------------------------" << endl;
150         return EXIT_FAILURE ;
151   };
152
153   try
154   {
155         mycoo.setCoordinatesSystem("cartesien");
156   }
157   catch ( const std::exception &e )
158   {
159         cout << "-------------------------------" << endl;
160         cout << "pb avec setCoordinatesSystem" << endl;
161         cout << "-------------------------------" << endl;
162         MESSAGE( "catched exception : " << e.what() ) ;
163         return EXIT_FAILURE ;
164   }
165   catch (...)
166   {
167         cout << "-------------------------------" << endl;
168         cout << "pb avec setCoordinatesSystem" << endl;
169         cout << "-------------------------------" << endl;
170         return EXIT_FAILURE ;
171   };
172
173   try
174   {
175         mycoo.setNodesNumbers(numbers);
176   }
177   catch ( const std::exception &e )
178   {
179         cout << "-------------------------------" << endl;
180         cout << "pb avec setNodesNumbers" << endl;
181         cout << "-------------------------------" << endl;
182         MESSAGE( "catched exception : " << e.what() ) ;
183         return EXIT_FAILURE ;
184   }
185   catch (...)
186   {
187         cout << "-------------------------------" << endl;
188         cout << "pb avec setNodesNumbers" << endl;
189         cout << "-------------------------------" << endl;
190         return EXIT_FAILURE ;
191   };
192   
193   //--------------------------------------------------------------------//
194   //                    Tests des methodes                              //
195   //                                                                    //
196   // - getCoordinatesNames                                              //
197   // - getCoordinatesUnits                                              //
198   // - getCoordinatesUnit                                               //
199   // - getCoordinatesSystem                                             //
200   // - getNodesNumbers                                                  //
201   //                                                                    //
202   //--------------------------------------------------------------------//
203
204   cout << endl << " Relecture des Coordonnees" << endl << endl;
205
206   try
207   {
208         cout << "  Le systeme est : " << mycoo.getCoordinatesSystem() << endl;
209   }
210   catch ( const std::exception &e )
211   {
212         cout << "-------------------------------" << endl;
213         cout << "pb avec getCoordinatesSystem" << endl;
214         cout << "-------------------------------" << endl;
215         MESSAGE( "catched exception : " << e.what() ) ;
216         return EXIT_FAILURE ;
217   }
218   catch (...)
219   {
220         cout << "-------------------------------" << endl;
221         cout << "pb avec getCoordinatesSystem" << endl;
222         cout << "-------------------------------" << endl;
223         return EXIT_FAILURE ;
224   };
225
226   const string * units2;
227   try
228   {
229         units2=mycoo.getCoordinatesUnits();
230         for (int axe = 0; axe < SpaceDim; axe++)
231         {
232                 try
233                 {
234                         string  verif = mycoo.getCoordinateUnit(axe+1);
235                         if (verif != units2[axe]) 
236                                 cout << "Pb avec les noms des axes" << endl;
237                 }
238                 catch ( const std::exception &e )
239                 {
240                         cout << "-------------------------" << endl;
241                         cout << "pb avec getCoordinateUnit" << endl;
242                         cout << "-------------------------" << endl;
243                         MESSAGE( "catched exception : " << e.what() ) ;
244                         return EXIT_FAILURE ;
245                 }
246                 catch (...)
247                 {
248                         cout << "-------------------------" << endl;
249                         cout << "pb avec getCoordinateUnit" << endl;
250                         cout << "-------------------------" << endl;
251                         return EXIT_FAILURE ;
252                 };
253         }
254   }
255   catch ( const std::exception &e )
256   {
257         cout << "---------------------------" << endl;
258         cout << "pb avec getCoordinatesUnits" << endl;
259         cout << "---------------------------" << endl;
260         MESSAGE( "catched exception : " << e.what() ) ;
261         return EXIT_FAILURE ;
262   }
263   catch (...)
264   {
265         cout << "---------------------------" << endl;
266         cout << "pb avec getCoordinatesUnits" << endl;
267         cout << "---------------------------" << endl;
268         return EXIT_FAILURE ;
269   };
270
271   const string * noms2;
272   try
273   {
274         noms2=mycoo.getCoordinatesNames();
275         for (int axe = 0; axe < SpaceDim; axe++)
276         {
277                 try
278                 {
279                         string  verif = mycoo.getCoordinateName(axe+1);
280                         if (verif != noms2[axe]) 
281                                 cout << "Pb avec les noms des axes" << endl;
282                 }
283                 catch ( const std::exception &e )
284                 {
285                         cout << "-------------------------" << endl;
286                         cout << "pb avec getCoordinateName" << endl;
287                         cout << "-------------------------" << endl;
288                         MESSAGE( "catched exception : " << e.what() ) ;
289                         return EXIT_FAILURE ;
290                 }
291                 catch (...)
292                 {
293                         cout << "-------------------------" << endl;
294                         cout << "pb avec getCoordinateName" << endl;
295                         cout << "-------------------------" << endl;
296                         return EXIT_FAILURE ;
297                 };
298         }
299   }
300   catch ( const std::exception &e )
301   {
302         cout << "---------------------------" << endl;
303         cout << "pb avec getCoordinatesNames" << endl;
304         cout << "---------------------------" << endl;
305         MESSAGE( "catched exception : " << e.what() ) ;
306         return EXIT_FAILURE ;
307   }
308   catch (...)
309   {
310         cout << "---------------------------" << endl;
311         cout << "pb avec getCoordinatesNames" << endl;
312         cout << "---------------------------" << endl;
313         return EXIT_FAILURE ;
314   };
315
316
317   try
318   {
319         const double * coor2=mycoo.getCoordinates(ModeFull);
320
321         for (int axe = 0; axe < SpaceDim; axe++)
322         {
323
324                 cout << "Coordonnees sur l'Axe : " <<  noms2[axe] ;
325                 cout << " dont l unite est " << units2[axe] << endl;
326
327                 try
328                 {
329                         const double * coor3=mycoo.getCoordinateAxis(axe+1);
330                         for (int num=0; num < NbOfNodes; num++)
331                         {
332                                 try
333                                 {
334                                         const double d = mycoo.getCoordinate(num + 1,axe+1);
335                                         cout << d <<" , ";
336                                         ASSERT(fabs(d - coor3[num])  < pouieme);
337                                         ASSERT(fabs(d - coor2[(num * SpaceDim)+axe]) < pouieme);
338                                         ASSERT(fabs(d - coor [(num * SpaceDim)+axe]) < pouieme);
339                                 }
340                                 catch ( const std::exception &e )
341                                 {
342                                         cout << "----------------------" << endl;
343                                         cout << "pb avec getCoordinates" << endl;
344                                         cout << "----------------------" << endl;
345                                         MESSAGE( "catched exception : " << e.what() ) ;
346                                         return EXIT_FAILURE ;
347                                 }
348                                 catch (...)
349                                 {
350                                         cout << "----------------------" << endl;
351                                         cout << "pb avec getCoordinates" << endl;
352                                         cout << "----------------------" << endl;
353                                         return EXIT_FAILURE ;
354                                 };
355                         }
356                         cout << endl;
357                 }
358                 catch ( const std::exception &e )
359                 {
360                         cout << "-------------------------" << endl;
361                         cout << "pb avec getCoordinateAxis" << endl;
362                         cout << "-------------------------" << endl;
363                         MESSAGE( "catched exception : " << e.what() ) ;
364                         return EXIT_FAILURE ;
365                 }
366                 catch (...)
367                 {
368                         cout << "-------------------------" << endl;
369                         cout << "pb avec getCoordinateAxis" << endl;
370                         cout << "-------------------------" << endl;
371                         return EXIT_FAILURE ;
372                 }
373         }
374   }
375   catch ( const std::exception &e )
376   {
377         cout << "----------------------" << endl;
378         cout << "pb avec getCoordinates" << endl;
379         cout << "----------------------" << endl;
380         MESSAGE( "catched exception : " << e.what() ) ;
381         return EXIT_FAILURE ;
382   }
383   catch (...)
384   {
385         cout << "----------------------" << endl;
386         cout << "pb avec getCoordinates" << endl;
387         cout << "----------------------" << endl;
388         return EXIT_FAILURE ;
389   };
390
391
392   delete [] noms ;
393   delete [] numbers;
394   delete [] coor1;
395
396   delete CoordinateArray ;
397
398   MESSAGE("FIN normale du traitement");
399   return EXIT_SUCCESS ;
400 }
401