1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "MEDMEMTest.hxx"
23 #include <cppunit/TestAssert.h>
25 #include "MEDMEM_Mesh.hxx"
26 #include "MEDMEM_STRING.hxx"
27 #include "MEDMEM_Support.hxx"
32 // use this define to enable lines, execution of which leads to Segmentation Fault
33 //#define ENABLE_FAULTS
35 // use this define to enable CPPUNIT asserts and fails, showing bugs
36 //#define ENABLE_FORCED_FAILURES
39 using namespace MEDMEM;
41 // #52: MEDMEM_Support.hxx } MEDMEMTest_Support.cxx
44 * Check methods (48), defined in MEDMEM_Support.hxx:
45 * class SUPPORT : public RCBASE {
47 * (+) SUPPORT(MESH* Mesh, string Name="", MED_EN::medEntityMesh Entity=MED_EN::MED_CELL);
48 * (+) SUPPORT(const SUPPORT & m);
49 * (+) virtual ~SUPPORT();
51 * (+) friend ostream & operator<<(ostream &os,const SUPPORT &my);
52 * (+) SUPPORT& operator=(const SUPPORT &support);
53 * (+) bool operator == (const SUPPORT &support) const;
54 * (+) bool deepCompare(const SUPPORT &support) const;
58 * (+) inline void setName(string Name);
59 * (+) inline void setDescription(string Description);
60 * (+) void setMesh(MESH *Mesh) const;
61 * (+) inline void setMeshName(const string & meshName);
62 * (+) inline void setAll(bool All);
63 * (+) inline void setEntity(MED_EN::medEntityMesh Entity);
65 * (+) inline void setNumberOfGeometricType(int NumberOfGeometricType);
66 * (+) inline void setGeometricType(const MED_EN::medGeometryElement *GeometricType);
67 * (+) inline void setNumberOfElements(const int *NumberOfElements);
68 * (+) inline void setTotalNumberOfElements(int TotalNumberOfElements);
69 * (+) inline void setNumber(MEDSKYLINEARRAY * Number);
70 * (+) inline void setNumber(const int * index, const int* value, bool shallowCopy=false);
72 * (+) inline string getName() const;
73 * (+) inline string getDescription() const;
74 * (+) virtual inline MESH * getMesh() const;
75 * (+) string getMeshName() const;
76 * (+) inline MED_EN::medEntityMesh getEntity() const;
77 * (+) inline bool isOnAllElements() const;
79 * (+) inline int getNumberOfTypes() const;
80 * (+) inline const MED_EN::medGeometryElement* getTypes() const;
81 * (+) inline int getNumberOfElements
82 * (MED_EN::medGeometryElement GeometricType) const throw (MEDEXCEPTION);
83 * (+) inline const int * getNumberOfElements() const throw (MEDEXCEPTION);
84 * (+) virtual inline MEDSKYLINEARRAY * getnumber() const throw (MEDEXCEPTION);
85 * (NO METHOD IN THIS BRANCH) virtual inline MEDSKYLINEARRAY * getnumberFromFile() const throw (MEDEXCEPTION);
86 * (+) virtual inline const int * getNumber
87 * (MED_EN::medGeometryElement GeometricType) const throw (MEDEXCEPTION);
88 * (NO METHOD IN THIS BRANCH) virtual inline const int * getNumberFromFile
89 * (MED_EN::medGeometryElement GeometricType) const throw (MEDEXCEPTION);
90 * (+) virtual inline const int * getNumberIndex() const throw (MEDEXCEPTION);
91 * (+) virtual int getValIndFromGlobalNumber(const int number) const throw (MEDEXCEPTION);
93 * (+) void blending(SUPPORT * mySupport) throw (MEDEXCEPTION);
95 * (+) void setpartial(string Description, int NumberOfGeometricType,
96 * int TotalNumberOfEntity, MED_EN::medGeometryElement *GeometricType,
97 * int *NumberOfEntity, int *NumberValue);
98 * (+) void setpartial(MEDSKYLINEARRAY * number, bool shallowCopy=false) throw (MEDEXCEPTION);
99 * (NO METHOD IN THIS BRANCH) void setpartial_fromfile(MEDSKYLINEARRAY * number, bool shallowCopy=false) throw (MEDEXCEPTION);
101 * (+) void setProfilNames(vector<string> profilNames) throw (MEDEXCEPTION);
102 * (+) vector<string> getProfilNames() const throw (MEDEXCEPTION);
104 * (+) void getBoundaryElements() throw (MEDEXCEPTION);
106 * (+) void changeElementsNbs(MED_EN::medEntityMesh entity, const int *renumberingFromOldToNew,
107 * int limitNbClassicPoly, const int *renumberingFromOldToNewPoly=0);
108 * (+) void intersecting(SUPPORT * mySupport) throw (MEDEXCEPTION);
109 * (+) bool belongsTo(const SUPPORT& other, bool deepCompare=false) const;
111 * (+) SUPPORT *getComplement() const;
112 * (+) SUPPORT *substract(const SUPPORT& other) const throw (MEDEXCEPTION);
114 * (+) SUPPORT *getBoundaryElements(MED_EN::medEntityMesh Entity) const throw (MEDEXCEPTION);
116 * (+) void fillFromNodeList(const list<int>& listOfNode) throw (MEDEXCEPTION);
117 * (+) void fillFromElementList(const list<int>& listOfElt) throw (MEDEXCEPTION);
119 * (+) void clearDataOnNumbers();
121 * (reference counter presently disconnected in C++) virtual void addReference() const;
122 * (reference counter presently disconnected in C++) virtual void removeReference() const;
125 void MEDMEMTest::testSupport()
127 // cells connectivities
128 //const int NumberOfCellTypes = 3;
129 //MED_EN::medGeometryElement CellTypes[NumberOfCellTypes] =
130 // {MED_EN::MED_TETRA4, MED_EN::MED_PYRA5, MED_EN::MED_HEXA8};
131 //const int NumberOfCells[NumberOfCellTypes] = {12, 2, 2};
133 // faces connectivities
134 //const int NumberOfFaceTypes = 2;
135 //MED_EN::medGeometryElement FaceTypes[NumberOfFaceTypes] = {MED_EN::MED_TRIA3, MED_EN::MED_QUAD4};
136 //const int NumberOfFaces[NumberOfFaceTypes] = {4, 4};
138 MESH * aMesh = MEDMEMTest_createTestMesh();
139 MESH * aMeshOneMore = MEDMEMTest_createTestMesh();
145 SUPPORT aSupportOnFaces1 (aMesh, "Support On Faces 1", MED_EN::MED_FACE);
146 SUPPORT aSupportOnCells1 (aMesh, "Support On Cells 1"/*, MED_EN::MED_CELL*/);
148 SUPPORT aSupportOnFaces2;
149 SUPPORT aSupportOnCells2;
151 SUPPORT aSupportOnFaces3 (aMeshOneMore, "Support On Faces 3", MED_EN::MED_FACE);
154 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aSupportOnFaces1.getEntity());
155 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_CELL, aSupportOnCells1.getEntity());
157 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_CELL, aSupportOnFaces2.getEntity());
158 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_CELL, aSupportOnCells2.getEntity());
160 aSupportOnFaces2.setEntity(MED_EN::MED_FACE);
161 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aSupportOnFaces2.getEntity());
164 CPPUNIT_ASSERT(aSupportOnFaces1.isOnAllElements());
165 CPPUNIT_ASSERT(aSupportOnCells1.isOnAllElements());
167 CPPUNIT_ASSERT(!aSupportOnFaces2.isOnAllElements());
168 CPPUNIT_ASSERT(!aSupportOnCells2.isOnAllElements());
170 // mesh and mesh name
171 CPPUNIT_ASSERT_THROW(aSupportOnFaces1.setMeshName("Mesh 1"), MEDEXCEPTION);
173 aSupportOnFaces2.setMeshName("Mesh 1");
174 aSupportOnCells2.setMeshName("Mesh 1");
175 CPPUNIT_ASSERT(aSupportOnFaces2.getMeshName() == "Mesh 1");
176 CPPUNIT_ASSERT(aSupportOnCells2.getMeshName() == "Mesh 1");
178 aSupportOnFaces2.setMesh(aMesh);
179 CPPUNIT_ASSERT_THROW(aSupportOnFaces2.setMeshName("Mesh 1"), MEDEXCEPTION);
181 aSupportOnCells1.setMesh(NULL);
182 aSupportOnCells1.setMeshName("Mesh 1");
184 CPPUNIT_ASSERT(aSupportOnFaces1.getMeshName() == "meshing");
185 CPPUNIT_ASSERT(aSupportOnFaces2.getMeshName() == "meshing");
186 CPPUNIT_ASSERT(aSupportOnCells1.getMeshName() == "Mesh 1");
187 CPPUNIT_ASSERT(aSupportOnCells2.getMeshName() == "Mesh 1");
189 CPPUNIT_ASSERT(aSupportOnFaces1.getMesh() == aMesh);
190 CPPUNIT_ASSERT(aSupportOnFaces2.getMesh() == aMesh);
191 CPPUNIT_ASSERT(aSupportOnCells1.getMesh() == NULL);
192 CPPUNIT_ASSERT(aSupportOnCells2.getMesh() == NULL);
195 aSupportOnFaces2.setName("Support On Faces 2");
196 aSupportOnCells2.setName("Support On Cells 2");
198 // because aSupportOnFaces1 is on all elements, but aSupportOnFaces2 not
199 CPPUNIT_ASSERT(!(aSupportOnFaces1 == aSupportOnFaces2));
201 aSupportOnCells1.setAll(false);
202 CPPUNIT_ASSERT(!aSupportOnCells1.isOnAllElements());
203 // this is only sets flag _isOnAllElts to false, but not clear elements and types
204 // information, so aSupportOnCells1 is not equal to aSupportOnCells2 at this moment
206 //#ifdef ENABLE_FAULTS
207 // (BUG) SUPPORT::operator= gives "Segmentation Fault" on supports with NULL meshes!!!
208 //CPPUNIT_ASSERT(!(aSupportOnCells1 == aSupportOnCells2));
210 //#ifdef ENABLE_FORCED_FAILURES
211 //CPPUNIT_FAIL("SUPPORT::operator= gives Segmentation Fault on supports with NULL meshes!!!");
214 aSupportOnFaces2.setAll(true);
215 CPPUNIT_ASSERT(aSupportOnFaces2.isOnAllElements());
216 // flag _isOnAllElts now is set to true, but we need also to call update()
217 // to set elements and types information from mesh to this support
218 CPPUNIT_ASSERT(!(aSupportOnFaces1 == aSupportOnFaces2));
219 aSupportOnFaces2.update();
220 CPPUNIT_ASSERT(aSupportOnFaces1 == aSupportOnFaces2);
223 CPPUNIT_ASSERT(aSupportOnFaces1.deepCompare(aSupportOnFaces2));
225 CPPUNIT_ASSERT(!(aSupportOnFaces1 == aSupportOnFaces3)); // different mesh pointers
226 CPPUNIT_ASSERT(aSupportOnFaces1.deepCompare(aSupportOnFaces3)); // meshes are really equal
229 aSupportOnFaces1.setDescription("Support on all faces with mesh pointer");
230 aSupportOnFaces2.setDescription("Support on all faces with mesh pointer");
232 aSupportOnCells1.setDescription("Support on a part of cells with mesh name");
233 aSupportOnCells2.setDescription("Support on a part of cells with mesh name");
235 CPPUNIT_ASSERT(aSupportOnFaces1.getDescription() == "Support on all faces with mesh pointer");
236 CPPUNIT_ASSERT(aSupportOnFaces2.getDescription() == "Support on all faces with mesh pointer");
237 CPPUNIT_ASSERT(aSupportOnCells1.getDescription() == "Support on a part of cells with mesh name");
238 CPPUNIT_ASSERT(aSupportOnCells2.getDescription() == "Support on a part of cells with mesh name");
242 ostr1 << aSupportOnFaces1;
243 CPPUNIT_ASSERT(ostr1.str() != "");
246 ostr2 << aSupportOnCells2;
247 CPPUNIT_ASSERT(ostr2.str() != "");
249 // set/get elements and types information
251 // 1. aSupportOnCells1 is not on all elements, but now it contains information
252 // about all cells of aMesh, because it was created on mesh and with parameters.
253 CPPUNIT_ASSERT_EQUAL(3, aSupportOnCells1.getNumberOfTypes());
254 CPPUNIT_ASSERT(aSupportOnCells1.getTypes() != NULL);
256 //const int * nbEltsSC_old = aSupportOnCells1.getNumberOfElements(); // {12, 2, 2}
258 aSupportOnCells1.setNumberOfGeometricType(0);
259 CPPUNIT_ASSERT_EQUAL(0, aSupportOnCells1.getNumberOfTypes());
260 CPPUNIT_ASSERT(aSupportOnCells1.getTypes() == NULL);
262 MED_EN::medGeometryElement aSCTypes[2] = {MED_EN::MED_PYRA5, MED_EN::MED_PENTA15};
263 aSupportOnCells1.setNumberOfGeometricType(2);
264 aSupportOnCells1.setGeometricType(aSCTypes);
266 CPPUNIT_ASSERT_EQUAL(2, aSupportOnCells1.getNumberOfTypes());
267 CPPUNIT_ASSERT(aSupportOnCells1.getTypes() != NULL);
268 CPPUNIT_ASSERT(aSupportOnCells1.getNumberOfElements() == NULL); // reset by setNumberOfGeometricType
270 int nbEltsSC[2] = {2, 1};
271 aSupportOnCells1.setNumberOfElements(nbEltsSC);
273 const int * nbEltsSCBack = aSupportOnCells1.getNumberOfElements();
274 CPPUNIT_ASSERT_EQUAL(2, aSupportOnCells1.getNumberOfElements(MED_EN::MED_PYRA5));
275 CPPUNIT_ASSERT_EQUAL(2, nbEltsSCBack[0]);
276 CPPUNIT_ASSERT_EQUAL(1, aSupportOnCells1.getNumberOfElements(MED_EN::MED_PENTA15));
277 CPPUNIT_ASSERT_EQUAL(1, nbEltsSCBack[1]);
278 CPPUNIT_ASSERT_EQUAL(3, aSupportOnCells1.getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
281 CPPUNIT_ASSERT_THROW(aSupportOnCells1.getNumberOfElements(MED_EN::MED_TETRA4), MEDEXCEPTION);
282 CPPUNIT_ASSERT_THROW(aSupportOnCells1.getNumberOfElements(MED_EN::MED_HEXA8), MEDEXCEPTION);
284 //_number= new MEDSKYLINEARRAY(_numberOfGeometricType,_totalNumberOfElements,index,value,shallowCopy);
285 int indexSC[3] = {1,3,4}; // length = nb.types + 1
286 int valueSC[3] = {21,22,47}; // length = total nb. of elements
287 aSupportOnCells1.setNumber(indexSC, valueSC);
290 MEDSKYLINEARRAY * aNumberSCBack = aSupportOnCells1.getnumber();
292 CPPUNIT_ASSERT_EQUAL(2, aNumberSCBack->getNumberOf());
293 CPPUNIT_ASSERT_EQUAL(3, aNumberSCBack->getLength());
294 const int * ind = aNumberSCBack->getIndex();
295 const int * val = aNumberSCBack->getValue();
296 CPPUNIT_ASSERT_EQUAL(1, ind[0]);
297 CPPUNIT_ASSERT_EQUAL(3, ind[1]);
298 CPPUNIT_ASSERT_EQUAL(4, ind[2]);
299 CPPUNIT_ASSERT_EQUAL(21, val[0]);
300 CPPUNIT_ASSERT_EQUAL(22, val[1]);
301 CPPUNIT_ASSERT_EQUAL(47, val[2]);
303 // 2. aSupportOnCells2 is not on all elements, and now it contains
304 // no information about elements of a mesh
305 CPPUNIT_ASSERT_EQUAL(0, aSupportOnCells2.getNumberOfTypes());
306 CPPUNIT_ASSERT(aSupportOnCells2.getTypes() == NULL);
308 aSupportOnCells2.setNumberOfGeometricType(2);
309 aSupportOnCells2.setGeometricType(aSCTypes);
311 CPPUNIT_ASSERT_EQUAL(2, aSupportOnCells2.getNumberOfTypes());
312 CPPUNIT_ASSERT(aSupportOnCells2.getTypes() != NULL);
314 aSupportOnCells2.setNumberOfElements(nbEltsSC);
316 // we create MEDSKYLINEARRAY as pointer, because aSupportOnCells2 will
317 // become an owner of it, and we must not delete it.
318 MEDSKYLINEARRAY * aNumberSC = new MEDSKYLINEARRAY(2, 3, indexSC, valueSC);
319 aSupportOnCells2.setNumber(aNumberSC);
322 const int * aNumberIndexSC = aSupportOnCells2.getNumberIndex();
323 CPPUNIT_ASSERT_EQUAL(1, aNumberIndexSC[0]);
324 CPPUNIT_ASSERT_EQUAL(3, aNumberIndexSC[1]);
325 CPPUNIT_ASSERT_EQUAL(4, aNumberIndexSC[2]);
327 const int * aNbPYRA5 = aSupportOnCells2.getNumber(MED_EN::MED_PYRA5);
328 const int * aNbPENTA15 = aSupportOnCells2.getNumber(MED_EN::MED_PENTA15);
329 CPPUNIT_ASSERT_THROW(aSupportOnCells2.getNumber(MED_EN::MED_TETRA4), MEDEXCEPTION);
331 const int * aNbC = aSupportOnCells2.getNumber(MED_EN::MED_ALL_ELEMENTS);
333 CPPUNIT_ASSERT_EQUAL(21, aNbPYRA5[0]);
334 CPPUNIT_ASSERT_EQUAL(22, aNbPYRA5[1]);
335 CPPUNIT_ASSERT_EQUAL(47, aNbPENTA15[0]);
337 CPPUNIT_ASSERT_EQUAL(21, aNbC[0]);
338 CPPUNIT_ASSERT_EQUAL(22, aNbC[1]);
339 CPPUNIT_ASSERT_EQUAL(47, aNbC[2]);
341 // getValIndFromGlobalNumber
342 CPPUNIT_ASSERT_EQUAL(1, aSupportOnCells2.getValIndFromGlobalNumber(21));
343 CPPUNIT_ASSERT_EQUAL(2, aSupportOnCells2.getValIndFromGlobalNumber(22));
344 CPPUNIT_ASSERT_EQUAL(3, aSupportOnCells2.getValIndFromGlobalNumber(47));
345 // not existing element
346 CPPUNIT_ASSERT_THROW(aSupportOnCells2.getValIndFromGlobalNumber(10), MEDEXCEPTION);
348 // compare aSupportOnCells1 and aSupportOnCells2
350 // temporary set mesh (because of bug with operator==)
351 aSupportOnCells1.setMesh(aMesh);
352 aSupportOnCells2.setMesh(aMesh);
354 CPPUNIT_ASSERT_EQUAL(aSupportOnCells1, aSupportOnCells2);
357 aSupportOnCells1.setMesh(NULL);
358 aSupportOnCells2.setMesh(NULL);
359 aSupportOnCells1.setMeshName("Mesh 1");
360 aSupportOnCells2.setMeshName("Mesh 1");
362 // 3. aSupportOnFacesN is on all elements, and it contains
363 // information about all faces of aMesh
364 CPPUNIT_ASSERT_EQUAL(2, aSupportOnFaces1.getNumberOfTypes());
365 const MED_EN::medGeometryElement* aSF1Types = aSupportOnFaces1.getTypes();
366 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_TRIA3, aSF1Types[0]);
367 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_QUAD4, aSF1Types[1]);
368 //#ifdef ENABLE_FORCED_FAILURES
369 // (BUG) Comment to method SUPPORT::getTypes() says:
370 // "If isOnAllElements is false, returns an array of %medGeometryElement types used by the support."
371 // But in fact it returns types in any case (comment to SUPPORT::setAll() gives more information).
372 //CPPUNIT_FAIL("Comment and implementation does not match for SUPPORT::getTypes()");
373 // This concerns also method SUPPORT::update(), being called from constructor,
374 // which fills internal SUPPORT structures with information about mesh elements
375 // in case of isOnAllElements == true.
376 // Also comments and implementation does not match for SUPPORT::getNumberOfElements().
377 // It seems that in case "isOnAllElements == true" calls like getNumberOfElements()
378 // must be redirected to mesh, but what if mesh is not set (mesh name used instead)?.
380 const int * nbEltsSF1 = aSupportOnFaces1.getNumberOfElements();
381 CPPUNIT_ASSERT_EQUAL(4, aSupportOnFaces1.getNumberOfElements(MED_EN::MED_TRIA3));
382 CPPUNIT_ASSERT_EQUAL(4, nbEltsSF1[0]);
383 CPPUNIT_ASSERT_EQUAL(4, aSupportOnFaces1.getNumberOfElements(MED_EN::MED_QUAD4));
384 CPPUNIT_ASSERT_EQUAL(4, nbEltsSF1[1]);
385 CPPUNIT_ASSERT_EQUAL(8, aSupportOnFaces1.getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
386 CPPUNIT_ASSERT_THROW(aSupportOnFaces1.getNumberOfElements(MED_EN::MED_TRIA6), MEDEXCEPTION);
387 CPPUNIT_ASSERT_THROW(aSupportOnFaces1.getNumberOfElements(MED_EN::MED_QUAD8), MEDEXCEPTION);
390 CPPUNIT_ASSERT_THROW(aSupportOnFaces1.getNumberIndex(), MEDEXCEPTION);
391 CPPUNIT_ASSERT_THROW(aSupportOnFaces1.getNumber(MED_EN::MED_TRIA3), MEDEXCEPTION);
392 CPPUNIT_ASSERT_THROW(aSupportOnFaces1.getNumber(MED_EN::MED_QUAD4), MEDEXCEPTION);
393 CPPUNIT_ASSERT_THROW(aSupportOnFaces1.getNumber(MED_EN::MED_ALL_ELEMENTS), MEDEXCEPTION);
394 CPPUNIT_ASSERT_THROW(aSupportOnFaces1.getnumber(), MEDEXCEPTION);
396 // getValIndFromGlobalNumber
397 CPPUNIT_ASSERT_EQUAL(8, aMesh->getNumberOfElements(MED_EN::MED_FACE, MED_EN::MED_ALL_ELEMENTS));
398 for (int i = 1; i <= 8; i++) {
399 CPPUNIT_ASSERT_EQUAL(i, aSupportOnFaces1.getValIndFromGlobalNumber(i));
402 //#ifdef ENABLE_FORCED_FAILURES
403 // Why methods setNumber do not throw exception in case "isOnAllElements == true",
404 // like methods getNumber do?
405 //skl??? CPPUNIT_ASSERT_THROW(aSupportOnFaces1.setNumber(indexSF1, valueSF1), MEDEXCEPTION);
408 //#ifdef ENABLE_FORCED_FAILURES
409 // It seems to be dangerous and useless to have method SUPPORT::setTotalNumberOfElements()
410 //CPPUNIT_FAIL("It seems to be dangerous and useless to have method SUPPORT::setTotalNumberOfElements()");
413 // following test is commented since method
414 // setTotalNumberOfElements() is removed.
415 // setTotalNumberOfElements
416 //aSupportOnFaces1.setTotalNumberOfElements(1000);
417 //CPPUNIT_ASSERT_EQUAL(1000, aSupportOnFaces1.getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
419 // clearDataOnNumbers
420 aSupportOnCells1.clearDataOnNumbers();
421 CPPUNIT_ASSERT_EQUAL(0, aSupportOnCells1.getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
422 CPPUNIT_ASSERT_EQUAL(0, aSupportOnCells1.getNumberOfTypes());
423 CPPUNIT_ASSERT_THROW(aSupportOnCells1.getnumber(), MEDEXCEPTION);
430 nodes137.push_back(1);
431 nodes137.push_back(3);
432 nodes137.push_back(7);
435 nodes248.push_back(2);
436 nodes248.push_back(4);
437 nodes248.push_back(8);
440 nodes27.push_back(2);
441 nodes27.push_back(7);
443 SUPPORT aNodes137 (aMesh, "Support On Nodes 1,3,7", MED_EN::MED_CELL);
444 SUPPORT aNodes248 (aMesh, "Support On Nodes 2,4,8", MED_EN::MED_CELL);
445 SUPPORT aNodes27 (aMesh, "Support On Nodes 2,7" , MED_EN::MED_CELL);
447 aNodes137.fillFromNodeList(nodes137);
448 aNodes248.fillFromNodeList(nodes248);
449 aNodes27.fillFromNodeList(nodes27);
451 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_NODE, aNodes137.getEntity());
452 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_NODE, aNodes248.getEntity());
454 list<int>::const_iterator iter137 = nodes137.begin();
455 list<int>::const_iterator iter248 = nodes248.begin();
456 for (int i = 1; i <= 3; i++, iter137++, iter248++) {
457 CPPUNIT_ASSERT_EQUAL(i, aNodes137.getValIndFromGlobalNumber(*iter137));
458 CPPUNIT_ASSERT_EQUAL(i, aNodes248.getValIndFromGlobalNumber(*iter248));
464 faces123.push_back(1);
465 faces123.push_back(2);
466 faces123.push_back(3);
469 faces135.push_back(1);
470 faces135.push_back(3);
471 faces135.push_back(5);
473 SUPPORT aFaces123 (aMesh, "Support On Faces 1,2,3", MED_EN::MED_FACE);
474 SUPPORT aFaces135 (aMesh, "Support On Faces 1,3,5", MED_EN::MED_FACE);
476 aFaces123.fillFromElementList(faces123);
477 aFaces135.fillFromElementList(faces135);
479 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aFaces123.getEntity());
480 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aFaces135.getEntity());
482 list<int>::const_iterator iter123 = faces123.begin();
483 list<int>::const_iterator iter135 = faces135.begin();
484 for (int i = 1; i <= 3; i++, iter123++, iter135++) {
485 CPPUNIT_ASSERT_EQUAL(i, aFaces123.getValIndFromGlobalNumber(*iter123));
486 CPPUNIT_ASSERT_EQUAL(i, aFaces135.getValIndFromGlobalNumber(*iter135));
490 SUPPORT * aFaces2 = aFaces123.substract(aFaces135); // => 2
491 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aFaces2->getEntity());
492 CPPUNIT_ASSERT_EQUAL(1, aFaces2->getValIndFromGlobalNumber(2));
493 CPPUNIT_ASSERT_EQUAL(1, aFaces2->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
495 CPPUNIT_ASSERT_THROW(aFaces123.substract(aNodes137), MEDEXCEPTION);
497 //#ifdef ENABLE_FORCED_FAILURES
498 // (BUG) SUPPORT::substract() does not work with supports on nodes,
499 // because it uses method MESH::buildSupportOnNodeFromElementList(),
500 // which does not work if entity = MED_NODE
501 //SUPPORT * aNodes137mesh = aMesh->buildSupportOnNodeFromElementList(nodes137, MED_EN::MED_NODE);
502 //delete aNodes137mesh;
503 SUPPORT * aNodes137sub = aNodes137.substract(aNodes248); // => 1,3,7
504 CPPUNIT_ASSERT_EQUAL(*aNodes137sub, aNodes137);
509 CPPUNIT_ASSERT(aFaces2->belongsTo(aFaces123));
510 CPPUNIT_ASSERT(!aFaces2->belongsTo(aFaces135));
512 CPPUNIT_ASSERT(!aFaces2->belongsTo(aSupportOnFaces3));
513 CPPUNIT_ASSERT(aFaces2->belongsTo(aSupportOnFaces3, /*deepCompare*/true));
518 SUPPORT * aFaces_135 = aFaces135.getComplement(); // => 2,4,6,7,8
519 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aFaces_135->getEntity());
520 CPPUNIT_ASSERT_EQUAL(5, aFaces_135->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
522 //#ifdef ENABLE_FORCED_FAILURES
523 // (BUG) Memory problem in SUPPORT::sub()
524 // Invalid read of size 4
525 // at 0x34902492: MEDMEM::SUPPORT::sub(int, int, int const*, int) (MEDMEM_Support.cxx:852)
526 // by 0x3490296B: MEDMEM::SUPPORT::getComplement() const (MEDMEM_Support.cxx:916)
527 // by 0x34398F1E: MEDMEMTest::testSupport() (MEDMEMTest_Support.cxx:514)
528 // Address 0x352DB91C is 0 bytes after a block of size 12 alloc'd
529 // at 0x3414C8E2: operator new[](unsigned) (vg_replace_malloc.c:138)
530 // by 0x3490243A: MEDMEM::SUPPORT::sub(int, int, int const*, int) (MEDMEM_Support.cxx:847)
531 // by 0x3490296B: MEDMEM::SUPPORT::getComplement() const (MEDMEM_Support.cxx:916)
532 // by 0x34398F1E: MEDMEMTest::testSupport() (MEDMEMTest_Support.cxx:514)
533 //CPPUNIT_FAIL("Memory problem in SUPPORT::sub(): Invalid read of size 4 from array <temp>");
536 //#ifdef ENABLE_FORCED_FAILURES
537 // (BUG) SUPPORT::getComplement() does not work with support on nodes,
538 // because it uses method MESH::buildSupportOnNodeFromElementList(),
539 // which does not work if entity = MED_NODE
540 SUPPORT * aNodes_137 = aNodes137.getComplement(); // => 2,4,5,6,8,9,10-19
541 CPPUNIT_ASSERT_EQUAL(MED_EN::MED_NODE, aNodes_137->getEntity());
542 CPPUNIT_ASSERT_EQUAL(16, aNodes_137->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
546 aFaces_135->intersecting(&aFaces123); // => 2
547 CPPUNIT_ASSERT_EQUAL(1, aFaces_135->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
548 CPPUNIT_ASSERT_EQUAL(1, aFaces_135->getValIndFromGlobalNumber(2));
550 //aNodes_137->intersecting(&aNodes248); // => 2,4,8
551 //CPPUNIT_ASSERT_EQUAL(3, aNodes_137->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
552 //CPPUNIT_ASSERT_EQUAL(*aNodes_137, aNodes248);
553 aNodes137.intersecting(&aNodes248); // => {}
554 CPPUNIT_ASSERT_EQUAL(0, aNodes137.getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
557 aFaces_135->blending(&aFaces135); // => 1,2,3,5
558 CPPUNIT_ASSERT_EQUAL(4, aFaces_135->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
560 aNodes248.blending(&aNodes27); // => 2,4,7,8
561 CPPUNIT_ASSERT_EQUAL(4, aNodes248.getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
566 CPPUNIT_ASSERT_EQUAL(aNodes248, aCopy1);
569 SUPPORT aCopy2 (aFaces135);
570 CPPUNIT_ASSERT_EQUAL(aFaces135, aCopy2);
573 //#ifdef ENABLE_FORCED_FAILURES
578 vector<string> aPrN2 (2); // nb. types
579 aPrN2[0] = "Profil 1";
580 aPrN2[1] = "Profil 2";
581 aFaces135.setProfilNames(aPrN2);
583 // because on all elements
584 CPPUNIT_ASSERT_THROW(aSupportOnFaces3.setProfilNames(aPrN2), MEDEXCEPTION);
586 // because length of vector is not equal to nb.types
587 vector<string> aPrN3 (3);
588 CPPUNIT_ASSERT_THROW(aFaces135.setProfilNames(aPrN3), MEDEXCEPTION);
590 vector<string> aPrN2Back = aFaces135.getProfilNames();
591 CPPUNIT_ASSERT_EQUAL(aPrN2[0], aPrN2Back[0]);
592 CPPUNIT_ASSERT_EQUAL(aPrN2[1], aPrN2Back[1]);
594 //#ifdef ENABLE_FORCED_FAILURES
595 // (BUG) profil names are not copied by copy constructor and operator=,
596 // not compared by operator==, not dumped in stream by operator<<
597 //CPPUNIT_FAIL("Not complete implementation for Profil Names");
604 SUPPORT aPartialCells (aMesh, "Support On Cells 2,3,4", MED_EN::MED_CELL);
605 SUPPORT aPartialNodes (aMesh, "Support On Nodes 2,3,4", MED_EN::MED_NODE);
608 MED_EN::medGeometryElement gtCells[1] = {MED_EN::MED_TETRA4};
609 int nbCells[1] = {3};
610 int cells[3] = {2,3,4};
611 aPartialCells.setpartial("with description", 1, 3, gtCells, nbCells, cells);
612 CPPUNIT_ASSERT_EQUAL(1, aPartialCells.getValIndFromGlobalNumber(2));
613 CPPUNIT_ASSERT_EQUAL(2, aPartialCells.getValIndFromGlobalNumber(3));
614 CPPUNIT_ASSERT_EQUAL(3, aPartialCells.getValIndFromGlobalNumber(4));
616 MED_EN::medGeometryElement gtNodes[1] = {MED_EN::MED_NONE};
617 aPartialNodes.setNumberOfGeometricType(1);
618 aPartialNodes.setGeometricType(gtNodes);
619 int indexSN[2] = {1,4};
620 int valueSN[3] = {2,3,4};
621 MEDSKYLINEARRAY * aNumberSN = new MEDSKYLINEARRAY(1, 3, indexSN, valueSN);
622 aPartialNodes.setpartial(aNumberSN, /*shallowCopy*/false);
624 CPPUNIT_ASSERT_EQUAL(1, aPartialNodes.getValIndFromGlobalNumber(2));
625 CPPUNIT_ASSERT_EQUAL(2, aPartialNodes.getValIndFromGlobalNumber(3));
626 CPPUNIT_ASSERT_EQUAL(3, aPartialNodes.getValIndFromGlobalNumber(4));
630 // {1,2,3,4,5,6,7,8,9,10} -> {10,9,8,7,6,5,4,3,2,1}
631 int renumberingFromOldToNew[10] = {10,9,8,7,6,5,4,3,2,1};
633 CPPUNIT_ASSERT_THROW(aPartialCells.changeElementsNbs
634 (MED_EN::MED_NODE, renumberingFromOldToNew, 10), MEDEXCEPTION);
636 aPartialCells.changeElementsNbs(MED_EN::MED_CELL, renumberingFromOldToNew, 10);
637 CPPUNIT_ASSERT_EQUAL(3, aPartialCells.getValIndFromGlobalNumber(9));
638 CPPUNIT_ASSERT_EQUAL(2, aPartialCells.getValIndFromGlobalNumber(8));
639 CPPUNIT_ASSERT_EQUAL(1, aPartialCells.getValIndFromGlobalNumber(7));
641 // {1,2,3,4,5,6,7} -> {1,3,5,7,2,4,6}, {8,9,10,11} -> {8,10,9,11}
642 int renumberingFromOldToNewP[7] = {1,3,5,7,2,4,6};
643 int renumberingFromOldToNewPolyP[4] = {8,10,9,11};
644 aPartialCells.changeElementsNbs(MED_EN::MED_CELL, renumberingFromOldToNewP,
645 7, renumberingFromOldToNewPolyP);
646 CPPUNIT_ASSERT_EQUAL(3, aPartialCells.getValIndFromGlobalNumber(10));
647 CPPUNIT_ASSERT_EQUAL(2, aPartialCells.getValIndFromGlobalNumber(8));
648 CPPUNIT_ASSERT_EQUAL(1, aPartialCells.getValIndFromGlobalNumber(6));
650 // this method does not suit for nodes renumbering!
651 // {1,2,3} -> {3,2,1}, {4,5,6,7} -> {5,6,7,4}
652 //int renumberingFromOldToNewN[3] = {3,2,1};
653 //int renumberingFromOldToNewPolyN[4] = {5,6,7,4};
654 //aPartialNodes.changeElementsNbs(MED_EN::MED_NODE, renumberingFromOldToNewN,
655 // 3, renumberingFromOldToNewPolyN);
657 // getBoundaryElements
658 //#ifdef ENABLE_FAULTS
659 // (BUG) Segmentation Fault during SUPPORT::getBoundaryElements()
660 // ??? May be mesh is not complete ???
661 SUPPORT aBoundaryFaces (aMesh, "meshing boundary faces", MED_EN::MED_FACE);
662 aBoundaryFaces.getBoundaryElements();
663 //cout << "aBoundaryFaces:" << endl;
664 //cout << aBoundaryFaces << endl;
666 SUPPORT * aBoundaryNodes = aSupportOnFaces3.getBoundaryElements(MED_EN::MED_NODE);
667 //cout << "aSupportOnFaces3:" << endl;
668 //cout << aSupportOnFaces3 << endl;
669 //cout << "aBoundaryNodes:" << endl;
670 //cout << aBoundaryNodes << endl;
671 delete aBoundaryNodes;
673 //#ifdef ENABLE_FORCED_FAILURES
674 //CPPUNIT_FAIL("Segmentation Fault during SUPPORT::getBoundaryElements()");
675 // Invalid write of size 4
676 // at 0x3439DFCE: void std::_Construct<int, int>(int*, int const&) (stl_construct.h:81)
677 // by 0x3476E4D1: std::vector<int, std::allocator<int> >::push_back(int const&) (stl_vector.h:560)
678 // by 0x34763DDB: MEDMEM::CONNECTIVITY::calculateReverseNodalConnectivity() (MEDMEM_Connectivity.cxx:1155)
679 // by 0x347655FF: MEDMEM::CONNECTIVITY::calculateDescendingConnectivity() (MEDMEM_Connectivity.cxx:1333)
680 // by 0x3476363E: MEDMEM::CONNECTIVITY::getReverseDescendingConnectivity() (MEDMEM_Connectivity.cxx:1090)
681 // by 0x34772AB6: MEDMEM::CONNECTIVITY::getReverseConnectivity(long, long) (MEDMEM_Connectivity.hxx:503)
682 // by 0x348F4F4B: MEDMEM::MESH::getReverseConnectivity(long, long) const (MEDMEM_Mesh.hxx:848)
683 // by 0x348FF559: MEDMEM::SUPPORT::getBoundaryElements() (MEDMEM_Support.cxx:483)
684 // by 0x3439C8E5: MEDMEMTest::testSupport() (MEDMEMTest_Support.cxx:641)
685 // Address 0x61666A2F is not stack'd, malloc'd or (recently) free'd