Back to index

salome-med  6.5.0
MEDLoaderTest.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 "MEDLoaderTest.hxx"
00021 #include "MEDLoader.hxx"
00022 #include "MEDLoaderBase.hxx"
00023 #include "MEDCouplingUMesh.hxx"
00024 #include "MEDCouplingFieldDouble.hxx"
00025 #include "MEDCouplingMemArray.hxx"
00026 
00027 #include <cmath>
00028 
00029 using namespace ParaMEDMEM;
00030 
00031 void MEDLoaderTest::testMesh1DRW()
00032 {
00033   MEDCouplingUMesh *mesh=build1DMesh_1();
00034   mesh->checkCoherency();
00035   MEDLoader::WriteUMesh("file1.med",mesh,true);
00036   MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile("file1.med",mesh->getName(),0);
00037   CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
00038   mesh_rw->decrRef();
00039   mesh->decrRef();
00040 }
00041 
00042 void MEDLoaderTest::testMesh2DCurveRW()
00043 {
00044   MEDCouplingUMesh *mesh=build2DCurveMesh_1();
00045   mesh->checkCoherency();
00046   MEDLoader::WriteUMesh("file2.med",mesh,true);
00047   MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile("file2.med",mesh->getName(),0);
00048   CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
00049   mesh_rw->decrRef();
00050   mesh->decrRef();
00051 }
00052 
00053 void MEDLoaderTest::testMesh2DRW()
00054 {
00055   MEDCouplingUMesh *mesh=build2DMesh_1();
00056   mesh->checkCoherency();
00057   MEDLoader::WriteUMesh("file3.med",mesh,true);
00058   MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile("file3.med",mesh->getName(),0);
00059   CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
00060   mesh_rw->decrRef();
00061   mesh->decrRef();
00062 }
00063 
00064 void MEDLoaderTest::testMesh3DSurfRW()
00065 {
00066   MEDCouplingUMesh *mesh=build3DSurfMesh_1();
00067   mesh->checkCoherency();
00068   MEDLoader::WriteUMesh("file4.med",mesh,true);
00069   MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile("file4.med",mesh->getName(),0);
00070   CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
00071   mesh_rw->decrRef();
00072   mesh->decrRef();
00073 }
00074 
00075 void MEDLoaderTest::testMesh3DRW()
00076 {
00077   MEDCouplingUMesh *mesh=build3DMesh_1();
00078   mesh->checkCoherency();
00079   MEDLoader::WriteUMesh("file5.med",mesh,true);
00080   MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile("file5.med",mesh->getName(),0);
00081   CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
00082   mesh_rw->decrRef();
00083   mesh->decrRef();
00084 }
00085 
00089 void MEDLoaderTest::testFieldRW1()
00090 {
00091   MEDCouplingFieldDouble *f1=buildVecFieldOnCells_1();
00092   MEDLoader::WriteField("file6.med",f1,true);
00093   MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldCell("file6.med",f1->getMesh()->getName(),0,f1->getName(),0,1);
00094   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
00095   f1->decrRef();
00096   f2->decrRef();
00097   //
00098   f1=buildVecFieldOnNodes_1();
00099   MEDLoader::WriteField("file7.med",f1,true);
00100   f2=MEDLoader::ReadFieldNode("file7.med",f1->getMesh()->getName(),0,f1->getName(),2,3);
00101   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
00102   // testing kind message on error of field type.
00103   CPPUNIT_ASSERT_THROW(MEDLoader::ReadFieldCell("file7.med",f1->getMesh()->getName(),0,f1->getName(),2,3),INTERP_KERNEL::Exception);
00104   //
00105   f1->decrRef();
00106   f2->decrRef();
00107 }
00108 
00112 void MEDLoaderTest::testFieldRW2()
00113 {
00114   const char fileName[]="file8.med";
00115   static const double VAL1=12345.67890314;
00116   static const double VAL2=-1111111111111.;
00117   MEDCouplingFieldDouble *f1=buildVecFieldOnCells_1();
00118   MEDLoader::WriteField(fileName,f1,true);
00119   f1->setTime(10.,8,9);
00120   double *tmp=f1->getArray()->getPointer();
00121   tmp[0]=VAL1;
00122   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00123   f1->setTime(10.14,18,19);
00124   tmp[0]=VAL2;
00125   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00126   //retrieving time steps...
00127   MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName(),0,f1->getName(),8,9);
00128   f1->setTime(10.,8,9);
00129   tmp[0]=VAL1;
00130   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
00131   f2->decrRef();
00132   f2=MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName(),0,f1->getName(),0,1);
00133   MEDCouplingFieldDouble *f3=buildVecFieldOnCells_1();
00134   CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
00135   f3->decrRef();
00136   f2->decrRef();
00137   f2=MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName(),0,f1->getName(),18,19);
00138   f1->setTime(10.14,18,19);
00139   tmp[0]=VAL2;
00140   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
00141   //test of throw on invalid (dt,it)
00142   CPPUNIT_ASSERT_THROW(MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName(),0,f1->getName(),28,19),INTERP_KERNEL::Exception);
00143   f2->decrRef();
00144   f1->decrRef();
00145   //ON NODES
00146   f1=buildVecFieldOnNodes_1();
00147   const char fileName2[]="file9.med";
00148   MEDLoader::WriteField(fileName2,f1,true);
00149   f1->setTime(110.,108,109);
00150   tmp=f1->getArray()->getPointer();
00151   tmp[3]=VAL1;
00152   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName2,f1);
00153   f1->setTime(210.,208,209);
00154   tmp[3]=VAL2;
00155   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName2,f1);
00156   f2=MEDLoader::ReadFieldNode(fileName2,f1->getMesh()->getName(),0,f1->getName(),108,109);
00157   f1->setTime(110.,108,109);
00158   tmp[3]=VAL1;
00159   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
00160   f2->decrRef();
00161   f2=MEDLoader::ReadFieldNode(fileName2,f1->getMesh()->getName(),0,f1->getName(),2,3);
00162   f3=buildVecFieldOnNodes_1();
00163   CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
00164   f3->decrRef();
00165   f2->decrRef();
00166   f2=MEDLoader::ReadFieldNode(fileName2,f1->getMesh()->getName(),0,f1->getName(),208,209);
00167   f1->setTime(210.,208,209);
00168   tmp[3]=VAL2;
00169   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
00170   f2->decrRef();
00171   f1->decrRef();
00172 }
00173 
00177 void MEDLoaderTest::testFieldRW3()
00178 {
00179   const char fileName[]="file11.med";
00180   static const double VAL1=12345.67890314;
00181   static const double VAL2=-1111111111111.;
00182   const char name1[]="AField";
00183   const char name3[]="AMesh1";
00184   MEDCouplingFieldDouble *f1=buildVecFieldOnCells_1();
00185   (const_cast<MEDCouplingMesh *>(f1->getMesh()))->setName(name3);
00186   f1->setName(name1);
00187   f1->setTime(10.,8,9);
00188   double *tmp=f1->getArray()->getPointer();
00189   tmp[0]=VAL1;
00190   MEDLoader::WriteField(fileName,f1,true);
00191   f1->setTime(10.14,18,19);
00192   tmp[0]=VAL2;
00193   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00194   f1->setTime(10.55,28,29);
00195   tmp[0]=3*VAL1;
00196   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00197   f1->setTime(10.66,38,39);
00198   tmp[0]=3*VAL2;
00199   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00200   f1->setTime(10.77,48,49);
00201   tmp[0]=4*VAL2;
00202   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00203   //ON NODES
00204   f1->decrRef();
00205   f1=buildVecFieldOnNodes_1();
00206   f1->setName(name1);
00207   (const_cast<MEDCouplingMesh *>(f1->getMesh()))->setName(name3);
00208   f1->setTime(110.,8,9);
00209   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00210   f1->setTime(110.,108,109);
00211   tmp=f1->getArray()->getPointer();
00212   tmp[3]=VAL1;
00213   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00214   f1->setTime(210.,208,209);
00215   tmp[3]=VAL2;
00216   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00217   //
00218   std::vector< std::pair<int,int> > it1=MEDLoader::GetCellFieldIterations(fileName,name3,name1);
00219   CPPUNIT_ASSERT_EQUAL(5,(int)it1.size());
00220   CPPUNIT_ASSERT_EQUAL(8,it1[0].first); CPPUNIT_ASSERT_EQUAL(9,it1[0].second);
00221   CPPUNIT_ASSERT_EQUAL(18,it1[1].first); CPPUNIT_ASSERT_EQUAL(19,it1[1].second);
00222   CPPUNIT_ASSERT_EQUAL(28,it1[2].first); CPPUNIT_ASSERT_EQUAL(29,it1[2].second);
00223   CPPUNIT_ASSERT_EQUAL(38,it1[3].first); CPPUNIT_ASSERT_EQUAL(39,it1[3].second);
00224   CPPUNIT_ASSERT_EQUAL(48,it1[4].first); CPPUNIT_ASSERT_EQUAL(49,it1[4].second);
00225   std::vector< std::pair<int,int> > it3=MEDLoader::GetNodeFieldIterations(fileName,name3,name1);
00226   CPPUNIT_ASSERT_EQUAL(3,(int)it3.size());
00227   CPPUNIT_ASSERT_EQUAL(8,it3[0].first); CPPUNIT_ASSERT_EQUAL(9,it3[0].second);
00228   CPPUNIT_ASSERT_EQUAL(108,it3[1].first); CPPUNIT_ASSERT_EQUAL(109,it3[1].second);
00229   CPPUNIT_ASSERT_EQUAL(208,it3[2].first); CPPUNIT_ASSERT_EQUAL(209,it3[2].second);
00230   //
00231   f1->decrRef();
00232   //
00233   f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,8,9);
00234   CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL1,f1->getArray()->getConstPointer()[0],1e-13);
00235   f1->decrRef();
00236   f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,18,19);
00237   CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL2,f1->getArray()->getConstPointer()[0],1e-13);
00238   f1->decrRef();
00239   f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,28,29);
00240   CPPUNIT_ASSERT_DOUBLES_EQUAL(3*VAL1,f1->getArray()->getConstPointer()[0],1e-13);
00241   f1->decrRef();
00242   f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,38,39);
00243   CPPUNIT_ASSERT_DOUBLES_EQUAL(3*VAL2,f1->getArray()->getConstPointer()[0],1e-13);
00244   f1->decrRef();
00245   f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,48,49);
00246   CPPUNIT_ASSERT_DOUBLES_EQUAL(4*VAL2,f1->getArray()->getConstPointer()[0],1e-13);
00247   f1->decrRef();
00248   //
00249   f1=MEDLoader::ReadFieldNode(fileName,name3,0,name1,8,9);
00250   CPPUNIT_ASSERT_DOUBLES_EQUAL(71.,f1->getArray()->getConstPointer()[3],1e-13);
00251   f1->decrRef();
00252   f1=MEDLoader::ReadFieldNode(fileName,name3,0,name1,108,109);
00253   CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL1,f1->getArray()->getConstPointer()[3],1e-13);
00254   f1->decrRef();
00255   f1=MEDLoader::ReadFieldNode(fileName,name3,0,name1,208,209);
00256   CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL2,f1->getArray()->getConstPointer()[3],1e-13);
00257   f1->decrRef();
00258 }
00259 
00260 void MEDLoaderTest::testMultiMeshRW1()
00261 {
00262   const char fileName[]="file10.med";
00263   MEDCouplingUMesh *mesh1=build3DMesh_1();
00264   const int part1[5]={1,2,4,13,15};
00265   MEDCouplingUMesh *mesh2=(MEDCouplingUMesh *)mesh1->buildPartOfMySelf(part1,part1+5,true);
00266   mesh2->setName("mesh2");
00267   const int part2[4]={3,4,13,14};
00268   MEDCouplingUMesh *mesh3=(MEDCouplingUMesh *)mesh1->buildPartOfMySelf(part2,part2+4,true);
00269   mesh3->setName("mesh3");
00270   MEDCouplingUMesh *mesh4=MEDCouplingUMesh::New();
00271   mesh4->setName("mesh4");
00272   mesh4->setMeshDimension(3);
00273   mesh4->allocateCells(1);
00274   int conn[4]={0,11,1,3};
00275   mesh4->insertNextCell(INTERP_KERNEL::NORM_TETRA4,4,conn);
00276   mesh4->finishInsertingCells();
00277   mesh4->setCoords(mesh1->getCoords());
00278   std::vector<const MEDCouplingUMesh *> meshes;
00279   meshes.push_back(mesh1);
00280   meshes.push_back(mesh2);
00281   meshes.push_back(mesh3);
00282   meshes.push_back(mesh4);
00283   const char mnane[]="3DToto";
00284   MEDLoader::WriteUMeshesPartition(fileName,mnane,meshes,true);
00285   //
00286   MEDCouplingUMesh *mesh5=MEDLoader::ReadUMeshFromFile(fileName,mnane);
00287   mesh1->setName(mnane);
00288   const int part3[18]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17};
00289   MEDCouplingUMesh *mesh6=(MEDCouplingUMesh *)mesh5->buildPartOfMySelf(part3,part3+18,true);
00290   mesh6->setName(mnane);
00291   mesh5->decrRef();
00292   CPPUNIT_ASSERT(mesh6->isEqual(mesh1,1e-12));
00293   mesh6->decrRef();
00294   std::vector<std::string> grps=MEDLoader::GetMeshGroupsNames(fileName,mnane);
00295   CPPUNIT_ASSERT_EQUAL(4,(int)grps.size());
00296   CPPUNIT_ASSERT(std::find(grps.begin(),grps.end(),std::string("mesh2"))!=grps.end());
00297   CPPUNIT_ASSERT(std::find(grps.begin(),grps.end(),std::string("mesh3"))!=grps.end());
00298   CPPUNIT_ASSERT(std::find(grps.begin(),grps.end(),std::string("mesh4"))!=grps.end());
00299   CPPUNIT_ASSERT(std::find(grps.begin(),grps.end(),std::string("3DMesh_1"))!=grps.end());
00300   //
00301   std::vector<std::string> vec;
00302   vec.push_back(std::string("mesh2"));
00303   MEDCouplingUMesh *mesh2_2=MEDLoader::ReadUMeshFromGroups(fileName,mnane,0,vec);
00304   CPPUNIT_ASSERT(mesh2_2->isEqual(mesh2,1e-12));
00305   mesh2_2->decrRef();
00306   vec.clear(); vec.push_back(std::string("mesh3"));
00307   MEDCouplingUMesh *mesh3_2=MEDLoader::ReadUMeshFromGroups(fileName,mnane,0,vec);
00308   CPPUNIT_ASSERT(mesh3_2->isEqual(mesh3,1e-12));
00309   mesh3_2->decrRef();
00310   vec.clear(); vec.push_back(std::string("mesh4"));
00311   MEDCouplingUMesh *mesh4_2=MEDLoader::ReadUMeshFromGroups(fileName,mnane,0,vec);
00312   CPPUNIT_ASSERT(mesh4_2->isEqual(mesh4,1e-12));
00313   mesh4_2->decrRef();
00314   vec.clear(); vec.push_back(std::string("3DMesh_1"));
00315   MEDCouplingUMesh *mesh1_2=MEDLoader::ReadUMeshFromGroups(fileName,mnane,0,vec);
00316   mesh1->setName("3DMesh_1");
00317   CPPUNIT_ASSERT(mesh1_2->isEqual(mesh1,1e-12));
00318   mesh1_2->decrRef();
00319   //
00320   vec.clear(); vec.push_back(std::string("Family_4")); vec.push_back(std::string("Family_2"));
00321   mesh2_2=MEDLoader::ReadUMeshFromFamilies(fileName,mnane,0,vec);
00322   mesh2_2->setName("mesh2");
00323   CPPUNIT_ASSERT(mesh2_2->isEqual(mesh2,1e-12));
00324   mesh2_2->decrRef();
00325   //
00326   std::vector<std::string> ret=MEDLoader::GetMeshFamiliesNamesOnGroup(fileName,"3DToto","3DMesh_1");
00327   CPPUNIT_ASSERT_EQUAL(4,(int)ret.size());
00328   CPPUNIT_ASSERT(ret[0]=="Family_1");
00329   CPPUNIT_ASSERT(ret[1]=="Family_2");
00330   CPPUNIT_ASSERT(ret[2]=="Family_3");
00331   CPPUNIT_ASSERT(ret[3]=="Family_4");
00332   //
00333   std::vector<std::string> ret1=MEDLoader::GetMeshGroupsNamesOnFamily(fileName,"3DToto","Family_2");
00334   CPPUNIT_ASSERT_EQUAL(2,(int)ret1.size());
00335   CPPUNIT_ASSERT(ret1[0]=="3DMesh_1");
00336   CPPUNIT_ASSERT(ret1[1]=="mesh2");
00337   //
00338   mesh4->decrRef();
00339   mesh3->decrRef();
00340   mesh2->decrRef();
00341   mesh1->decrRef();
00342 }
00343 
00344 void MEDLoaderTest::testFieldProfilRW1()
00345 {
00346   const char fileName[]="file12.med";
00347   MEDCouplingUMesh *mesh1=build3DMesh_1();
00348   bool b;
00349   int newNbOfNodes;
00350   DataArrayInt *da=mesh1->mergeNodes(1e-12,b,newNbOfNodes);
00351   da->decrRef();
00352   MEDLoader::WriteUMesh(fileName,mesh1,true);
00353   const int part1[5]={1,2,4,13,15};
00354   MEDCouplingUMesh *mesh2=(MEDCouplingUMesh *)mesh1->buildPartOfMySelf(part1,part1+5,true);
00355   mesh2->setName(mesh1->getName());//<- important for the test
00356   //
00357   int nbOfCells=mesh2->getNumberOfCells();
00358   CPPUNIT_ASSERT_EQUAL(5,nbOfCells);
00359   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
00360   f1->setName("VectorFieldOnCells");
00361   f1->setMesh(mesh2);
00362   DataArrayDouble *array=DataArrayDouble::New();
00363   array->alloc(nbOfCells,2);
00364   f1->setArray(array);
00365   array->decrRef();
00366   double *tmp=array->getPointer();
00367   const double arr1[10]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.};
00368   std::copy(arr1,arr1+10,tmp);
00369   f1->setTime(3.14,2,7);
00370   f1->checkCoherency();
00371   //
00372   MEDLoader::WriteField(fileName,f1,false);//<- false important for the test
00373   //
00374   MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName(),0,f1->getName(),2,7);
00375   std::vector<ParaMEDMEM::TypeOfField> types=MEDLoader::GetTypesOfField(fileName,f1->getMesh()->getName(),f1->getName());
00376   CPPUNIT_ASSERT_EQUAL(1,(int)types.size());
00377   CPPUNIT_ASSERT(types[0]==ON_CELLS);
00378   f2->checkCoherency();
00379   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
00380   //
00381   f2->decrRef();
00382   f1->decrRef();
00383   mesh1->decrRef();
00384   mesh2->decrRef();
00385 }
00386 
00390 void MEDLoaderTest::testFieldNodeProfilRW1()
00391 {
00392   const char fileName[]="file19.med";
00393   const char fileName2[]="file20.med";
00394   MEDCouplingUMesh *m=build2DMesh_1();
00395   int nbOfNodes=m->getNumberOfNodes();
00396   MEDLoader::WriteUMesh(fileName,m,true);
00397   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
00398   f1->setName("VFieldOnNodes");
00399   f1->setMesh(m);
00400   DataArrayDouble *array=DataArrayDouble::New();
00401   const double arr1[24]={1.,101.,2.,102.,3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.};
00402   array->alloc(nbOfNodes,2);
00403   std::copy(arr1,arr1+24,array->getPointer());
00404   f1->setArray(array);
00405   array->setInfoOnComponent(0,"tyty [mm]");
00406   array->setInfoOnComponent(1,"uiop [MW]");
00407   array->decrRef();
00408   f1->setTime(3.14,2,7);
00409   f1->checkCoherency();
00410   const int arr2[2]={1,4};//node ids are 2,4,5,3,6,7
00411   MEDCouplingFieldDouble *f2=f1->buildSubPart(arr2,arr2+2);
00412   (const_cast<MEDCouplingMesh *>(f2->getMesh()))->setName(f1->getMesh()->getName());
00413   MEDLoader::WriteField(fileName,f2,false);//<- false important for the test
00414   //
00415   MEDCouplingFieldDouble *f3=MEDLoader::ReadFieldNode(fileName,f2->getMesh()->getName(),0,f2->getName(),2,7);
00416   f3->checkCoherency();
00417   CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
00418   f3->decrRef();
00419   //
00420   const int arr3[6]={1,3,0,5,2,4};
00421   f2->renumberNodes(arr3);
00422   MEDLoader::WriteUMesh(fileName2,m,true);
00423   MEDLoader::WriteField(fileName2,f2,false);//<- false important for the test
00424   f3=MEDLoader::ReadFieldNode(fileName2,f2->getMesh()->getName(),0,f2->getName(),2,7);
00425   f3->checkCoherency();
00426   CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
00427   f3->decrRef();
00428   f2->decrRef();
00429   //
00430   f1->decrRef();
00431   m->decrRef();
00432 }
00433 
00434 void MEDLoaderTest::testFieldNodeProfilRW2()
00435 {
00436   const char fileName[]="file23.med";
00437   MEDCouplingUMesh *mesh=build3DSurfMesh_1();
00438   MEDLoader::WriteUMesh(fileName,mesh,true);
00439   //
00440   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
00441   f1->setName("FieldMix");
00442   f1->setMesh(mesh);
00443   const double arr2[24]={
00444     1071.,1171.,1010.,1110.,1020.,1120.,1030.,1130.,1040.,1140.,1050.,1150.,
00445     1060.,1160.,1070.,1170.,1080.,1180.,1090.,1190.,1091.,1191.,1092.,1192.
00446   };
00447   DataArrayDouble *array=DataArrayDouble::New();
00448   array->alloc(12,2);
00449   f1->setArray(array);
00450   array->setInfoOnComponent(0,"plkj [mm]");
00451   array->setInfoOnComponent(1,"pqqqss [mm]");
00452   array->decrRef();
00453   double *tmp=array->getPointer();
00454   std::copy(arr2,arr2+24,tmp);
00455   f1->setTime(3.17,2,7);
00456   //
00457   const int renumArr[12]={3,7,2,1,5,11,10,0,9,6,8,4};
00458   f1->renumberNodes(renumArr);
00459   f1->checkCoherency();
00460   MEDLoader::WriteField(fileName,f1,false);//<- false important for the test
00461   MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldNode(fileName,f1->getMesh()->getName(),0,f1->getName(),2,7);
00462   CPPUNIT_ASSERT(f2->isEqual(f1,1e-12,1e-12));
00463   //
00464   f2->decrRef();
00465   mesh->decrRef();
00466   f1->decrRef();
00467 }
00468 
00469 void MEDLoaderTest::testFieldGaussRW1()
00470 {
00471   const char fileName[]="file13.med";
00472   MEDCouplingFieldDouble *f1=buildVecFieldOnGauss_1();
00473   MEDLoader::WriteField(fileName,f1,true);
00474   MEDCouplingFieldDouble *f2=MEDLoader::ReadField(ON_GAUSS_PT,fileName,f1->getMesh()->getName(),0,f1->getName(),1,5);
00475   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
00476   f2->decrRef();
00477   f1->decrRef();
00478 }
00479 
00480 void MEDLoaderTest::testFieldGaussNERW1()
00481 {
00482   const char fileName[]="file14.med";
00483   MEDCouplingFieldDouble *f1=buildVecFieldOnGaussNE_1();
00484   MEDLoader::WriteField(fileName,f1,true);
00485   MEDCouplingFieldDouble *f2=MEDLoader::ReadField(ON_GAUSS_NE,fileName,f1->getMesh()->getName(),0,f1->getName(),1,5);
00486   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
00487   f2->decrRef();
00488   f1->decrRef();
00489 }
00490 
00491 void MEDLoaderTest::testLittleStrings1()
00492 {
00493   std::string s("azeeeerrrtty");
00494   MEDLoaderBase::zipEqualConsChar(s,3);
00495   CPPUNIT_ASSERT(s=="azertty");
00496 }
00497 
00498 void MEDLoaderTest::testSplitIntoNameAndUnit1()
00499 {
00500   std::string s(" []");
00501   std::string c,u;
00502   MEDLoaderBase::splitIntoNameAndUnit(s,c,u);
00503   CPPUNIT_ASSERT(c.empty());
00504   CPPUNIT_ASSERT(u.empty());
00505   s="   lmmm  kki jjj      ";
00506   MEDLoaderBase::strip(s);
00507   CPPUNIT_ASSERT(s=="lmmm  kki jjj");
00508   s=" ";
00509   MEDLoaderBase::strip(s);
00510   CPPUNIT_ASSERT(s.empty());
00511   s="";
00512   MEDLoaderBase::strip(s);
00513   CPPUNIT_ASSERT(s.empty());
00514   s="      ";
00515   MEDLoaderBase::strip(s);
00516   CPPUNIT_ASSERT(s.empty());
00517   s="     pp";
00518   MEDLoaderBase::strip(s);
00519   CPPUNIT_ASSERT(s=="pp");
00520 }
00521 
00522 void MEDLoaderTest::testMesh3DSurfShuffleRW()
00523 {
00524   const char fileName[]="file15.med";
00525   MEDCouplingUMesh *mesh=build3DSurfMesh_1();
00526   const int renumber1[6]={2,5,1,0,3,4};
00527   mesh->renumberCells(renumber1,false);
00528   mesh->checkCoherency();
00529   MEDLoader::WriteUMesh(fileName,mesh,true);
00530   MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile(fileName,mesh->getName(),0);
00531   CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
00532   mesh_rw->decrRef();
00533   mesh->decrRef();
00534 }
00535 
00536 void MEDLoaderTest::testFieldShuffleRW1()
00537 {
00538   const char fileName[]="file16.med";
00539   MEDCouplingUMesh *mesh=build3DSurfMesh_1();
00540   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
00541   f1->setName("FieldOnCellsShuffle");
00542   f1->setMesh(mesh);
00543   DataArrayDouble *array=DataArrayDouble::New();
00544   array->alloc(6,2);
00545   f1->setArray(array);
00546   array->decrRef();
00547   double *tmp=array->getPointer();
00548   const double arr1[12]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.};
00549   std::copy(arr1,arr1+12,tmp);
00550   f1->setTime(3.14,2,7);
00551   f1->checkCoherency();
00552   //
00553   const int renumber1[6]={2,1,5,0,3,4};
00554   f1->renumberCells(renumber1,false);
00555   MEDLoader::WriteField(fileName,f1,true);
00556   MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldCell(fileName,mesh->getName(),0,f1->getName(),2,7);
00557   CPPUNIT_ASSERT(f2->isEqual(f1,1e-12,1e-12));
00558   f2->decrRef();
00559   //
00560   mesh->decrRef();
00561   f1->decrRef();
00562 }
00563 
00567 void MEDLoaderTest::testMultiFieldShuffleRW1()
00568 {
00569   const char fileName[]="file17.med";
00570   MEDCouplingUMesh *m=build3DMesh_2();
00571   CPPUNIT_ASSERT_EQUAL(20,m->getNumberOfCells());
00572   CPPUNIT_ASSERT_EQUAL(45,m->getNumberOfNodes());
00573   const int polys[3]={1,4,6};
00574   std::vector<int> poly2(polys,polys+3);
00575   m->convertToPolyTypes(&poly2[0],&poly2[0]+poly2.size());
00576   const int renum[20]={1,3,2,8,9,12,13,16,19,0,4,7,5,15,14,17,10,18,6,11};
00577   m->renumberCells(renum,false);
00578   m->orientCorrectlyPolyhedrons();
00579   // Writing
00580   MEDLoader::WriteUMesh(fileName,m,true);
00581   MEDCouplingFieldDouble *f1Tmp=m->getMeasureField(false);
00582   MEDCouplingFieldDouble *f1=f1Tmp->buildNewTimeReprFromThis(ONE_TIME,false);
00583   f1Tmp->decrRef();
00584   f1->setTime(0.,1,2);
00585   MEDCouplingFieldDouble *f_1=f1->cloneWithMesh(true);
00586   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00587   f1->applyFunc("2*x");
00588   f1->setTime(0.01,3,4);
00589   MEDCouplingFieldDouble *f_2=f1->cloneWithMesh(true);
00590   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00591   f1->applyFunc("2*x/3");
00592   f1->setTime(0.02,5,6);
00593   MEDCouplingFieldDouble *f_3=f1->cloneWithMesh(true);
00594   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00595   f1->decrRef();
00596   // Reading
00597   std::vector<std::pair<int,int> > its;
00598   its.push_back(std::pair<int,int>(1,2));
00599   its.push_back(std::pair<int,int>(3,4));
00600   its.push_back(std::pair<int,int>(5,6));
00601   std::vector<MEDCouplingFieldDouble *> fs=MEDLoader::ReadFieldsOnSameMesh(ON_CELLS,fileName,f_1->getMesh()->getName(),0,f_1->getName(),its);
00602   CPPUNIT_ASSERT_EQUAL(3,(int)fs.size());
00603   const MEDCouplingMesh *mm=fs[0]->getMesh();
00604   CPPUNIT_ASSERT(fs[0]->isEqual(f_1,1e-12,1e-12));
00605   CPPUNIT_ASSERT(fs[1]->isEqual(f_2,1e-12,1e-12));
00606   CPPUNIT_ASSERT(fs[2]->isEqual(f_3,1e-12,1e-12));
00607   CPPUNIT_ASSERT(mm==fs[1]->getMesh());// <- important for the test
00608   CPPUNIT_ASSERT(mm==fs[2]->getMesh());// <- important for the test
00609   for(std::vector<MEDCouplingFieldDouble *>::iterator iter=fs.begin();iter!=fs.end();iter++)
00610     (*iter)->decrRef();
00611   //
00612   f_1->decrRef();
00613   f_2->decrRef();
00614   f_3->decrRef();
00615   //
00616   m->decrRef();
00617 }
00618 
00619 void MEDLoaderTest::testWriteUMeshesRW1()
00620 {
00621   const char fileName[]="file18.med";
00622   MEDCouplingUMesh *m3d=build3DMesh_2();
00623   const double pt[3]={0.,0.,-0.3};
00624   const double vec[3]={0.,0.,1.};
00625   std::vector<int> nodes;
00626   m3d->findNodesOnPlane(pt,vec,1e-12,nodes);
00627   MEDCouplingUMesh *m2d=(MEDCouplingUMesh *)m3d->buildFacePartOfMySelfNode(&nodes[0],&nodes[0]+nodes.size(),true);
00628   const int renumber[5]={1,2,0,4,3};
00629   m2d->renumberCells(renumber,false);
00630   m2d->setName("ExampleOfMultiDimW");
00631   std::vector<const MEDCouplingUMesh *> meshes;
00632   meshes.push_back(m2d);
00633   meshes.push_back(m3d);
00634   MEDLoader::WriteUMeshes(fileName,meshes,true);
00635   MEDCouplingUMesh *m3d_bis=MEDLoader::ReadUMeshFromFile(fileName,m2d->getName(),0);
00636   CPPUNIT_ASSERT(!m3d_bis->isEqual(m3d,1e-12));
00637   m3d_bis->setName(m3d->getName());
00638   CPPUNIT_ASSERT(m3d_bis->isEqual(m3d,1e-12));
00639   MEDCouplingUMesh *m2d_bis=MEDLoader::ReadUMeshFromFile(fileName,m2d->getName(),-1);//-1 for faces
00640   CPPUNIT_ASSERT(m2d_bis->isEqual(m2d,1e-12));
00641   // Creation of a field on faces.
00642   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
00643   f1->setName("FieldOnFacesShuffle");
00644   f1->setMesh(m2d);
00645   DataArrayDouble *array=DataArrayDouble::New();
00646   array->alloc(m2d->getNumberOfCells(),2);
00647   array->setInfoOnComponent(0,"plkj [mm]");
00648   array->setInfoOnComponent(1,"pqqqss [mm]");
00649   f1->setArray(array);
00650   array->decrRef();
00651   double *tmp=array->getPointer();
00652   const double arr1[10]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.};
00653   std::copy(arr1,arr1+10,tmp);
00654   f1->setTime(3.14,2,7);
00655   f1->checkCoherency();
00656   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00657   MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName(),-1,f1->getName(),2,7);
00658   CPPUNIT_ASSERT(f2->isEqual(f1,1e-12,1e-12));
00659   f1->decrRef();
00660   f2->decrRef();
00661   //
00662   m2d_bis->decrRef();
00663   m3d_bis->decrRef();
00664   m2d->decrRef();
00665   m3d->decrRef();
00666 }
00667 
00668 void MEDLoaderTest::testMixCellAndNodesFieldRW1()
00669 {
00670   const char fileName[]="file21.med";
00671   MEDCouplingUMesh *mesh=build3DSurfMesh_1();
00672   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
00673   f1->setName("FieldMix");
00674   f1->setMesh(mesh);
00675   DataArrayDouble *array=DataArrayDouble::New();
00676   array->alloc(6,2);
00677   f1->setArray(array);
00678   array->setInfoOnComponent(0,"plkj [mm]");
00679   array->setInfoOnComponent(1,"pqqqss [mm]");
00680   array->decrRef();
00681   double *tmp=array->getPointer();
00682   const double arr1[12]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.};
00683   std::copy(arr1,arr1+12,tmp);
00684   f1->setTime(3.14,2,7);
00685   f1->checkCoherency();
00686   //
00687   MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
00688   f2->setName("FieldMix");
00689   f2->setMesh(mesh);
00690   array=DataArrayDouble::New();
00691   array->alloc(12,2);
00692   f2->setArray(array);
00693   array->setInfoOnComponent(0,"plkj [mm]");
00694   array->setInfoOnComponent(1,"pqqqss [mm]");
00695   array->decrRef();
00696   tmp=array->getPointer();
00697   const double arr2[24]={
00698     1071.,1171.,1010.,1110.,1020.,1120.,1030.,1130.,1040.,1140.,1050.,1150.,
00699     1060.,1160.,1070.,1170.,1080.,1180.,1090.,1190.,1091.,1191.,1092.,1192.
00700   };
00701   std::copy(arr2,arr2+24,tmp);
00702   f2->setTime(3.14,2,7);
00703   f2->checkCoherency();
00704   //
00705   MEDLoader::WriteField(fileName,f1,true);
00706   std::vector<ParaMEDMEM::TypeOfField> ts=MEDLoader::GetTypesOfField(fileName,f1->getMesh()->getName(),f1->getName());
00707   CPPUNIT_ASSERT_EQUAL(1,(int)ts.size());
00708   CPPUNIT_ASSERT_EQUAL(ON_CELLS,ts[0]);
00709   std::vector<std::string> fs=MEDLoader::GetAllFieldNamesOnMesh(fileName,f1->getMesh()->getName());
00710   CPPUNIT_ASSERT_EQUAL(1,(int)fs.size());
00711   CPPUNIT_ASSERT(fs[0]=="FieldMix");
00712   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f2);
00713   fs=MEDLoader::GetAllFieldNamesOnMesh(fileName,f1->getMesh()->getName());
00714   CPPUNIT_ASSERT_EQUAL(1,(int)fs.size());
00715   CPPUNIT_ASSERT(fs[0]=="FieldMix");
00716   //
00717   ts=MEDLoader::GetTypesOfField(fileName,f1->getMesh()->getName(),f1->getName());
00718   CPPUNIT_ASSERT_EQUAL(2,(int)ts.size());
00719   CPPUNIT_ASSERT_EQUAL(ON_NODES,ts[0]);
00720   CPPUNIT_ASSERT_EQUAL(ON_CELLS,ts[1]);
00721   //
00722   MEDCouplingFieldDouble *f3=MEDLoader::ReadFieldNode(fileName,f1->getMesh()->getName(),0,f1->getName(),2,7);
00723   CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
00724   f3->decrRef();
00725   f3=MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName(),0,f1->getName(),2,7);
00726   CPPUNIT_ASSERT(f3->isEqual(f1,1e-12,1e-12));
00727   f3->decrRef();
00728   //
00729   f1->decrRef();
00730   f2->decrRef();
00731   mesh->decrRef();
00732 }
00733 
00734 void MEDLoaderTest::testGetAllFieldNamesRW1()
00735 {
00736   const char fileName[]="file22.med";
00737   MEDCouplingUMesh *mesh=build2DMesh_2();
00738   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
00739   f1->setName("Field1");
00740   f1->setTime(3.44,5,6);
00741   f1->setMesh(mesh);
00742   f1->fillFromAnalytic(2,"x+y");
00743   MEDLoader::WriteField(fileName,f1,true);
00744   f1->setTime(1002.3,7,8);
00745   f1->fillFromAnalytic(2,"x+77.*y");
00746   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00747   f1->setName("Field2");
00748   MEDLoader::WriteField(fileName,f1,false);
00749   f1->setName("Field3");
00750   mesh->setName("2DMesh_2Bis");
00751   MEDLoader::WriteField(fileName,f1,false);
00752   f1->decrRef();
00753   f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
00754   f1->setName("Field8");
00755   f1->setTime(8.99,7,9);
00756   f1->setMesh(mesh);
00757   f1->fillFromAnalytic(3,"3*x+y");
00758   MEDLoader::WriteField(fileName,f1,false);
00759   f1->decrRef();
00760   std::vector<std::string> fs=MEDLoader::GetAllFieldNames(fileName);
00761   CPPUNIT_ASSERT_EQUAL(4,(int)fs.size());
00762   CPPUNIT_ASSERT(fs[0]=="Field1");
00763   CPPUNIT_ASSERT(fs[1]=="Field2");
00764   CPPUNIT_ASSERT(fs[2]=="Field3");
00765   CPPUNIT_ASSERT(fs[3]=="Field8");
00766   mesh->decrRef();
00767 }
00768 
00769 MEDCouplingUMesh *MEDLoaderTest::build1DMesh_1()
00770 {
00771   double coords[6]={ 0.0, 0.3, 0.75, 1.0, 1.4, 1.3 };
00772   int conn[9]={ 0,1, 1,2, 2,3 , 3,4,5};
00773   MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
00774   mesh->setName("1DMesh_1");
00775   mesh->setMeshDimension(1);
00776   mesh->allocateCells(4);
00777   mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn);
00778   mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+2);
00779   mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+4);
00780   mesh->insertNextCell(INTERP_KERNEL::NORM_SEG3,3,conn+6);
00781   mesh->finishInsertingCells();
00782   DataArrayDouble *myCoords=DataArrayDouble::New();
00783   myCoords->alloc(6,1);
00784   myCoords->setInfoOnComponent(0,"tototototototot [m*m*m*m*m*m*m*m]");
00785   std::copy(coords,coords+6,myCoords->getPointer());
00786   mesh->setCoords(myCoords);
00787   myCoords->decrRef();
00788   return mesh;
00789 }
00790 
00791 MEDCouplingUMesh *MEDLoaderTest::build2DCurveMesh_1()
00792 {
00793   double coords[12]={ 0.0,0.0, 0.3,0.3, 0.75,0.75, 1.0,1.0, 1.4,1.4, 1.3,1.3 };
00794   int conn[9]={ 0,1, 1,2, 2,3 , 3,4,5};
00795   MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
00796   mesh->setName("2DCurveMesh_1");
00797   mesh->setMeshDimension(1);
00798   mesh->allocateCells(4);
00799   mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn);
00800   mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+2);
00801   mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+4);
00802   mesh->insertNextCell(INTERP_KERNEL::NORM_SEG3,3,conn+6);
00803   mesh->finishInsertingCells();
00804   DataArrayDouble *myCoords=DataArrayDouble::New();
00805   myCoords->alloc(6,2);
00806   std::copy(coords,coords+12,myCoords->getPointer());
00807   mesh->setCoords(myCoords);
00808   myCoords->decrRef();
00809   return mesh;
00810 }
00811 
00812 MEDCouplingUMesh *MEDLoaderTest::build2DMesh_1()
00813 {
00814   double targetCoords[24]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7, -0.05,0.95, 0.2,1.2, 0.45,0.95 };
00815   int targetConn[24]={1,4,2, 4,5,2, 6,10,8,9,11,7, 0,3,4,1, 6,7,4,3, 7,8,5,4};
00816   MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
00817   targetMesh->setMeshDimension(2);
00818   targetMesh->allocateCells(6);
00819   targetMesh->setName("2DMesh_1");
00820   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn);
00821   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+3);
00822   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,targetConn+6);
00823   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+12);
00824   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+16);
00825   targetMesh->insertNextCell(INTERP_KERNEL::NORM_POLYGON,4,targetConn+20);
00826   targetMesh->finishInsertingCells();
00827   DataArrayDouble *myCoords=DataArrayDouble::New();
00828   myCoords->alloc(12,2);
00829   myCoords->setInfoOnComponent(0,"tototototototot [m]");
00830   myCoords->setInfoOnComponent(1,"energie [kW]");
00831   std::copy(targetCoords,targetCoords+24,myCoords->getPointer());
00832   targetMesh->setCoords(myCoords);
00833   myCoords->decrRef();
00834   return targetMesh;
00835 }
00836 
00837 MEDCouplingUMesh *MEDLoaderTest::build2DMesh_2()
00838 {
00839   double targetCoords[24]={
00840     -0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7,
00841     -0.05,0.95, 0.2,1.2, 0.45,0.95
00842   };
00843   int targetConn[24]={1,4,2, 4,5,2, 6,10,8,9,11,7, 0,3,4,1, 6,7,4,3, 7,8,5,4};
00844   MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
00845   targetMesh->setMeshDimension(2);
00846   targetMesh->allocateCells(5);
00847   targetMesh->setName("2DMesh_2");
00848   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn);
00849   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+3);
00850   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+12);
00851   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+16);
00852   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,targetConn+6);
00853   targetMesh->finishInsertingCells();
00854   DataArrayDouble *myCoords=DataArrayDouble::New();
00855   myCoords->alloc(12,2);
00856   myCoords->setInfoOnComponent(0,"toto [m]");
00857   myCoords->setInfoOnComponent(1,"energie [kW]");
00858   std::copy(targetCoords,targetCoords+24,myCoords->getPointer());
00859   targetMesh->setCoords(myCoords);
00860   myCoords->decrRef();
00861   return targetMesh;
00862 }
00863 
00864 MEDCouplingUMesh *MEDLoaderTest::build3DSurfMesh_1()
00865 {
00866   double targetCoords[36]={
00867     -0.3,-0.3,-0.3, 0.2,-0.3,-0.3, 0.7,-0.3,-0.3, -0.3,0.2,-0.3, 0.2,0.2,-0.3, 0.7,0.2,-0.3, -0.3,0.7,-0.3, 0.2,0.7,-0.3, 0.7,0.7,-0.3
00868     ,-0.05,0.95,-0.3, 0.2,1.2,-0.3, 0.45,0.95,-0.3
00869   };
00870   int targetConn[24]={1,4,2, 4,5,2, 6,10,8,9,11,7, 0,3,4,1, 6,7,4,3, 7,8,5,4};
00871   MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
00872   targetMesh->setMeshDimension(2);
00873   targetMesh->allocateCells(6);
00874   targetMesh->setName("3DSurfMesh_1");
00875   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn);
00876   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+3);
00877   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+12);
00878   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+16);
00879   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,targetConn+6);
00880   targetMesh->insertNextCell(INTERP_KERNEL::NORM_POLYGON,4,targetConn+20);
00881   targetMesh->finishInsertingCells();
00882   DataArrayDouble *myCoords=DataArrayDouble::New();
00883   myCoords->alloc(12,3);
00884   myCoords->setInfoOnComponent(0,"toto [m]");
00885   myCoords->setInfoOnComponent(2,"ff [km]");//component 1 is not set for test
00886   std::copy(targetCoords,targetCoords+36,myCoords->getPointer());
00887   targetMesh->setCoords(myCoords);
00888   myCoords->decrRef();
00889   return targetMesh;
00890 }
00891 
00892 MEDCouplingUMesh *MEDLoaderTest::build3DMesh_1()
00893 {
00894   double coords[180]={
00895     0.,0.,0., 1.,1.,0., 1.,1.25,0., 0.,1.,0., 1.,1.5,0., 2.,0.,0., 2.,1.,0., 1.,2.,0., 0.,2.,0., 3.,1.,0.,
00896     3.,2.,0., 0.,1.,0., 1.,3.,0., 2.,2.,0., 2.,3.,0.,
00897     0.,0.,1., 1.,1.,1., 1.,1.25,1., 0.,1.,1., 1.,1.5,1., 2.,0.,1., 2.,1.,1., 1.,2.,1., 0.,2.,1., 3.,1.,1.,
00898     3.,2.,1., 0.,1.,1., 1.,3.,1., 2.,2.,1., 2.,3.,1.,
00899     0.,0.,2., 1.,1.,2., 1.,1.25,2., 0.,1.,2., 1.,1.5,2., 2.,0.,2., 2.,1.,2., 1.,2.,2., 0.,2.,2., 3.,1.,2.,
00900     3.,2.,2., 0.,1.,2., 1.,3.,2., 2.,2.,2., 2.,3.,2.,
00901     0.,0.,3., 1.,1.,3., 1.,1.25,3., 0.,1.,3., 1.,1.5,3., 2.,0.,3., 2.,1.,3., 1.,2.,3., 0.,2.,3., 3.,1.,3.,
00902     3.,2.,3., 0.,1.,3., 1.,3.,3., 2.,2.,3., 2.,3.,3.};
00903 
00904   int conn[354]={
00905     // 0
00906     0,11,1,3,15,26,16,18,   1,2,4,7,13,6,-1,1,16,21,6,-1,6,21,28,13,-1,13,7,22,28,-1,7,4,19,22,-1,4,2,17,19,-1,2,1,16,17,-1,16,21,28,22,19,17,
00907     1,6,5,3,16,21,20,18,   13,10,9,6,28,25,24,21,
00908     11,8,7,4,2,1,-1,11,26,16,1,-1,1,16,17,2,-1,2,17,19,4,-1,4,19,22,7,-1,7,8,23,22,-1,8,11,26,23,-1,26,16,17,19,22,23,
00909     7,12,14,13,22,27,29,28,
00910     // 1
00911     15,26,16,18,30,41,31,33,   16,17,19,22,28,21,-1,16,31,36,21,-1,21,36,43,28,-1,28,22,37,43,-1,22,19,34,37,-1,19,17,32,34,-1,17,16,31,32,-1,31,36,43,37,34,32,
00912     16,21,20,18,31,36,35,33,   28,25,24,21,43,40,39,36,
00913     26,23,22,19,17,16,-1,26,41,31,16,-1,16,31,32,17,-1,17,32,34,19,-1,19,34,37,22,-1,22,23,38,37,-1,23,26,41,38,-1,41,31,32,34,37,38,
00914     22,27,29,28,37,42,44,43,
00915     // 2
00916     30,41,31,33,45,56,46,48,  31,32,34,37,43,36,-1,31,46,51,36,-1,36,51,58,43,-1,43,37,52,58,-1,37,34,49,52,-1,34,32,47,49,-1,32,31,46,47,-1,46,51,58,52,49,47,
00917     31,36,35,33,46,51,50,48,  43,40,39,36,58,55,54,51,
00918     41,38,37,34,32,31,-1,41,56,46,31,-1,31,46,47,32,-1,32,47,49,34,-1,34,49,52,37,-1,37,38,53,52,-1,38,41,56,53,-1,56,46,47,49,52,53,
00919     37,42,44,43,52,57,59,58
00920   };
00921   //
00922   MEDCouplingUMesh *ret=MEDCouplingUMesh::New();
00923   ret->setName("3DMesh_1");
00924   ret->setMeshDimension(3);
00925   ret->allocateCells(18);
00926   //
00927   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn);
00928   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+51);
00929   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+59);
00930   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+110);
00931   //
00932   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+118);
00933   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+169);
00934   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+177);
00935   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+228);
00936   //
00937   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+236);
00938   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+287);
00939   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+295);
00940   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+346);
00941   //
00942   ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+8);
00943   ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+67);
00944   ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+126);
00945   ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+185);
00946   ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+244);
00947   ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+303);
00948   //
00949   ret->finishInsertingCells();
00950   DataArrayDouble *myCoords=DataArrayDouble::New();
00951   myCoords->alloc(60,3);
00952   myCoords->setInfoOnComponent(0,"titi [m]");
00953   myCoords->setInfoOnComponent(1,"density power [MW/m^3]");
00954   myCoords->setInfoOnComponent(2,"t [kW]");
00955   std::copy(coords,coords+180,myCoords->getPointer());
00956   ret->setCoords(myCoords);
00957   myCoords->decrRef();
00958   return ret;
00959 }
00960 
00961 MEDCouplingUMesh *MEDLoaderTest::build3DMesh_2()
00962 {
00963   MEDCouplingUMesh *m3dsurfBase=build3DSurfMesh_1();
00964   int numbers[5]={0,1,2,3,5};
00965   MEDCouplingUMesh *m3dsurf=(MEDCouplingUMesh *)m3dsurfBase->buildPartOfMySelf(numbers,numbers+5,false);
00966   m3dsurfBase->decrRef();
00967   MEDCouplingUMesh *m1dBase=build1DMesh_1();
00968   int numbers2[4]={0,1,2,3};
00969   MEDCouplingUMesh *m1d=(MEDCouplingUMesh *)m1dBase->buildPartOfMySelf(numbers2,numbers2+4,false);
00970   m1dBase->decrRef();
00971   m1d->changeSpaceDimension(3);
00972   const double vec[3]={0.,1.,0.};
00973   const double pt[3]={0.,0.,0.};
00974   m1d->rotate(pt,vec,-M_PI/2.);
00975   MEDCouplingUMesh *ret=m3dsurf->buildExtrudedMesh(m1d,0);
00976   m1d->decrRef();
00977   m3dsurf->decrRef();
00978   return ret;
00979 }
00980 
00981 MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnCells_1()
00982 {
00983   MEDCouplingUMesh *mesh=build3DSurfMesh_1();
00984   int nbOfCells=mesh->getNumberOfCells();
00985   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
00986   f1->setName("VectorFieldOnCells");
00987   f1->setMesh(mesh);
00988   DataArrayDouble *array=DataArrayDouble::New();
00989   array->alloc(nbOfCells,3);
00990   array->setInfoOnComponent(0,"power [MW/m^3]");
00991   array->setInfoOnComponent(1,"density [g/cm^3]");
00992   array->setInfoOnComponent(2,"temperature [K]");
00993   f1->setArray(array);
00994   array->decrRef();
00995   double *tmp=array->getPointer();
00996   const double arr1[18]={0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.,5.,15.,25.};
00997   std::copy(arr1,arr1+18,tmp);
00998   f1->setTime(2.,0,1);
00999   f1->checkCoherency();
01000   mesh->decrRef();
01001   return f1;
01002 }
01003 
01004 MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnNodes_1()
01005 {
01006   MEDCouplingUMesh *mesh=build3DSurfMesh_1();
01007   int nbOfNodes=mesh->getNumberOfNodes();
01008   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
01009   f1->setName("VectorFieldOnNodes");
01010   f1->setMesh(mesh);
01011   DataArrayDouble *array=DataArrayDouble::New();
01012   array->alloc(nbOfNodes,3);
01013   f1->setArray(array);
01014   array->setInfoOnComponent(0,"power [MW/m^3]");
01015   array->setInfoOnComponent(1,"density [g/cm^3]");
01016   array->setInfoOnComponent(2,"temperature [K]");
01017   array->decrRef();
01018   double *tmp=array->getPointer();
01019   const double arr1[36]={
01020     70.,80.,90.,71.,81.,91.,72.,82.,92.,73.,83.,93.,74.,84.,94.,75.,85.,95.,
01021     1000.,10010.,10020.,1001.,10011.,10021.,1002.,10012.,10022.,1003.,10013.,10023.,1004.,10014.,10024.,1005.,10015.,10025.,
01022   };
01023   std::copy(arr1,arr1+36,tmp);
01024   f1->setTime(2.12,2,3);
01025   f1->checkCoherency();
01026   mesh->decrRef();
01027   return f1;
01028 }
01029 
01030 MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnGauss_1()
01031 {
01032   const double _a=0.446948490915965;
01033   const double _b=0.091576213509771;
01034   const double _p1=0.11169079483905;
01035   const double _p2=0.0549758718227661;
01036   const double refCoo1[6]={ 0.,0., 1.,0., 0.,1. };
01037   const double gsCoo1[12]={ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b,
01038                             2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 };
01039   const double wg1[6]={ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 };
01040   std::vector<double> _refCoo1(refCoo1,refCoo1+6);
01041   std::vector<double> _gsCoo1(gsCoo1,gsCoo1+12);
01042   std::vector<double> _wg1(wg1,wg1+6);
01043   MEDCouplingUMesh *m=build2DMesh_2();
01044   MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_GAUSS_PT,ONE_TIME);
01045   f->setTime(3.14,1,5);
01046   f->setMesh(m);
01047   f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI3,_refCoo1,_gsCoo1,_wg1);
01048   const double refCoo2[12]={-1.0,1.0, -1.0,-1.0, 1.0,-1.0, -1.0,0.0, 0.0,-1.0, 0.0,0.0 };
01049   std::vector<double> _refCoo2(refCoo2,refCoo2+12);
01050   std::vector<double> _gsCoo2(_gsCoo1);
01051   std::vector<double> _wg2(_wg1);
01052   _gsCoo2.resize(6); _wg2.resize(3);
01053   const double refCoo3[8]={ 0.,0., 1.,0., 1.,1., 0.,1. };
01054   std::vector<double> _refCoo3(refCoo3,refCoo3+8);
01055   _gsCoo1.resize(4); _wg1.resize(2);
01056   f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_QUAD4,_refCoo3,_gsCoo1,_wg1);
01057   f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI6,_refCoo2,_gsCoo2,_wg2);
01058   DataArrayDouble *array=DataArrayDouble::New();
01059   array->alloc(19,2);
01060   double *ptr=array->getPointer();
01061   for(int i=0;i<19*2;i++)
01062     ptr[i]=(double)(i+7);
01063   f->setArray(array);
01064   f->setName("MyFirstFieldOnGaussPoint");
01065   array->setInfoOnComponent(0,"power [MW/m^3]");
01066   array->setInfoOnComponent(1,"density");
01067   array->decrRef();
01068   f->checkCoherency();
01069   m->decrRef();
01070   return f;
01071 }
01072 
01073 MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnGaussNE_1()
01074 {
01075   MEDCouplingUMesh *m=build2DMesh_2();
01076   MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_GAUSS_NE,ONE_TIME);
01077   f->setTime(3.14,1,5);
01078   f->setMesh(m);
01079   DataArrayDouble *array=DataArrayDouble::New();
01080   array->alloc(20,2);
01081   double *ptr=array->getPointer();
01082   for(int i=0;i<20*2;i++)
01083     ptr[i]=(double)(i+8);
01084   f->setArray(array);
01085   array->setInfoOnComponent(0,"power [W]");
01086   array->setInfoOnComponent(1,"temperature");
01087   f->setName("MyFieldOnGaussNE");
01088   array->decrRef();
01089   f->checkCoherency();
01090   m->decrRef();
01091   return f;
01092 }
01093