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