Back to index

salome-med  6.5.0
MEDMEMTest_Support_fault.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_Mesh.hxx"
00024 #include "MEDMEM_STRING.hxx"
00025 #include "MEDMEM_Support.hxx"
00026 
00027 #include <sstream>
00028 #include <cmath>
00029 
00030 // use this define to enable lines, execution of which leads to Segmentation Fault
00031 //#define ENABLE_FAULTS
00032 
00033 // use this define to enable CPPUNIT asserts and fails, showing bugs
00034 //#define ENABLE_FORCED_FAILURES
00035 
00036 using namespace std;
00037 using namespace MEDMEM;
00038 
00039 // #52: MEDMEM_Support.hxx  }  MEDMEMTest_Support.cxx
00040 
00124 static void MEDMEMTest_testSupport()
00125 {
00126   MESH * aMesh = MEDMEMTest_createTestMesh();
00127   MESH * aMeshOneMore = MEDMEMTest_createTestMesh();
00128 
00130   // TEST 1 //
00132 
00133   SUPPORT *aSupportOnFaces1 = new SUPPORT;
00134   aSupportOnFaces1->setMesh( aMesh );
00135   aSupportOnFaces1->setName( "Support On Faces 1" );
00136   aSupportOnFaces1->setEntity( MED_EN::MED_FACE );
00137   aSupportOnFaces1->setAll( true );
00138   aSupportOnFaces1->update();
00139 
00140   SUPPORT *aSupportOnCells1 = new SUPPORT;
00141   aSupportOnCells1->setMesh( aMesh );
00142   aSupportOnCells1->setName( "Support On Cells 1" );
00143   aSupportOnFaces1->setAll( true );
00144   aSupportOnFaces1->update();
00145 
00146   SUPPORT *aSupportOnFaces2=new SUPPORT;
00147   SUPPORT *aSupportOnCells2=new SUPPORT;
00148 
00149   SUPPORT *aSupportOnFaces3 = new SUPPORT;
00150   aSupportOnFaces3->setMesh( aMeshOneMore );
00151   aSupportOnFaces3->setName( "Support On Faces 3" );
00152   aSupportOnFaces3->setEntity( MED_EN::MED_FACE );
00153   aSupportOnFaces1->setAll( true );
00154   aSupportOnFaces1->update();
00155 
00156   // entity
00157   CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aSupportOnFaces1->getEntity());
00158   CPPUNIT_ASSERT_EQUAL(MED_EN::MED_CELL, aSupportOnCells1->getEntity());
00159 
00160   CPPUNIT_ASSERT_EQUAL(MED_EN::MED_CELL, aSupportOnFaces2->getEntity());
00161   CPPUNIT_ASSERT_EQUAL(MED_EN::MED_CELL, aSupportOnCells2->getEntity());
00162 
00163   aSupportOnFaces2->setEntity(MED_EN::MED_FACE);
00164   CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aSupportOnFaces2->getEntity());
00165 
00166   // isOnAllElements
00167   CPPUNIT_ASSERT(aSupportOnFaces1->isOnAllElements());
00168   CPPUNIT_ASSERT(aSupportOnCells1->isOnAllElements());
00169 
00170   CPPUNIT_ASSERT(!aSupportOnFaces2->isOnAllElements());
00171   CPPUNIT_ASSERT(!aSupportOnCells2->isOnAllElements());
00172 
00173   // mesh and mesh name
00174   CPPUNIT_ASSERT_THROW(aSupportOnFaces1->setMeshName("Mesh 1"), MEDEXCEPTION);
00175 
00176   aSupportOnFaces2->setMeshName("Mesh 1");
00177   aSupportOnCells2->setMeshName("Mesh 1");
00178   CPPUNIT_ASSERT(aSupportOnFaces2->getMeshName() == "Mesh 1");
00179   CPPUNIT_ASSERT(aSupportOnCells2->getMeshName() == "Mesh 1");
00180 
00181   aSupportOnFaces2->setMesh(aMesh);
00182   CPPUNIT_ASSERT_THROW(aSupportOnFaces2->setMeshName("Mesh 1"), MEDEXCEPTION);
00183 
00184   aSupportOnCells1->setMesh(NULL);
00185   aSupportOnCells1->setMeshName("Mesh 1");
00186 
00187   CPPUNIT_ASSERT(aSupportOnFaces1->getMeshName() == "meshing");
00188   CPPUNIT_ASSERT(aSupportOnFaces2->getMeshName() == "meshing");
00189   CPPUNIT_ASSERT(aSupportOnCells1->getMeshName() == "Mesh 1");
00190   CPPUNIT_ASSERT(aSupportOnCells2->getMeshName() == "Mesh 1");
00191 
00192   CPPUNIT_ASSERT(aSupportOnFaces1->getMesh() == aMesh);
00193   CPPUNIT_ASSERT(aSupportOnFaces2->getMesh() == aMesh);
00194   CPPUNIT_ASSERT(aSupportOnCells1->getMesh() == NULL);
00195   CPPUNIT_ASSERT(aSupportOnCells2->getMesh() == NULL);
00196 
00197   // operator ==
00198   aSupportOnFaces2->setName("Support On Faces 2");
00199   aSupportOnCells2->setName("Support On Cells 2");
00200 
00201   // because aSupportOnFaces1 is on all elements, but aSupportOnFaces2 not
00202   CPPUNIT_ASSERT(!(aSupportOnFaces1 == aSupportOnFaces2));
00203 
00204   aSupportOnCells1->setAll(false);
00205   CPPUNIT_ASSERT(!aSupportOnCells1->isOnAllElements());
00206   // this is only sets flag _isOnAllElts to false, but not clear elements and types
00207   // information, so aSupportOnCells1 is not equal to aSupportOnCells2 at this moment
00208 
00209   //#ifdef ENABLE_FAULTS
00210   // (BUG) SUPPORT::operator= gives "Segmentation Fault" on supports with NULL meshes!!!
00211   CPPUNIT_ASSERT(!(aSupportOnCells1 == aSupportOnCells2));
00212   //#endif
00213   //#ifdef ENABLE_FORCED_FAILURES
00214   //  CPPUNIT_FAIL("SUPPORT::operator= gives Segmentation Fault on supports with NULL meshes!!!");
00215   //#endif
00216 
00217   aSupportOnFaces2->setAll(true);
00218   CPPUNIT_ASSERT(aSupportOnFaces2->isOnAllElements());
00219   // flag _isOnAllElts now is set to true, but we need also to call update()
00220   // to set elements and types information from mesh to this support
00221   CPPUNIT_ASSERT(!(aSupportOnFaces1 == aSupportOnFaces2));
00222   aSupportOnFaces2->update();
00223   CPPUNIT_ASSERT(aSupportOnFaces1 == aSupportOnFaces2);
00224 
00225   // deep compare
00226   CPPUNIT_ASSERT(aSupportOnFaces1->deepCompare(*aSupportOnFaces2));
00227 
00228   CPPUNIT_ASSERT(!(aSupportOnFaces1 == aSupportOnFaces3)); // different mesh pointers
00229   CPPUNIT_ASSERT(aSupportOnFaces1->deepCompare(*aSupportOnFaces3)); // meshes are really equal
00230 
00231   // description
00232   aSupportOnFaces1->setDescription("Support on all faces with mesh pointer");
00233   aSupportOnFaces2->setDescription("Support on all faces with mesh pointer");
00234 
00235   aSupportOnCells1->setDescription("Support on a part of cells with mesh name");
00236   aSupportOnCells2->setDescription("Support on a part of cells with mesh name");
00237 
00238   CPPUNIT_ASSERT(aSupportOnFaces1->getDescription() == "Support on all faces with mesh pointer");
00239   CPPUNIT_ASSERT(aSupportOnFaces2->getDescription() == "Support on all faces with mesh pointer");
00240   CPPUNIT_ASSERT(aSupportOnCells1->getDescription() == "Support on a part of cells with mesh name");
00241   CPPUNIT_ASSERT(aSupportOnCells2->getDescription() == "Support on a part of cells with mesh name");
00242 
00243   // operator<<
00244   ostringstream ostr1;
00245   ostr1 << aSupportOnFaces1;
00246   CPPUNIT_ASSERT(ostr1.str() != "");
00247 
00248   ostringstream ostr2;
00249   ostr2 << aSupportOnCells2;
00250   CPPUNIT_ASSERT(ostr2.str() != "");
00251 
00252   // set/get elements and types information
00253 
00254   // 1. aSupportOnCells1 is not on all elements, but now it contains information
00255   //    about all cells of aMesh, because it was created on mesh and with parameters.
00256   CPPUNIT_ASSERT_EQUAL(3, aSupportOnCells1->getNumberOfTypes());
00257   CPPUNIT_ASSERT(aSupportOnCells1->getTypes() != NULL);
00258 
00259   aSupportOnCells1->setNumberOfGeometricType(0);
00260   CPPUNIT_ASSERT_EQUAL(0, aSupportOnCells1->getNumberOfTypes());
00261   CPPUNIT_ASSERT(aSupportOnCells1->getTypes() == NULL);
00262 
00263   MED_EN::medGeometryElement aSCTypes[2] = 
00264     {
00265       MED_EN::MED_PYRA5, MED_EN::MED_PENTA15
00266     };
00267   aSupportOnCells1->setNumberOfGeometricType(2);
00268   aSupportOnCells1->setGeometricType(aSCTypes);
00269 
00270   CPPUNIT_ASSERT_EQUAL(2, aSupportOnCells1->getNumberOfTypes());
00271   CPPUNIT_ASSERT(aSupportOnCells1->getTypes() != NULL);
00272   CPPUNIT_ASSERT(aSupportOnCells1->getNumberOfElements() == NULL); // reset by setNumberOfGeometricType
00273 
00274   int nbEltsSC[2] = 
00275     {
00276       2, 1
00277     };
00278   aSupportOnCells1->setNumberOfElements(nbEltsSC);
00279 
00280   const int * nbEltsSCBack = aSupportOnCells1->getNumberOfElements();
00281   CPPUNIT_ASSERT_EQUAL(2, aSupportOnCells1->getNumberOfElements(MED_EN::MED_PYRA5));
00282   CPPUNIT_ASSERT_EQUAL(2, nbEltsSCBack[0]);
00283   CPPUNIT_ASSERT_EQUAL(1, aSupportOnCells1->getNumberOfElements(MED_EN::MED_PENTA15));
00284   CPPUNIT_ASSERT_EQUAL(1, nbEltsSCBack[1]);
00285   CPPUNIT_ASSERT_EQUAL(3, aSupportOnCells1->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
00286 
00287   // old types
00288   CPPUNIT_ASSERT_THROW(aSupportOnCells1->getNumberOfElements(MED_EN::MED_TETRA4), MEDEXCEPTION);
00289   CPPUNIT_ASSERT_THROW(aSupportOnCells1->getNumberOfElements(MED_EN::MED_HEXA8), MEDEXCEPTION);
00290 
00291   //_number= new MEDSKYLINEARRAY(_numberOfGeometricType,_totalNumberOfElements,index,value,shallowCopy);
00292   int indexSC[3] = 
00293     {
00294       1,3,4
00295     }; // length = nb.types + 1
00296   int valueSC[3] = 
00297     {
00298       21,22,47
00299     }; // length = total nb. of elements
00300   aSupportOnCells1->setNumber(indexSC, valueSC);
00301 
00302   // check number
00303   MEDSKYLINEARRAY * aNumberSCBack = aSupportOnCells1->getnumber();
00304 
00305   CPPUNIT_ASSERT_EQUAL(2, aNumberSCBack->getNumberOf());
00306   CPPUNIT_ASSERT_EQUAL(3, aNumberSCBack->getLength());
00307   const int * ind = aNumberSCBack->getIndex();
00308   const int * val = aNumberSCBack->getValue();
00309   CPPUNIT_ASSERT_EQUAL(1, ind[0]);
00310   CPPUNIT_ASSERT_EQUAL(3, ind[1]);
00311   CPPUNIT_ASSERT_EQUAL(4, ind[2]);
00312   CPPUNIT_ASSERT_EQUAL(21, val[0]);
00313   CPPUNIT_ASSERT_EQUAL(22, val[1]);
00314   CPPUNIT_ASSERT_EQUAL(47, val[2]);
00315 
00316   // 2. aSupportOnCells2 is not on all elements, and now it contains
00317   //    no information about elements of a mesh
00318   CPPUNIT_ASSERT_EQUAL(0, aSupportOnCells2->getNumberOfTypes());
00319   CPPUNIT_ASSERT(aSupportOnCells2->getTypes() == NULL);
00320 
00321   aSupportOnCells2->setNumberOfGeometricType(2);
00322   aSupportOnCells2->setGeometricType(aSCTypes);
00323 
00324   CPPUNIT_ASSERT_EQUAL(2, aSupportOnCells2->getNumberOfTypes());
00325   CPPUNIT_ASSERT(aSupportOnCells2->getTypes() != NULL);
00326 
00327   aSupportOnCells2->setNumberOfElements(nbEltsSC);
00328 
00329   // we create MEDSKYLINEARRAY as pointer, because aSupportOnCells2 will
00330   // become an owner of it, and we must not delete it.
00331   MEDSKYLINEARRAY * aNumberSC = new MEDSKYLINEARRAY(2, 3, indexSC, valueSC);
00332   aSupportOnCells2->setNumber(aNumberSC);
00333 
00334   // check number
00335   const int * aNumberIndexSC = aSupportOnCells2->getNumberIndex();
00336   CPPUNIT_ASSERT_EQUAL(1, aNumberIndexSC[0]);
00337   CPPUNIT_ASSERT_EQUAL(3, aNumberIndexSC[1]);
00338   CPPUNIT_ASSERT_EQUAL(4, aNumberIndexSC[2]);
00339 
00340   const int * aNbPYRA5 = aSupportOnCells2->getNumber(MED_EN::MED_PYRA5);
00341   const int * aNbPENTA15 = aSupportOnCells2->getNumber(MED_EN::MED_PENTA15);
00342   CPPUNIT_ASSERT_THROW(aSupportOnCells2->getNumber(MED_EN::MED_TETRA4), MEDEXCEPTION);
00343 
00344   const int * aNbC = aSupportOnCells2->getNumber(MED_EN::MED_ALL_ELEMENTS);
00345 
00346   CPPUNIT_ASSERT_EQUAL(21, aNbPYRA5[0]);
00347   CPPUNIT_ASSERT_EQUAL(22, aNbPYRA5[1]);
00348   CPPUNIT_ASSERT_EQUAL(47, aNbPENTA15[0]);
00349 
00350   CPPUNIT_ASSERT_EQUAL(21, aNbC[0]);
00351   CPPUNIT_ASSERT_EQUAL(22, aNbC[1]);
00352   CPPUNIT_ASSERT_EQUAL(47, aNbC[2]);
00353 
00354   // getValIndFromGlobalNumber
00355   CPPUNIT_ASSERT_EQUAL(1, aSupportOnCells2->getValIndFromGlobalNumber(21));
00356   CPPUNIT_ASSERT_EQUAL(2, aSupportOnCells2->getValIndFromGlobalNumber(22));
00357   CPPUNIT_ASSERT_EQUAL(3, aSupportOnCells2->getValIndFromGlobalNumber(47));
00358   // not existing element
00359   CPPUNIT_ASSERT_THROW(aSupportOnCells2->getValIndFromGlobalNumber(10), MEDEXCEPTION);
00360 
00361   // compare aSupportOnCells1 and aSupportOnCells2
00362 
00363   // temporary set mesh (because of bug with operator==)
00364   aSupportOnCells1->setMesh(aMesh);
00365   aSupportOnCells2->setMesh(aMesh);
00366 
00367   CPPUNIT_ASSERT_EQUAL(aSupportOnCells1, aSupportOnCells2);
00368 
00369   // restore mesh name
00370   aSupportOnCells1->setMesh(NULL);
00371   aSupportOnCells2->setMesh(NULL);
00372   aSupportOnCells1->setMeshName("Mesh 1");
00373   aSupportOnCells2->setMeshName("Mesh 1");
00374 
00375   // 3. aSupportOnFacesN is on all elements, and it contains
00376   //    information about all faces of aMesh
00377   CPPUNIT_ASSERT_EQUAL(2, aSupportOnFaces1->getNumberOfTypes());
00378   const MED_EN::medGeometryElement* aSF1Types = aSupportOnFaces1->getTypes();
00379   CPPUNIT_ASSERT_EQUAL(MED_EN::MED_TRIA3, aSF1Types[0]);
00380   CPPUNIT_ASSERT_EQUAL(MED_EN::MED_QUAD4, aSF1Types[1]);
00381   //#ifdef ENABLE_FORCED_FAILURES
00382   // (BUG) Comment to method SUPPORT::getTypes() says:
00383   // "If isOnAllElements is false, returns an array of %medGeometryElement types used by the support."
00384   // But in fact it returns types in any case (comment to SUPPORT::setAll() gives more information).
00385   //  CPPUNIT_FAIL("Comment and implementation does not match for SUPPORT::getTypes()");
00386   // This concerns also method SUPPORT::update(), being called from constructor,
00387   // which fills internal SUPPORT structures with information about mesh elements
00388   // in case of isOnAllElements == true.
00389   // Also comments and implementation does not match for SUPPORT::getNumberOfElements().
00390   // It seems that in case "isOnAllElements == true" calls like getNumberOfElements()
00391   // must be redirected to mesh, but what if mesh is not set (mesh name used instead)?.
00392   //#endif
00393   const int * nbEltsSF1 = aSupportOnFaces1->getNumberOfElements();
00394   CPPUNIT_ASSERT_EQUAL(4, aSupportOnFaces1->getNumberOfElements(MED_EN::MED_TRIA3));
00395   CPPUNIT_ASSERT_EQUAL(4, nbEltsSF1[0]);
00396   CPPUNIT_ASSERT_EQUAL(4, aSupportOnFaces1->getNumberOfElements(MED_EN::MED_QUAD4));
00397   CPPUNIT_ASSERT_EQUAL(4, nbEltsSF1[1]);
00398   CPPUNIT_ASSERT_EQUAL(8, aSupportOnFaces1->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
00399   CPPUNIT_ASSERT_THROW(aSupportOnFaces1->getNumberOfElements(MED_EN::MED_TRIA6), MEDEXCEPTION);
00400   CPPUNIT_ASSERT_THROW(aSupportOnFaces1->getNumberOfElements(MED_EN::MED_QUAD8), MEDEXCEPTION);
00401 
00402   // check number
00403   CPPUNIT_ASSERT_THROW(aSupportOnFaces1->getNumberIndex(), MEDEXCEPTION);
00404   CPPUNIT_ASSERT_THROW(aSupportOnFaces1->getNumber(MED_EN::MED_TRIA3), MEDEXCEPTION);
00405   CPPUNIT_ASSERT_THROW(aSupportOnFaces1->getNumber(MED_EN::MED_QUAD4), MEDEXCEPTION);
00406   CPPUNIT_ASSERT_THROW(aSupportOnFaces1->getNumber(MED_EN::MED_ALL_ELEMENTS), MEDEXCEPTION);
00407   CPPUNIT_ASSERT_THROW(aSupportOnFaces1->getnumber(), MEDEXCEPTION);
00408 
00409   // getValIndFromGlobalNumber
00410   CPPUNIT_ASSERT_EQUAL(8, aMesh->getNumberOfElements(MED_EN::MED_FACE, MED_EN::MED_ALL_ELEMENTS));
00411   for (int i = 1; i <= 8; i++) 
00412     {
00413       CPPUNIT_ASSERT_EQUAL(i, aSupportOnFaces1->getValIndFromGlobalNumber(i));
00414     }
00415 
00416   //#ifdef ENABLE_FORCED_FAILURES
00417   // Why methods setNumber do not throw exception in case "isOnAllElements == true",
00418   // like methods getNumber do?
00419   //CPPUNIT_ASSERT_THROW(aSupportOnFaces1->setNumber(indexSF1, valueSF1));
00420   //#endif
00421 
00422   // skl: setTotalNumberOfElements() is removed.
00423   //#ifdef ENABLE_FORCED_FAILURES
00424   // It seems to be dangerous and useless to have method SUPPORT::setTotalNumberOfElements()
00425   //CPPUNIT_FAIL("It seems to be dangerous and useless to have method SUPPORT::setTotalNumberOfElements()");
00426   //#endif
00427 
00428   // following test is commented since method
00429   // setTotalNumberOfElements() is removed.
00430   /*
00431   // setTotalNumberOfElements
00432   aSupportOnFaces1->setTotalNumberOfElements(1000);
00433   CPPUNIT_ASSERT_EQUAL(1000, aSupportOnFaces1->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
00434   */
00435 
00436   // clearDataOnNumbers
00437   aSupportOnCells1->clearDataOnNumbers();
00438   CPPUNIT_ASSERT_EQUAL(0, aSupportOnCells1->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
00439   CPPUNIT_ASSERT_EQUAL(0, aSupportOnCells1->getNumberOfTypes());
00440   CPPUNIT_ASSERT_THROW(aSupportOnCells1->getnumber(), MEDEXCEPTION);
00441 
00443   // TEST 2 //
00445 
00446   list<int> nodes137;
00447   nodes137.push_back(1);
00448   nodes137.push_back(3);
00449   nodes137.push_back(7);
00450 
00451   list<int> nodes248;
00452   nodes248.push_back(2);
00453   nodes248.push_back(4);
00454   nodes248.push_back(8);
00455 
00456   list<int> nodes27;
00457   nodes27.push_back(2);
00458   nodes27.push_back(7);
00459 
00460   SUPPORT *aNodes137 = new SUPPORT;
00461   SUPPORT *aNodes248 = new SUPPORT;
00462   SUPPORT *aNodes27 = new SUPPORT;
00463   aNodes137->setMesh( aMesh );
00464   aNodes248->setMesh( aMesh );
00465   aNodes27->setMesh( aMesh );
00466   aNodes137->setName( "Support On Nodes 1,3,7" );
00467   aNodes248->setName( "Support On Nodes 2,4,8" );
00468   aNodes27->setName( "Support On Nodes 2,7" );
00469 
00470   aNodes137->fillFromNodeList(nodes137);
00471   aNodes248->fillFromNodeList(nodes248);
00472   aNodes27->fillFromNodeList(nodes27);
00473 
00474   CPPUNIT_ASSERT_EQUAL(MED_EN::MED_NODE, aNodes137->getEntity());
00475   CPPUNIT_ASSERT_EQUAL(MED_EN::MED_NODE, aNodes248->getEntity());
00476 
00477   list<int>::const_iterator iter137 = nodes137.begin();
00478   list<int>::const_iterator iter248 = nodes248.begin();
00479   for (int i = 1; i <= 3; i++, iter137++, iter248++) 
00480     {
00481       CPPUNIT_ASSERT_EQUAL(i, aNodes137->getValIndFromGlobalNumber(*iter137));
00482       CPPUNIT_ASSERT_EQUAL(i, aNodes248->getValIndFromGlobalNumber(*iter248));
00483     }
00484 
00486 
00487   list<int> faces123;
00488   faces123.push_back(1);
00489   faces123.push_back(2);
00490   faces123.push_back(3);
00491 
00492   list<int> faces135;
00493   faces135.push_back(1);
00494   faces135.push_back(3);
00495   faces135.push_back(5);
00496 
00497   SUPPORT *aFaces123 = new SUPPORT;
00498   aFaces123->setMesh( aMesh );
00499   aFaces123->setName( "Support On Faces 1,2,3" );
00500   aFaces123->setEntity( MED_EN::MED_FACE );
00501   SUPPORT *aFaces135 = new SUPPORT;
00502   aFaces135->setMesh( aMesh );
00503   aFaces135->setName( "Support On Faces 1,3,5" );
00504   aFaces135->setEntity( MED_EN::MED_FACE );
00505 
00506   aFaces123->fillFromElementList(faces123);
00507   aFaces135->fillFromElementList(faces135);
00508 
00509   CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aFaces123->getEntity());
00510   CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aFaces135->getEntity());
00511 
00512   list<int>::const_iterator iter123 = faces123.begin();
00513   list<int>::const_iterator iter135 = faces135.begin();
00514   for (int i = 1; i <= 3; i++, iter123++, iter135++) 
00515     {
00516       CPPUNIT_ASSERT_EQUAL(i, aFaces123->getValIndFromGlobalNumber(*iter123));
00517       CPPUNIT_ASSERT_EQUAL(i, aFaces135->getValIndFromGlobalNumber(*iter135));
00518     }
00519 
00520   // substract
00521   SUPPORT * aFaces2 = aFaces123->substract(*aFaces135); // => 2
00522   CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aFaces2->getEntity());
00523   CPPUNIT_ASSERT_EQUAL(1, aFaces2->getValIndFromGlobalNumber(2));
00524   CPPUNIT_ASSERT_EQUAL(1, aFaces2->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
00525 
00526   CPPUNIT_ASSERT_THROW(aFaces123->substract(*aNodes137), MEDEXCEPTION);
00527 
00528   //#ifdef ENABLE_FORCED_FAILURES
00529   // (BUG) SUPPORT::substract() does not work with supports on nodes,
00530   //       because it uses method MESH::buildSupportOnNodeFromElementList(),
00531   //       which does not work if entity = MED_NODE
00532   //SUPPORT * aNodes137mesh = aMesh->buildSupportOnNodeFromElementList(nodes137, MED_EN::MED_NODE);
00533   //delete aNodes137mesh;
00534   SUPPORT * aNodes137sub = aNodes137->substract(*aNodes248); // => 1,3,7
00535   CPPUNIT_ASSERT_EQUAL(*aNodes137sub, *aNodes137);
00536   aNodes137sub->removeReference();
00537   //#endif
00538 
00539   // belongsTo
00540   CPPUNIT_ASSERT(aFaces2->belongsTo(*aFaces123));
00541   CPPUNIT_ASSERT(!aFaces2->belongsTo(*aFaces135));
00542 
00543   CPPUNIT_ASSERT(!aFaces2->belongsTo(*aSupportOnFaces3));
00544   CPPUNIT_ASSERT(aFaces2->belongsTo(*aSupportOnFaces3, /*deepCompare*/true));
00545 
00546   aFaces2->removeReference();
00547 
00548   // getComplement
00549   SUPPORT * aFaces_135 = aFaces135->getComplement(); // => 2,4,6,7,8
00550   CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aFaces_135->getEntity());
00551   CPPUNIT_ASSERT_EQUAL(5, aFaces_135->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
00552 
00553   //#ifdef ENABLE_FORCED_FAILURES
00554   // (BUG) Memory problem in SUPPORT::sub()
00555   // Invalid read of size 4
00556   //    at 0x34902492: MEDMEM::SUPPORT::sub(int, int, int const*, int) (MEDMEM_Support.cxx:852)
00557   //    by 0x3490296B: MEDMEM::SUPPORT::getComplement() const (MEDMEM_Support.cxx:916)
00558   //    by 0x34398F1E: MEDMEMTest::testSupport() (MEDMEMTest_Support.cxx:514)
00559   //  Address 0x352DB91C is 0 bytes after a block of size 12 alloc'd
00560   //    at 0x3414C8E2: operator new[](unsigned) (vg_replace_malloc.c:138)
00561   //    by 0x3490243A: MEDMEM::SUPPORT::sub(int, int, int const*, int) (MEDMEM_Support.cxx:847)
00562   //    by 0x3490296B: MEDMEM::SUPPORT::getComplement() const (MEDMEM_Support.cxx:916)
00563   //    by 0x34398F1E: MEDMEMTest::testSupport() (MEDMEMTest_Support.cxx:514)
00564   //  CPPUNIT_FAIL("Memory problem in SUPPORT::sub(): Invalid read of size 4 from array <temp>");
00565   //#endif
00566 
00567   //#ifdef ENABLE_FORCED_FAILURES
00568   // (BUG) SUPPORT::getComplement() does not work with support on nodes,
00569   //       because it uses method MESH::buildSupportOnNodeFromElementList(),
00570   //       which does not work if entity = MED_NODE
00571   SUPPORT * aNodes_137 = aNodes137->getComplement(); // => 2,4,5,6,8,9,10-19
00572   CPPUNIT_ASSERT_EQUAL(MED_EN::MED_NODE, aNodes_137->getEntity());
00573   CPPUNIT_ASSERT_EQUAL(16, aNodes_137->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
00574   //#endif
00575 
00576   // intersecting
00577   aFaces_135->intersecting(aFaces123); // => 2
00578   CPPUNIT_ASSERT_EQUAL(1, aFaces_135->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
00579   CPPUNIT_ASSERT_EQUAL(1, aFaces_135->getValIndFromGlobalNumber(2));
00580 
00581   //aNodes_137->intersecting(&aNodes248); // => 2,4,8
00582   //CPPUNIT_ASSERT_EQUAL(3, aNodes_137->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
00583   //CPPUNIT_ASSERT_EQUAL(*aNodes_137, aNodes248);
00584   aNodes137->intersecting(aNodes248); // => 
00585   {
00586   }
00587   CPPUNIT_ASSERT_EQUAL(0, aNodes137->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
00588 
00589   // blending
00590   aFaces_135->blending(aFaces135); // => 1,2,3,5
00591   CPPUNIT_ASSERT_EQUAL(4, aFaces_135->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
00592 
00593   aNodes248->blending(aNodes27); // => 2,4,7,8
00594   CPPUNIT_ASSERT_EQUAL(4, aNodes248->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
00595 
00596   // operator=
00597   SUPPORT *aCopy1=new SUPPORT;
00598   *aCopy1 = *aNodes248;
00599   CPPUNIT_ASSERT_EQUAL(*aNodes248, *aCopy1);
00600 
00601   // copy constructor
00602   SUPPORT *aCopy2=new SUPPORT(*aFaces135);
00603   CPPUNIT_ASSERT_EQUAL(*aFaces135, *aCopy2);
00604 
00605   aFaces_135->removeReference();
00606   //#ifdef ENABLE_FORCED_FAILURES
00607   aNodes_137->removeReference();
00608   //#endif
00609 
00610   // profil names
00611   vector<string> aPrN2 (2); // nb. types
00612   aPrN2[0] = "Profil 1";
00613   aPrN2[1] = "Profil 2";
00614   aFaces135->setProfilNames(aPrN2);
00615 
00616   // because on all elements
00617   CPPUNIT_ASSERT_THROW(aSupportOnFaces3->setProfilNames(aPrN2), MEDEXCEPTION);
00618 
00619   // because length of vector is not equal to nb.types
00620   vector<string> aPrN3 (3);
00621   CPPUNIT_ASSERT_THROW(aFaces135->setProfilNames(aPrN3), MEDEXCEPTION);
00622 
00623   vector<string> aPrN2Back = aFaces135->getProfilNames();
00624   CPPUNIT_ASSERT_EQUAL(aPrN2[0], aPrN2Back[0]);
00625   CPPUNIT_ASSERT_EQUAL(aPrN2[1], aPrN2Back[1]);
00626 
00627   //#ifdef ENABLE_FORCED_FAILURES
00628   // (BUG) profil names are not copied by copy constructor and operator=,
00629   // not compared by operator==, not dumped in stream by operator<<
00630   //CPPUNIT_FAIL("Not complete implementation for Profil Names");
00631   //#endif
00632 
00634   // TEST 3 //
00636 
00637   SUPPORT *aPartialCells = new SUPPORT;
00638   aPartialCells->setMesh( aMesh );
00639   aPartialCells->setName( "Support On Cells 2,3,4" );
00640   aPartialCells->setEntity( MED_EN::MED_CELL );
00641 
00642   SUPPORT *aPartialNodes = new SUPPORT;
00643   aPartialNodes->setMesh( aMesh );
00644   aPartialNodes->setName( "Support On Nodes 2,3,4" );
00645   aPartialNodes->setEntity( MED_EN::MED_NODE );
00646 
00647   // setpartial
00648   MED_EN::medGeometryElement gtCells[1] = 
00649     {
00650       MED_EN::MED_TETRA4
00651     };
00652   int nbCells[1] = 
00653     {
00654       3
00655     };
00656   int cells[3] = 
00657     {
00658       2,3,4
00659     };
00660   aPartialCells->setpartial("with description", 1, 3, gtCells, nbCells, cells);
00661   CPPUNIT_ASSERT_EQUAL(1, aPartialCells->getValIndFromGlobalNumber(2));
00662   CPPUNIT_ASSERT_EQUAL(2, aPartialCells->getValIndFromGlobalNumber(3));
00663   CPPUNIT_ASSERT_EQUAL(3, aPartialCells->getValIndFromGlobalNumber(4));
00664 
00665   MED_EN::medGeometryElement gtNodes[1] = 
00666     {
00667       MED_EN::MED_NONE
00668     };
00669   aPartialNodes->setNumberOfGeometricType(1);
00670   aPartialNodes->setGeometricType(gtNodes);
00671   int indexSN[2] = 
00672     {
00673       1,4
00674     };
00675   int valueSN[3] = 
00676     {
00677       2,3,4
00678     };
00679   MEDSKYLINEARRAY * aNumberSN = new MEDSKYLINEARRAY(1, 3, indexSN, valueSN);
00680   aPartialNodes->setpartial(aNumberSN, /*shallowCopy*/false);
00681   delete aNumberSN;
00682   CPPUNIT_ASSERT_EQUAL(1, aPartialNodes->getValIndFromGlobalNumber(2));
00683   CPPUNIT_ASSERT_EQUAL(2, aPartialNodes->getValIndFromGlobalNumber(3));
00684   CPPUNIT_ASSERT_EQUAL(3, aPartialNodes->getValIndFromGlobalNumber(4));
00685 
00686   // changeElementsNbs
00687 
00688   // {1,2,3,4,5,6,7,8,9,10} -> {10,9,8,7,6,5,4,3,2,1}
00689   int renumberingFromOldToNew[10] = 
00690     {
00691       10,9,8,7,6,5,4,3,2,1
00692     };
00693 
00694   CPPUNIT_ASSERT_THROW(aPartialCells->changeElementsNbs
00695                        (MED_EN::MED_NODE, renumberingFromOldToNew), MEDEXCEPTION);
00696 
00697   aPartialCells->changeElementsNbs(MED_EN::MED_CELL, renumberingFromOldToNew);
00698   CPPUNIT_ASSERT_EQUAL(3, aPartialCells->getValIndFromGlobalNumber(9));
00699   CPPUNIT_ASSERT_EQUAL(2, aPartialCells->getValIndFromGlobalNumber(8));
00700   CPPUNIT_ASSERT_EQUAL(1, aPartialCells->getValIndFromGlobalNumber(7));
00701 
00702   // {1,2,3,4,5,6,7} -> {1,3,5,7,2,4,6}, {8,9,10,11} -> {8,10,9,11}
00703   int renumberingFromOldToNewP[11] = 
00704     {
00705       1,3,5,7,2,4,6,8,10,9,11
00706     };
00707   aPartialCells->changeElementsNbs(MED_EN::MED_CELL, renumberingFromOldToNewP);
00708   CPPUNIT_ASSERT_EQUAL(3, aPartialCells->getValIndFromGlobalNumber(10));
00709   CPPUNIT_ASSERT_EQUAL(2, aPartialCells->getValIndFromGlobalNumber(8));
00710   CPPUNIT_ASSERT_EQUAL(1, aPartialCells->getValIndFromGlobalNumber(6));
00711 
00712   // this method does not suit for nodes renumbering!
00713   // {1,2,3} -> {3,2,1}, {4,5,6,7} -> {5,6,7,4}
00714   //int renumberingFromOldToNewN[3] = {3,2,1};
00715   //int renumberingFromOldToNewPolyN[4] = {5,6,7,4};
00716   //aPartialNodes.changeElementsNbs(MED_EN::MED_NODE, renumberingFromOldToNewN,
00717   //                                3, renumberingFromOldToNewPolyN);
00718 
00719   // getBoundaryElements
00720   //#ifdef ENABLE_FAULTS
00721   // (BUG) Segmentation Fault during SUPPORT::getBoundaryElements()
00722   // ??? May be mesh is not complete ???
00723   SUPPORT *aBoundaryFaces = new SUPPORT;
00724   aBoundaryFaces->setMesh( aMesh );
00725   aBoundaryFaces->setName( "meshing boundary faces" );
00726   aBoundaryFaces->setEntity( MED_EN::MED_FACE );
00727   //cout << "aBoundaryFaces:" << endl;
00728   //cout << aBoundaryFaces << endl;
00729   aBoundaryFaces->removeReference();
00730 
00731   SUPPORT * aBoundaryNodes = aSupportOnFaces3->getBoundaryElements(MED_EN::MED_NODE);
00732   //cout << "aSupportOnFaces3:" << endl;
00733   //cout << aSupportOnFaces3 << endl;
00734   //cout << "aBoundaryNodes:" << endl;
00735   //cout << aBoundaryNodes << endl;
00736   aBoundaryNodes->removeReference();
00737   //#endif
00738   //#ifdef ENABLE_FORCED_FAILURES
00739   //  CPPUNIT_FAIL("Segmentation Fault during SUPPORT::getBoundaryElements()");
00740   // Invalid write of size 4
00741   //   at 0x3439DFCE: void std::_Construct<int, int>(int*, int const&) (stl_construct.h:81)
00742   //   by 0x3476E4D1: std::vector<int, std::allocator<int> >::push_back(int const&) (stl_vector.h:560)
00743   //   by 0x34763DDB: MEDMEM::CONNECTIVITY::calculateReverseNodalConnectivity() (MEDMEM_Connectivity.cxx:1155)
00744   //   by 0x347655FF: MEDMEM::CONNECTIVITY::calculateDescendingConnectivity() (MEDMEM_Connectivity.cxx:1333)
00745   //   by 0x3476363E: MEDMEM::CONNECTIVITY::getReverseDescendingConnectivity() (MEDMEM_Connectivity.cxx:1090)
00746   //   by 0x34772AB6: MEDMEM::CONNECTIVITY::getReverseConnectivity(long, long) (MEDMEM_Connectivity.hxx:503)
00747   //   by 0x348F4F4B: MEDMEM::MESH::getReverseConnectivity(long, long) const (MEDMEM_Mesh.hxx:848)
00748   //   by 0x348FF559: MEDMEM::SUPPORT::getBoundaryElements() (MEDMEM_Support.cxx:483)
00749   //   by 0x3439C8E5: MEDMEMTest::testSupport() (MEDMEMTest_Support.cxx:641)
00750   //  Address 0x61666A2F is not stack'd, malloc'd or (recently) free'd
00751   //#endif
00752 
00753   delete aMesh;
00754   delete aMeshOneMore;
00755 }
00756 
00757 int main (int argc, char** argv)
00758 {
00759   MEDMEMTest_testSupport();
00760 }