Back to index

salome-med  6.5.0
MEDMEMTest_GaussLocalization.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_GaussLocalization.hxx"
00024 #include "MEDMEM_STRING.hxx"
00025 
00026 #include <sstream>
00027 #include <cmath>
00028 
00029 // use this define to enable lines, execution of which leads to Segmentation Fault
00030 //#define ENABLE_FAULTS
00031 
00032 // use this define to enable CPPUNIT asserts and fails, showing bugs
00033 //#define ENABLE_FORCED_FAILURES
00034 
00035 using namespace std;
00036 using namespace MEDMEM;
00037 
00038 // #18: MEDMEM_GaussLocalization.hxx  }  MEDMEMTest.cxx
00039 
00081 void MEDMEMTest::testGaussLocalization()
00082 {
00083   // GAUSS_LOCALIZATION_
00084   GAUSS_LOCALIZATION_ aGL_;
00085   CPPUNIT_ASSERT_EQUAL(MED_EN::MED_UNDEFINED_INTERLACE, aGL_.getInterlacingType());
00086 
00087   // GAUSS_LOCALIZATION empty constructor and InterlaceType
00088   GAUSS_LOCALIZATION<> anEmptyGL1;
00089   MED_EN::medModeSwitch aDefaultInterlaceType = anEmptyGL1.getInterlacingType();
00090   CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FULL_INTERLACE, aDefaultInterlaceType);
00091 
00092   GAUSS_LOCALIZATION<NoInterlace> anEmptyGL2;
00093   MED_EN::medModeSwitch anInterlaceType2 = anEmptyGL2.getInterlacingType();
00094   CPPUNIT_ASSERT_EQUAL(MED_EN::MED_NO_INTERLACE, anInterlaceType2);
00095 
00096   // Construction from C++ arrays
00097   double cooRef[6] = {1.,1., 2.,4., 3.,9.}; // xy xy xy
00098   double cooGauss[10] = {7.,7., 6.,6., 5.,5., 4.,3., 2.,1.}; // x1,y1  x2,y2  x3,y3  x4,y4  x5,y5
00099   double wg[5] = {1., 2., 3., 4., 5.};
00100 
00101   GAUSS_LOCALIZATION<> gl1 ("GL1", MED_EN::MED_TRIA3, /*nGauss*/5, cooRef, cooGauss, wg);
00102   GAUSS_LOCALIZATION<> gl2 ("GL1", MED_EN::MED_TRIA3, /*nGauss*/5, cooRef, cooGauss, wg);
00103 
00104   // getXXX
00105   CPPUNIT_ASSERT(gl1.getName() == "GL1");
00106   CPPUNIT_ASSERT_EQUAL(MED_EN::MED_TRIA3, gl1.getType());
00107   CPPUNIT_ASSERT_EQUAL(5, gl1.getNbGauss());
00108 
00109   GAUSS_LOCALIZATION<>::ArrayNoGauss cooRefBack   = gl1.getRefCoo();
00110   GAUSS_LOCALIZATION<>::ArrayNoGauss cooGaussBack = gl1.getGsCoo();
00111   vector<double> wgBack = gl1.getWeight();
00112 
00113   double * cooRefBack_ptr = cooRefBack.getPtr();
00114   double * cooGaussBack_ptr = cooGaussBack.getPtr();
00115 
00116   // (BUG)Reading uninitialized memory here
00117   // TODO fix
00118   for (int i = 0; i < 10; i++) {
00119     CPPUNIT_ASSERT_DOUBLES_EQUAL(cooRef[i%6], cooRefBack_ptr[i%6], 0.000001);
00120     CPPUNIT_ASSERT_DOUBLES_EQUAL(cooGauss[i], cooGaussBack_ptr[i], 0.000001);
00121     CPPUNIT_ASSERT_DOUBLES_EQUAL(wg[i%5]    , wgBack[i%5]        , 0.000001);
00122   }
00123 
00124   // Operators == and =
00125   CPPUNIT_ASSERT(gl1 == gl2);
00126   CPPUNIT_ASSERT_EQUAL(gl1, gl2);
00127 
00128   GAUSS_LOCALIZATION<> gl1_c;
00129   gl1_c = gl1;
00130 
00131   //#ifdef ENABLE_FORCED_FAILURES
00132   // (BUG) Badly copyed arrays as a result of operator= usage
00133   CPPUNIT_ASSERT_EQUAL(gl1, gl1_c);
00134   // Invalid read of size 8
00135   //    at 0x342B157A: MEDMEM::MEDMEM_Array<double, MEDMEM::FullInterlaceNoGaussPolicy, MEDMEM::IndexCheckPolicy>::operator==(MEDMEM::MEDMEM_Array<double, MEDMEM::FullInterlaceNoGaussPolicy, MEDMEM::IndexCheckPolicy> const&) const (MEDMEM_nArray.hxx:255)
00136   //    by 0x342A1CDA: MEDMEM::GAUSS_LOCALIZATION<MEDMEM::FullInterlace>::operator==(MEDMEM::GAUSS_LOCALIZATION<MEDMEM::FullInterlace> const&) const (MEDMEM_GaussLocalization.hxx:175)
00137   //    by 0x34315F98: CppUnit::assertion_traits<MEDMEM::GAUSS_LOCALIZATION<MEDMEM::FullInterlace> >::equal(MEDMEM::GAUSS_LOCALIZATION<MEDMEM::FullInterlace> const&, MEDMEM::GAUSS_LOCALIZATION<MEDMEM::FullInterlace> const&) (TestAssert.h:40)
00138   //    by 0x34314D35: void CppUnit::assertEquals<MEDMEM::GAUSS_LOCALIZATION<MEDMEM::FullInterlace> >(MEDMEM::GAUSS_LOCALIZATION<MEDMEM::FullInterlace> const&, MEDMEM::GAUSS_LOCALIZATION<MEDMEM::FullInterlace> const&, CppUnit::SourceLine, std::string const&) (TestAssert.h:62)
00139   //    by 0x34311D6F: MEDMEMTest::testGaussLocalization() (MEDMEMTest_GaussLocalization.cxx:132)
00140   //  Address 0x35B5FC98 is 0 bytes inside a block of size 48 free'd
00141   //    at 0x3414CD61: operator delete[](void*) (vg_replace_malloc.c:161)
00142   //    by 0x341D88CA: MEDMEM::PointerOf<double>::~PointerOf() (MEDMEM_PointerOf.hxx:141)
00143   //    by 0x341D56C7: MEDMEM::MEDMEM_Array<double, MEDMEM::FullInterlaceNoGaussPolicy, MEDMEM::IndexCheckPolicy>::~MEDMEM_Array() (MEDMEM_nArray.hxx:52)
00144   //    by 0x34314F58: MEDMEM::GAUSS_LOCALIZATION<MEDMEM::FullInterlace>::operator=(MEDMEM::GAUSS_LOCALIZATION<MEDMEM::FullInterlace> const&) (MEDMEM_GaussLocalization.hxx:166)
00145   //    by 0x34311CCC: MEDMEMTest::testGaussLocalization() (MEDMEMTest_GaussLocalization.cxx:128)
00146   //#endif
00147 
00148   // same name, type and nb.gauss, but different coords or weights
00149   double cooRef_ch[6] = {1.,1., 2.,8., 3.,9.};
00150   double cooGauss_ch[10] = {7.,8., 6.,6., 5.,5., 4.,3., 2.,1.};
00151   double wg_ch[5] = {1., 2., 8., 4., 5.};
00152 
00153   GAUSS_LOCALIZATION<> gl3 ("GL1", MED_EN::MED_TRIA3, /*nGauss*/5, cooRef_ch, cooGauss, wg);
00154   GAUSS_LOCALIZATION<> gl4 ("GL1", MED_EN::MED_TRIA3, /*nGauss*/5, cooRef, cooGauss_ch, wg);
00155   GAUSS_LOCALIZATION<> gl5 ("GL1", MED_EN::MED_TRIA3, /*nGauss*/5, cooRef, cooGauss, wg_ch);
00156 
00157   CPPUNIT_ASSERT(!(gl1 == gl3));
00158   CPPUNIT_ASSERT(!(gl1 == gl4));
00159   CPPUNIT_ASSERT(!(gl1 == gl5));
00160 
00161   // different name or type, or nb.gauss
00162   double cooRef_quad[8] = {1.,1., 2.,4., 3.,9., 4., 16.};
00163   double cooGauss_4[8] = {7.,8., 6.,6., 5.,5., 4.,3.};
00164   double wg_4[4] = {1., 2., 8., 4.};
00165 
00166   GAUSS_LOCALIZATION<> gl6 ("GL6", MED_EN::MED_TRIA3, /*nGauss*/5, cooRef, cooGauss, wg);
00167   GAUSS_LOCALIZATION<> gl7 ("GL1", MED_EN::MED_QUAD4, /*nGauss*/5, cooRef_quad, cooGauss, wg);
00168   GAUSS_LOCALIZATION<> gl8 ("GL1", MED_EN::MED_TRIA3, /*nGauss*/4, cooRef, cooGauss_4, wg_4);
00169 
00170   CPPUNIT_ASSERT(!(gl1 == gl6));
00171   CPPUNIT_ASSERT(!(gl1 == gl7));
00172   CPPUNIT_ASSERT(!(gl1 == gl8));
00173 
00174   // Operator <<
00175   ostringstream ostr1;
00176   ostr1 << gl1;
00177   CPPUNIT_ASSERT(ostr1.str() != "");
00178 
00179   ostringstream ostr2;
00180   ostr2 << gl2;
00181   CPPUNIT_ASSERT_EQUAL(ostr1.str(), ostr2.str());
00182 
00183   // Construction from ArrayNoGauss and vector<double>
00184   GAUSS_LOCALIZATION<> gl9 ("GL1", MED_EN::MED_TRIA3, /*nGauss*/5, cooRefBack, cooGaussBack, wgBack);
00185   CPPUNIT_ASSERT(gl1 == gl9);
00186 
00187   // NoInterlace
00188   double cooRef_ni[6] = {1.,2.,3., 1.,4.,9.}; // xxx yyy
00189   double cooGauss_ni[10] = {7.,6.,5.,4.,2., 7.,6.,5.,3.,1.}; // x1,x2,x3,x4,x5  y1,y2,y3,y4,y5
00190 
00191   GAUSS_LOCALIZATION<NoInterlace> gl10 ("GL10", MED_EN::MED_TRIA3, /*nGauss*/5, cooRef_ni, cooGauss_ni, wg);
00192 
00193   GAUSS_LOCALIZATION<NoInterlace>::ArrayNoGauss cooRefBack_ni   = gl10.getRefCoo();
00194   GAUSS_LOCALIZATION<NoInterlace>::ArrayNoGauss cooGaussBack_ni = gl10.getGsCoo();
00195 
00196   for (int i = 1; i <= 3; i++) { // nb. nodes
00197     for (int j = 1; j <= 2; j++) { // dim
00198       CPPUNIT_ASSERT_DOUBLES_EQUAL(cooRefBack.getIJ(i, j), cooRefBack_ni.getIJ(i, j), 0.000001);
00199     }
00200   }
00201 
00202   for (int i = 1; i <= 5; i++) { // nGauss
00203     for (int j = 1; j <= 2; j++) { // dim
00204       CPPUNIT_ASSERT_DOUBLES_EQUAL(cooGaussBack.getIJ(i, j), cooGaussBack_ni.getIJ(i, j), 0.000001);
00205     }
00206   }
00207 }