Back to index

salome-med  6.5.0
ParaMEDMEMTest_MEDLoader.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "ParaMEDMEMTest.hxx"
00021 #include "MEDLoader.hxx"
00022 #include "MEDCouplingUMesh.hxx"
00023 #include "MEDCouplingFieldDouble.hxx"
00024 
00025 #include <cppunit/TestAssert.h>
00026 
00027 #include <algorithm>
00028 #include <numeric>
00029 #include <iostream>
00030 #include <iterator>
00031 
00032 using namespace std;
00033 using namespace INTERP_KERNEL;
00034 using namespace ParaMEDMEM;
00035 
00036 void ParaMEDMEMTest::testMEDLoaderRead1()
00037 {
00038   string fileName=getResourceFile("pointe.med");
00039   vector<string> meshNames=MEDLoader::GetMeshNames(fileName.c_str());
00040   CPPUNIT_ASSERT_EQUAL(1,(int)meshNames.size());
00041   MEDCouplingUMesh *mesh=MEDLoader::ReadUMeshFromFile(fileName.c_str(),meshNames[0].c_str(),0);
00042   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
00043   CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension());
00044   CPPUNIT_ASSERT_EQUAL(16,mesh->getNumberOfCells());
00045   CPPUNIT_ASSERT_EQUAL(19,mesh->getNumberOfNodes());
00046   CPPUNIT_ASSERT_EQUAL(3,(int)mesh->getAllTypes().size());
00047   for(int i=0;i<12;i++)
00048     CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,mesh->getTypeOfCell(i));
00049   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,mesh->getTypeOfCell(12));
00050   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,mesh->getTypeOfCell(13));
00051   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,mesh->getTypeOfCell(14));
00052   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,mesh->getTypeOfCell(15));
00053   CPPUNIT_ASSERT_EQUAL(90,mesh->getNodalConnectivity()->getNbOfElems());
00054   CPPUNIT_ASSERT_EQUAL(701,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+90,0));
00055   CPPUNIT_ASSERT_EQUAL(705,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+17,0));
00056   CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12);
00057   mesh->decrRef();
00058   //
00059   vector<string> families=MEDLoader::GetMeshFamiliesNames(fileName.c_str(),meshNames[0].c_str());
00060   CPPUNIT_ASSERT_EQUAL(8,(int)families.size());
00061   CPPUNIT_ASSERT(families[2]=="FAMILLE_ELEMENT_3");
00062   //
00063   vector<string> families2;
00064   families2.push_back(families[2]);
00065   mesh=MEDLoader::ReadUMeshFromFamilies(fileName.c_str(),meshNames[0].c_str(),0,families2);
00066   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
00067   CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension());
00068   CPPUNIT_ASSERT_EQUAL(2,mesh->getNumberOfCells());
00069   CPPUNIT_ASSERT_EQUAL(19,mesh->getNumberOfNodes());
00070   CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllTypes().size());
00071   CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,mesh->getTypeOfCell(0));
00072   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,mesh->getTypeOfCell(1));
00073   CPPUNIT_ASSERT_EQUAL(11,mesh->getNodalConnectivity()->getNbOfElems());
00074   CPPUNIT_ASSERT_EQUAL(132,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+11,0));
00075   CPPUNIT_ASSERT_EQUAL(16,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+3,0));
00076   CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12);
00077   mesh->decrRef();
00078   //
00079   vector<string> groups=MEDLoader::GetMeshGroupsNames(fileName.c_str(),meshNames[0].c_str());
00080   CPPUNIT_ASSERT_EQUAL(5,(int)groups.size());
00081   CPPUNIT_ASSERT(groups[0]=="groupe1");
00082   CPPUNIT_ASSERT(groups[1]=="groupe2");
00083   CPPUNIT_ASSERT(groups[2]=="groupe3");
00084   CPPUNIT_ASSERT(groups[3]=="groupe4");
00085   CPPUNIT_ASSERT(groups[4]=="groupe5");
00086   vector<string> groups2;
00087   groups2.push_back(groups[0]);
00088   mesh=MEDLoader::ReadUMeshFromGroups(fileName.c_str(),meshNames[0].c_str(),0,groups2);
00089   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
00090   CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension());
00091   CPPUNIT_ASSERT_EQUAL(7,mesh->getNumberOfCells());
00092   CPPUNIT_ASSERT_EQUAL(19,mesh->getNumberOfNodes());
00093   CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllTypes().size());
00094   for(int i=0;i<6;i++)
00095     CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,mesh->getTypeOfCell(i));
00096   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,mesh->getTypeOfCell(6));
00097   CPPUNIT_ASSERT_EQUAL(36,mesh->getNodalConnectivity()->getNbOfElems());
00098   CPPUNIT_ASSERT_EQUAL(254,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+36,0));
00099   CPPUNIT_ASSERT_EQUAL(141,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+8,0));
00100   CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12);
00101   mesh->decrRef();
00102   //
00103   std::vector<std::string> fieldsName=MEDLoader::GetCellFieldNamesOnMesh(fileName.c_str(),meshNames[0].c_str());
00104   CPPUNIT_ASSERT_EQUAL(2,(int)fieldsName.size());
00105   CPPUNIT_ASSERT(fieldsName[0]=="fieldcelldoublescalar");
00106   CPPUNIT_ASSERT(fieldsName[1]=="fieldcelldoublevector");
00107   std::vector<std::pair<int,int> > its0=MEDLoader::GetCellFieldIterations(fileName.c_str(),meshNames[0].c_str(),fieldsName[0].c_str());
00108   CPPUNIT_ASSERT_EQUAL(1,(int)its0.size());
00109   CPPUNIT_ASSERT_EQUAL(-1,its0[0].first);
00110   CPPUNIT_ASSERT_EQUAL(-1,its0[0].second);
00111   std::vector<std::pair<int,int> > its1=MEDLoader::GetCellFieldIterations(fileName.c_str(),meshNames[0].c_str(),fieldsName[1].c_str());
00112   CPPUNIT_ASSERT_EQUAL(1,(int)its1.size());
00113   CPPUNIT_ASSERT_EQUAL(-1,its1[0].first);
00114   CPPUNIT_ASSERT_EQUAL(-1,its1[0].second);
00115   //
00116   MEDCouplingFieldDouble *field0=MEDLoader::ReadFieldCell(fileName.c_str(),meshNames[0].c_str(),0,fieldsName[0].c_str(),its0[0].first,its0[0].second);
00117   field0->checkCoherency();
00118   CPPUNIT_ASSERT(field0->getName()==fieldsName[0]);
00119   CPPUNIT_ASSERT_EQUAL(1,field0->getNumberOfComponents());
00120   CPPUNIT_ASSERT_EQUAL(16,field0->getNumberOfTuples());
00121   const double expectedValues[16]={1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,2.,3.,3.,2.};
00122   double diffValue[16];
00123   std::transform(field0->getArray()->getPointer(),field0->getArray()->getPointer()+16,expectedValues,diffValue,std::minus<double>());
00124   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue,diffValue+16),1e-12);
00125   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue,diffValue+16),1e-12);
00126   const MEDCouplingUMesh *constMesh=dynamic_cast<const MEDCouplingUMesh *>(field0->getMesh());
00127   CPPUNIT_ASSERT(constMesh);
00128   CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension());
00129   CPPUNIT_ASSERT_EQUAL(3,constMesh->getMeshDimension());
00130   CPPUNIT_ASSERT_EQUAL(16,constMesh->getNumberOfCells());
00131   CPPUNIT_ASSERT_EQUAL(19,constMesh->getNumberOfNodes());
00132   CPPUNIT_ASSERT_EQUAL(3,(int)constMesh->getAllTypes().size());
00133   for(int i=0;i<12;i++)
00134     CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,constMesh->getTypeOfCell(i));
00135   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(12));
00136   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(13));
00137   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(14));
00138   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(15));
00139   CPPUNIT_ASSERT_EQUAL(90,constMesh->getNodalConnectivity()->getNbOfElems());
00140   CPPUNIT_ASSERT_EQUAL(701,std::accumulate(constMesh->getNodalConnectivity()->getConstPointer(),constMesh->getNodalConnectivity()->getConstPointer()+90,0));
00141   CPPUNIT_ASSERT_EQUAL(705,std::accumulate(constMesh->getNodalConnectivityIndex()->getConstPointer(),constMesh->getNodalConnectivityIndex()->getConstPointer()+17,0));
00142   CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+57,0),1e-12);
00143   field0->decrRef();
00144   //
00145   MEDCouplingFieldDouble *field1=MEDLoader::ReadFieldCell(fileName.c_str(),meshNames[0].c_str(),0,fieldsName[1].c_str(),its1[0].first,its1[0].second);
00146   field1->checkCoherency();
00147   CPPUNIT_ASSERT(field1->getName()==fieldsName[1]);
00148   CPPUNIT_ASSERT_EQUAL(3,field1->getNumberOfComponents());
00149   CPPUNIT_ASSERT_EQUAL(16,field1->getNumberOfTuples());
00150   const double expectedValues2[48]={1.,0.,1.,1.,0.,1.,1.,0.,1.,2.,1.,0.,2.,1.,0.,2.,1.,0.,3.,0.,1.,3.,0.,1.,3.,0.,1.,4.,1.,0.,4.,1.,0.,4.,1.,0.,5.,0.,0.,6.,1.,1.,6.,0.,0.,5.,1.,1.};
00151   double diffValue2[48];
00152   std::transform(field1->getArray()->getPointer(),field1->getArray()->getPointer()+48,expectedValues2,diffValue2,std::minus<double>());
00153   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue2,diffValue2+48),1e-12);
00154   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue2,diffValue2+48),1e-12);
00155   constMesh=dynamic_cast<const MEDCouplingUMesh *>(field1->getMesh());
00156   CPPUNIT_ASSERT(constMesh);
00157   CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension());
00158   CPPUNIT_ASSERT_EQUAL(3,constMesh->getMeshDimension());
00159   CPPUNIT_ASSERT_EQUAL(16,constMesh->getNumberOfCells());
00160   CPPUNIT_ASSERT_EQUAL(19,constMesh->getNumberOfNodes());
00161   CPPUNIT_ASSERT_EQUAL(3,(int)constMesh->getAllTypes().size());
00162   for(int i=0;i<12;i++)
00163     CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,constMesh->getTypeOfCell(i));
00164   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(12));
00165   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(13));
00166   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(14));
00167   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(15));
00168   CPPUNIT_ASSERT_EQUAL(90,constMesh->getNodalConnectivity()->getNbOfElems());
00169   CPPUNIT_ASSERT_EQUAL(701,std::accumulate(constMesh->getNodalConnectivity()->getConstPointer(),constMesh->getNodalConnectivity()->getConstPointer()+90,0));
00170   CPPUNIT_ASSERT_EQUAL(705,std::accumulate(constMesh->getNodalConnectivityIndex()->getConstPointer(),constMesh->getNodalConnectivityIndex()->getConstPointer()+17,0));
00171   CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+57,0),1e-12);
00172   field1->decrRef();
00173   //fields on nodes
00174   std::vector<std::string> fieldsNameNode=MEDLoader::GetNodeFieldNamesOnMesh(fileName.c_str(),meshNames[0].c_str());
00175   CPPUNIT_ASSERT_EQUAL(2,(int)fieldsNameNode.size());
00176   CPPUNIT_ASSERT(fieldsNameNode[0]=="fieldnodedouble");
00177   CPPUNIT_ASSERT(fieldsNameNode[1]=="fieldnodeint");
00178   std::vector<std::pair<int,int> > its0Node=MEDLoader::GetNodeFieldIterations(fileName.c_str(),meshNames[0].c_str(),fieldsNameNode[0].c_str());
00179   CPPUNIT_ASSERT_EQUAL(3,(int)its0Node.size());
00180   CPPUNIT_ASSERT_EQUAL(-1,its0Node[0].first);
00181   CPPUNIT_ASSERT_EQUAL(-1,its0Node[0].second);
00182   CPPUNIT_ASSERT_EQUAL(1,its0Node[1].first);
00183   CPPUNIT_ASSERT_EQUAL(-1,its0Node[1].second);
00184   CPPUNIT_ASSERT_EQUAL(2,its0Node[2].first);
00185   CPPUNIT_ASSERT_EQUAL(-1,its0Node[2].second);
00186   MEDCouplingFieldDouble *field0Nodes=MEDLoader::ReadFieldNode(fileName.c_str(),meshNames[0].c_str(),0,fieldsNameNode[0].c_str(),its0Node[0].first,its0Node[0].second);
00187   field0Nodes->checkCoherency();
00188   CPPUNIT_ASSERT(field0Nodes->getName()==fieldsNameNode[0]);
00189   CPPUNIT_ASSERT_EQUAL(1,field0Nodes->getNumberOfComponents());
00190   CPPUNIT_ASSERT_EQUAL(19,field0Nodes->getNumberOfTuples());
00191   const double expectedValues3[19]={1.,1.,1.,2.,2.,2.,3.,3.,3.,4.,4.,4.,5.,5.,5.,6.,6.,6.,7.};
00192   double diffValue3[19];
00193   std::transform(field0Nodes->getArray()->getPointer(),field0Nodes->getArray()->getPointer()+19,expectedValues3,diffValue3,std::minus<double>());
00194   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue3,diffValue3+19),1e-12);
00195   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue3,diffValue3+19),1e-12);
00196   constMesh=dynamic_cast<const MEDCouplingUMesh *>(field0Nodes->getMesh());
00197   CPPUNIT_ASSERT(constMesh);
00198   field0Nodes->decrRef();
00199   //
00200   field0Nodes=MEDLoader::ReadFieldNode(fileName.c_str(),meshNames[0].c_str(),0,fieldsNameNode[0].c_str(),its0Node[2].first,its0Node[2].second);
00201   field0Nodes->checkCoherency();
00202   CPPUNIT_ASSERT(field0Nodes->getName()==fieldsNameNode[0]);
00203   CPPUNIT_ASSERT_EQUAL(1,field0Nodes->getNumberOfComponents());
00204   CPPUNIT_ASSERT_EQUAL(19,field0Nodes->getNumberOfTuples());
00205   const double expectedValues4[19]={1.,2.,2.,2.,3.,3.,3.,4.,4.,4.,5.,5.,5.,6.,6.,6.,7.,7.,7.};
00206   std::transform(field0Nodes->getArray()->getPointer(),field0Nodes->getArray()->getPointer()+19,expectedValues4,diffValue3,std::minus<double>());
00207   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue3,diffValue3+19),1e-12);
00208   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue3,diffValue3+19),1e-12);
00209   constMesh=dynamic_cast<const MEDCouplingUMesh *>(field0Nodes->getMesh());
00210   CPPUNIT_ASSERT(constMesh);
00211   CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension());
00212   CPPUNIT_ASSERT_EQUAL(3,constMesh->getMeshDimension());
00213   CPPUNIT_ASSERT_EQUAL(16,constMesh->getNumberOfCells());
00214   CPPUNIT_ASSERT_EQUAL(19,constMesh->getNumberOfNodes());
00215   CPPUNIT_ASSERT_EQUAL(3,(int)constMesh->getAllTypes().size());
00216   for(int i=0;i<12;i++)
00217     CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,constMesh->getTypeOfCell(i));
00218   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(12));
00219   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(13));
00220   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(14));
00221   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(15));
00222   CPPUNIT_ASSERT_EQUAL(90,constMesh->getNodalConnectivity()->getNbOfElems());
00223   CPPUNIT_ASSERT_EQUAL(701,std::accumulate(constMesh->getNodalConnectivity()->getConstPointer(),constMesh->getNodalConnectivity()->getConstPointer()+90,0));
00224   CPPUNIT_ASSERT_EQUAL(705,std::accumulate(constMesh->getNodalConnectivityIndex()->getConstPointer(),constMesh->getNodalConnectivityIndex()->getConstPointer()+17,0));
00225   CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+57,0),1e-12);
00226   field0Nodes->decrRef();
00227   //
00228   field0Nodes=MEDLoader::ReadFieldNode(fileName.c_str(),meshNames[0].c_str(),0,fieldsNameNode[0].c_str(),its0Node[0].first,its0Node[0].second);
00229   field0Nodes->checkCoherency();
00230   CPPUNIT_ASSERT(field0Nodes->getName()==fieldsNameNode[0]);
00231   CPPUNIT_ASSERT_EQUAL(1,field0Nodes->getNumberOfComponents());
00232   CPPUNIT_ASSERT_EQUAL(19,field0Nodes->getNumberOfTuples());
00233   const double expectedValues5[19]={1.,1.,1.,2.,2.,2.,3.,3.,3.,4.,4.,4.,5.,5.,5.,6.,6.,6.,7.};
00234   std::transform(field0Nodes->getArray()->getPointer(),field0Nodes->getArray()->getPointer()+19,expectedValues5,diffValue3,std::minus<double>());
00235   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue3,diffValue3+19),1e-12);
00236   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue3,diffValue3+19),1e-12);
00237   constMesh=dynamic_cast<const MEDCouplingUMesh *>(field0Nodes->getMesh());
00238   CPPUNIT_ASSERT(constMesh);
00239   CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension());
00240   CPPUNIT_ASSERT_EQUAL(3,constMesh->getMeshDimension());
00241   CPPUNIT_ASSERT_EQUAL(16,constMesh->getNumberOfCells());
00242   CPPUNIT_ASSERT_EQUAL(19,constMesh->getNumberOfNodes());
00243   CPPUNIT_ASSERT_EQUAL(3,(int)constMesh->getAllTypes().size());
00244   for(int i=0;i<12;i++)
00245     CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,constMesh->getTypeOfCell(i));
00246   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(12));
00247   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(13));
00248   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(14));
00249   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(15));
00250   CPPUNIT_ASSERT_EQUAL(90,constMesh->getNodalConnectivity()->getNbOfElems());
00251   CPPUNIT_ASSERT_EQUAL(701,std::accumulate(constMesh->getNodalConnectivity()->getConstPointer(),constMesh->getNodalConnectivity()->getConstPointer()+90,0));
00252   CPPUNIT_ASSERT_EQUAL(705,std::accumulate(constMesh->getNodalConnectivityIndex()->getConstPointer(),constMesh->getNodalConnectivityIndex()->getConstPointer()+17,0));
00253   CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+57,0),1e-12);
00254   field0Nodes->decrRef();
00255 }
00256 
00257 void ParaMEDMEMTest::testMEDLoaderPolygonRead()
00258 {
00259   string fileName=getResourceFile("polygones.med");
00260   vector<string> meshNames=MEDLoader::GetMeshNames(fileName.c_str());
00261   CPPUNIT_ASSERT_EQUAL(1,(int)meshNames.size());
00262   CPPUNIT_ASSERT(meshNames[0]=="Bord");
00263   MEDCouplingUMesh *mesh=MEDLoader::ReadUMeshFromFile(fileName.c_str(),meshNames[0].c_str(),0);
00264   mesh->checkCoherency();
00265   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
00266   CPPUNIT_ASSERT_EQUAL(2,mesh->getMeshDimension());
00267   CPPUNIT_ASSERT_EQUAL(538,mesh->getNumberOfCells());
00268   CPPUNIT_ASSERT_EQUAL(579,mesh->getNumberOfNodes());
00269   CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllTypes().size());
00270   for(int i=0;i<514;i++)
00271     CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(i));
00272   for(int i=514;i<538;i++)
00273     CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(i));
00274   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+1737,0),1e-12);
00275   const double expectedVals1[12]={1.4851585216522212,-0.5,0.,1.4851585216522212,-0.4,0.,1.4851585216522212,-0.3,0., 1.5741585216522211, -0.5, 0. };
00276   double diffValue1[12];
00277   std::transform(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+12,expectedVals1,diffValue1,std::minus<double>());
00278   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue1,diffValue1+12),1e-12);
00279   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue1,diffValue1+12),1e-12);
00280   CPPUNIT_ASSERT_EQUAL(2768,mesh->getNodalConnectivity()->getNbOfElems());
00281   CPPUNIT_ASSERT_EQUAL(651050,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+2768,0));
00282   CPPUNIT_ASSERT_EQUAL(725943,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+539,0));
00283   mesh->decrRef();
00284   //
00285   std::vector<std::string> fieldsName=MEDLoader::GetCellFieldNamesOnMesh(fileName.c_str(),meshNames[0].c_str());
00286   CPPUNIT_ASSERT_EQUAL(3,(int)fieldsName.size());
00287   CPPUNIT_ASSERT(fieldsName[0]=="bord_:_distorsion");
00288   CPPUNIT_ASSERT(fieldsName[1]=="bord_:_familles");
00289   CPPUNIT_ASSERT(fieldsName[2]=="bord_:_non-ortho");
00290   std::vector<std::pair<int,int> > its0=MEDLoader::GetCellFieldIterations(fileName.c_str(),meshNames[0].c_str(),fieldsName[0].c_str());
00291   CPPUNIT_ASSERT_EQUAL(1,(int)its0.size());
00292   MEDCouplingFieldDouble *field=MEDLoader::ReadFieldCell(fileName.c_str(),meshNames[0].c_str(),0,fieldsName[0].c_str(),its0[0].first,its0[0].second);
00293   field->checkCoherency();
00294   CPPUNIT_ASSERT(field->getName()==fieldsName[0]);
00295   CPPUNIT_ASSERT_EQUAL(1,field->getNumberOfComponents());
00296   CPPUNIT_ASSERT_EQUAL(538,field->getNumberOfTuples());
00297   const MEDCouplingUMesh *constMesh=dynamic_cast<const MEDCouplingUMesh *>(field->getMesh());
00298   CPPUNIT_ASSERT(constMesh);
00299   CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension());
00300   CPPUNIT_ASSERT_EQUAL(2,constMesh->getMeshDimension());
00301   CPPUNIT_ASSERT_EQUAL(538,constMesh->getNumberOfCells());
00302   CPPUNIT_ASSERT_EQUAL(579,constMesh->getNumberOfNodes());
00303   CPPUNIT_ASSERT_EQUAL(2,(int)constMesh->getAllTypes().size());
00304   for(int i=0;i<514;i++)
00305     CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,constMesh->getTypeOfCell(i));
00306   for(int i=514;i<538;i++)
00307     CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,constMesh->getTypeOfCell(i));
00308   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,std::accumulate(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+1737,0),1e-12);
00309   std::transform(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+12,expectedVals1,diffValue1,std::minus<double>());
00310   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue1,diffValue1+12),1e-12);
00311   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue1,diffValue1+12),1e-12);
00312   CPPUNIT_ASSERT_EQUAL(2768,constMesh->getNodalConnectivity()->getNbOfElems());
00313   CPPUNIT_ASSERT_EQUAL(651050,std::accumulate(constMesh->getNodalConnectivity()->getConstPointer(),constMesh->getNodalConnectivity()->getConstPointer()+2768,0));
00314   CPPUNIT_ASSERT_EQUAL(725943,std::accumulate(constMesh->getNodalConnectivityIndex()->getConstPointer(),constMesh->getNodalConnectivityIndex()->getConstPointer()+539,0));
00315   const double *values=field->getArray()->getPointer();
00316   CPPUNIT_ASSERT_DOUBLES_EQUAL(2.87214203182918,std::accumulate(values,values+538,0.),1e-12);
00317   field->decrRef();
00318 }
00319 
00320 void ParaMEDMEMTest::testMEDLoaderPolyhedronRead()
00321 {
00322   string fileName=getResourceFile("poly3D.med");
00323   vector<string> meshNames=MEDLoader::GetMeshNames(fileName.c_str());
00324   CPPUNIT_ASSERT_EQUAL(1,(int)meshNames.size());
00325   CPPUNIT_ASSERT(meshNames[0]=="poly3D");
00326   MEDCouplingUMesh *mesh=MEDLoader::ReadUMeshFromFile(fileName.c_str(),meshNames[0].c_str(),0);
00327   mesh->checkCoherency();
00328   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
00329   CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension());
00330   CPPUNIT_ASSERT_EQUAL(3,mesh->getNumberOfCells());
00331   CPPUNIT_ASSERT_EQUAL(19,mesh->getNumberOfNodes());
00332   CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllTypes().size());
00333   CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,mesh->getTypeOfCell(0));
00334   CPPUNIT_ASSERT_EQUAL(NORM_POLYHED,mesh->getTypeOfCell(1));
00335   CPPUNIT_ASSERT_EQUAL(NORM_POLYHED,mesh->getTypeOfCell(2));
00336   CPPUNIT_ASSERT_EQUAL(98,mesh->getNodalConnectivity()->getNbOfElems());
00337   CPPUNIT_ASSERT_EQUAL(725,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+98,0));
00338   CPPUNIT_ASSERT_DOUBLES_EQUAL(110.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12);
00339   CPPUNIT_ASSERT_EQUAL(155,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+4,0));
00340   mesh->decrRef();
00341   //
00342   mesh=MEDLoader::ReadUMeshFromFile(fileName.c_str(),meshNames[0].c_str(),-1);
00343   mesh->checkCoherency();
00344   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
00345   CPPUNIT_ASSERT_EQUAL(2,mesh->getMeshDimension());
00346   CPPUNIT_ASSERT_EQUAL(17,mesh->getNumberOfCells());
00347   CPPUNIT_ASSERT_EQUAL(19,mesh->getNumberOfNodes());
00348   CPPUNIT_ASSERT_EQUAL(3,(int)mesh->getAllTypes().size());
00349   CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(0));
00350   CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(1));
00351   CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(2));
00352   CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(3));
00353   CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(4));
00354   CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(5));
00355   CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(6));
00356   CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(7));
00357   CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(8));
00358   CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(9));
00359   CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(10));
00360   CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(11));
00361   CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(12));
00362   CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(13));
00363   CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(14));
00364   CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(15));
00365   CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(16));
00366   CPPUNIT_ASSERT_DOUBLES_EQUAL(110.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12);
00367   CPPUNIT_ASSERT_EQUAL(83,mesh->getNodalConnectivity()->getNbOfElems());
00368   CPPUNIT_ASSERT_EQUAL(619,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+83,0));
00369   mesh->decrRef();
00370   //
00371   vector<string> families=MEDLoader::GetMeshFamiliesNames(fileName.c_str(),meshNames[0].c_str());
00372   CPPUNIT_ASSERT_EQUAL(4,(int)families.size());
00373   CPPUNIT_ASSERT(families[0]=="FAMILLE_FACE_POLYGONS3");
00374   CPPUNIT_ASSERT(families[1]=="FAMILLE_FACE_QUAD41");
00375   CPPUNIT_ASSERT(families[2]=="FAMILLE_FACE_TRIA32");
00376   CPPUNIT_ASSERT(families[3]=="FAMILLE_ZERO");
00377   vector<string> families2;
00378   families2.push_back(families[0]);
00379   mesh=MEDLoader::ReadUMeshFromFamilies(fileName.c_str(),meshNames[0].c_str(),-1,families2);
00380   mesh->checkCoherency();
00381   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
00382   CPPUNIT_ASSERT_EQUAL(2,mesh->getMeshDimension());
00383   CPPUNIT_ASSERT_EQUAL(3,mesh->getNumberOfCells());
00384   CPPUNIT_ASSERT_EQUAL(19,mesh->getNumberOfNodes());
00385   CPPUNIT_ASSERT_EQUAL(1,(int)mesh->getAllTypes().size());
00386   for(int i=0;i<3;i++)
00387     CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(i));
00388   CPPUNIT_ASSERT_EQUAL(19,mesh->getNodalConnectivity()->getNbOfElems());
00389   CPPUNIT_ASSERT_EQUAL(117,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+19,0));
00390   mesh->decrRef();
00391   //
00392   mesh=MEDLoader::ReadUMeshFromFamilies(fileName.c_str(),meshNames[0].c_str(),0,families2);
00393   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
00394   CPPUNIT_ASSERT_EQUAL(0,mesh->getNumberOfCells());
00395   CPPUNIT_ASSERT_EQUAL(19,mesh->getNumberOfNodes());
00396   CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension());
00397   CPPUNIT_ASSERT_EQUAL(0,(int)mesh->getAllTypes().size());
00398   mesh->decrRef();
00399 }