Back to index

salome-med  6.5.0
MEDMEMTest_Array.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "MEDMEMTest.hxx"
00021 #include <cppunit/TestAssert.h>
00022 
00023 #include "MEDMEM_nArray.hxx"
00024 #include "MEDMEM_ArrayConvert.hxx"
00025 #include "MEDMEM_Array.hxx"
00026 //#include "MEDMEM_ArrayInterface.hxx"
00027 #include "MEDMEM_STRING.hxx"
00028 
00029 #include <sstream>
00030 #include <cmath>
00031 
00032 // use this define to enable lines, execution of which leads to Segmentation Fault
00033 //#define ENABLE_FAULTS
00034 
00035 // use this define to enable CPPUNIT asserts and fails, showing bugs
00036 //#define ENABLE_FORCED_FAILURES
00037 
00038 using namespace std;
00039 using namespace MEDMEM;
00040 
00041 // #1,2,3: MEDMEMTest_Array.cxx
00042 // Check methods from MEDMEM_Array.hxx, MEDMEM_ArrayConvert.hxx, MEDMEM_ArrayInterface.hxx
00043 
00077 void MEDMEMTest::testArray()
00078 {
00079   int SpaceDimension = 3;
00080   int NumberOfNodes  = 4;
00081 
00083   // TEST 1 //
00085 
00086   /* ---------------------------------------------------------- */
00087   /*                                                            */
00088   /*                      INITIALISATION                        */
00089   /*                                                            */
00090   /* - constructeur new MEDARRAY<int>(int,int,mode)             */
00091   /* - get sur le pointeur MED_FULL_INTERLACE                   */
00092   /* - initialisation des valeurs (coordonnées ieme elt = I+1)  */
00093   /* - get sur le pointeur MED_NO_INTERLACE                     */
00094   /* ---------------------------------------------------------- */
00095 
00096   MEDARRAY<int> * myArrayfull =
00097     new MEDARRAY<int> (SpaceDimension, NumberOfNodes, MED_EN::MED_FULL_INTERLACE);
00098   CPPUNIT_ASSERT(myArrayfull != NULL);
00099 
00100   const int * myValues = myArrayfull->get(MED_EN::MED_FULL_INTERLACE);
00101   CPPUNIT_ASSERT(myValues != NULL);
00102 
00103   for (int i = 0; i < NumberOfNodes; i++) {
00104     for (int k = 0; k < SpaceDimension; k++) {
00105       myArrayfull->setIJ(i+1, k+1, i+1);
00106     }
00107   }
00108 
00109   const int * myOthers = myArrayfull->get(MED_EN::MED_NO_INTERLACE);
00110   CPPUNIT_ASSERT(myOthers != NULL);
00111 
00112   MEDARRAY<int> * myArrayno = new MEDARRAY<int>(SpaceDimension, NumberOfNodes, MED_EN::MED_NO_INTERLACE);
00113   CPPUNIT_ASSERT(myArrayno != NULL);
00114   const int * myValuesno = myArrayno->get(MED_EN::MED_NO_INTERLACE);
00115   CPPUNIT_ASSERT(myValuesno != NULL);
00116 
00117   for (int k = 0; k < SpaceDimension; k++) {
00118     for (int i = 0; i < NumberOfNodes; i++) {
00119       myArrayno->setIJ(i+1, k+1, k+1);
00120     }
00121   }
00122 
00123   const int * myOthersno = myArrayno->get(MED_EN::MED_FULL_INTERLACE);
00124   CPPUNIT_ASSERT(myOthersno != NULL);
00125 
00126   /* ---------------------------------------------------------- */
00127   /*                                                            */
00128   /*                  Tests des Fonctions Set                   */
00129   /*                                                            */
00130   /* - setI sur l'element 1 avec des coordonnees a 100          */
00131   /* - setJ sur l'element 1 avec des coordonnees a 100          */
00132   /* - setIJ sur (1,2) avec une coordonnee = 1992               */
00133   /* - set   avec l ensemble des coordonnes remises à i         */
00134   /* ---------------------------------------------------------- */
00135 
00136   int * myNewLine = new int[SpaceDimension];
00137   for (int i = 0; i < SpaceDimension; i++)
00138     myNewLine[i] = myValues[i] * 100;
00139   try
00140   {
00141     myArrayfull->setI(1, myNewLine);
00142   }
00143   catch (const std::exception &e)
00144   {
00145     CPPUNIT_FAIL(e.what());
00146   }
00147   catch (...)
00148   {
00149     CPPUNIT_FAIL("Unknown exception in myArrayfull->setI()");
00150   }
00151 
00152   delete [] myNewLine;
00153 
00154   int * myNewCol = new int[NumberOfNodes];
00155   for (int i = 0; i < NumberOfNodes; i++)
00156     myNewCol[i] = 100;
00157   try
00158   {
00159     myArrayno->setJ(1, myNewCol);
00160   }
00161   catch (const std::exception &e)
00162   {
00163     CPPUNIT_FAIL(e.what());
00164   }
00165   catch (...)
00166   {
00167     CPPUNIT_FAIL("Unknown exception in myArrayno->setJ()");
00168   }
00169 
00170   delete [] myNewCol;
00171 
00172   try
00173   {
00174     myArrayfull->setIJ(1, 2, 1992);
00175   }
00176   catch (const std::exception &e)
00177   {
00178     CPPUNIT_FAIL(e.what());
00179   }
00180   catch (...)
00181   {
00182     CPPUNIT_FAIL("Unknown exception in myArrayfull->setIJ()");
00183   }
00184 
00185   try
00186   {
00187     myArrayno->setIJ(1, 2, 1992);
00188   }
00189   catch (const std::exception &e)
00190   {
00191     CPPUNIT_FAIL(e.what());
00192   }
00193   catch (...)
00194   {
00195     CPPUNIT_FAIL("Unknown exception in myArrayno->setIJ()");
00196   }
00197 
00198   int * mynewvalues = new int [ NumberOfNodes*SpaceDimension ];
00199   for (int i = 0; i < NumberOfNodes*SpaceDimension; i++) {
00200     mynewvalues[i] = i;
00201   }
00202   try
00203   {
00204     myArrayfull->set(MED_EN::MED_FULL_INTERLACE, mynewvalues);
00205     myValues = myArrayfull->get(MED_EN::MED_FULL_INTERLACE);
00206     myOthers = myArrayfull->get(MED_EN::MED_NO_INTERLACE);
00207   }
00208   catch (const std::exception &e)
00209   {
00210     CPPUNIT_FAIL(e.what());
00211   }
00212   catch (...)
00213   {
00214     CPPUNIT_FAIL("Unknown exception");
00215   }
00216 
00217   try
00218   {
00219     myArrayno->set(MED_EN::MED_FULL_INTERLACE, mynewvalues);
00220     myValuesno = myArrayfull->get(MED_EN::MED_FULL_INTERLACE);
00221     myOthersno = NULL;
00222   }
00223   catch (const std::exception &e)
00224   {
00225     CPPUNIT_FAIL(e.what());
00226   }
00227   catch (...)
00228   {
00229     CPPUNIT_FAIL("Unknown exception");
00230   }
00231 
00232   /* ---------------------------------------------------------- */
00233   /*                                                            */
00234   /*                Tests des constructeurs                     */
00235   /*                Tests des Fonctions Get                     */
00236   /*                                                            */
00237   /* ---------------------------------------------------------- */
00238 
00239   // check sharing
00240   MEDARRAY<int> * myArrayShare = new MEDARRAY<int>(*myArrayfull);
00241   const int * sharevalues = myArrayShare->get(MED_EN::MED_FULL_INTERLACE);
00242   const int * shareno = myArrayShare->get(MED_EN::MED_NO_INTERLACE);
00243 
00244   myArrayfull->setIJ(1, 2, 1993);
00245   CPPUNIT_ASSERT(myArrayShare->getIJ(1,2) == 1993);
00246 
00247   myArrayShare->setIJ(1, 2, 1995);
00248   CPPUNIT_ASSERT(myArrayfull->getIJ(1,2) == 1995);
00249 
00250   delete myArrayShare;
00251 
00252   // check no sharing
00253   MEDARRAY<int> * myArrayShare2 = new MEDARRAY<int>(*myArrayfull, true);
00254   sharevalues = myArrayShare2->get(MED_EN::MED_FULL_INTERLACE);
00255   shareno = myArrayShare2->get(MED_EN::MED_NO_INTERLACE);
00256 
00257   myArrayfull->setIJ(1, 2, 18);
00258   CPPUNIT_ASSERT(myArrayShare2->getIJ(1,2) == 1995);
00259   myArrayShare2->setIJ(1, 2, 19);
00260   CPPUNIT_ASSERT(myArrayfull->getIJ(1,2) == 18);
00261 
00262   // check myArrayno
00263   myArrayno->set(MED_EN::MED_NO_INTERLACE, mynewvalues);
00264   myArrayno->setIJ(2, 1, 1);
00265   myValuesno = myArrayno->get(MED_EN::MED_NO_INTERLACE);
00266   myOthersno = myArrayno->get(MED_EN::MED_FULL_INTERLACE);
00267 
00268   MEDARRAY<int> * myArrayShare3 = new MEDARRAY<int>(*myArrayno);
00269   sharevalues = myArrayShare3->get(MED_EN::MED_FULL_INTERLACE);
00270   shareno = myArrayShare3->get(MED_EN::MED_NO_INTERLACE);
00271 
00272   myArrayno->setIJ(1, 2, 1992);
00273   CPPUNIT_ASSERT(myArrayShare3->getIJ(1,2) == 1992);
00274 
00275   myArrayShare3->setIJ(1, 2, 1995);
00276   CPPUNIT_ASSERT(myArrayno->getIJ(1,2) == 1995);
00277 
00278   delete myArrayno;
00279   delete [] mynewvalues;
00280   delete myArrayfull;
00281   delete myArrayShare2;
00282   delete myArrayShare3;
00283 
00284 
00286   // TEST 2 //
00288 
00289   MEDARRAY<int> * myArray =
00290     new MEDARRAY<int> (SpaceDimension, NumberOfNodes, MED_EN::MED_FULL_INTERLACE);
00291 
00292   // - 1 1 1
00293   // - 2 2 2
00294   // - 3 3 3
00295   // - 4 4 4
00296   for (int i = 1; i <= NumberOfNodes; i++)
00297     for (int j = 1; j <= SpaceDimension; j++)
00298       myArray->setIJ(i, j, i);
00299 
00300   CPPUNIT_ASSERT(myArray->getLengthValue()  == NumberOfNodes);
00301   CPPUNIT_ASSERT(myArray->getLeadingValue() == SpaceDimension);
00302 
00303   int numberof = myArray->getLeadingValue(); // nb. of columns ~ space dimension
00304   for (int i = 1; i <= myArray->getLengthValue(); i++) {
00305     const int * node = myArray->getRow(i);
00306     for (int j = 0; j < numberof; j++) {
00307       CPPUNIT_ASSERT(node[j] == i);
00308     }
00309   }
00310 
00311   numberof = myArray->getLengthValue(); // nb. of rows ~ nb. of nodes
00312   for (int i = 1; i <= myArray->getLeadingValue(); i++) {
00313     const int * node = myArray->getColumn(i);
00314     for (int j = 0; j < numberof; j++) {
00315       CPPUNIT_ASSERT(node[j] == j + 1);
00316     }
00317   }
00318 
00319   numberof = myArray->getLeadingValue();
00320   for (int i = 1; i <= myArray->getLengthValue(); i++) {
00321     for (int j = 1; j < numberof + 1; j++) {
00322       CPPUNIT_ASSERT(myArray->getIJ(i,j) == i);
00323     }
00324   }
00325 
00326   numberof = myArray->getLeadingValue();
00327   int length = myArray->getLengthValue();
00328   const int * NoInterlaceArray = myArray->get(MED_EN::MED_NO_INTERLACE);
00329   for (int i = 0; i < length; i++) {
00330     for (int j = 0; j < numberof; j++) {
00331       CPPUNIT_ASSERT(NoInterlaceArray[j*length+i] == i + 1);
00332     }
00333   }
00334 
00335   delete myArray;
00336 
00337 
00339   // TEST 3 //
00341 
00342   // MEDARRAY (T* values, const int ld_values,
00343   //           const int length_values, const MED_EN::medModeSwitch mode=MED_EN::MED_FULL_INTERLACE,
00344   //           bool shallowCopy=false, bool ownershipOfValues=false);
00345 
00346   int ld = 7, nb = 4;
00347   double rr = 13.0, h0 = 7.0;
00348   double * aValues = new double [ld * nb];
00349   for (int nn = 0; nn < nb; nn++) {
00350     aValues[nn*ld + 0] = nn;
00351     aValues[nn*ld + 1] = rr * cos(nn * M_PI/4.);
00352     aValues[nn*ld + 2] = rr * sin(nn * M_PI/4.);
00353     aValues[nn*ld + 3] = h0 + nn;
00354     aValues[nn*ld + 4] = 2.0 * rr * cos(nn * M_PI/4.);
00355     aValues[nn*ld + 5] = 2.0 * rr * sin(nn * M_PI/4.);
00356     aValues[nn*ld + 6] = h0 - nn;
00357   }
00358 
00359   MEDARRAY<double> * aSpiral =
00360     new MEDARRAY<double> (aValues, ld, nb, MED_EN::MED_FULL_INTERLACE,
00361                           /*shallowCopy=*/false, /*ownershipOfValues=*/false);
00363 
00364   if (aSpiral->isOtherCalculated())
00365     aSpiral->clearOtherMode();
00366   CPPUNIT_ASSERT(!aSpiral->isOtherCalculated());
00367 
00368   CPPUNIT_ASSERT(aSpiral->getMode() == MED_EN::MED_FULL_INTERLACE);
00369   aSpiral->calculateOther();
00370   CPPUNIT_ASSERT(aSpiral->getMode() == MED_EN::MED_FULL_INTERLACE);
00371   CPPUNIT_ASSERT(aSpiral->getLeadingValue() == ld);
00372   CPPUNIT_ASSERT(aSpiral->getLengthValue() == nb);
00373 
00374   //CPPUNIT_ASSERT_DOUBLES_EQUAL(expected, actual, delta);
00375   double delta = 0.000001;
00376   const double* comp5 = aSpiral->getColumn(5);
00377   for (int nn = 0; nn < nb; nn++) {
00378     const double* pnt = aSpiral->getRow(nn + 1);
00379     CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0 * rr * cos(nn * M_PI/4.), pnt[4], delta);
00380     CPPUNIT_ASSERT_DOUBLES_EQUAL(comp5[nn],                    pnt[4], delta);
00381   }
00382 
00383   // Check operator= and method shallowCopy()
00384   double c7n3 = aSpiral->getIJ(3, 7);
00385   MEDARRAY<double> shc, cpy;
00386 
00387   //#ifdef ENABLE_FAULTS
00388   // (BUG) MEDARRAY<T>::shallowCopy() usage leads to memory leaks,
00389   // because on attemp to free both arrays we have Segmentation Fault
00390 
00391   // EAP: It's misusage of shallowcopy - BUT what is a correct usage ???
00392   // TODO: check ownership of qrgument
00393   //???skl shc.shallowCopy(*aSpiral);
00394 
00395   // hangs up
00396   //MEDARRAY<double> arr (10, 10);
00397   //MEDARRAY<double> shc;
00398   //shc.shallowCopy(arr);
00399 
00400   // Segmentation fault
00401   //MEDARRAY<double>* arr = new MEDARRAY<double> (10, 10);
00402   //MEDARRAY<double>* shc = new MEDARRAY<double> (10, 10);
00403   //shc->shallowCopy(*arr);
00404   //delete arr;
00405   //delete shc;
00406   //#endif
00407   //#ifdef ENABLE_FORCED_FAILURES
00408   //  CPPUNIT_FAIL("MEDARRAY<T>::shallowCopy(): wrong memory management");
00409   //#endif
00410 
00411   cpy = *aSpiral;
00412 
00413   aSpiral->setIJ(3, 7, c7n3 * 2.0);
00414 
00415   //#ifdef ENABLE_FAULTS
00416   //???skl CPPUNIT_ASSERT_DOUBLES_EQUAL(c7n3 * 2.0, shc.getIJ(3, 7), delta);
00417   //#endif
00418         
00419   //CPPUNIT_ASSERT_DOUBLES_EQUAL(c7n3 * 2.0, cpy.getIJ(3, 7), delta);
00420   CPPUNIT_ASSERT_DOUBLES_EQUAL(c7n3, cpy.getIJ(3, 7), delta);
00421 
00422 // #ifdef ENABLE_FORCED_FAILURES
00423 //   // Comments to deep copy constructor do not correspond to actual implementation
00424 //   CPPUNIT_FAIL("Comments to MEDARRAY<T> deep copy constructor do not correspond to actual implementation");
00425 // #endif
00426 
00427   aSpiral->clearOtherMode();
00428   //CPPUNIT_ASSERT_THROW(MEDARRAY<double> co (*aSpiral, true), MEDEXCEPTION);
00429   CPPUNIT_ASSERT_NO_THROW(MEDARRAY<double> co (*aSpiral, true));
00430 
00431   // invalid cases
00432   //double arr3 [3] = {1., 2., 3.};
00433   double arr4 [4] = {1., 2., 3., 4.};
00434   double arr7 [7] = {1., 2., 3., 4., 5., 6., 7.};
00435   CPPUNIT_ASSERT_THROW(aSpiral->getRow(0), MEDEXCEPTION);
00436   CPPUNIT_ASSERT_THROW(aSpiral->getRow(nb + 1), MEDEXCEPTION);
00437   CPPUNIT_ASSERT_THROW(aSpiral->getColumn(0), MEDEXCEPTION);
00438   CPPUNIT_ASSERT_THROW(aSpiral->getColumn(ld + 1), MEDEXCEPTION);
00439   //CPPUNIT_ASSERT_THROW(aSpiral->set(MED_EN::MED_FULL_INTERLACE, NULL), MEDEXCEPTION);
00440   CPPUNIT_ASSERT_THROW(aSpiral->setI(-1, arr7), MEDEXCEPTION);
00441   //CPPUNIT_ASSERT_THROW(aSpiral->setI(1, NULL), MEDEXCEPTION);
00442   CPPUNIT_ASSERT_THROW(aSpiral->setJ(-1, arr4), MEDEXCEPTION);
00443   //CPPUNIT_ASSERT_THROW(aSpiral->setJ(1, NULL), MEDEXCEPTION);
00444   CPPUNIT_ASSERT_THROW(aSpiral->setIJ(-1, -1, 13.), MEDEXCEPTION);
00445   CPPUNIT_ASSERT_THROW(aSpiral->setIJ(1, 0, 13.), MEDEXCEPTION);
00446   //CPPUNIT_ASSERT_THROW(aSpiral->setI(1, arr3), MEDEXCEPTION); // user must control itself
00447 
00448   delete aSpiral;
00449 
00450   // check empty array
00451 
00452   MEDARRAY<double> anEmptyArray;
00453   //CPPUNIT_ASSERT_NO_THROW(MEDARRAY<double> anArr1 (anEmptyArray)); // INTERRUPTION
00454   //CPPUNIT_ASSERT_NO_THROW(MEDARRAY<double> anArr2 (anEmptyArray, false)); // fails
00455   //CPPUNIT_ASSERT_NO_THROW(MEDARRAY<double> anArr4 = anEmptyArray); // INTERRUPTION
00456   //MEDARRAY<double> anArr5;
00457   //CPPUNIT_ASSERT_NO_THROW(anArr5.shallowCopy(anEmptyArray));
00458 
00459   // invalid cases
00460   CPPUNIT_ASSERT_THROW(anEmptyArray.get(MED_EN::MED_FULL_INTERLACE), MEDEXCEPTION);
00461   CPPUNIT_ASSERT_THROW(anEmptyArray.get(MED_EN::MED_NO_INTERLACE), MEDEXCEPTION);
00462   CPPUNIT_ASSERT_THROW(anEmptyArray.getRow(0), MEDEXCEPTION);
00463   CPPUNIT_ASSERT_THROW(anEmptyArray.getRow(5), MEDEXCEPTION);
00464   CPPUNIT_ASSERT_THROW(anEmptyArray.getColumn(0), MEDEXCEPTION);
00465   CPPUNIT_ASSERT_THROW(anEmptyArray.getIJ(0, 0), MEDEXCEPTION);
00466   CPPUNIT_ASSERT_THROW(anEmptyArray.getIJ(1, 1), MEDEXCEPTION);
00467   CPPUNIT_ASSERT_NO_THROW(anEmptyArray.set(MED_EN::MED_FULL_INTERLACE, aValues));
00468   CPPUNIT_ASSERT_THROW(anEmptyArray.setI(1, aValues), MEDEXCEPTION);
00469   CPPUNIT_ASSERT_THROW(anEmptyArray.setIJ(0, 0, 3.), MEDEXCEPTION);
00470   CPPUNIT_ASSERT_THROW(anEmptyArray.setIJ(1, 1, 3.), MEDEXCEPTION);
00471 
00472   CPPUNIT_ASSERT_THROW(MEDARRAY<double> bad (-1, 10), MEDEXCEPTION);
00473   CPPUNIT_ASSERT_THROW(MEDARRAY<double> bad (10, -1), MEDEXCEPTION);
00474   CPPUNIT_ASSERT_THROW(MEDARRAY<double> bad (-1, -1), MEDEXCEPTION);
00475 
00476   delete [] aValues;
00477 
00478   // construction with taking ownership of values
00479   int ld1 = 7, nb1 = 4;
00480   double * val1 = new double [ld * nb];
00481   for (int nn = 0; nn < nb1; nn++) {
00482     for (int cc = 0; cc < ld1; cc++) {
00483       val1[nn*ld1 + cc] = nn;
00484     }
00485   }
00486   MEDARRAY<double> * arr1 =
00487     new MEDARRAY<double> (val1, ld1, nb1, MED_EN::MED_FULL_INTERLACE,
00488                           /*shallowCopy=*/true, /*ownershipOfValues=*/true);
00489   for (int nn = 1; nn <= nb1; nn++) {
00490     for (int cc = 1; cc <= ld1; cc++) {
00491       CPPUNIT_ASSERT_DOUBLES_EQUAL(nn - 1, arr1->getIJ(nn, cc), delta);
00492     }
00493   }
00494   delete arr1;
00495 }
00496 
00522 void MEDMEMTest::testArrayConvert()
00523 {
00524   // TEST n°1 : FullInterlaceNoGaussPolicy -> NoInterlaceNoGaussPolicy
00525 
00526   const int mdim = 2;
00527   const int nbelem1 = 20;
00528 
00529   const double array1Ref[] = { 11 , 12 , 21 , 22 , 31 , 32 , 41 , 42 , 51 , 52 ,
00530                                61 , 62 , 71 , 72 , 81 , 82 , 91 , 92 , 101, 102,
00531                                111, 112, 121, 122, 131, 132, 141, 142, 151, 152,
00532                                161, 162, 171, 172, 181, 182, 191, 192, 201, 202 };
00533 
00534   const double array2Ref[] = { 11 , 21 , 31 , 41 , 51 , 61 , 71 , 81 , 91 , 101,
00535                                111, 121, 131, 141, 151, 161, 171, 181, 191, 201,
00536                                12 , 22 , 32 , 42 , 52 , 62 , 72 , 82 , 92 , 102,
00537                                112, 122, 132, 142, 152, 162, 172, 182, 192, 202 };
00538 
00539   MEDMEM_Array<double> myArray1 (mdim, nbelem1);
00540 
00541   for (int i = 1; i <= nbelem1; i++)
00542     for (int j = 1; j <= mdim; j++)
00543       myArray1.setIJ(i, j, i*10+j);
00544 
00545   const double * myArray1Ptr = myArray1.getPtr();
00546   for (int i = 0; i < mdim*nbelem1; i++)
00547     CPPUNIT_ASSERT(myArray1Ptr[i] == array1Ref[i]);
00548 
00549   MEDMEM_Array<double, NoInterlaceNoGaussPolicy> * myArray1cin = ArrayConvert(myArray1);
00550   myArray1Ptr = myArray1cin->getPtr();
00551   int elemno = 0;
00552   for (int j = 1; j <= mdim; j++) {
00553     for (int  i = 1; i <= nbelem1; i++) {
00554       CPPUNIT_ASSERT(myArray1cin->getIJ(i,j) == array2Ref[elemno]);
00555       CPPUNIT_ASSERT(myArray1Ptr[elemno]     == array2Ref[elemno]);
00556       elemno++;
00557     }
00558   }
00559   delete myArray1cin;
00560   // TEST n°2 : NoInterlaceNoGaussPolicy -> FullInterlaceNoGaussPolicy
00561 
00562   MEDMEM_Array<double, NoInterlaceNoGaussPolicy> myArray2 (mdim, nbelem1);
00563 
00564   for (int i = 1; i <= nbelem1; i++)
00565     for (int j = 1; j <= mdim; j++)
00566       myArray2.setIJ(i, j, i*10+j);
00567 
00568   const double * myArray2Ptr = myArray2.getPtr();
00569   for (int i = 0; i < mdim*nbelem1; i++)
00570     CPPUNIT_ASSERT(myArray2Ptr[i] == array2Ref[i]);
00571 
00572   MEDMEM_Array<double, FullInterlaceNoGaussPolicy> * myArray2cin = ArrayConvert(myArray2);
00573   myArray2Ptr = myArray2cin->getPtr();
00574   elemno = 0;
00575   for (int i = 1; i <= nbelem1; i++) {
00576     for (int j = 1; j <= mdim; j++) {
00577       CPPUNIT_ASSERT(myArray2cin->getIJ(i,j) == array1Ref[elemno]);
00578       CPPUNIT_ASSERT(myArray2Ptr[elemno]     == array1Ref[elemno]);
00579       elemno++;
00580     }
00581   }
00582   delete myArray2cin;
00583   // TEST n°3 : FullInterlaceGaussPolicy -> NoInterlaceGaussPolicy
00584 
00585   const int nbelem2 = 5;
00586   const int nbtypegeo = 2;
00587   const int nbelgeoc[nbtypegeo+1]   = {1,3,6};
00588   const int nbgaussgeo[nbtypegeo+1] = {-1,2,3};
00589 
00590   const double * myArray3Ptr = 0;
00591   const double array3Ref[] = {  1.11,  1.12,  1.21,  1.22,
00592                                 2.11,  2.12,  2.21,  2.22,
00593                                13.11, 13.12, 13.21, 13.22, 13.31, 13.32,
00594                                14.11, 14.12, 14.21, 14.22, 14.31, 14.32,
00595                                15.11, 15.12, 15.21, 15.22, 15.31, 15.32 };
00596 
00597   const double array4Ref[] = {  1.11,  1.21,  2.11,  2.21,
00598                                13.11, 13.21, 13.31, 14.11, 14.21, 14.31,
00599                                15.11, 15.21, 15.31,
00600                                 1.12,  1.22,  2.12,  2.22,
00601                                13.12, 13.22, 13.32, 14.12, 14.22, 14.32,
00602                                15.12, 15.22, 15.32 };
00603 
00604   MEDMEM_Array<double, FullInterlaceGaussPolicy> myArray3
00605     (mdim, nbelem2, nbtypegeo, nbelgeoc, nbgaussgeo);
00606 
00607   elemno = 1;
00608   for (int ntyp = 1; ntyp <= nbtypegeo; ntyp++) {
00609     for (int i = 0; i < (nbelgeoc[ntyp]-nbelgeoc[ntyp-1]); i++) {
00610       for (int k = 1; k <= nbgaussgeo[ntyp]; k++) {
00611         for (int j = 1; j <= mdim; j++) {
00612           myArray3.setIJK(elemno, j, k, elemno+(ntyp-1)*10+0.1*k+0.01*j);
00613         }
00614       }
00615       elemno++;
00616     }
00617   }
00618   myArray3Ptr = myArray3.getPtr();
00619   for (int i = 0; i < myArray3.getArraySize(); i++)
00620     CPPUNIT_ASSERT( abs(myArray3Ptr[i] - array3Ref[i]) < 1e-7);
00621 
00622   MEDMEM_Array<double, NoInterlaceGaussPolicy> * myArray3cin = ArrayConvert(myArray3);
00623   myArray3Ptr = myArray3cin->getPtr();
00624   elemno = 0;
00625   for (int j = 1; j <= mdim; j++)
00626     for (int i = 1; i < nbelgeoc[nbtypegeo]; i++)
00627       for (int k = 1; k <= myArray3cin->getNbGauss(i); k++) {
00628         CPPUNIT_ASSERT( abs(myArray3cin->getIJK(i,j,k) - array4Ref[elemno]) < 1e-7);
00629         CPPUNIT_ASSERT( abs(myArray3Ptr[elemno] - array4Ref[elemno]) < 1e-7);
00630         elemno++;
00631       }
00632   delete myArray3cin;
00633   // TEST n°4 : NoInterlaceGaussPolicy -> FullInterlaceGaussPolicy
00634 
00635   const double * myArray4Ptr = 0;
00636 
00637   MEDMEM_Array<double, NoInterlaceGaussPolicy> myArray4
00638     (mdim, nbelem2, nbtypegeo, nbelgeoc, nbgaussgeo);
00639 
00640   elemno = 1;
00641   for (int ntyp = 1; ntyp <= nbtypegeo; ntyp++) {
00642     for (int i = 0; i < (nbelgeoc[ntyp]-nbelgeoc[ntyp-1]); i++) {
00643       for (int k = 1; k <= nbgaussgeo[ntyp]; k++) {
00644         for (int j = 1; j <= mdim; j++) {
00645           myArray4.setIJK(elemno, j, k, elemno+(ntyp-1)*10+0.1*k+0.01*j);
00646         }
00647       }
00648       elemno++;
00649     }
00650   }
00651   myArray4Ptr = myArray4.getPtr();
00652 
00653   for (int i = 0; i < myArray4.getArraySize(); i++)
00654     CPPUNIT_ASSERT( abs(myArray4Ptr[i] - array4Ref[i]) < 1e-7);
00655 
00656   MEDMEM_Array<double, FullInterlaceGaussPolicy> * myArray4cin = ArrayConvert(myArray4);
00657   myArray4Ptr = myArray4cin->getPtr();
00658   elemno = 0;
00659   for (int i = 1; i < nbelgeoc[nbtypegeo]; i++)
00660     for (int k = 1; k <= myArray4cin->getNbGauss(i); k++)
00661       for (int j = 1; j <= mdim; j++) {
00662         CPPUNIT_ASSERT( abs(myArray4cin->getIJK(i,j,k) - array3Ref[elemno]) < 1e-7);
00663         CPPUNIT_ASSERT( abs(myArray4cin->getIJK(i,j,k) - myArray3.getIJK(i,j,k)) < 1e-7);
00664         CPPUNIT_ASSERT( abs(myArray4Ptr[elemno] - array3Ref[elemno]) < 1e-7);
00665         elemno++;
00666       }
00667   delete myArray4cin;
00668 }
00672 //void MEDMEMTest::testArrayInterface()
00673 //{
00674 //  CPPUNIT_FAIL("Case Not Implemented (not in spec)");
00675 //}