1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MEDMEMTest.hxx"
21 #include <cppunit/TestAssert.h>
23 #include "MEDMEM_Mesh.hxx"
24 #include "MEDMEM_STRING.hxx"
25 #include "MEDMEM_Support.hxx"
30 // use this define to enable lines, execution of which leads to Segmentation Fault
31 //#define ENABLE_FAULTS
33 // use this define to enable CPPUNIT asserts and fails, showing bugs
34 //#define ENABLE_FORCED_FAILURES
37 using namespace MEDMEM;
39 // #52: MEDMEM_Support.hxx } MEDMEMTest_Support.cxx
42 * Check methods (48), defined in MEDMEM_Support.hxx:
43 * class SUPPORT : public RCBASE
46 * (+) SUPPORT(MESH* Mesh, string Name="", MED_EN::medEntityMesh Entity=MED_EN::MED_CELL);
47 * (+) SUPPORT(const SUPPORT & m);
48 * (+) virtual ~SUPPORT();
50 * (+) friend ostream & operator<<(ostream &os,const SUPPORT &my);
51 * (+) SUPPORT& operator=(const SUPPORT &support);
52 * (+) bool operator == (const SUPPORT &support) const;
53 * (+) bool deepCompare(const SUPPORT &support) const;
57 * (+) inline void setName(string Name);
58 * (+) inline void setDescription(string Description);
59 * (+) void setMesh(MESH *Mesh) const;
60 * (+) inline void setMeshName(const string & meshName);
61 * (+) inline void setAll(bool All);
62 * (+) inline void setEntity(MED_EN::medEntityMesh Entity);
64 * (+) inline void setNumberOfGeometricType(int NumberOfGeometricType);
65 * (+) inline void setGeometricType(const MED_EN::medGeometryElement *GeometricType);
66 * (+) inline void setNumberOfElements(const int *NumberOfElements);
67 * (+) inline void setTotalNumberOfElements(int TotalNumberOfElements);
68 * (+) inline void setNumber(MEDSKYLINEARRAY * Number);
69 * (+) inline void setNumber(const int * index, const int* value, bool shallowCopy=false);
71 * (+) inline string getName() const;
72 * (+) inline string getDescription() const;
73 * (+) virtual inline MESH * getMesh() const;
74 * (+) string getMeshName() const;
75 * (+) inline MED_EN::medEntityMesh getEntity() const;
76 * (+) inline bool isOnAllElements() const;
78 * (+) inline int getNumberOfTypes() const;
79 * (+) inline const MED_EN::medGeometryElement* getTypes() const;
80 * (+) inline int getNumberOfElements
81 * (MED_EN::medGeometryElement GeometricType) const throw (MEDEXCEPTION);
82 * (+) inline const int * getNumberOfElements() const throw (MEDEXCEPTION);
83 * (+) virtual inline MEDSKYLINEARRAY * getnumber() const throw (MEDEXCEPTION);
84 * (NO METHOD IN THIS BRANCH) virtual inline MEDSKYLINEARRAY * getnumberFromFile() const throw (MEDEXCEPTION);
85 * (+) virtual inline const int * getNumber
86 * (MED_EN::medGeometryElement GeometricType) const throw (MEDEXCEPTION);
87 * (NO METHOD IN THIS BRANCH) virtual inline const int * getNumberFromFile
88 * (MED_EN::medGeometryElement GeometricType) const throw (MEDEXCEPTION);
89 * (+) virtual inline const int * getNumberIndex() const throw (MEDEXCEPTION);
90 * (+) virtual int getValIndFromGlobalNumber(const int number) const throw (MEDEXCEPTION);
92 * (+) void blending(SUPPORT * mySupport) throw (MEDEXCEPTION);
94 * (+) void setpartial(string Description, int NumberOfGeometricType,
95 * int TotalNumberOfEntity, MED_EN::medGeometryElement *GeometricType,
96 * int *NumberOfEntity, int *NumberValue);
97 * (+) void setpartial(MEDSKYLINEARRAY * number, bool shallowCopy=false) throw (MEDEXCEPTION);
98 * (NO METHOD IN THIS BRANCH) void setpartial_fromfile(MEDSKYLINEARRAY * number, bool shallowCopy=false) throw (MEDEXCEPTION);
100 * (+) void setProfilNames(vector<string> profilNames) throw (MEDEXCEPTION);
101 * (+) vector<string> getProfilNames() const throw (MEDEXCEPTION);
103 * (+) void getBoundaryElements() throw (MEDEXCEPTION);
105 * (+) void changeElementsNbs(MED_EN::medEntityMesh entity, const int *renumberingFromOldToNew);
106 * (+) void intersecting(SUPPORT * mySupport) throw (MEDEXCEPTION);
107 * (+) bool belongsTo(const SUPPORT& other, bool deepCompare=false) const;
109 * (+) SUPPORT *getComplement() const;
110 * (+) SUPPORT *substract(const SUPPORT& other) const throw (MEDEXCEPTION);
112 * (+) SUPPORT *getBoundaryElements(MED_EN::medEntityMesh Entity) const throw (MEDEXCEPTION);
114 * (+) void fillFromNodeList(const list<int>& listOfNode) throw (MEDEXCEPTION);
115 * (+) void fillFromElementList(const list<int>& listOfElt) throw (MEDEXCEPTION);
117 * (+) void clearDataOnNumbers();
119 * (reference counter presently disconnected in C++) virtual void addReference() const;
120 * (reference counter presently disconnected in C++) virtual void removeReference() const;
124 static void MEDMEMTest_testSupport()
126 MESH * aMesh = MEDMEMTest_createTestMesh();
127 MESH * aMeshOneMore = MEDMEMTest_createTestMesh();
133 SUPPORT *aSupportOnFaces1 = new SUPPORT;
134 aSupportOnFaces1->setMesh( aMesh );
135 aSupportOnFaces1->setName( "Support On Faces 1" );
136 aSupportOnFaces1->setEntity( MED_EN::MED_FACE );
137 aSupportOnFaces1->setAll( true );
138 aSupportOnFaces1->update();
140 SUPPORT *aSupportOnCells1 = new SUPPORT;
141 aSupportOnCells1->setMesh( aMesh );
142 aSupportOnCells1->setName( "Support On Cells 1" );
143 aSupportOnFaces1->setAll( true );
144 aSupportOnFaces1->update();
146 SUPPORT *aSupportOnFaces2=new SUPPORT;
147 SUPPORT *aSupportOnCells2=new SUPPORT;
149 SUPPORT *aSupportOnFaces3 = new SUPPORT;
150 aSupportOnFaces3->setMesh( aMeshOneMore );
151 aSupportOnFaces3->setName( "Support On Faces 3" );
152 aSupportOnFaces3->setEntity( MED_EN::MED_FACE );
153 aSupportOnFaces1->setAll( true );
154 aSupportOnFaces1->update();
157 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aSupportOnFaces1->getEntity());
158 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_CELL, aSupportOnCells1->getEntity());
160 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_CELL, aSupportOnFaces2->getEntity());
161 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_CELL, aSupportOnCells2->getEntity());
163 aSupportOnFaces2->setEntity(MED_EN::MED_FACE);
164 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aSupportOnFaces2->getEntity());
167 CPPUNIT_ASSERT(aSupportOnFaces1->isOnAllElements());
168 CPPUNIT_ASSERT(aSupportOnCells1->isOnAllElements());
170 CPPUNIT_ASSERT(!aSupportOnFaces2->isOnAllElements());
171 CPPUNIT_ASSERT(!aSupportOnCells2->isOnAllElements());
173 // mesh and mesh name
174 CPPUNIT_ASSERT_THROW(aSupportOnFaces1->setMeshName("Mesh 1"), MEDEXCEPTION);
176 aSupportOnFaces2->setMeshName("Mesh 1");
177 aSupportOnCells2->setMeshName("Mesh 1");
178 CPPUNIT_ASSERT(aSupportOnFaces2->getMeshName() == "Mesh 1");
179 CPPUNIT_ASSERT(aSupportOnCells2->getMeshName() == "Mesh 1");
181 aSupportOnFaces2->setMesh(aMesh);
182 CPPUNIT_ASSERT_THROW(aSupportOnFaces2->setMeshName("Mesh 1"), MEDEXCEPTION);
184 aSupportOnCells1->setMesh(NULL);
185 aSupportOnCells1->setMeshName("Mesh 1");
187 CPPUNIT_ASSERT(aSupportOnFaces1->getMeshName() == "meshing");
188 CPPUNIT_ASSERT(aSupportOnFaces2->getMeshName() == "meshing");
189 CPPUNIT_ASSERT(aSupportOnCells1->getMeshName() == "Mesh 1");
190 CPPUNIT_ASSERT(aSupportOnCells2->getMeshName() == "Mesh 1");
192 CPPUNIT_ASSERT(aSupportOnFaces1->getMesh() == aMesh);
193 CPPUNIT_ASSERT(aSupportOnFaces2->getMesh() == aMesh);
194 CPPUNIT_ASSERT(aSupportOnCells1->getMesh() == NULL);
195 CPPUNIT_ASSERT(aSupportOnCells2->getMesh() == NULL);
198 aSupportOnFaces2->setName("Support On Faces 2");
199 aSupportOnCells2->setName("Support On Cells 2");
201 // because aSupportOnFaces1 is on all elements, but aSupportOnFaces2 not
202 CPPUNIT_ASSERT(!(aSupportOnFaces1 == aSupportOnFaces2));
204 aSupportOnCells1->setAll(false);
205 CPPUNIT_ASSERT(!aSupportOnCells1->isOnAllElements());
206 // this is only sets flag _isOnAllElts to false, but not clear elements and types
207 // information, so aSupportOnCells1 is not equal to aSupportOnCells2 at this moment
209 //#ifdef ENABLE_FAULTS
210 // (BUG) SUPPORT::operator= gives "Segmentation Fault" on supports with NULL meshes!!!
211 CPPUNIT_ASSERT(!(aSupportOnCells1 == aSupportOnCells2));
213 //#ifdef ENABLE_FORCED_FAILURES
214 // CPPUNIT_FAIL("SUPPORT::operator= gives Segmentation Fault on supports with NULL meshes!!!");
217 aSupportOnFaces2->setAll(true);
218 CPPUNIT_ASSERT(aSupportOnFaces2->isOnAllElements());
219 // flag _isOnAllElts now is set to true, but we need also to call update()
220 // to set elements and types information from mesh to this support
221 CPPUNIT_ASSERT(!(aSupportOnFaces1 == aSupportOnFaces2));
222 aSupportOnFaces2->update();
223 CPPUNIT_ASSERT(aSupportOnFaces1 == aSupportOnFaces2);
226 CPPUNIT_ASSERT(aSupportOnFaces1->deepCompare(*aSupportOnFaces2));
228 CPPUNIT_ASSERT(!(aSupportOnFaces1 == aSupportOnFaces3)); // different mesh pointers
229 CPPUNIT_ASSERT(aSupportOnFaces1->deepCompare(*aSupportOnFaces3)); // meshes are really equal
232 aSupportOnFaces1->setDescription("Support on all faces with mesh pointer");
233 aSupportOnFaces2->setDescription("Support on all faces with mesh pointer");
235 aSupportOnCells1->setDescription("Support on a part of cells with mesh name");
236 aSupportOnCells2->setDescription("Support on a part of cells with mesh name");
238 CPPUNIT_ASSERT(aSupportOnFaces1->getDescription() == "Support on all faces with mesh pointer");
239 CPPUNIT_ASSERT(aSupportOnFaces2->getDescription() == "Support on all faces with mesh pointer");
240 CPPUNIT_ASSERT(aSupportOnCells1->getDescription() == "Support on a part of cells with mesh name");
241 CPPUNIT_ASSERT(aSupportOnCells2->getDescription() == "Support on a part of cells with mesh name");
245 ostr1 << aSupportOnFaces1;
246 CPPUNIT_ASSERT(ostr1.str() != "");
249 ostr2 << aSupportOnCells2;
250 CPPUNIT_ASSERT(ostr2.str() != "");
252 // set/get elements and types information
254 // 1. aSupportOnCells1 is not on all elements, but now it contains information
255 // about all cells of aMesh, because it was created on mesh and with parameters.
256 CPPUNIT_ASSERT_EQUAL(3, aSupportOnCells1->getNumberOfTypes());
257 CPPUNIT_ASSERT(aSupportOnCells1->getTypes() != NULL);
259 aSupportOnCells1->setNumberOfGeometricType(0);
260 CPPUNIT_ASSERT_EQUAL(0, aSupportOnCells1->getNumberOfTypes());
261 CPPUNIT_ASSERT(aSupportOnCells1->getTypes() == NULL);
263 MED_EN::medGeometryElement aSCTypes[2] =
265 MED_EN::MED_PYRA5, MED_EN::MED_PENTA15
267 aSupportOnCells1->setNumberOfGeometricType(2);
268 aSupportOnCells1->setGeometricType(aSCTypes);
270 CPPUNIT_ASSERT_EQUAL(2, aSupportOnCells1->getNumberOfTypes());
271 CPPUNIT_ASSERT(aSupportOnCells1->getTypes() != NULL);
272 CPPUNIT_ASSERT(aSupportOnCells1->getNumberOfElements() == NULL); // reset by setNumberOfGeometricType
278 aSupportOnCells1->setNumberOfElements(nbEltsSC);
280 const int * nbEltsSCBack = aSupportOnCells1->getNumberOfElements();
281 CPPUNIT_ASSERT_EQUAL(2, aSupportOnCells1->getNumberOfElements(MED_EN::MED_PYRA5));
282 CPPUNIT_ASSERT_EQUAL(2, nbEltsSCBack[0]);
283 CPPUNIT_ASSERT_EQUAL(1, aSupportOnCells1->getNumberOfElements(MED_EN::MED_PENTA15));
284 CPPUNIT_ASSERT_EQUAL(1, nbEltsSCBack[1]);
285 CPPUNIT_ASSERT_EQUAL(3, aSupportOnCells1->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
288 CPPUNIT_ASSERT_THROW(aSupportOnCells1->getNumberOfElements(MED_EN::MED_TETRA4), MEDEXCEPTION);
289 CPPUNIT_ASSERT_THROW(aSupportOnCells1->getNumberOfElements(MED_EN::MED_HEXA8), MEDEXCEPTION);
291 //_number= new MEDSKYLINEARRAY(_numberOfGeometricType,_totalNumberOfElements,index,value,shallowCopy);
295 }; // length = nb.types + 1
299 }; // length = total nb. of elements
300 aSupportOnCells1->setNumber(indexSC, valueSC);
303 MEDSKYLINEARRAY * aNumberSCBack = aSupportOnCells1->getnumber();
305 CPPUNIT_ASSERT_EQUAL(2, aNumberSCBack->getNumberOf());
306 CPPUNIT_ASSERT_EQUAL(3, aNumberSCBack->getLength());
307 const int * ind = aNumberSCBack->getIndex();
308 const int * val = aNumberSCBack->getValue();
309 CPPUNIT_ASSERT_EQUAL(1, ind[0]);
310 CPPUNIT_ASSERT_EQUAL(3, ind[1]);
311 CPPUNIT_ASSERT_EQUAL(4, ind[2]);
312 CPPUNIT_ASSERT_EQUAL(21, val[0]);
313 CPPUNIT_ASSERT_EQUAL(22, val[1]);
314 CPPUNIT_ASSERT_EQUAL(47, val[2]);
316 // 2. aSupportOnCells2 is not on all elements, and now it contains
317 // no information about elements of a mesh
318 CPPUNIT_ASSERT_EQUAL(0, aSupportOnCells2->getNumberOfTypes());
319 CPPUNIT_ASSERT(aSupportOnCells2->getTypes() == NULL);
321 aSupportOnCells2->setNumberOfGeometricType(2);
322 aSupportOnCells2->setGeometricType(aSCTypes);
324 CPPUNIT_ASSERT_EQUAL(2, aSupportOnCells2->getNumberOfTypes());
325 CPPUNIT_ASSERT(aSupportOnCells2->getTypes() != NULL);
327 aSupportOnCells2->setNumberOfElements(nbEltsSC);
329 // we create MEDSKYLINEARRAY as pointer, because aSupportOnCells2 will
330 // become an owner of it, and we must not delete it.
331 MEDSKYLINEARRAY * aNumberSC = new MEDSKYLINEARRAY(2, 3, indexSC, valueSC);
332 aSupportOnCells2->setNumber(aNumberSC);
335 const int * aNumberIndexSC = aSupportOnCells2->getNumberIndex();
336 CPPUNIT_ASSERT_EQUAL(1, aNumberIndexSC[0]);
337 CPPUNIT_ASSERT_EQUAL(3, aNumberIndexSC[1]);
338 CPPUNIT_ASSERT_EQUAL(4, aNumberIndexSC[2]);
340 const int * aNbPYRA5 = aSupportOnCells2->getNumber(MED_EN::MED_PYRA5);
341 const int * aNbPENTA15 = aSupportOnCells2->getNumber(MED_EN::MED_PENTA15);
342 CPPUNIT_ASSERT_THROW(aSupportOnCells2->getNumber(MED_EN::MED_TETRA4), MEDEXCEPTION);
344 const int * aNbC = aSupportOnCells2->getNumber(MED_EN::MED_ALL_ELEMENTS);
346 CPPUNIT_ASSERT_EQUAL(21, aNbPYRA5[0]);
347 CPPUNIT_ASSERT_EQUAL(22, aNbPYRA5[1]);
348 CPPUNIT_ASSERT_EQUAL(47, aNbPENTA15[0]);
350 CPPUNIT_ASSERT_EQUAL(21, aNbC[0]);
351 CPPUNIT_ASSERT_EQUAL(22, aNbC[1]);
352 CPPUNIT_ASSERT_EQUAL(47, aNbC[2]);
354 // getValIndFromGlobalNumber
355 CPPUNIT_ASSERT_EQUAL(1, aSupportOnCells2->getValIndFromGlobalNumber(21));
356 CPPUNIT_ASSERT_EQUAL(2, aSupportOnCells2->getValIndFromGlobalNumber(22));
357 CPPUNIT_ASSERT_EQUAL(3, aSupportOnCells2->getValIndFromGlobalNumber(47));
358 // not existing element
359 CPPUNIT_ASSERT_THROW(aSupportOnCells2->getValIndFromGlobalNumber(10), MEDEXCEPTION);
361 // compare aSupportOnCells1 and aSupportOnCells2
363 // temporary set mesh (because of bug with operator==)
364 aSupportOnCells1->setMesh(aMesh);
365 aSupportOnCells2->setMesh(aMesh);
367 CPPUNIT_ASSERT_EQUAL(aSupportOnCells1, aSupportOnCells2);
370 aSupportOnCells1->setMesh(NULL);
371 aSupportOnCells2->setMesh(NULL);
372 aSupportOnCells1->setMeshName("Mesh 1");
373 aSupportOnCells2->setMeshName("Mesh 1");
375 // 3. aSupportOnFacesN is on all elements, and it contains
376 // information about all faces of aMesh
377 CPPUNIT_ASSERT_EQUAL(2, aSupportOnFaces1->getNumberOfTypes());
378 const MED_EN::medGeometryElement* aSF1Types = aSupportOnFaces1->getTypes();
379 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_TRIA3, aSF1Types[0]);
380 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_QUAD4, aSF1Types[1]);
381 //#ifdef ENABLE_FORCED_FAILURES
382 // (BUG) Comment to method SUPPORT::getTypes() says:
383 // "If isOnAllElements is false, returns an array of %medGeometryElement types used by the support."
384 // But in fact it returns types in any case (comment to SUPPORT::setAll() gives more information).
385 // CPPUNIT_FAIL("Comment and implementation does not match for SUPPORT::getTypes()");
386 // This concerns also method SUPPORT::update(), being called from constructor,
387 // which fills internal SUPPORT structures with information about mesh elements
388 // in case of isOnAllElements == true.
389 // Also comments and implementation does not match for SUPPORT::getNumberOfElements().
390 // It seems that in case "isOnAllElements == true" calls like getNumberOfElements()
391 // must be redirected to mesh, but what if mesh is not set (mesh name used instead)?.
393 const int * nbEltsSF1 = aSupportOnFaces1->getNumberOfElements();
394 CPPUNIT_ASSERT_EQUAL(4, aSupportOnFaces1->getNumberOfElements(MED_EN::MED_TRIA3));
395 CPPUNIT_ASSERT_EQUAL(4, nbEltsSF1[0]);
396 CPPUNIT_ASSERT_EQUAL(4, aSupportOnFaces1->getNumberOfElements(MED_EN::MED_QUAD4));
397 CPPUNIT_ASSERT_EQUAL(4, nbEltsSF1[1]);
398 CPPUNIT_ASSERT_EQUAL(8, aSupportOnFaces1->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
399 CPPUNIT_ASSERT_THROW(aSupportOnFaces1->getNumberOfElements(MED_EN::MED_TRIA6), MEDEXCEPTION);
400 CPPUNIT_ASSERT_THROW(aSupportOnFaces1->getNumberOfElements(MED_EN::MED_QUAD8), MEDEXCEPTION);
403 CPPUNIT_ASSERT_THROW(aSupportOnFaces1->getNumberIndex(), MEDEXCEPTION);
404 CPPUNIT_ASSERT_THROW(aSupportOnFaces1->getNumber(MED_EN::MED_TRIA3), MEDEXCEPTION);
405 CPPUNIT_ASSERT_THROW(aSupportOnFaces1->getNumber(MED_EN::MED_QUAD4), MEDEXCEPTION);
406 CPPUNIT_ASSERT_THROW(aSupportOnFaces1->getNumber(MED_EN::MED_ALL_ELEMENTS), MEDEXCEPTION);
407 CPPUNIT_ASSERT_THROW(aSupportOnFaces1->getnumber(), MEDEXCEPTION);
409 // getValIndFromGlobalNumber
410 CPPUNIT_ASSERT_EQUAL(8, aMesh->getNumberOfElements(MED_EN::MED_FACE, MED_EN::MED_ALL_ELEMENTS));
411 for (int i = 1; i <= 8; i++)
413 CPPUNIT_ASSERT_EQUAL(i, aSupportOnFaces1->getValIndFromGlobalNumber(i));
416 //#ifdef ENABLE_FORCED_FAILURES
417 // Why methods setNumber do not throw exception in case "isOnAllElements == true",
418 // like methods getNumber do?
419 //CPPUNIT_ASSERT_THROW(aSupportOnFaces1->setNumber(indexSF1, valueSF1));
422 // skl: setTotalNumberOfElements() is removed.
423 //#ifdef ENABLE_FORCED_FAILURES
424 // It seems to be dangerous and useless to have method SUPPORT::setTotalNumberOfElements()
425 //CPPUNIT_FAIL("It seems to be dangerous and useless to have method SUPPORT::setTotalNumberOfElements()");
428 // following test is commented since method
429 // setTotalNumberOfElements() is removed.
431 // setTotalNumberOfElements
432 aSupportOnFaces1->setTotalNumberOfElements(1000);
433 CPPUNIT_ASSERT_EQUAL(1000, aSupportOnFaces1->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
436 // clearDataOnNumbers
437 aSupportOnCells1->clearDataOnNumbers();
438 CPPUNIT_ASSERT_EQUAL(0, aSupportOnCells1->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
439 CPPUNIT_ASSERT_EQUAL(0, aSupportOnCells1->getNumberOfTypes());
440 CPPUNIT_ASSERT_THROW(aSupportOnCells1->getnumber(), MEDEXCEPTION);
447 nodes137.push_back(1);
448 nodes137.push_back(3);
449 nodes137.push_back(7);
452 nodes248.push_back(2);
453 nodes248.push_back(4);
454 nodes248.push_back(8);
457 nodes27.push_back(2);
458 nodes27.push_back(7);
460 SUPPORT *aNodes137 = new SUPPORT;
461 SUPPORT *aNodes248 = new SUPPORT;
462 SUPPORT *aNodes27 = new SUPPORT;
463 aNodes137->setMesh( aMesh );
464 aNodes248->setMesh( aMesh );
465 aNodes27->setMesh( aMesh );
466 aNodes137->setName( "Support On Nodes 1,3,7" );
467 aNodes248->setName( "Support On Nodes 2,4,8" );
468 aNodes27->setName( "Support On Nodes 2,7" );
470 aNodes137->fillFromNodeList(nodes137);
471 aNodes248->fillFromNodeList(nodes248);
472 aNodes27->fillFromNodeList(nodes27);
474 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_NODE, aNodes137->getEntity());
475 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_NODE, aNodes248->getEntity());
477 list<int>::const_iterator iter137 = nodes137.begin();
478 list<int>::const_iterator iter248 = nodes248.begin();
479 for (int i = 1; i <= 3; i++, iter137++, iter248++)
481 CPPUNIT_ASSERT_EQUAL(i, aNodes137->getValIndFromGlobalNumber(*iter137));
482 CPPUNIT_ASSERT_EQUAL(i, aNodes248->getValIndFromGlobalNumber(*iter248));
488 faces123.push_back(1);
489 faces123.push_back(2);
490 faces123.push_back(3);
493 faces135.push_back(1);
494 faces135.push_back(3);
495 faces135.push_back(5);
497 SUPPORT *aFaces123 = new SUPPORT;
498 aFaces123->setMesh( aMesh );
499 aFaces123->setName( "Support On Faces 1,2,3" );
500 aFaces123->setEntity( MED_EN::MED_FACE );
501 SUPPORT *aFaces135 = new SUPPORT;
502 aFaces135->setMesh( aMesh );
503 aFaces135->setName( "Support On Faces 1,3,5" );
504 aFaces135->setEntity( MED_EN::MED_FACE );
506 aFaces123->fillFromElementList(faces123);
507 aFaces135->fillFromElementList(faces135);
509 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aFaces123->getEntity());
510 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aFaces135->getEntity());
512 list<int>::const_iterator iter123 = faces123.begin();
513 list<int>::const_iterator iter135 = faces135.begin();
514 for (int i = 1; i <= 3; i++, iter123++, iter135++)
516 CPPUNIT_ASSERT_EQUAL(i, aFaces123->getValIndFromGlobalNumber(*iter123));
517 CPPUNIT_ASSERT_EQUAL(i, aFaces135->getValIndFromGlobalNumber(*iter135));
521 SUPPORT * aFaces2 = aFaces123->substract(*aFaces135); // => 2
522 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aFaces2->getEntity());
523 CPPUNIT_ASSERT_EQUAL(1, aFaces2->getValIndFromGlobalNumber(2));
524 CPPUNIT_ASSERT_EQUAL(1, aFaces2->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
526 CPPUNIT_ASSERT_THROW(aFaces123->substract(*aNodes137), MEDEXCEPTION);
528 //#ifdef ENABLE_FORCED_FAILURES
529 // (BUG) SUPPORT::substract() does not work with supports on nodes,
530 // because it uses method MESH::buildSupportOnNodeFromElementList(),
531 // which does not work if entity = MED_NODE
532 //SUPPORT * aNodes137mesh = aMesh->buildSupportOnNodeFromElementList(nodes137, MED_EN::MED_NODE);
533 //delete aNodes137mesh;
534 SUPPORT * aNodes137sub = aNodes137->substract(*aNodes248); // => 1,3,7
535 CPPUNIT_ASSERT_EQUAL(*aNodes137sub, *aNodes137);
536 aNodes137sub->removeReference();
540 CPPUNIT_ASSERT(aFaces2->belongsTo(*aFaces123));
541 CPPUNIT_ASSERT(!aFaces2->belongsTo(*aFaces135));
543 CPPUNIT_ASSERT(!aFaces2->belongsTo(*aSupportOnFaces3));
544 CPPUNIT_ASSERT(aFaces2->belongsTo(*aSupportOnFaces3, /*deepCompare*/true));
546 aFaces2->removeReference();
549 SUPPORT * aFaces_135 = aFaces135->getComplement(); // => 2,4,6,7,8
550 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aFaces_135->getEntity());
551 CPPUNIT_ASSERT_EQUAL(5, aFaces_135->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
553 //#ifdef ENABLE_FORCED_FAILURES
554 // (BUG) Memory problem in SUPPORT::sub()
555 // Invalid read of size 4
556 // at 0x34902492: MEDMEM::SUPPORT::sub(int, int, int const*, int) (MEDMEM_Support.cxx:852)
557 // by 0x3490296B: MEDMEM::SUPPORT::getComplement() const (MEDMEM_Support.cxx:916)
558 // by 0x34398F1E: MEDMEMTest::testSupport() (MEDMEMTest_Support.cxx:514)
559 // Address 0x352DB91C is 0 bytes after a block of size 12 alloc'd
560 // at 0x3414C8E2: operator new[](unsigned) (vg_replace_malloc.c:138)
561 // by 0x3490243A: MEDMEM::SUPPORT::sub(int, int, int const*, int) (MEDMEM_Support.cxx:847)
562 // by 0x3490296B: MEDMEM::SUPPORT::getComplement() const (MEDMEM_Support.cxx:916)
563 // by 0x34398F1E: MEDMEMTest::testSupport() (MEDMEMTest_Support.cxx:514)
564 // CPPUNIT_FAIL("Memory problem in SUPPORT::sub(): Invalid read of size 4 from array <temp>");
567 //#ifdef ENABLE_FORCED_FAILURES
568 // (BUG) SUPPORT::getComplement() does not work with support on nodes,
569 // because it uses method MESH::buildSupportOnNodeFromElementList(),
570 // which does not work if entity = MED_NODE
571 SUPPORT * aNodes_137 = aNodes137->getComplement(); // => 2,4,5,6,8,9,10-19
572 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_NODE, aNodes_137->getEntity());
573 CPPUNIT_ASSERT_EQUAL(16, aNodes_137->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
577 aFaces_135->intersecting(aFaces123); // => 2
578 CPPUNIT_ASSERT_EQUAL(1, aFaces_135->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
579 CPPUNIT_ASSERT_EQUAL(1, aFaces_135->getValIndFromGlobalNumber(2));
581 //aNodes_137->intersecting(&aNodes248); // => 2,4,8
582 //CPPUNIT_ASSERT_EQUAL(3, aNodes_137->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
583 //CPPUNIT_ASSERT_EQUAL(*aNodes_137, aNodes248);
584 aNodes137->intersecting(aNodes248); // =>
587 CPPUNIT_ASSERT_EQUAL(0, aNodes137->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
590 aFaces_135->blending(aFaces135); // => 1,2,3,5
591 CPPUNIT_ASSERT_EQUAL(4, aFaces_135->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
593 aNodes248->blending(aNodes27); // => 2,4,7,8
594 CPPUNIT_ASSERT_EQUAL(4, aNodes248->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
597 SUPPORT *aCopy1=new SUPPORT;
598 *aCopy1 = *aNodes248;
599 CPPUNIT_ASSERT_EQUAL(*aNodes248, *aCopy1);
602 SUPPORT *aCopy2=new SUPPORT(*aFaces135);
603 CPPUNIT_ASSERT_EQUAL(*aFaces135, *aCopy2);
605 aFaces_135->removeReference();
606 //#ifdef ENABLE_FORCED_FAILURES
607 aNodes_137->removeReference();
611 vector<string> aPrN2 (2); // nb. types
612 aPrN2[0] = "Profil 1";
613 aPrN2[1] = "Profil 2";
614 aFaces135->setProfilNames(aPrN2);
616 // because on all elements
617 CPPUNIT_ASSERT_THROW(aSupportOnFaces3->setProfilNames(aPrN2), MEDEXCEPTION);
619 // because length of vector is not equal to nb.types
620 vector<string> aPrN3 (3);
621 CPPUNIT_ASSERT_THROW(aFaces135->setProfilNames(aPrN3), MEDEXCEPTION);
623 vector<string> aPrN2Back = aFaces135->getProfilNames();
624 CPPUNIT_ASSERT_EQUAL(aPrN2[0], aPrN2Back[0]);
625 CPPUNIT_ASSERT_EQUAL(aPrN2[1], aPrN2Back[1]);
627 //#ifdef ENABLE_FORCED_FAILURES
628 // (BUG) profil names are not copied by copy constructor and operator=,
629 // not compared by operator==, not dumped in stream by operator<<
630 //CPPUNIT_FAIL("Not complete implementation for Profil Names");
637 SUPPORT *aPartialCells = new SUPPORT;
638 aPartialCells->setMesh( aMesh );
639 aPartialCells->setName( "Support On Cells 2,3,4" );
640 aPartialCells->setEntity( MED_EN::MED_CELL );
642 SUPPORT *aPartialNodes = new SUPPORT;
643 aPartialNodes->setMesh( aMesh );
644 aPartialNodes->setName( "Support On Nodes 2,3,4" );
645 aPartialNodes->setEntity( MED_EN::MED_NODE );
648 MED_EN::medGeometryElement gtCells[1] =
660 aPartialCells->setpartial("with description", 1, 3, gtCells, nbCells, cells);
661 CPPUNIT_ASSERT_EQUAL(1, aPartialCells->getValIndFromGlobalNumber(2));
662 CPPUNIT_ASSERT_EQUAL(2, aPartialCells->getValIndFromGlobalNumber(3));
663 CPPUNIT_ASSERT_EQUAL(3, aPartialCells->getValIndFromGlobalNumber(4));
665 MED_EN::medGeometryElement gtNodes[1] =
669 aPartialNodes->setNumberOfGeometricType(1);
670 aPartialNodes->setGeometricType(gtNodes);
679 MEDSKYLINEARRAY * aNumberSN = new MEDSKYLINEARRAY(1, 3, indexSN, valueSN);
680 aPartialNodes->setpartial(aNumberSN, /*shallowCopy*/false);
682 CPPUNIT_ASSERT_EQUAL(1, aPartialNodes->getValIndFromGlobalNumber(2));
683 CPPUNIT_ASSERT_EQUAL(2, aPartialNodes->getValIndFromGlobalNumber(3));
684 CPPUNIT_ASSERT_EQUAL(3, aPartialNodes->getValIndFromGlobalNumber(4));
688 // {1,2,3,4,5,6,7,8,9,10} -> {10,9,8,7,6,5,4,3,2,1}
689 int renumberingFromOldToNew[10] =
694 CPPUNIT_ASSERT_THROW(aPartialCells->changeElementsNbs
695 (MED_EN::MED_NODE, renumberingFromOldToNew), MEDEXCEPTION);
697 aPartialCells->changeElementsNbs(MED_EN::MED_CELL, renumberingFromOldToNew);
698 CPPUNIT_ASSERT_EQUAL(3, aPartialCells->getValIndFromGlobalNumber(9));
699 CPPUNIT_ASSERT_EQUAL(2, aPartialCells->getValIndFromGlobalNumber(8));
700 CPPUNIT_ASSERT_EQUAL(1, aPartialCells->getValIndFromGlobalNumber(7));
702 // {1,2,3,4,5,6,7} -> {1,3,5,7,2,4,6}, {8,9,10,11} -> {8,10,9,11}
703 int renumberingFromOldToNewP[11] =
705 1,3,5,7,2,4,6,8,10,9,11
707 aPartialCells->changeElementsNbs(MED_EN::MED_CELL, renumberingFromOldToNewP);
708 CPPUNIT_ASSERT_EQUAL(3, aPartialCells->getValIndFromGlobalNumber(10));
709 CPPUNIT_ASSERT_EQUAL(2, aPartialCells->getValIndFromGlobalNumber(8));
710 CPPUNIT_ASSERT_EQUAL(1, aPartialCells->getValIndFromGlobalNumber(6));
712 // this method does not suit for nodes renumbering!
713 // {1,2,3} -> {3,2,1}, {4,5,6,7} -> {5,6,7,4}
714 //int renumberingFromOldToNewN[3] = {3,2,1};
715 //int renumberingFromOldToNewPolyN[4] = {5,6,7,4};
716 //aPartialNodes.changeElementsNbs(MED_EN::MED_NODE, renumberingFromOldToNewN,
717 // 3, renumberingFromOldToNewPolyN);
719 // getBoundaryElements
720 //#ifdef ENABLE_FAULTS
721 // (BUG) Segmentation Fault during SUPPORT::getBoundaryElements()
722 // ??? May be mesh is not complete ???
723 SUPPORT *aBoundaryFaces = new SUPPORT;
724 aBoundaryFaces->setMesh( aMesh );
725 aBoundaryFaces->setName( "meshing boundary faces" );
726 aBoundaryFaces->setEntity( MED_EN::MED_FACE );
727 //cout << "aBoundaryFaces:" << endl;
728 //cout << aBoundaryFaces << endl;
729 aBoundaryFaces->removeReference();
731 SUPPORT * aBoundaryNodes = aSupportOnFaces3->getBoundaryElements(MED_EN::MED_NODE);
732 //cout << "aSupportOnFaces3:" << endl;
733 //cout << aSupportOnFaces3 << endl;
734 //cout << "aBoundaryNodes:" << endl;
735 //cout << aBoundaryNodes << endl;
736 aBoundaryNodes->removeReference();
738 //#ifdef ENABLE_FORCED_FAILURES
739 // CPPUNIT_FAIL("Segmentation Fault during SUPPORT::getBoundaryElements()");
740 // Invalid write of size 4
741 // at 0x3439DFCE: void std::_Construct<int, int>(int*, int const&) (stl_construct.h:81)
742 // by 0x3476E4D1: std::vector<int, std::allocator<int> >::push_back(int const&) (stl_vector.h:560)
743 // by 0x34763DDB: MEDMEM::CONNECTIVITY::calculateReverseNodalConnectivity() (MEDMEM_Connectivity.cxx:1155)
744 // by 0x347655FF: MEDMEM::CONNECTIVITY::calculateDescendingConnectivity() (MEDMEM_Connectivity.cxx:1333)
745 // by 0x3476363E: MEDMEM::CONNECTIVITY::getReverseDescendingConnectivity() (MEDMEM_Connectivity.cxx:1090)
746 // by 0x34772AB6: MEDMEM::CONNECTIVITY::getReverseConnectivity(long, long) (MEDMEM_Connectivity.hxx:503)
747 // by 0x348F4F4B: MEDMEM::MESH::getReverseConnectivity(long, long) const (MEDMEM_Mesh.hxx:848)
748 // by 0x348FF559: MEDMEM::SUPPORT::getBoundaryElements() (MEDMEM_Support.cxx:483)
749 // by 0x3439C8E5: MEDMEMTest::testSupport() (MEDMEMTest_Support.cxx:641)
750 // Address 0x61666A2F is not stack'd, malloc'd or (recently) free'd
757 int main (int argc, char** argv)
759 MEDMEMTest_testSupport();