1 // Copyright (C) 2007-2012 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 "MEDMEM_define.hxx"
23 #include "MEDMEM_Mesh.hxx"
24 #include "MEDMEM_Support.hxx"
25 #include "MEDMEM_Family.hxx"
26 #include "MEDMEM_Field.hxx"
27 #include "MEDMEM_ModulusArray.hxx"
28 #include "MEDMEM_MedMeshDriver.hxx"
31 #define MESHNAME "poly3D"
34 using namespace MEDMEM;
35 using namespace MED_EN;
37 #define DIM_OF_FIELD 3
43 const int *_tabOfNodes;
44 vector<int> _eltsActiveYet;
45 vector<int> _lgthOfEltsActiveYet;
47 SupportTester(const int *tabOfNodes, int nbOfElts, int nbOfNodesPerElt);
48 SupportTester(const int *tabOfNodes, int nbOfElts, const int *nbOfNodesPerElt);
49 bool isIncludedAndNotAlreadyConsumed(const int *tabOfNodesOfTheElementToTest);
50 bool areAllEltsConsumed();
52 static bool areEquivalent(const int *nodes1, const int *nodes2, int nbOfNodes);
55 SupportTester::SupportTester(const int *tabOfNodes, int nbOfElts, int nbOfNodesPerElt):_tabOfNodes(tabOfNodes)
57 for(int i=0;i<nbOfElts;i++)
59 _eltsActiveYet.push_back(i*nbOfNodesPerElt);
60 _lgthOfEltsActiveYet.push_back(nbOfNodesPerElt);
64 SupportTester::SupportTester(const int *tabOfNodes, int nbOfElts, const int *nbOfNodesPerElt):_tabOfNodes(tabOfNodes)
67 for(int i=0;i<nbOfElts;i++)
69 _eltsActiveYet.push_back(offset);
70 _lgthOfEltsActiveYet.push_back(nbOfNodesPerElt[i]);
74 bool SupportTester::isIncludedAndNotAlreadyConsumed(const int *tabOfNodesOfTheElementToTest)
76 vector<int>::iterator iter2=_lgthOfEltsActiveYet.begin();
77 for(vector<int>::iterator iter=_eltsActiveYet.begin();iter!=_eltsActiveYet.end();iter++)
78 if(areEquivalent(_tabOfNodes+(*iter),tabOfNodesOfTheElementToTest,*iter2))
80 _eltsActiveYet.erase(iter);
81 _lgthOfEltsActiveYet.erase(iter2);
91 bool SupportTester::areAllEltsConsumed()
93 return _eltsActiveYet.size()==0;
96 bool SupportTester::areEquivalent(const int *nodes1, const int *nodes2, int nbOfNodes)
98 MEDMODULUSARRAY arr1(nbOfNodes,nodes1);
99 MEDMODULUSARRAY arr2(nbOfNodes,nodes2);
100 return arr1.compare(arr2)!=0;
103 int main (int argc, char ** argv)
105 if (argc<2) // after 2, ignored !
107 cerr << "Usage : " << argv[0] << " poly3D.med typically in ../../share/salome/resources/med" << endl << endl;
110 int nbOfPtsForTest=0;
112 string filename = argv[1];
113 MESH * myMesh = new MESH;
114 myMesh->setName(MESHNAME);
115 MED_MESH_RDONLY_DRIVER myMeshReadDriver(filename,myMesh);
116 myMeshReadDriver.setMeshName(MESHNAME);
117 myMeshReadDriver.open();
118 myMeshReadDriver.read();
119 myMeshReadDriver.close();
120 //Test 1 : test if connectivity of poly3D mesh is OK
121 if(myMesh->getMeshDimension()==3 && myMesh->getSpaceDimension()==3)
123 if(myMesh->getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_TETRA4)==1 && myMesh->getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_POLYHEDRA)==2)
125 const int REFnodalConnForTetra[4]=
129 const int *connForTetraToTest=myMesh->getConnectivity(MED_NODAL,MED_CELL,MED_TETRA4);
130 const int *connIndForTetraToTest=myMesh->getConnectivityIndex(MED_NODAL,MED_CELL);
131 for(i=connIndForTetraToTest[0]-1;i<connIndForTetraToTest[1]-1;i++)
132 if(connForTetraToTest[i]==REFnodalConnForTetra[i])
135 const int *globIndex=connIndForTetraToTest + 1; // skip 1 tetra
136 const int *nodalConnOfFaces=myMesh->getConnectivity(MED_NODAL,MED_CELL,MED_POLYHEDRA);
137 if(globIndex[1]-globIndex[0]==46 && globIndex[2]-globIndex[1]==45)// resp 46 nodes and 45 nodes are in polyh 1 and 2.
140 const int REFnodalConnOfFaces[91]=
142 1, 2, 3, 4, 5, 6, -1,// Polyhedron 1
152 13, 14, 15, 3, 2, -1,// Polyhedron 2
164 if(REFnodalConnOfFaces[i]==nodalConnOfFaces[i])
166 if(nbOfPtsForTest!=7+74)
168 cout << "TEST1 K0 ! : Invalid Globaldata in memory..." << endl;
173 vector<FAMILY*> families=myMesh->getFamilies(MED_FACE);
174 if(families.size()==3)
176 vector<FAMILY *>::iterator iter=families.begin();
177 FAMILY *fam1=*(iter++);
178 FAMILY *fam2=*(iter++);
179 FAMILY *fam3=*(iter);
182 if(fam1->getNumberOfTypes()==1 && fam1->getTypes()[0]==MED_POLYGON && fam1->getNumberOfElements(MED_ALL_ELEMENTS)==3)
184 nbs=fam1->getNumber(MED_ALL_ELEMENTS);
185 const int REFTabForPolyg[16]=
187 1, 2, 3, 4, 5, 6, 10, 9, 8, 12, 11, 13, 14, 15, 3, 2
189 const int REFTabForPolygLgth[3]=
193 SupportTester test1(REFTabForPolyg,3,REFTabForPolygLgth);
197 const int *conn=((CONNECTIVITY *)myMesh->getConnectivityptr())->getConnectivityOfAnElement(MED_NODAL,MED_FACE,nbs[i],lgth);
198 if(test1.isIncludedAndNotAlreadyConsumed(conn))
201 if(test1.areAllEltsConsumed())
204 if(fam2->getNumberOfElements(MED_ALL_ELEMENTS)==8)
206 nbs=fam2->getNumber(MED_ALL_ELEMENTS);
207 const int REFTabForQuad[32]=
209 1, 7, 8, 2, 2, 8, 9, 3, 4, 3, 9, 10, 5, 4, 10, 11, 6, 5, 11, 12, 1, 6, 12, 7, 14, 13, 16, 17, 8, 9, 17, 16
211 SupportTester test2(REFTabForQuad,8,4);
215 const int *conn=((CONNECTIVITY *)myMesh->getConnectivityptr())->getConnectivityOfAnElement(MED_NODAL,MED_FACE,nbs[i],lgth);
216 if(test2.isIncludedAndNotAlreadyConsumed(conn))
219 if(test2.areAllEltsConsumed())
222 if(fam3->getNumberOfElements(MED_ALL_ELEMENTS)==6)
224 nbs=fam3->getNumber(MED_ALL_ELEMENTS);
225 const int REFTabForTria[18]=
227 7, 12, 8, 15, 14, 17, 15, 17, 18, 15, 18, 9, 3, 15, 9, 18, 17, 9
229 SupportTester test3(REFTabForTria,6,3);
233 const int *conn=((CONNECTIVITY *)myMesh->getConnectivityptr())->getConnectivityOfAnElement(MED_NODAL,MED_FACE,nbs[i],lgth);
234 if(test3.isIncludedAndNotAlreadyConsumed(conn))
237 if(test3.areAllEltsConsumed())
239 if(nbOfPtsForTest!=21)
241 cout << "TEST2 K0 ! : Invalid data in memory for families !!!" << endl;
244 // TEST 3 : volumes, areas, barycenter
246 const SUPPORT *supOnCell=myMesh->getSupportOnAll(MED_CELL);
247 FIELD<double>* vol1=myMesh->getVolume(supOnCell, false);
248 int lgth=vol1->getValueLength();
249 const double *vals=vol1->getValue();
252 const double REFVolOfPolyHedron[3]=
254 2.333333333333333,-11.66666666666666,-13.83224131414673
257 if(fabs(REFVolOfPolyHedron[i]-vals[i])<1e-12)
259 vol1->removeReference();
260 vol1=myMesh->getVolume(supOnCell, true);
261 lgth=vol1->getValueLength();
262 vals=vol1->getValue();
266 if(fabs(fabs(REFVolOfPolyHedron[i])-vals[i])<1e-12)
268 vol1->removeReference();
269 FIELD<double>* bary=myMesh->getBarycenter(supOnCell);
270 lgth=bary->getValueLength();
271 vals=bary->getValue();
274 const double REFBaryOfPolyHedron[9]=
276 5.5, 1, -1, 2, 1.5, 1.0833333333333333, 5.1, 1.6, 0.9
279 if(fabs(REFBaryOfPolyHedron[i]-vals[i])<1e-12)
281 bary->removeReference();
283 vol1=myMesh->getArea(fam1);
284 lgth=vol1->getValueLength();
285 vals=vol1->getValue();
288 const double REFAreaForPolyg[3]=
293 if(fabs(REFAreaForPolyg[i]-vals[i])<1e-12)
295 vol1->removeReference();
297 vol1=myMesh->getArea(fam2);
298 lgth=vol1->getValueLength();
299 vals=vol1->getValue();
302 const double REFAreaForQuad[8]=
304 2.1213203435596424, 2.8284271247461903, 4.4721359549995796, 4.4721359549995796,
305 2.8284271247461903, 2.1213203435596428, 3.6798724963767362, 4
308 if(fabs(REFAreaForQuad[i]-vals[i])<1e-12)
310 vol1->removeReference();
312 vol1=myMesh->getArea(fam3);
313 lgth=vol1->getValueLength();
314 vals=vol1->getValue();
317 const double REFAreaForTri[6]=
319 2.9580398915498081, 1.4142135623730951, 2.2360679774997898,
320 3.3541019662496847, 3.3541019662496847, 2.2360679774997898
323 if(fabs(REFAreaForTri[i]-vals[i])<1e-12)
325 vol1->removeReference();
326 if(nbOfPtsForTest!=38)
328 cout << "TEST3 K0 ! : Error in calculation of basic properties !!!" << endl;
331 // TEST 4 -- CHECK FOR Reverse descending using getBoundaryElements.
333 SUPPORT *bound=myMesh->getBoundaryElements(MED_NODE);
334 if(bound->getNumberOfElements(MED_ALL_ELEMENTS)==19)
336 if(bound->isOnAllElements())
338 if(nbOfPtsForTest!=2)
340 cout << "TEST4 K0 ! : Error in getBoundaryElements probably due to Reverse descending !!!" << endl;
343 bound->removeReference();
345 cout << "ALL TESTS OK !!!" << endl;
346 myMesh->removeReference();