1 // This program test the implementation of the class MED_MESH_RDONLY_DRIVER for Polygons and Polyhedron. //
3 #include "MEDMEM_define.hxx"
4 #include "MEDMEM_Mesh.hxx"
5 #include "MEDMEM_Support.hxx"
6 #include "MEDMEM_Family.hxx"
7 #include "MEDMEM_Field.hxx"
8 #include "MEDMEM_ModulusArray.hxx"
9 #include "MEDMEM_MedMeshDriver.hxx"
10 #include "LocalTraceCollector.hxx"
13 #define MESHNAME "poly3D"
16 using namespace MEDMEM;
17 using namespace MED_EN;
19 #define DIM_OF_FIELD 3
24 const int *_tabOfNodes;
25 vector<int> _eltsActiveYet;
26 vector<int> _lgthOfEltsActiveYet;
28 SupportTester(const int *tabOfNodes, int nbOfElts, int nbOfNodesPerElt);
29 SupportTester(const int *tabOfNodes, int nbOfElts, const int *nbOfNodesPerElt);
30 bool isIncludedAndNotAlreadyConsumed(const int *tabOfNodesOfTheElementToTest);
31 bool areAllEltsConsumed();
33 static bool areEquivalent(const int *nodes1, const int *nodes2, int nbOfNodes);
36 SupportTester::SupportTester(const int *tabOfNodes, int nbOfElts, int nbOfNodesPerElt):_tabOfNodes(tabOfNodes)
38 for(int i=0;i<nbOfElts;i++)
40 _eltsActiveYet.push_back(i*nbOfNodesPerElt);
41 _lgthOfEltsActiveYet.push_back(nbOfNodesPerElt);
45 SupportTester::SupportTester(const int *tabOfNodes, int nbOfElts, const int *nbOfNodesPerElt):_tabOfNodes(tabOfNodes)
48 for(int i=0;i<nbOfElts;i++)
50 _eltsActiveYet.push_back(offset);
51 _lgthOfEltsActiveYet.push_back(nbOfNodesPerElt[i]);
55 bool SupportTester::isIncludedAndNotAlreadyConsumed(const int *tabOfNodesOfTheElementToTest)
57 vector<int>::iterator iter2=_lgthOfEltsActiveYet.begin();
58 for(vector<int>::iterator iter=_eltsActiveYet.begin();iter!=_eltsActiveYet.end();iter++)
59 if(areEquivalent(_tabOfNodes+(*iter),tabOfNodesOfTheElementToTest,*iter2))
61 _eltsActiveYet.erase(iter);
62 _lgthOfEltsActiveYet.erase(iter2);
72 bool SupportTester::areAllEltsConsumed()
74 return _eltsActiveYet.size()==0;
77 bool SupportTester::areEquivalent(const int *nodes1, const int *nodes2, int nbOfNodes)
79 MEDMODULUSARRAY arr1(nbOfNodes,nodes1);
80 MEDMODULUSARRAY arr2(nbOfNodes,nodes2);
81 return arr1.compare(arr2)!=0;
84 int main (int argc, char ** argv)
86 LocalTraceCollector::instance();
87 if (argc<2) // after 2, ignored !
89 cerr << "Usage : " << argv[0] << " poly3D.med typically in ../../share/salome/resources" << endl << endl;
94 string filename = argv[1];
95 MESH * myMesh = new MESH;
96 myMesh->setName(MESHNAME);
97 MED_MESH_RDONLY_DRIVER myMeshReadDriver(filename,myMesh);
98 myMeshReadDriver.setMeshName(MESHNAME);
99 myMeshReadDriver.open();
100 myMeshReadDriver.read();
101 myMeshReadDriver.close();
102 //Test 1 : test if connectivity of poly3D mesh is OK
103 if(myMesh->getMeshDimension()==3 && myMesh->getSpaceDimension()==3)
105 if(myMesh->getNumberOfElementsWithPoly(MED_EN::MED_CELL,MED_EN::MED_TETRA4)==1 && myMesh->getNumberOfElementsWithPoly(MED_EN::MED_CELL,MED_EN::MED_POLYHEDRA)==2)
107 const int REFnodalConnForTetra[4]={17, 9, 18, 19};
108 const int *connForTetraToTest=myMesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,MED_TETRA4);
109 const int *connIndForTetraToTest=myMesh->getConnectivityIndex(MED_NODAL,MED_CELL);
110 for(i=connIndForTetraToTest[0]-1;i<connIndForTetraToTest[1]-1;i++)
111 if(connForTetraToTest[i]==REFnodalConnForTetra[i])
114 const int *globIndex=myMesh->getPolyhedronIndex(MED_NODAL);
115 const int *nodalConnOfFaces=myMesh->getPolyhedronConnectivity(MED_NODAL);
116 const int *facesIndex=myMesh->getPolyhedronFacesIndex();
117 if(globIndex[1]-globIndex[0]==9 && globIndex[2]-globIndex[1]==10)// resp 9 faces and 10 faces are in polyh 1 and 2.
120 const int REFfacesIndex[20]={1, 7, 11, 15, 19, 23, 27, 31, 34, 39, 44, 48, 52, 55, 58, 61, 64, 68, 72, 75};
121 const int REFnodalConnOfFaces[74]={1, 2, 3, 4, 5, 6, // Polyhedron 1
131 13, 14, 15, 3, 2, // Polyhedron 2
142 if(REFfacesIndex[i]==facesIndex[i])
145 if(REFnodalConnOfFaces[i]==nodalConnOfFaces[i])
147 if(nbOfPtsForTest!=101)
149 cout << "TEST1 K0 ! : Invalid Globaldata in memory..." << endl;
154 vector<FAMILY*> families=myMesh->getFamilies(MED_FACE);
155 if(families.size()==3)
157 vector<FAMILY *>::iterator iter=families.begin();
158 FAMILY *fam1=*(iter++);
159 FAMILY *fam2=*(iter++);
160 FAMILY *fam3=*(iter);
163 if(fam1->getNumberOfTypes()==1 && fam1->getTypes()[0]==MED_POLYGON && fam1->getNumberOfElements(MED_ALL_ELEMENTS)==3)
165 nbs=fam1->getNumber(MED_ALL_ELEMENTS);
166 const int REFTabForPolyg[16]={1, 2, 3, 4, 5, 6, 10, 9, 8, 12, 11, 13, 14, 15, 3, 2};
167 const int REFTabForPolygLgth[3]={6,5,5};
168 SupportTester test1(REFTabForPolyg,3,REFTabForPolygLgth);
172 const int *conn=((CONNECTIVITY *)myMesh->getConnectivityptr())->getConnectivityOfAnElementWithPoly(MED_NODAL,MED_FACE,nbs[i],lgth);
173 if(test1.isIncludedAndNotAlreadyConsumed(conn))
176 if(test1.areAllEltsConsumed())
179 if(fam2->getNumberOfElements(MED_ALL_ELEMENTS)==8)
181 nbs=fam2->getNumber(MED_ALL_ELEMENTS);
182 const int REFTabForQuad[32]={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};
183 SupportTester test2(REFTabForQuad,8,4);
187 const int *conn=((CONNECTIVITY *)myMesh->getConnectivityptr())->getConnectivityOfAnElementWithPoly(MED_NODAL,MED_FACE,nbs[i],lgth);
188 if(test2.isIncludedAndNotAlreadyConsumed(conn))
191 if(test2.areAllEltsConsumed())
194 if(fam3->getNumberOfElements(MED_ALL_ELEMENTS)==6)
196 nbs=fam3->getNumber(MED_ALL_ELEMENTS);
197 const int REFTabForTria[18]={7, 12, 8, 15, 14, 17, 15, 17, 18, 15, 18, 9, 3, 15, 9, 18, 17, 9};
198 SupportTester test3(REFTabForTria,6,3);
202 const int *conn=((CONNECTIVITY *)myMesh->getConnectivityptr())->getConnectivityOfAnElementWithPoly(MED_NODAL,MED_FACE,nbs[i],lgth);
203 if(test3.isIncludedAndNotAlreadyConsumed(conn))
206 if(test3.areAllEltsConsumed())
208 if(nbOfPtsForTest!=21)
210 cout << "TEST2 K0 ! : Invalid data in memory for families !!!" << endl;
213 // TEST 3 : volumes, aeras, barycenter
215 SUPPORT *supOnCell=new SUPPORT(myMesh);
216 FIELD<double>* vol1=myMesh->getVolume(supOnCell);
217 int lgth=vol1->getValueLength(MED_FULL_INTERLACE);
218 const double *vals=vol1->getValue(MED_FULL_INTERLACE);
221 const double REFVolOfPolyHedron[3]={2.333333333333333,11.66666666666666,13.83224131414673};
223 if(fabs(REFVolOfPolyHedron[i]-vals[i])<1e-12)
226 FIELD<double>* bary=myMesh->getBarycenter(supOnCell);
227 lgth=bary->getValueLength(MED_FULL_INTERLACE);
228 vals=bary->getValue(MED_FULL_INTERLACE);
231 const double REFBaryOfPolyHedron[9]= {5.5, 1, -1, 2, 1.5, 1.0833333333333333, 5.1, 1.6, 0.9};
233 if(fabs(REFBaryOfPolyHedron[i]-vals[i])<1e-12)
238 vol1=myMesh->getArea(fam1);
239 lgth=vol1->getValueLength(MED_FULL_INTERLACE);
240 vals=vol1->getValue(MED_FULL_INTERLACE);
243 const double REFAreaForPolyg[3]={6,5,6.5};
245 if(fabs(REFAreaForPolyg[i]-vals[i])<1e-12)
248 vol1=myMesh->getArea(fam2);
249 lgth=vol1->getValueLength(MED_FULL_INTERLACE);
250 vals=vol1->getValue(MED_FULL_INTERLACE);
253 const double REFAreaForQuad[8]={2.1213203435596424, 2.8284271247461903, 4.4721359549995796, 4.4721359549995796,
254 2.8284271247461903, 2.1213203435596428, 3.6798724963767362, 4};
256 if(fabs(REFAreaForQuad[i]-vals[i])<1e-12)
260 vol1=myMesh->getArea(fam3);
261 lgth=vol1->getValueLength(MED_FULL_INTERLACE);
262 vals=vol1->getValue(MED_FULL_INTERLACE);
265 const double REFAreaForTri[6]={2.9580398915498081, 1.4142135623730951, 2.2360679774997898,
266 3.3541019662496847, 3.3541019662496847, 2.2360679774997898};
268 if(fabs(REFAreaForTri[i]-vals[i])<1e-12)
271 if(nbOfPtsForTest!=34)
273 cout << "TEST3 K0 ! : Error in caluclation of basic properties !!!" << endl;
276 // TEST 4 -- CHECK FOR Reverse descending using getBoundaryElements.
278 SUPPORT *bound=myMesh->getBoundaryElements(MED_NODE);
279 if(bound->getNumberOfElements(MED_ALL_ELEMENTS)==19)
281 if(bound->isOnAllElements())
283 if(nbOfPtsForTest!=2)
285 cout << "TEST4 K0 ! : Error in getBoundaryElements probably due to Reverse descending !!!" << endl;
290 cout << "ALL TESTS OK !!!" << endl;