1 // Copyright (C) 2007-2013 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 "MEDMEM_Meshing.hxx"
22 #include "MEDMEM_Group.hxx"
23 #include "MEDMEM_define.hxx"
24 #include "MEDMEM_MedMeshDriver.hxx"
25 #include "MEDMEM_Field.hxx"
26 #include "MEDMEM_Grid.hxx"
28 #include <cppunit/Message.h>
29 #include <cppunit/TestAssert.h>
34 // use this define to enable lines, execution of which leads to Segmentation Fault
35 //#define ENABLE_FAULTS
37 // use this define to enable CPPUNIT asserts and fails, showing bugs
38 //#define ENABLE_FORCED_FAILURES
41 using namespace MEDMEM;
42 using namespace MED_EN;
44 double dmax(double x, double y)
49 double dmin(double x, double y)
55 * Check methods (18), defined in MEDMEM_Meshing.hxx:
56 * class MESHING: public MESH
60 * (+) void setSpaceDimension (const int SpaceDimension);
61 * (+) void setMeshDimension (const int MeshDimension);
62 * (+) void setNumberOfNodes (const int NumberOfNodes);
63 * (+) void setCoordinates (const int SpaceDimension, const int NumberOfNodes,
64 * const double * Coordinates,
65 * const string System, const MED_EN::medModeSwitch Mode);
66 * (+) void setCoordinatesSystem(const string System) throw (MEDEXCEPTION);
67 * (+) void setCoordinatesNames (const string * names);
68 * (+) void setCoordinateName (const string name, const int i);
69 * (+) void setCoordinatesUnits (const string * units);
70 * (+) void setCoordinateUnit (const string unit, const int i);
71 * (+) void setNumberOfTypes (const int NumberOfTypes,
72 * const MED_EN::medEntityMesh Entity) throw (MEDEXCEPTION);
73 * (+) void setTypes (const MED_EN::medGeometryElement * Types,
74 * const MED_EN::medEntityMesh Entity) throw (MEDEXCEPTION);
75 * (+) void setNumberOfElements (const int * NumberOfElements,
76 * const MED_EN::medEntityMesh Entity) throw (MEDEXCEPTION);
77 * (+) void setConnectivity (const int * Connectivity, const MED_EN::medEntityMesh Entity,
78 * const MED_EN::medGeometryElement Type) throw (MEDEXCEPTION);
79 * (+) void setPolygonsConnectivity (const int * ConnectivityIndex, const int * ConnectivityValue,
81 * const MED_EN::medEntityMesh Entity) throw (MEDEXCEPTION);
82 * (+) void setPolyhedraConnectivity (const int * PolyhedronIndex, const int * FacesIndex,
83 * const int * Nodes, int nbOfPolyhedra,
84 * const MED_EN::medEntityMesh Entity) throw (MEDEXCEPTION);
85 * (NOT YET IMPLEMENTED!!!) void setConnectivities (const int * ConnectivityIndex,
86 * const int * ConnectivityValue,
87 * const MED_EN::medConnectivity ConnectivityType,
88 * const MED_EN::medEntityMesh Entity) throw (MEDEXCEPTION);
89 * (+) void addGroup (const GROUP & Group) throw (MEDEXCEPTION);
95 * Check methods (87), defined in MEDMEM_Mesh.hxx:
96 * class MESH : public RCBASE
101 * (+) MESH & operator=(const MESH &m);
102 * (+) virtual bool operator==(const MESH& other) const;
103 * (+) virtual bool deepCompare(const MESH& other) const;
104 * (+) MESH(driverTypes driverType, const string & fileName="",
105 * const string & meshName="") throw (MEDEXCEPTION);
106 * (+) virtual ~MESH();
107 * (+) friend ostream & operator<<(ostream &os, const MESH &my);
108 * (+) int addDriver(driverTypes driverType,
109 * const string & fileName="Default File Name.med",
110 * const string & driverName="Default Mesh Name",
111 * MED_EN::med_mode_acces access=MED_EN::MED_REMP);
112 * (+) int addDriver(GENDRIVER & driver);
113 * (+) void rmDriver(int index=0);
114 * (+) virtual void read(int index=0);
115 * (must be private) inline void read(const GENDRIVER & genDriver);
116 * (+) inline void write(int index=0, const string & driverName = "");
117 * (must be private) inline void write(const GENDRIVER & genDriver);
118 * (+) inline void setName(string name);
119 * (+) inline void setDescription(string description);
120 * (+) inline string getName() const;
121 * (+) inline string getDescription() const;
122 * (+) inline int getSpaceDimension() const;
123 * (+) inline int getMeshDimension() const;
124 * (+) inline bool getIsAGrid();
125 * (+) inline int getNumberOfNodes() const;
126 * (+) virtual inline const COORDINATE * getCoordinateptr() const;
127 * (+) inline string getCoordinatesSystem() const;
128 * (+) virtual inline const double * getCoordinates(MED_EN::medModeSwitch Mode) const;
129 * (+) virtual inline const double getCoordinate(int Number,int Axis) const;
130 * (+) inline const string * getCoordinatesNames() const;
131 * (+) inline const string * getCoordinatesUnits() const;
132 * (+) virtual inline int getNumberOfTypes(MED_EN::medEntityMesh Entity) const;
133 * (+) virtual int getNumberOfTypesWithPoly(MED_EN::medEntityMesh Entity) const;
134 * (+) virtual inline const MED_EN::medGeometryElement * getTypes(MED_EN::medEntityMesh Entity) const;
135 * (+) virtual MED_EN::medGeometryElement * getTypesWithPoly(MED_EN::medEntityMesh Entity) const;
136 * (+) virtual inline const CELLMODEL * getCellsTypes(MED_EN::medEntityMesh Entity) const;
137 * (+) virtual inline string * getCellTypeNames(MED_EN::medEntityMesh Entity) const;
138 * (+) virtual const int * getGlobalNumberingIndex(MED_EN::medEntityMesh Entity) const;
139 * (+) virtual inline int getNumberOfElements(MED_EN::medEntityMesh Entity,
140 * MED_EN::medGeometryElement Type) const;
141 * (+) virtual int getNumberOfElementsWithPoly(MED_EN::medEntityMesh Entity,
142 * MED_EN::medGeometryElement Type) const;
143 * (+) virtual inline bool existConnectivity(MED_EN::medConnectivity ConnectivityType,
144 * MED_EN::medEntityMesh Entity) const;
145 * (+) inline bool existPolygonsConnectivity(MED_EN::medConnectivity ConnectivityType,
146 * MED_EN::medEntityMesh Entity) const;
147 * (+) inline bool existPolyhedronConnectivity(MED_EN::medConnectivity ConnectivityType,
148 * MED_EN::medEntityMesh Entity) const;
149 * (+) virtual inline MED_EN::medGeometryElement getElementType
150 * (MED_EN::medEntityMesh Entity, int Number) const;
151 * (+) virtual inline MED_EN::medGeometryElement getElementTypeWithPoly
152 * (MED_EN::medEntityMesh Entity, int Number) const;
153 * (+) virtual inline void calculateConnectivity(MED_EN::medModeSwitch Mode,
154 * MED_EN::medConnectivity ConnectivityType,
155 * MED_EN::medEntityMesh Entity) const;
156 * (+) virtual inline int getConnectivityLength(MED_EN::medModeSwitch Mode,
157 * MED_EN::medConnectivity ConnectivityType,
158 * MED_EN::medEntityMesh Entity,
159 * MED_EN::medGeometryElement Type) const;
160 * (+) virtual inline const int * getConnectivity(MED_EN::medModeSwitch Mode,
161 * MED_EN::medConnectivity ConnectivityType,
162 * MED_EN::medEntityMesh Entity,
163 * MED_EN::medGeometryElement Type) const;
164 * (+) virtual inline const int * getConnectivityIndex
165 * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity) const;
166 * (+) inline int getPolygonsConnectivityLength
167 * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity) const;
168 * (+) inline const int * getPolygonsConnectivity
169 * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity) const;
170 * (+) inline const int * getPolygonsConnectivityIndex
171 * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity) const;
172 * (+) inline int getNumberOfPolygons(MED_EN::medEntityMesh Entity=MED_EN::MED_ALL_ENTITIES) const;
173 * (+) inline int getPolyhedronConnectivityLength(MED_EN::medConnectivity ConnectivityType) const;
174 * (+) inline const int * getPolyhedronConnectivity(MED_EN::medConnectivity ConnectivityType) const;
175 * (+) inline const int * getPolyhedronFacesIndex() const;
176 * (+) inline const int * getPolyhedronIndex(MED_EN::medConnectivity ConnectivityType) const;
177 * (+) inline int getNumberOfPolyhedronFaces() const;
178 * (+) inline int getNumberOfPolyhedron() const;
179 * (+) virtual int getElementNumber(MED_EN::medConnectivity ConnectivityType,
180 * MED_EN::medEntityMesh Entity, MED_EN::medGeometryElement Type,
181 * int * connectivity) const;
182 * (+) virtual inline int getReverseConnectivityLength
183 * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity=MED_EN::MED_CELL) const;
184 * (+) virtual inline const int * getReverseConnectivity
185 * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity=MED_EN::MED_CELL) const;
186 * (+) virtual inline int getReverseConnectivityIndexLength
187 * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity=MED_EN::MED_CELL) const;
188 * (+) virtual inline const int * getReverseConnectivityIndex
189 * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity=MED_EN::MED_CELL) const;
190 * (+) virtual int getNumberOfFamilies(MED_EN::medEntityMesh Entity) const;
191 * (+) virtual inline const vector<FAMILY*> getFamilies(MED_EN::medEntityMesh Entity) const;
192 * (+) virtual inline const FAMILY* getFamily(MED_EN::medEntityMesh Entity,int i) const;
193 * (+) virtual int getNumberOfGroups(MED_EN::medEntityMesh Entity) const;
194 * (+) virtual inline const vector<GROUP*> getGroups(MED_EN::medEntityMesh Entity) const;
195 * (+) virtual inline const GROUP* getGroup(MED_EN::medEntityMesh Entity,int i) const;
196 * (+) virtual inline const CONNECTIVITY* getConnectivityptr() const;
197 * (+) virtual SUPPORT * getBoundaryElements(MED_EN::medEntityMesh Entity) throw (MEDEXCEPTION);
198 * (+) SUPPORT * getSkin(const SUPPORT * Support3D) throw (MEDEXCEPTION);
199 * (+) virtual FIELD<double>* getVolume (const SUPPORT * Support) const throw (MEDEXCEPTION);
200 * (+) virtual FIELD<double>* getArea (const SUPPORT * Support) const throw (MEDEXCEPTION);
201 * (+) virtual FIELD<double>* getLength (const SUPPORT * Support) const throw (MEDEXCEPTION);
202 * (+) virtual FIELD<double>* getNormal (const SUPPORT * Support) const throw (MEDEXCEPTION);
203 * (+) virtual FIELD<double>* getBarycenter (const SUPPORT * Support) const throw (MEDEXCEPTION);
204 * (+) static SUPPORT * mergeSupports(const vector<SUPPORT *> Supports) throw (MEDEXCEPTION);
205 * (+) static SUPPORT * intersectSupports(const vector<SUPPORT *> Supports) throw (MEDEXCEPTION);
206 * (+) void createFamilies();
207 * (+) SUPPORT *buildSupportOnNodeFromElementList
208 * (const list<int>& listOfElt, MED_EN::medEntityMesh entity) const throw (MEDEXCEPTION);
209 * (do the same thing as buildSupportOnNodeFromElementList except that a SUPPORT is not created) void fillSupportOnNodeFromElementList
210 * (const list<int>& listOfElt, SUPPORT *supportToFill) const throw (MEDEXCEPTION);
211 * (+) SUPPORT *buildSupportOnElementsFromElementList
212 * (const list<int>& listOfElt, MED_EN::medEntityMesh entity) const throw (MEDEXCEPTION);
213 * (+) int getElementContainingPoint(const double *coord);
214 * (+) vector< vector<double> > getBoundingBox() const;
215 * (+) template<class T> static
216 * FIELD<T> * mergeFields(const vector< FIELD<T> * > & others, bool meshCompare=false);
217 * (Presently disconnected in C++) virtual void addReference() const;
218 * (Presently disconnected in C++) virtual void removeReference() const;
222 void MEDMEMTest_testMeshAndMeshing()
224 string filename = getResourceFile("pointe.med");
225 string meshname = "maa1";
226 string filenameout21 = makeTmpFile("myMeshWrite4_pointe21.med");
228 // To remove tmp files from disk
229 MEDMEMTest_TmpFilesRemover aRemover;
230 aRemover.Register(filenameout21);
236 MESH * myMesh= new MESH();
237 myMesh->setName("FIRST_MESH");
238 CPPUNIT_ASSERT(myMesh != NULL);
241 //#ifdef ENABLE_FAULTS
242 //CPPUNIT_ASSERT_NO_THROW(cout << *myMesh << endl);
244 //#ifdef ENABLE_FORCED_FAILURES
245 // CPPUNIT_FAIL("ERROR: operator << : if mesh is empty then attempt"
246 // " to get values from null object causes error");
250 MESH myMesh1 = *myMesh;
253 //#ifdef ENABLE_FAULTS
254 bool isEqual = false;
255 CPPUNIT_ASSERT_NO_THROW(isEqual = myMesh1.deepCompare(*myMesh));
256 CPPUNIT_ASSERT(isEqual);
258 //#ifdef ENABLE_FORCED_FAILURES
259 // CPPUNIT_FAIL("ERROR: deepCompare(...) fails if mesh is empty");
262 //ensure it imposible to compare meshes
263 MESH *myMeshPointer = myMesh;
265 CPPUNIT_ASSERT(*myMeshPointer == *myMesh);
270 MESHING *myMeshing=new MESHING;
271 myMeshing->setName("meshing");
272 // define coordinates
274 int SpaceDimension = 3;
275 int NumberOfNodes = 19;
276 double Coordinates[57] =
300 myMeshing->setCoordinates(SpaceDimension,NumberOfNodes,Coordinates,"CARTESIAN",MED_FULL_INTERLACE);
302 catch (const std::exception &e)
304 CPPUNIT_FAIL(e.what());
308 CPPUNIT_FAIL("Unknown exception");
317 myMeshing->setCoordinatesNames(Names);
319 catch (const std::exception &e)
321 CPPUNIT_FAIL(e.what());
325 CPPUNIT_FAIL("Unknown exception");
334 myMeshing->setCoordinatesUnits(Units);
336 catch (const std::exception &e)
338 CPPUNIT_FAIL(e.what());
342 CPPUNIT_FAIL("Unknown exception");
345 // define conectivities
349 const int NumberOfTypes = 3;
350 medGeometryElement Types[NumberOfTypes] =
352 MED_TETRA4,MED_PYRA5,MED_HEXA8
354 const int NumberOfElements[NumberOfTypes] =
359 CPPUNIT_ASSERT_NO_THROW(myMeshing->setNumberOfTypes(NumberOfTypes,MED_CELL));
361 CPPUNIT_ASSERT_NO_THROW(myMeshing->setTypes(Types,MED_CELL));
363 CPPUNIT_ASSERT_NO_THROW(myMeshing->setNumberOfElements(NumberOfElements,MED_CELL));
365 const int sizeTetra = 12*4;
366 int ConnectivityTetra[sizeTetra]=
382 CPPUNIT_ASSERT_NO_THROW(myMeshing->setConnectivity( MED_CELL, MED_TETRA4, ConnectivityTetra ));
384 int ConnectivityPyra[2*5]=
390 CPPUNIT_ASSERT_NO_THROW(myMeshing->setConnectivity( MED_CELL, MED_PYRA5, ConnectivityPyra ));
392 int ConnectivityHexa[2*8]=
394 11,12,13,14,7,8,9,10,
395 15,16,17,18,11,12,13,14
398 CPPUNIT_ASSERT_NO_THROW(myMeshing->setConnectivity( MED_CELL, MED_HEXA8, ConnectivityHexa ));
401 const int NumberOfFacesTypes = 2;
402 medGeometryElement FacesTypes[NumberOfFacesTypes] =
406 const int NumberOfFacesElements[NumberOfFacesTypes] =
411 CPPUNIT_ASSERT_NO_THROW(myMeshing->setNumberOfTypes(NumberOfFacesTypes,MED_FACE));
412 CPPUNIT_ASSERT_NO_THROW(myMeshing->setTypes(FacesTypes,MED_FACE));
413 CPPUNIT_ASSERT_NO_THROW(myMeshing->setNumberOfElements(NumberOfFacesElements,MED_FACE));
414 const int nbTria = 4;
415 const int sizeTria = nbTria*3;
416 int ConnectivityTria[sizeTria]=
424 CPPUNIT_ASSERT_NO_THROW(myMeshing->setConnectivity( MED_FACE, MED_TRIA3, ConnectivityTria ));
426 int ConnectivityQua[nbQua*4]=
434 CPPUNIT_ASSERT_NO_THROW(myMeshing->setConnectivity( MED_FACE, MED_QUAD4, ConnectivityQua ));
436 int meshDimension = SpaceDimension; // because there 3D cells in the mesh
440 // not yet implemented : if set, results are unpredictable.
446 GROUP *myGroup=new GROUP;
447 myGroup->setName("SomeNodes");
448 myGroup->setMesh(myMeshing);
449 myGroup->setEntity(MED_NODE);
450 myGroup->setNumberOfGeometricType(1);
451 medGeometryElement myTypes[1] =
455 myGroup->setGeometricType(myTypes);
456 const int myNumberOfElements[1] =
460 myGroup->setNumberOfElements(myNumberOfElements);
461 const int index[1+1] =
469 myGroup->setNumber(index,value);
470 CPPUNIT_ASSERT_NO_THROW(myMeshing->addGroup(*myGroup));
471 myGroup->removeReference();
474 GROUP *myGroup=new GROUP;
475 myGroup->setName("OtherNodes");
476 myGroup->setMesh(myMeshing);
477 myGroup->setEntity(MED_NODE);
478 myGroup->setNumberOfGeometricType(1);
479 medGeometryElement myTypes[1] =
483 myGroup->setGeometricType(myTypes);
484 const int myNumberOfElements[1] =
488 myGroup->setNumberOfElements(myNumberOfElements);
489 const int index[1+1] =
497 myGroup->setNumber(index,value);
498 CPPUNIT_ASSERT_NO_THROW(myMeshing->addGroup(*myGroup));
499 myGroup->removeReference();
504 GROUP *myGroup=new GROUP;
505 myGroup->setName("SomeCells");
506 myGroup->setMesh(myMeshing);
507 myGroup->setEntity(MED_CELL);
508 myGroup->setNumberOfGeometricType(3);
509 medGeometryElement myTypes[3] =
511 MED_TETRA4,MED_PYRA5,MED_HEXA8
513 myGroup->setGeometricType(myTypes);
514 const int myNumberOfElements[3] =
518 myGroup->setNumberOfElements(myNumberOfElements);
519 const int index[3+1] =
523 const int value[4+1+2]=
529 myGroup->setNumber(index,value);
530 CPPUNIT_ASSERT_NO_THROW(myMeshing->addGroup(*myGroup));
531 myGroup->removeReference();
534 GROUP *myGroup=new GROUP;
535 myGroup->setName("OtherCells");
536 myGroup->setMesh(myMeshing);
537 myGroup->setEntity(MED_CELL);
538 myGroup->setNumberOfGeometricType(2);
539 medGeometryElement myTypes[] =
543 myGroup->setGeometricType(myTypes);
544 const int myNumberOfElements[] =
548 myGroup->setNumberOfElements(myNumberOfElements);
549 const int index[2+1] =
553 const int value[4+1]=
558 myGroup->setNumber(index,value);
559 CPPUNIT_ASSERT_NO_THROW(myMeshing->addGroup(*myGroup));
560 myGroup->removeReference();
565 GROUP *myGroup=new GROUP;
566 myGroup->setName("SomeFaces");
567 myGroup->setMesh(myMeshing);
568 myGroup->setEntity(MED_FACE);
569 myGroup->setNumberOfGeometricType(2);
570 medGeometryElement myTypes[2] =
574 myGroup->setGeometricType(myTypes);
575 const int myNumberOfElements[2] =
579 myGroup->setNumberOfElements(myNumberOfElements);
580 const int index[2+1] =
584 const int value[2+3]=
589 myGroup->setNumber(index,value);
590 CPPUNIT_ASSERT_NO_THROW(myMeshing->addGroup(*myGroup));
591 myGroup->removeReference();
594 GROUP *myGroup=new GROUP;
595 myGroup->setName("OtherFaces");
596 myGroup->setMesh(myMeshing);
597 myGroup->setEntity(MED_FACE);
598 myGroup->setNumberOfGeometricType(1);
599 medGeometryElement myTypes[1] =
603 myGroup->setGeometricType(myTypes);
604 const int myNumberOfElements[1] =
608 myGroup->setNumberOfElements(myNumberOfElements);
609 const int index[1+1] =
617 myGroup->setNumber(index,value);
618 CPPUNIT_ASSERT_NO_THROW(myMeshing->addGroup(*myGroup));
619 myGroup->removeReference();
624 MESH * myMesh2 = new MESH( *myMeshing );
625 CPPUNIT_ASSERT(myMesh2->deepCompare(*myMeshing));
627 cout<<*myMesh2<<endl;
630 CPPUNIT_ASSERT(os.str() != "");
632 CPPUNIT_ASSERT_EQUAL(myMesh2->getName(),(string)"meshing");
633 CPPUNIT_ASSERT((myMesh2->getDescription()).size() == 0);
634 myMesh2->setDescription("This class contains all information related to a 'meshing' mesh ");
635 CPPUNIT_ASSERT((myMesh2->getDescription()).size() != 0);
637 CPPUNIT_ASSERT(myMesh2->getSpaceDimension() == SpaceDimension);
638 CPPUNIT_ASSERT(myMesh2->getMeshDimension() == meshDimension);
639 CPPUNIT_ASSERT(myMesh2->getNumberOfNodes() == NumberOfNodes);
641 const COORDINATE* coord = myMesh2->getCoordinateptr();
644 CPPUNIT_ASSERT(myMesh2->getCoordinatesSystem() != "catresian");
646 catch (const std::exception &e)
648 CPPUNIT_FAIL(e.what());
652 CPPUNIT_FAIL("Unknown exception");
655 const string * units;
658 units = myMesh2->getCoordinatesUnits();
659 for (int axe = 0; axe < SpaceDimension; axe++)
661 string verif = coord->getCoordinateUnit(axe+1);
662 CPPUNIT_ASSERT(verif == units[axe]);
665 catch (const std::exception &e)
667 CPPUNIT_FAIL(e.what());
671 CPPUNIT_FAIL("Unknown exception");
677 noms = myMesh2->getCoordinatesNames();
678 for (int axe = 0; axe < SpaceDimension; axe++)
680 string verif = coord->getCoordinateName(axe+1);
681 CPPUNIT_ASSERT(verif == noms[axe]);
684 catch (const std::exception &e)
686 CPPUNIT_FAIL(e.what());
690 CPPUNIT_FAIL("Unknown exception");
695 const double * coor2 = myMesh2->getCoordinates(MED_FULL_INTERLACE);
697 for (int axe = 0; axe < SpaceDimension; axe++)
701 for (int num = 0; num < NumberOfNodes; num++)
705 const double d = myMesh2->getCoordinate(num + 1, axe + 1);
706 CPPUNIT_ASSERT(fabs(d - coor2[(num * SpaceDimension)+axe]) < 0.001);
708 catch (const std::exception &e)
710 CPPUNIT_FAIL(e.what());
714 CPPUNIT_FAIL("Unknown exception");
718 catch (const std::exception &e)
720 CPPUNIT_FAIL(e.what());
724 CPPUNIT_FAIL("Unknown exception");
728 catch (const std::exception &e)
730 CPPUNIT_FAIL(e.what());
734 CPPUNIT_FAIL("Unknown exception");
737 const CONNECTIVITY * myConnectivity = myMesh2->getConnectivityptr();
740 MED_EN::medEntityMesh entity = myConnectivity->getEntity();
741 CPPUNIT_ASSERT_EQUAL(MED_CELL, entity);
744 CPPUNIT_ASSERT_NO_THROW(typesNb= myConnectivity->getNumberOfTypes(entity));
745 CPPUNIT_ASSERT_EQUAL(NumberOfTypes, typesNb);
747 const MED_EN::medGeometryElement * Types1;
748 CPPUNIT_ASSERT_NO_THROW(Types1 = myMesh2->getTypes(entity));
750 medConnectivity myMedConnect;
751 bool existConnect = false;
752 if (myMesh2->existConnectivity(MED_NODAL, entity))
755 myMedConnect = MED_NODAL;
757 else if(myMesh2->existConnectivity(MED_DESCENDING, entity))
760 myMedConnect = MED_DESCENDING;
763 for(int t = 0; t < NumberOfTypes; t++ )
765 CPPUNIT_ASSERT_EQUAL(Types1[t], Types[t]);
766 int NumberOfElements1 = 0;
767 CPPUNIT_ASSERT_NO_THROW(NumberOfElements1 = myMesh2->getNumberOfElements(entity, Types1[t]));
768 CPPUNIT_ASSERT_EQUAL(NumberOfElements1, NumberOfElements[t]);
771 const int * connectivity;
772 const int * connectivity_index;
773 CPPUNIT_ASSERT_NO_THROW(connectivity = myMesh2->getConnectivity
774 (myMedConnect, entity, Types1[t]));
775 connectivity_index = myMesh2->getConnectivityIndex(myMedConnect, entity);
776 for (int j = 0; j < NumberOfElements1; j++)
778 cout<<"!!!!!!!!!!!!!!!"<<endl;
779 for (int k = connectivity_index[j]; k < connectivity_index[j+1]; k++)
780 cout << connectivity[k-1] << " ";
786 const CELLMODEL* myCellModel = myMesh2->getCellsTypes(entity);
788 CPPUNIT_ASSERT_NO_THROW(TypeNames = myMesh2->getCellTypeNames(entity));
790 for(int k = 0; k < NumberOfTypes; k++ )
792 CPPUNIT_ASSERT_EQUAL(TypeNames[k], myCellModel[k].getName());
796 const int* myGlobalNbIdx;
797 CPPUNIT_ASSERT_NO_THROW(myGlobalNbIdx = myMesh2->getGlobalNumberingIndex(MED_FACE));
798 for(int i = 0; i <= NumberOfFacesTypes; i++)
800 if(i == NumberOfFacesTypes)
802 CPPUNIT_ASSERT_EQUAL(myGlobalNbIdx[i],nbTria+nbQua+1);
803 CPPUNIT_ASSERT_THROW(myMesh2->getElementType(MED_FACE, myGlobalNbIdx[i]), MEDEXCEPTION);
806 cout<<"Global number of first element of each geom type : "<<myGlobalNbIdx[i]<<endl;
809 const int * ReverseNodalConnectivity;
811 // Show Reverse Nodal Connectivity
812 //#ifndef ENABLE_FAULTS
813 // (BUG) CONNECTIVITY::_numberOfNodes is not set
814 ((CONNECTIVITY*)myConnectivity)->setNumberOfNodes(NumberOfNodes);
816 //#ifdef ENABLE_FORCED_FAILURES
817 // CPPUNIT_FAIL("ERROR in CONNECTIVITY::calculateReverseNodalConnectivity()"
818 // " because myMesh2->_connectivity->_numberOfNodes is not set");
821 CPPUNIT_ASSERT_NO_THROW(ReverseNodalConnectivity = myMesh2->getReverseConnectivity(MED_NODAL, entity));
822 CPPUNIT_ASSERT_NO_THROW(myMesh2->getReverseConnectivityLength(MED_NODAL, entity));
823 const int * ReverseNodalConnectivityIndex = myMesh2->getReverseConnectivityIndex(MED_NODAL, entity);
824 const int ReverseIdxLength = myMesh2->getReverseConnectivityIndexLength(MED_NODAL, entity);
825 CPPUNIT_ASSERT(ReverseIdxLength == NumberOfNodes+1);
826 for (int i = 0; i < NumberOfNodes; i++)
828 cout << "Node "<< i+1 << " : ";
829 for (int j = ReverseNodalConnectivityIndex[i]; j < ReverseNodalConnectivityIndex[i+1]; j++)
830 cout << ReverseNodalConnectivity[j-1] << " ";
834 // Show Descending Connectivity
835 int NumberOfElements1;
836 const int * connectivity;
837 const int * connectivity_index;
838 myMesh2->calculateConnectivity(MED_DESCENDING, entity);
841 NumberOfElements1 = myMesh2->getNumberOfElements(entity, MED_ALL_ELEMENTS);
842 connectivity = myMesh2->getConnectivity( MED_DESCENDING, entity, MED_ALL_ELEMENTS);
843 connectivity_index = myMesh2->getConnectivityIndex(MED_DESCENDING, entity);
845 catch (MEDEXCEPTION m)
847 CPPUNIT_FAIL(m.what());
850 for (int j = 0; j < NumberOfElements1; j++)
852 cout << "Element " << j+1 << " : ";
853 for (int k = connectivity_index[j]; k < connectivity_index[j+1]; k++)
854 cout << connectivity[k-1] << " ";
859 if (myMesh2->existConnectivity(MED_NODAL, MED_FACE))
865 CPPUNIT_ASSERT_NO_THROW(myMesh2->getElementNumber(MED_NODAL,MED_FACE,MED_TRIA3,myTr));
869 //test family and group
871 CPPUNIT_ASSERT_THROW(myMesh2->getNumberOfGroups(MED_ALL_ENTITIES), MEDEXCEPTION);
872 CPPUNIT_ASSERT_NO_THROW(NumberOfGroups = myMesh2->getNumberOfGroups(MED_CELL));
873 CPPUNIT_ASSERT_EQUAL(NumberOfGroups, 2);
874 vector<GROUP*> groups;
875 CPPUNIT_ASSERT_NO_THROW(groups = myMesh2->getGroups(MED_CELL));
876 CPPUNIT_ASSERT(groups.size() != 0);
877 for(int nb = 1; nb <= NumberOfGroups; nb++ )
880 CPPUNIT_ASSERT_NO_THROW(group = myMesh2->getGroup(MED_CELL, nb));
881 CPPUNIT_ASSERT_EQUAL(group->getName(), groups[nb-1]->getName());
884 int NumberOfFamilies;
885 CPPUNIT_ASSERT_NO_THROW(NumberOfFamilies = myMesh2->getNumberOfFamilies(MED_CELL));
886 CPPUNIT_ASSERT_MESSAGE("Current mesh hasn't Families", NumberOfFamilies == 0);
888 //create families - it's not possible to create, becase not all entities are defined
889 CPPUNIT_ASSERT_THROW( myMesh2->createFamilies(),MEDEXCEPTION);
891 /*CPPUNIT_ASSERT_NO_THROW(NumberOfFamilies = myMesh2->getNumberOfFamilies(MED_CELL));
892 CPPUNIT_ASSERT( NumberOfFamilies != 0);*/
897 //////////////////////////////////////////////////////////////
898 // TEST 2: Polygon and Polyhedron(only NODAL connectivity) //
899 /////////////////////////////////////////////////////////////
901 double CoordinatesPoly[57] =
924 const int REFnodalConnOfFaces[91] =
926 1, 2, 3, 4, 5, 6, -1,// Polyhedron 1
936 13, 14, 15, 3, 2, -1,// Polyhedron 2
947 const int NumberOfFaces = 19;
948 const int NumberOfPolyhedron = 2;
949 const int nbOfPolygons = 2;
951 const int REFpolyIndex[NumberOfPolyhedron+1] =
956 double PolygonCoordinates[27] =
969 const int REFpolygonFaces[11] =
971 1, 2, 3, 4, 5, 6, // Polygon 1
975 const int REFpolygonIndex[nbOfPolygons+1] =
980 MESHING *myMeshingPoly=new MESHING;
981 myMeshingPoly->setName("meshingpoly");
983 const int NbOfTypes = 1;
984 medGeometryElement TypesPoly[NbOfTypes] =
988 const int NbOfElements[NbOfTypes] =
993 CPPUNIT_ASSERT_NO_THROW(myMeshingPoly->setNumberOfTypes(NbOfTypes, MED_CELL));
997 myMeshingPoly->setCoordinates(SpaceDimension, NumberOfNodes, CoordinatesPoly,
998 "CARTESIAN", MED_FULL_INTERLACE);
1000 catch (const std::exception &e)
1002 CPPUNIT_FAIL(e.what());
1006 CPPUNIT_FAIL("Unknown exception");
1009 CPPUNIT_ASSERT_NO_THROW(myMeshingPoly->setTypes(TypesPoly, MED_CELL));
1010 CPPUNIT_ASSERT_NO_THROW(myMeshingPoly->setNumberOfElements(NbOfElements, MED_CELL));
1013 for(int i = 0; i < SpaceDimension; i++ )
1017 myMeshingPoly->setCoordinateName(Names[i],i);
1019 catch (const std::exception &e)
1021 CPPUNIT_FAIL(e.what());
1025 CPPUNIT_FAIL("Unknown exception");
1029 myMeshingPoly->setCoordinateUnit(Unit, i);
1031 catch (const std::exception &e)
1033 CPPUNIT_FAIL(e.what());
1037 CPPUNIT_FAIL("Unknown exception");
1041 int ConnectivityTetraPoly[4*1]=
1046 CPPUNIT_ASSERT_NO_THROW(myMeshingPoly->setConnectivity( MED_CELL, MED_TETRA4, ConnectivityTetraPoly ));
1048 CPPUNIT_ASSERT_NO_THROW(myMeshingPoly->setConnectivity(MED_CELL, MED_POLYHEDRA,REFnodalConnOfFaces,REFpolyIndex));
1050 bool PolyConn = false;
1051 CPPUNIT_ASSERT_NO_THROW(PolyConn = myMeshingPoly->existConnectivity(MED_NODAL, MED_CELL));
1052 CPPUNIT_ASSERT(PolyConn);
1054 CPPUNIT_ASSERT_EQUAL(NumberOfPolyhedron,
1055 myMeshingPoly->getNumberOfElements(MED_CELL,MED_POLYHEDRA));
1056 CPPUNIT_ASSERT_NO_THROW( myMeshingPoly->calculateConnectivity (MED_NODAL,MED_FACE));
1057 CPPUNIT_ASSERT_EQUAL(NumberOfFaces-1, myMeshingPoly->getNumberOfElements(MED_FACE,MED_POLYGON)); // -1: one face is shared with tetra
1058 CPPUNIT_ASSERT_EQUAL(91,myMeshingPoly->getConnectivityLength(MED_NODAL,MED_CELL,MED_POLYHEDRA));
1059 const int * PolyConn;
1060 const int * PolyIdx;
1061 CPPUNIT_ASSERT_NO_THROW(PolyConn = myMeshingPoly->getConnectivity(MED_NODAL,MED_CELL,MED_ALL_ELEMENTS));
1062 CPPUNIT_ASSERT_NO_THROW(PolyIdx = myMeshingPoly->getConnectivityIndex(MED_NODAL,MED_CELL));
1063 for(int i = NbOfElements[0], iRef=0; i<NbOfElements[0]+NumberOfPolyhedron; i++)
1065 int NodeIdxBegin = PolyIdx[i];
1066 int NodeIdxEnd = PolyIdx[i+1];
1067 for(int k = NodeIdxBegin; k < NodeIdxEnd; k++)
1068 CPPUNIT_ASSERT_EQUAL(REFnodalConnOfFaces[iRef++], PolyConn[k-1]);
1072 MESHING *myPolygonMeshing=new MESHING;
1073 myPolygonMeshing->setName("PolygonMeshing");
1075 medGeometryElement PolygonTypes[NbOfTypes] =
1079 const int PolygonNumberOfElements[NbOfTypes] =
1084 CPPUNIT_ASSERT_NO_THROW(myPolygonMeshing->setNumberOfTypes(NbOfTypes, MED_CELL));
1088 myPolygonMeshing->setCoordinates(SpaceDimension, NumberOfNodes, PolygonCoordinates,
1089 "CARTESIAN", MED_FULL_INTERLACE);
1091 catch (const std::exception &e)
1093 CPPUNIT_FAIL(e.what());
1097 CPPUNIT_FAIL("Unknown exception");
1100 CPPUNIT_ASSERT_EQUAL(SpaceDimension, myPolygonMeshing->getSpaceDimension());
1101 CPPUNIT_ASSERT_EQUAL(NumberOfNodes, myPolygonMeshing->getNumberOfNodes());
1103 CPPUNIT_ASSERT_NO_THROW(myPolygonMeshing->setTypes(PolygonTypes, MED_CELL));
1104 CPPUNIT_ASSERT_NO_THROW(myPolygonMeshing->setNumberOfElements(PolygonNumberOfElements, MED_CELL));
1105 CPPUNIT_ASSERT_EQUAL(2, myPolygonMeshing->getMeshDimension());
1109 myPolygonMeshing->setCoordinatesNames(Names);
1111 catch (const std::exception &e)
1113 CPPUNIT_FAIL(e.what());
1117 CPPUNIT_FAIL("Unknown exception");
1122 myPolygonMeshing->setCoordinatesUnits(Units);
1124 catch (const std::exception &e)
1126 CPPUNIT_FAIL(e.what());
1130 CPPUNIT_FAIL("Unknown exception");
1133 const int sizeTri = 3*2;
1134 int ConnectivityTri[sizeTri]=
1139 CPPUNIT_ASSERT_NO_THROW(myPolygonMeshing->setConnectivity( MED_CELL, MED_TRIA3, ConnectivityTri ));
1140 CPPUNIT_ASSERT_NO_THROW(myPolygonMeshing->setConnectivity( MED_CELL, MED_POLYGON, REFpolygonFaces, REFpolygonIndex ));
1142 bool PolygonConn = false;
1143 CPPUNIT_ASSERT_NO_THROW(PolygonConn = myPolygonMeshing->existConnectivity(MED_NODAL, MED_CELL));
1147 CPPUNIT_ASSERT_NO_THROW(Polytypes = myPolygonMeshing->getNumberOfTypes(MED_CELL));
1148 CPPUNIT_ASSERT_EQUAL(NbOfTypes,Polytypes);
1150 const MED_EN::medGeometryElement * PolyTypes;
1151 CPPUNIT_ASSERT_NO_THROW(PolyTypes = myPolygonMeshing->getTypes(MED_CELL));
1152 CPPUNIT_ASSERT_EQUAL(PolyTypes[NbOfTypes-1],MED_POLYGON);
1154 for(int t = 0; t < Polytypes; t++)
1156 CPPUNIT_ASSERT_NO_THROW( myPolygonMeshing->getNumberOfElements(MED_CELL, PolyTypes[t]));
1159 medGeometryElement geomPolyElem;
1160 CPPUNIT_ASSERT_NO_THROW(geomPolyElem = myPolygonMeshing->getElementType(MED_CELL, 1));
1161 CPPUNIT_ASSERT_EQUAL(geomPolyElem, MED_TRIA3);
1163 CPPUNIT_ASSERT_EQUAL(myPolygonMeshing->getNumberOfElements(MED_CELL,MED_POLYGON),nbOfPolygons);
1164 CPPUNIT_ASSERT_NO_THROW(myPolygonMeshing->getConnectivityLength(MED_NODAL,MED_CELL,MED_POLYGON));
1165 myPolygonMeshing->removeReference();
1166 const int * PolygonConn;
1167 CPPUNIT_ASSERT_THROW(PolygonConn = myMeshingPoly->getConnectivity(MED_NODAL,MED_CELL,MED_POLYGON),MEDEXCEPTION);
1170 ////////////////////////////////////////////////////////////
1171 // TEST : SUPPORT* sup = myMeshPointe->getSupportOnAll()) //
1172 ////////////////////////////////////////////////////////////
1174 //#ifdef ENABLE_FAULTS
1176 MESH * myMeshPointe = new MESH(MED_DRIVER, filename, meshname);
1177 const SUPPORT* sup = myMeshPointe->getSupportOnAll(MED_CELL);
1178 CPPUNIT_ASSERT( sup->isOnAllElements() );
1179 CPPUNIT_ASSERT_EQUAL( myMeshPointe->getNumberOfTypes( sup->getEntity() ),
1180 sup->getNumberOfTypes());
1181 CPPUNIT_ASSERT( sup->getNumber( MED_ALL_ELEMENTS ));
1182 myMeshPointe->removeReference();
1185 //#ifdef ENABLE_FORCED_FAILURES
1186 // CPPUNIT_FAIL("ERROR: can not create SUPPORT on mesh, read from pointe.med");
1189 ////////////////////////////////////////////////////////
1190 // TEST 3: test MESH on MEDMEMTest::createTestMesh()//
1191 ///////////////////////////////////////////////////////
1193 MESH* myMesh3 = MEDMEMTest_createTestMesh();
1195 int MeshDim = myMesh3->getMeshDimension();
1196 medEntityMesh constituentEntity;
1199 constituentEntity = MED_CELL;
1203 constituentEntity = MED_FACE;
1207 constituentEntity = MED_EDGE;
1210 int SpaceDim = myMesh3->getSpaceDimension();
1212 // Show Reverse Nodal Connectivity
1213 const int* ReverseNodalConnectivity;
1214 const int* ReverseNodalConnectivityIndex;
1216 int ReverseIdxLength;
1218 CONNECTIVITY* myConnectivity3 = (CONNECTIVITY*)myMesh3->getConnectivityptr();
1219 myConnectivity3->setNumberOfNodes(myMesh3->getNumberOfNodes());
1221 CPPUNIT_ASSERT_NO_THROW(ReverseNodalConnectivity= myMesh3->getReverseConnectivity(MED_NODAL, MED_CELL));
1222 CPPUNIT_ASSERT_NO_THROW(ReverseLength = myMesh3->getReverseConnectivityLength(MED_NODAL, MED_CELL));
1223 CPPUNIT_ASSERT_NO_THROW(ReverseNodalConnectivityIndex = myMesh3->getReverseConnectivityIndex(MED_NODAL, MED_CELL));
1224 CPPUNIT_ASSERT_NO_THROW(ReverseIdxLength = myMesh3->getReverseConnectivityIndexLength(MED_NODAL, MED_CELL));
1225 CPPUNIT_ASSERT(ReverseIdxLength == myMesh3->getNumberOfNodes()+1);
1227 for (int i = 0; i < myMesh3->getNumberOfNodes(); i++)
1229 cout << "Node "<< i+1 << " : ";
1230 for (int j = ReverseNodalConnectivityIndex[i]; j < ReverseNodalConnectivityIndex[i+1]; j++)
1231 cout << ReverseNodalConnectivity[j-1] << " ";
1235 // Show Descending Connectivity
1236 int NumberOfElements1;
1237 const int * connectivity;
1238 const int * connectivity_index;
1239 myMesh3->calculateConnectivity(MED_DESCENDING, MED_EN::MED_CELL);
1242 NumberOfElements1 = myMesh3->getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS);
1243 connectivity = myMesh3->getConnectivity( MED_DESCENDING, MED_CELL, MED_ALL_ELEMENTS);
1244 connectivity_index = myMesh3->getConnectivityIndex(MED_DESCENDING, MED_CELL);
1246 catch (MEDEXCEPTION m)
1248 CPPUNIT_FAIL(m.what());
1251 for (int j = 0; j < NumberOfElements1; j++)
1253 cout << "Element " << j+1 << " : ";
1254 for (int k = connectivity_index[j]; k < connectivity_index[j+1]; k++)
1255 cout << connectivity[k-1] << " ";
1260 for(int ind = SpaceDim; ind > 1; ind-- )
1262 int NumberOfElem = myMesh3->getNumberOfElements (constituentEntity,MED_ALL_ELEMENTS);
1263 if(NumberOfElem < 1) continue;
1265 const SUPPORT * sup = myMesh3->getSupportOnAll( constituentEntity );
1269 // test of normal(for 1d or 2d elements)
1270 FIELD<double>* normal;
1271 CPPUNIT_ASSERT_NO_THROW(normal = myMesh3->getNormal(sup));
1273 double normal_square, norm;
1277 for (int i = 1; i<=NumberOfElem; i++)
1280 cout << "Normal " << i << " ";
1281 for (int j=1; j<=SpaceDim; j++)
1283 tmp_value = normal->getValueIJ(i,j);
1284 normal_square += tmp_value*tmp_value;
1285 cout << tmp_value << " ";
1287 norm = sqrt(normal_square);
1288 maxnorm = dmax(maxnorm,norm);
1289 minnorm = dmin(minnorm,norm);
1290 cout << ", Norm = " << norm << endl;
1292 cout << "Max Norm " << maxnorm << " Min Norm " << minnorm << endl;
1295 // test of area(for 2d elements)
1296 FIELD<double>* area;
1297 CPPUNIT_ASSERT_NO_THROW(area = myMesh3->getArea(sup));
1299 double maxarea,minarea,areatot;
1303 for (int i = 1; i<=NumberOfElem;i++)
1305 cout << "Area " << i << " " << area->getValueIJ(i,1) << endl;
1306 maxarea = dmax(maxarea,area->getValueIJ(i,1));
1307 minarea = dmin(minarea,area->getValueIJ(i,1));
1308 areatot = areatot + area->getValueIJ(i,1);
1311 cout << "Max Area " << maxarea << " Min Area " << minarea << endl;
1312 cout << "Support Area " << areatot << endl;
1317 // test of barycenter(for 3d and 2d elements)
1318 FIELD<double>* barycenter;
1319 CPPUNIT_ASSERT_NO_THROW(barycenter = myMesh3->getBarycenter(sup));
1321 CPPUNIT_ASSERT_NO_THROW(NumberOfElem = myMesh3->getNumberOfElements(constituentEntity,MED_ALL_ELEMENTS));
1323 for (int i = 1; i<=NumberOfElem;i++)
1326 cout << "Barycenter " << i << " " << barycenter->getValueIJ(i,1) << " " << barycenter->getValueIJ(i,2) << " " << barycenter->getValueIJ(i,3) << endl;
1329 cout << "Barycenter " << i << " " << barycenter->getValueIJ(i,1) << " " << barycenter->getValueIJ(i,2) << endl;
1333 // test of volume(for 3d elements)
1336 FIELD<double>* volume;
1337 CPPUNIT_ASSERT_NO_THROW(volume= myMesh3->getVolume(sup));
1339 double maxvol,minvol,voltot;
1343 for (int i = 1; i<=NumberOfElem;i++)
1345 cout << "Volume " << i << " " << volume->getValueIJ(i,1) << endl;
1346 maxvol = dmax(maxvol,volume->getValueIJ(i,1));
1347 minvol = dmin(minvol,volume->getValueIJ(i,1));
1348 voltot = voltot + volume->getValueIJ(i,1);
1351 cout << "Max Volume " << maxvol << " Min Volume " << minvol << endl;
1352 cout << "Support Volume " << voltot << endl;
1358 CPPUNIT_ASSERT_NO_THROW(skin = myMesh3->getSkin(sup));
1360 //test mergeSupports and intersectSupports. vactor contains only 1 elements
1361 vector<SUPPORT *> myVectSup;
1362 myVectSup.push_back(skin);
1364 //method return a copy of skin object
1365 SUPPORT *copyMergeSkin;
1366 CPPUNIT_ASSERT_NO_THROW(copyMergeSkin = myMesh3->mergeSupports(myVectSup));
1369 CPPUNIT_ASSERT(copyMergeSkin->deepCompare(*skin));
1371 catch (const std::exception &e)
1373 CPPUNIT_FAIL(e.what());
1377 CPPUNIT_FAIL("Unknown exception");
1380 //method return a copy of skin object
1381 SUPPORT *copyIntersectSkin;
1382 CPPUNIT_ASSERT_NO_THROW(copyIntersectSkin = myMesh3->intersectSupports(myVectSup));
1385 CPPUNIT_ASSERT(copyIntersectSkin->deepCompare(*skin));
1387 catch (const std::exception &e)
1389 CPPUNIT_FAIL(e.what());
1393 CPPUNIT_FAIL("Unknown exception");
1396 skin->removeReference();
1397 copyMergeSkin->removeReference();
1398 copyIntersectSkin->removeReference();
1401 constituentEntity++;
1405 // Testing length and normal vectors on 1d elements
1408 int NumberOfNodes3 = 4;
1419 double Coordinates3[4*2] =
1427 const int NumberOfEdgeTypes = 1;
1428 MED_EN::medGeometryElement EdgeTypes[NumberOfEdgeTypes] =
1432 const int NumberOfEdges[NumberOfEdgeTypes] =
1436 int ConnectivityEdge[4*2] =
1442 MEDMEM::MESHING* myMeshing3 = new MEDMEM::MESHING;
1443 myMeshing3->setName("meshing3");
1444 myMeshing3->setCoordinates(/*SpaceDimension*/2, NumberOfNodes3, Coordinates3,
1445 "CARTESIAN", MED_EN::MED_FULL_INTERLACE);
1446 myMeshing3->setCoordinatesNames(Names3);
1447 myMeshing3->setCoordinatesUnits(Units3);
1449 // define connectivities
1451 const int NumberOfTypes3 = 1;
1452 medGeometryElement Types3[NumberOfTypes3] =
1456 const int NumberOfElements3[NumberOfTypes3] =
1461 myMeshing3->setNumberOfTypes(NumberOfTypes3,MED_CELL);
1462 myMeshing3->setTypes(Types3,MED_CELL);
1463 myMeshing3->setNumberOfElements(NumberOfElements3,MED_CELL);
1465 int Connectivityquad[1*4] =
1470 myMeshing3->setConnectivity( MED_CELL, MED_QUAD4, Connectivityquad );
1472 myMeshing3->setNumberOfTypes(NumberOfEdgeTypes, MED_EDGE);
1473 myMeshing3->setTypes(EdgeTypes, MED_EDGE);
1474 myMeshing3->setNumberOfElements(NumberOfEdges, MED_EDGE);
1476 myMeshing3->setConnectivity( MED_EDGE, MED_SEG2, ConnectivityEdge );
1479 int NumberOfElem = myMeshing3->getNumberOfElements (MED_EDGE, MED_ALL_ELEMENTS);
1481 const SUPPORT * sup = myMeshing3->getSupportOnAll( MED_EDGE );
1483 // test of normal(for 1d or 2d elements)
1484 FIELD<double>* normal;
1485 CPPUNIT_ASSERT_NO_THROW(normal = myMeshing3->getNormal(sup));
1487 double normal_square, norm;
1491 for (int i = 1; i<=NumberOfElem; i++)
1494 cout << "Normal " << i << " ";
1495 for (int j=1; j<=/*SpaceDimension*/2; j++)
1497 tmp_value = normal->getValueIJ(i,j);
1498 normal_square += tmp_value*tmp_value;
1499 cout << tmp_value << " ";
1501 norm = sqrt(normal_square);
1502 maxnorm = dmax(maxnorm,norm);
1503 minnorm = dmin(minnorm,norm);
1504 cout << ", Norm = " << norm << endl;
1506 cout << "Max Norm " << maxnorm << " Min Norm " << minnorm << endl;
1508 // test of length(for 1d elements)
1509 FIELD<double>* length;
1510 CPPUNIT_ASSERT_NO_THROW(length = myMeshing3->getLength(sup));
1512 double length_value,maxlength,minlength;
1515 for (int i = 1; i<=NumberOfElem;i++)
1517 length_value = length->getValueIJ(i,1);
1518 cout << "Length " << i << " " << length_value << endl;
1519 maxlength = dmax(maxlength,length_value);
1520 minlength = dmin(minlength,length_value);
1522 cout << "Max Length " << maxlength << " Min Length " << minlength << endl;
1524 vector< FIELD<double> *> myVectField1;
1525 myVectField1.push_back(normal);
1526 myVectField1.push_back(length);
1527 CPPUNIT_ASSERT_NO_THROW(myMeshing3->mergeFields(myVectField1));
1532 //#ifdef ENABLE_FAULTS
1534 // (BUG) Segmentation fault if vector is empty
1535 vector<SUPPORT *> myVectSupEmpty;
1536 CPPUNIT_ASSERT_THROW(myMesh3->mergeSupports(myVectSupEmpty), MEDEXCEPTION);
1540 // test mergeFields method: Fields have the same value type
1541 //intersectSupports and mergeSupports methods
1543 SUPPORT * sup1 = new SUPPORT;
1544 sup1->setMesh( myMeshing3 );
1545 sup1->setEntity( MED_EDGE );
1546 SUPPORT * sup2 = new SUPPORT;
1547 sup2->setMesh( myMeshing3 );
1548 sup2->setEntity( MED_EDGE );
1549 MED_EN::medGeometryElement gtEdges[1] =
1569 sup1->setpartial("description 1", 1, 1, gtEdges, nbEdges1, edges1);
1570 sup2->setpartial("description 1", 1, 2, gtEdges, nbEdges2, edges2);
1572 vector<SUPPORT *> myVectSup3;
1573 myVectSup3.push_back(sup1);
1574 myVectSup3.push_back(sup2);
1575 //method return a MergeSup on the union of all SUPPORTs in Supports.
1577 CPPUNIT_ASSERT_NO_THROW(MergeSup = myMesh3->mergeSupports(myVectSup3));
1578 cout << *MergeSup << endl;
1579 MergeSup->removeReference();
1581 //method return a intersection of all SUPPORTs in IntersectSup
1582 SUPPORT *IntersectSup;
1583 CPPUNIT_ASSERT_NO_THROW(IntersectSup = myMesh3->intersectSupports(myVectSup3));
1584 if (IntersectSup != NULL) cout<< *IntersectSup <<endl;
1585 IntersectSup->removeReference();
1587 FIELD<double> * length1 = myMeshing3->getLength(sup1);
1588 FIELD<double> * length2 = myMeshing3->getLength(sup2);
1590 vector< FIELD<double> *> myVect12;
1591 myVect12.push_back(length1);
1592 myVect12.push_back(length2);
1594 FIELD<double> * length12;
1595 CPPUNIT_ASSERT_NO_THROW(length12 = myMeshing3->mergeFields(myVect12));
1598 sup1->removeReference();
1599 sup2->removeReference();
1605 /////////////////////////////////////////////////////////
1606 // TEST 4: test MESH constructed from file pointe.med //
1607 ////////////////////////////////////////////////////////
1608 MESH * myMesh4 = new MESH();
1609 myMesh4->setName(meshname);
1610 MED_MESH_RDONLY_DRIVER myMeshDriver (filename, myMesh4);
1611 myMeshDriver.setMeshName(meshname);
1613 //Mesh has no driver->segmentation violation
1614 //CPPUNIT_ASSERT_THROW(myMesh4->read(), MEDEXCEPTION);
1616 //Add an existing MESH driver.
1618 CPPUNIT_ASSERT_NO_THROW(myDriver4 = myMesh4->addDriver(myMeshDriver));
1620 //read all objects in the file
1621 CPPUNIT_ASSERT_NO_THROW(myMesh4->read(myDriver4));
1623 if (myMesh4->getIsAGrid())
1625 GRID* myGrid = dynamic_cast<GRID*>(myMesh4);
1626 CPPUNIT_ASSERT(myGrid);
1629 //myDriver4->DRONLY->can't write
1630 CPPUNIT_ASSERT_THROW(myMesh4->write(myDriver4), MEDEXCEPTION);
1634 CPPUNIT_ASSERT_NO_THROW(idMeshV21 = myMesh4->addDriver(MED_DRIVER,filenameout21));
1636 //Write all the content of the MESH using driver referenced by the integer handler index.
1637 CPPUNIT_ASSERT_NO_THROW(myMesh4->write(idMeshV21));
1639 // remove driver from mesh
1640 CPPUNIT_ASSERT_NO_THROW(myMesh4->rmDriver(myDriver4));
1641 //#ifdef ENABLE_FORCED_FAILURES
1642 // CPPUNIT_FAIL("ERROR: driver with index idMedV21 has not been removed");
1644 // ensure exception is raised on second attempt to remove driver
1645 //CPPUNIT_ASSERT_THROW(myMesh4->rmDriver(myDriver4),MEDEXCEPTION);
1647 // Create a MESH object using a MESH driver of type MED_DRIVER associated with file fileName.
1649 CPPUNIT_ASSERT_NO_THROW(myMesh5 = new MESH(MED_DRIVER, filename, meshname));
1650 if(myMesh5->getIsAGrid())
1652 GRID* myGrid = dynamic_cast<GRID*>(myMesh4);
1653 CPPUNIT_ASSERT(myGrid);
1656 //ensure two meshes constracted from one file in two different ways are equal
1657 CPPUNIT_ASSERT(myMesh5->deepCompare(*myMesh4));
1660 MESH* myMesh6 = new MESH();
1663 myDriver6 = myMesh6->addDriver(MED_DRIVER, filename, meshname, RDONLY);
1665 catch (const std::exception &e)
1667 CPPUNIT_FAIL(e.what());
1671 CPPUNIT_FAIL("Unknown exception");
1676 myMesh6->read(myDriver6);
1678 catch (const std::exception &e)
1680 CPPUNIT_FAIL(e.what());
1684 CPPUNIT_FAIL("Unknown exception");
1687 //ensure two meshes constracted from one file in two different ways are equal
1688 CPPUNIT_ASSERT(myMesh6->deepCompare(*myMesh4));
1691 int NumberOfFamilies4;
1692 CPPUNIT_ASSERT_NO_THROW(NumberOfFamilies4 = myMesh6->getNumberOfFamilies(MED_CELL));
1693 CPPUNIT_ASSERT_MESSAGE("Current mesh hasn't Families", NumberOfFamilies4 != 0);
1695 vector<FAMILY*> families4;
1696 CPPUNIT_ASSERT_NO_THROW(families4 = myMesh6->getFamilies(MED_CELL));
1697 CPPUNIT_ASSERT(families4.size() == NumberOfFamilies4);
1698 for(int nb = 1; nb <= NumberOfFamilies4; nb++ )
1700 const FAMILY* family;
1701 CPPUNIT_ASSERT_NO_THROW(family = myMesh6->getFamily(MED_CELL, nb));
1702 CPPUNIT_ASSERT_EQUAL(family->getName(), families4[nb-1]->getName());
1705 //get support which reference all elements on the boundary of mesh.
1707 CPPUNIT_ASSERT_THROW(myMesh6->getBoundaryElements(MED_CELL), MEDEXCEPTION);
1708 //get only face in 3D.
1709 CPPUNIT_ASSERT_NO_THROW(myBndSup = myMesh6->getBoundaryElements(MED_FACE));
1711 //test buildSupportOnElementsFromElementList and buildSupportOnNodeFromElementList
1712 const int * myConnectivityValue6;
1713 CPPUNIT_ASSERT_NO_THROW(myConnectivityValue6 = myMesh6->getReverseConnectivity(MED_DESCENDING));
1714 const int * myConnectivityIndex6;
1715 CPPUNIT_ASSERT_NO_THROW(myConnectivityIndex6 = myMesh6->getReverseConnectivityIndex(MED_DESCENDING));
1717 CPPUNIT_ASSERT_NO_THROW(numberOfElem6 = myMesh6->getNumberOfElements(MED_FACE,MED_ALL_ELEMENTS));
1718 list<int> myElementsList6;
1720 for (int i=0; i<numberOfElem6; i++)
1721 if (myConnectivityValue6[myConnectivityIndex6[i]] == 0)
1723 myElementsList6.push_back(i+1);
1726 SUPPORT * mySupportOnNode;
1727 SUPPORT * mySupportOnElem;
1728 CPPUNIT_ASSERT_NO_THROW(mySupportOnElem = myMesh6->buildSupportOnElementsFromElementList(myElementsList6,MED_FACE));
1729 CPPUNIT_ASSERT(mySupportOnElem->deepCompare(*myBndSup));
1730 CPPUNIT_ASSERT_EQUAL(MED_FACE, mySupportOnElem->getEntity());
1732 list<int>::const_iterator iteronelem = myElementsList6.begin();
1733 for (int i = 1; i <= 3; i++, iteronelem++)
1735 CPPUNIT_ASSERT_EQUAL(i, mySupportOnElem->getValIndFromGlobalNumber(*iteronelem));
1738 CPPUNIT_ASSERT_NO_THROW(mySupportOnNode = myMesh6->buildSupportOnNodeFromElementList(myElementsList6,MED_FACE));
1739 CPPUNIT_ASSERT(mySupportOnNode->deepCompare( *(myMesh6->getBoundaryElements(MED_NODE))));
1741 //sets mesh fields to initial values
1746 catch (const std::exception &e)
1748 CPPUNIT_FAIL(e.what());
1752 CPPUNIT_FAIL("Unknown exception");
1755 //ensure two meshes constracted from one file in two different ways are equal
1756 CPPUNIT_ASSERT(!myMesh6->deepCompare(*myMesh4));
1758 //ensure mesh is empty
1759 CPPUNIT_ASSERT(myMesh6->getSpaceDimension() == MED_INVALID);
1760 CPPUNIT_ASSERT(myMesh6->getNumberOfNodes() == MED_INVALID);
1761 CPPUNIT_ASSERT(myMesh6->getCoordinateptr() == NULL);
1767 MESH* myMesh7 = MEDMEMTest_createTestMesh();
1768 vector< vector<double> > myBndBox;
1771 myBndBox = myMesh7->getBoundingBox();
1773 catch (const std::exception &e)
1775 CPPUNIT_FAIL(e.what());
1779 CPPUNIT_FAIL("Unknown exception");
1782 cout<<"Bounding box for createTestMesh()"<<endl;
1783 for(int i = 0; i < myBndBox.size(); i++)
1785 for(int j = 0; j < myBndBox[i].size(); j++)
1786 cout<<" "<< myBndBox[i][j]<<" ";
1790 double CoorPoint[3] =
1797 idxElem = myMesh7->getElementContainingPoint(CoorPoint);
1799 catch (const std::exception &e)
1801 CPPUNIT_FAIL(e.what());
1805 CPPUNIT_FAIL("Unknown exception");
1807 CPPUNIT_ASSERT(idxElem != -1);
1809 double CoorNoPoint[3] =
1812 }; //there is no such point
1816 idxNoElem = myMesh7->getElementContainingPoint(CoorNoPoint);
1818 catch (const std::exception &e)
1820 CPPUNIT_FAIL(e.what());
1824 CPPUNIT_FAIL("Unknown exception");
1826 CPPUNIT_ASSERT(idxNoElem == -1);
1829 int main (int argc, char** argv)
1831 MEDMEMTest_testMeshAndMeshing();