Back to index

salome-med  6.5.0
MEDSPLITTERTest_MESHCollection.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 "MEDSPLITTERTest.hxx"
00021 #include "MEDSPLITTERTest_Utils.hxx"
00022 
00023 #include "MEDMEM_ConnectZone.hxx"
00024 #include "MEDMEM_DriversDef.hxx"
00025 #include "MEDMEM_Mesh.hxx"
00026 #include "MEDMEM_Meshing.hxx"
00027 #include "MEDMEM_GaussLocalization.hxx"
00028 #include "MEDMEM_Field.hxx"
00029 #include "MEDMEM_CellModel.hxx"
00030 #include "MEDMEM_Group.hxx"
00031 
00032 #include "MEDSPLITTER_Graph.hxx"
00033 #include "MEDSPLITTER_Topology.hxx"
00034 #include "MEDSPLITTER_ParallelTopology.hxx"
00035 #include "MEDSPLITTER_SequentialTopology.hxx"
00036 #include "MEDSPLITTER_MESHCollection.hxx"
00037 #include "MEDSPLITTER_MESHCollectionDriver.hxx"
00038 
00039 #include "MEDMEM_Exception.hxx"
00040 
00041 #include <string>
00042 #include <cppunit/TestAssert.h>
00043 
00044 // use this define to enable lines, execution of which leads to Segmentation Fault
00045 //#define ENABLE_FAULTS
00046 
00047 // use this define to enable CPPUNIT asserts and fails, showing bugs
00048 #define ENABLE_FORCED_FAILURES
00049 
00050 
00051 using namespace std;
00052 using namespace MEDSPLITTER;
00053 using namespace MEDMEM;
00094 void MEDSPLITTERTest::testMESHCollection_constructor()
00095 {
00096   string filename_rd      = MEDSPLITTERTest_Utils::getResourceFile("carre_en_quad4.med");
00097   string fileNotExist_rd  = "notExist22.med";
00098   string emptyfilename    = "";
00099 
00100 
00101   //--------------------------Test READ ONLY part------------------------------//
00102 
00104                 //  TEST1a: Open not existing sequential and parallel file  //
00106     string meshname="non_existent";
00107     
00108     CPPUNIT_ASSERT_THROW(MESHCollection mc1(fileNotExist_rd, meshname), MEDEXCEPTION);
00109     
00110     CPPUNIT_ASSERT_THROW(MESHCollection mc2(fileNotExist_rd), MEDEXCEPTION);
00111     
00112     CPPUNIT_ASSERT_THROW(MESHCollection mc3(filename_rd, meshname), MEDEXCEPTION);
00113 
00114                 //  //////////////////////////////////////////////
00115                 //  //  TEST1b: Open file with empty file name  ///
00116                 //  //////////////////////////////////////////////
00117                 //
00118     CPPUNIT_ASSERT_THROW(MESHCollection mc4(emptyfilename, meshname), MEDEXCEPTION);
00119     CPPUNIT_ASSERT_THROW(MESHCollection mc5(emptyfilename), MEDEXCEPTION);
00120 
00121 }
00122  
00123  
00125 void MEDSPLITTERTest::testMESHCollection_read_seq()
00126 {
00127   string filename_rd      = MEDSPLITTERTest_Utils::getResourceFile("pointe.med");
00128   string filename_seq_wr  = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_seq_pointe22");
00129   string filename_seq_med = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_seq_pointe221.med");
00130   
00131   // To remove tmp files from disk
00132   MEDSPLITTERTest_TmpFilesRemover aRemover;
00133   aRemover.Register(filename_seq_wr);
00134   aRemover.Register(filename_seq_med);
00135   
00136         //--------------------------Test READ ONLY part------------------------------//
00137 
00138         //  /////////////////////////////////////////////
00139         //  //  TEST2: Manipulation of a single MED file
00140         //  /////////////////////////////////////////////
00141   string meshname="maa1";
00142   MESHCollection collection(filename_rd,meshname);
00143         collection.setDriverType(MEDSPLITTER::MedAscii);
00144   CPPUNIT_ASSERT_EQUAL(meshname,collection.getName());
00145   string newname = "New_name";
00146   collection.setName(newname);
00147   CPPUNIT_ASSERT_EQUAL(newname,collection.getName());
00148   string systemname="CARTESIAN";
00149   CPPUNIT_ASSERT_EQUAL(systemname,collection.getSystem());
00150   CPPUNIT_ASSERT_EQUAL(3,collection.getMeshDimension());
00151   CPPUNIT_ASSERT_EQUAL(3,collection.getSpaceDimension());
00152         
00153   collection.write(filename_seq_wr);
00154   
00155   //Reading from the master file
00156   MESHCollection collection2(filename_seq_wr);
00157   CPPUNIT_ASSERT_EQUAL(collection.getName(),collection2.getName());
00158   
00159   //Reading from the med file
00160   MESHCollection collection3(filename_seq_med,meshname);
00161   CPPUNIT_ASSERT_EQUAL(meshname,collection3.getName());
00162     
00163 }
00164 
00166 
00167 void MEDSPLITTERTest::testMESHCollection_read_para()
00168 {
00169   string filename_rd        = MEDSPLITTERTest_Utils::getResourceFile("pointe.med");
00170   string filename_para_wr   = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_para_pointe22_");
00171   string filename_xml       = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_para_pointe22_.xml");
00172   string filename_para_med0 = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_para_pointe22_1.med");
00173   string filename_para_med1 = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_para_pointe22_2.med");
00174   
00175   
00176   // To remove tmp files from disk
00177   MEDSPLITTERTest_TmpFilesRemover aRemover;
00178   aRemover.Register(filename_xml);
00179   aRemover.Register(filename_para_med0);
00180   aRemover.Register(filename_para_med1);
00181   
00182   string meshname="maa1";
00183   MESHCollection collection(filename_rd,meshname);
00184   Topology* topo=0;
00185   CPPUNIT_ASSERT_THROW(topo=collection.createPartition(0,Graph::METIS),MEDEXCEPTION);
00186   if (topo!=0) delete topo;
00187 #ifdef MED_ENABLE_METIS
00188   CPPUNIT_ASSERT_NO_THROW(topo=collection.createPartition(2,Graph::METIS));
00189 #else
00190   CPPUNIT_ASSERT_THROW(topo=collection.createPartition(2,Graph::METIS), MEDEXCEPTION);
00191   CPPUNIT_FAIL("METIS is not available, further test execution is not possible.");
00192 #endif
00193   MESHCollection new_collection(collection, topo);
00194   new_collection.write(filename_para_wr);
00195     
00196   CPPUNIT_ASSERT_EQUAL(meshname,new_collection.getName());
00197   MESHCollection new_collection2(filename_xml);
00198   CPPUNIT_ASSERT_EQUAL(collection.getName(),new_collection2.getName());
00199   
00200   MESHCollection new_collection3(filename_para_med0,"maa1_1");
00201   CPPUNIT_ASSERT_EQUAL(collection.getName()+"_1",new_collection3.getName());
00202   delete topo;
00203 }
00204 
00206 
00207 /*
00208  * test_SPLITTER_square
00209  * 
00210  * computes a partitioning for the following geometry
00211  * 
00212  * 
00213  * 
00214  * 7------------8------------9
00215  * |            |            |
00216  * |            |            |
00217  * |     3      |     4      |
00218  * |            |            |
00219  * |            |            |
00220  * 4------------5------------6
00221  * |            |            |
00222  * |            |            |
00223  * |     1      |     2      |
00224  * |            |            |
00225  * |            |            |
00226  * 1------------2------------3 
00227  *
00228  * Result of the 2 domain split :
00229  *  
00230  * 5------------6 5------------6
00231  * |            | |            |
00232  * |            | |            |
00233  * |     2      | |     2      |
00234  * |            | |            |
00235  * |            | |            |
00236  * 1------------2 1------------2
00237  * |            | |            |
00238  * |            | |            |
00239  * |     1      | |     1      |
00240  * |            | |            |
00241  * |            | |            |
00242  * 4------------3 4------------3 
00243  */
00244 
00245 
00246 void MEDSPLITTERTest::testMESHCollection_square()
00247 {
00248   string filename_rd   = MEDSPLITTERTest_Utils::getResourceFile("carre_en_quad4.med");
00249   string filename_wr   = MEDSPLITTERTest_Utils::makeTmpFile("carre_split");
00250   string filename_wr_1 = MEDSPLITTERTest_Utils::makeTmpFile("carre_split1.med");
00251   string filename_wr_2 = MEDSPLITTERTest_Utils::makeTmpFile("carre_split2.med");
00252   
00253   // To remove tmp files from disk
00254   MEDSPLITTERTest_TmpFilesRemover aRemover;
00255   aRemover.Register(filename_wr);
00256   aRemover.Register(filename_wr+".xml");
00257   aRemover.Register(filename_wr_1);
00258   aRemover.Register(filename_wr_2);
00259   
00260   char meshname[20]  = "carre_en_quad4";
00261   char meshname1[20]  = "carre_en_quad4_1";
00262   char meshname2[20]  = "carre_en_quad4_2";
00263     
00264   MESHCollection collection(filename_rd,meshname);
00265   MEDSPLITTER::Topology* topo;
00266 #ifdef MED_ENABLE_METIS
00267   CPPUNIT_ASSERT_NO_THROW(topo = collection.createPartition(2,Graph::METIS));
00268 #else
00269   CPPUNIT_ASSERT_THROW(topo = collection.createPartition(2,Graph::METIS), MEDEXCEPTION);
00270   CPPUNIT_FAIL("METIS is not available, further test execution is not possible.");
00271 #endif
00272   MESHCollection new_collection(collection, topo);
00273     
00274   //collection.write("/export/home/test_splitter");
00275   new_collection.write(filename_wr);
00276   new_collection.castAllFields(collection);
00277     
00278   MEDMEM::MESH mesh1(MEDMEM::MED_DRIVER, filename_wr_1, meshname1);
00279   MEDMEM::MESH mesh2(MEDMEM::MED_DRIVER, filename_wr_2, meshname2);
00280     
00281   // testing number of elements for each partition
00282   int nbelem1=mesh1.getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS);
00283   int nbelem2=mesh2.getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS);
00284     
00285   CPPUNIT_ASSERT_EQUAL(nbelem1,2);
00286   CPPUNIT_ASSERT_EQUAL(nbelem2,2);
00287   
00288   
00289   //testing number of joints
00290   med_2_3::med_idt fid1 = med_2_3::MEDfileOpen(filename_wr_1.c_str(),med_2_3::MED_ACC_RDONLY);
00291   med_2_3::med_idt fid2 = med_2_3::MEDfileOpen(filename_wr_2.c_str(),med_2_3::MED_ACC_RDONLY);
00292   int nj1= med_2_3::MEDnSubdomainJoint(fid1, meshname1);
00293   int nj2= med_2_3::MEDnSubdomainJoint(fid2, meshname2);
00294   CPPUNIT_ASSERT_EQUAL(nj1,1);
00295   CPPUNIT_ASSERT_EQUAL(nj2,1);
00296        
00297   //testing distant domains
00298     
00299   char desc1[MED_COMMENT_SIZE+1];
00300   char maa_dist1[MED_NAME_SIZE+1], jn1[MED_NAME_SIZE+1];
00301   char desc2[MED_COMMENT_SIZE+1], maa_dist2[MED_NAME_SIZE+1], jn2[MED_NAME_SIZE+1];
00302   int dom1, dom2;
00303   int nstep,nocstp;
00304   med_2_3::MEDsubdomainJointInfo(fid1, meshname1, 1, jn1, desc1, &dom1, maa_dist1, &nstep, &nocstp);
00305   med_2_3::MEDsubdomainJointInfo(fid2, meshname2, 1, jn2, desc2, &dom2, maa_dist2, &nstep, &nocstp);
00306   CPPUNIT_ASSERT(strcmp(jn1,"joint_2")==0);
00307   CPPUNIT_ASSERT(strcmp(jn2,"joint_1")==0);
00308   CPPUNIT_ASSERT_EQUAL(dom1,1);
00309   CPPUNIT_ASSERT_EQUAL(dom2,0);
00310   
00311   // testing node-node correspondency
00312   med_2_3::med_entity_type typ_ent_loc=med_2_3::MED_NODE;
00313   med_2_3::med_entity_type typ_ent_dist=med_2_3::MED_NODE;
00314   med_2_3::med_geometry_type typ_geo_loc= MED_POINT1;
00315   med_2_3::med_geometry_type typ_geo_dist= MED_POINT1;
00316 
00317   int n1;
00318   med_2_3::MEDsubdomainCorrespondenceSize(fid1,meshname1,jn1,MED_NO_DT, MED_NO_IT, typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist, &n1);
00319   med_2_3::med_int* tab = new med_2_3::med_int[2*n1];
00320    
00321   med_2_3::MEDsubdomainCorrespondenceRd(fid1,meshname1,jn1,MED_NO_DT, MED_NO_IT,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist, tab);
00322     
00323   med_2_3::med_int tabreference1[6] = {2,1,3,4,6,5};
00324   for (int i=0; i<2*n1; i++)
00325                 CPPUNIT_ASSERT_EQUAL(tab[i],tabreference1[i]);
00326 
00327   delete[] tab;
00328 
00329   int n2;
00330   med_2_3::MEDsubdomainCorrespondenceSize(fid2,meshname2,jn2,MED_NO_DT, MED_NO_IT,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist,&n2);
00331   tab = new med_2_3::med_int[2*n2];
00332 
00333   med_2_3::MEDsubdomainCorrespondenceRd(fid2,meshname2,jn2,MED_NO_DT, MED_NO_IT,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist,tab);
00334 
00335   med_2_3::med_int tabreference2[] = {1,2,4,3,5,6};
00336   for (int i=0; i<2*n1; i++)
00337                 CPPUNIT_ASSERT_EQUAL(tab[i],tabreference2[i]);
00338   delete[] tab;
00339 
00340   //testing nodes global numbering
00341   med_2_3::med_int* num = new med_2_3::med_int[6];
00342   cout << "Reading global " << MEDmeshGlobalNumberRd(fid1, meshname1, MED_NO_DT, MED_NO_IT, typ_ent_loc, typ_geo_loc, num) << endl;
00343   
00344   med_2_3::med_int globnoderef1[] = {4,5,2,1,7,8};
00345 
00346   for (int i=0; i<6; i++)
00347                 CPPUNIT_ASSERT_EQUAL(num[i],globnoderef1[i]);
00348   delete[] num;
00349 
00350   //testing nodes global numbering
00351   num = new med_2_3::med_int[6];
00352   MEDmeshGlobalNumberRd(fid2, meshname2, MED_NO_DT, MED_NO_IT, typ_ent_loc, typ_geo_loc, num);
00353   med_2_3::med_int globnoderef2[] = {5,6,3,2,8,9};
00354   for (int i=0; i<6; i++)
00355     CPPUNIT_ASSERT_EQUAL(num[i],globnoderef2[i]);
00356   delete[] num;
00357 
00358   //testing cell-cell correspondency
00359   typ_ent_loc=med_2_3::MED_CELL;
00360   typ_ent_dist=med_2_3::MED_CELL;
00361   typ_geo_loc= MED_QUAD4;
00362   typ_geo_dist= MED_QUAD4;
00363   //joint1
00364   med_2_3::MEDsubdomainCorrespondenceSize(fid1,meshname1,jn1,MED_NO_DT, MED_NO_IT,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist,&n1);
00365   CPPUNIT_ASSERT_EQUAL(n1,2);
00366   tab = new med_2_3::med_int[2*n1];
00367   med_2_3::MEDsubdomainCorrespondenceRd(fid1,meshname1,jn1,MED_NO_DT, MED_NO_IT,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist,tab);
00368 
00369   med_2_3::med_int tabreferencecell1[4] = {1,1,2,2};
00370   for (int i=0; i<2*n1; i++)
00371     CPPUNIT_ASSERT_EQUAL(tab[i],tabreferencecell1[i]);
00372 
00373   med_2_3::MEDsubdomainCorrespondenceSize(fid2,meshname2,jn2,MED_NO_DT, MED_NO_IT, typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist, &n2);
00374   CPPUNIT_ASSERT_EQUAL(n2,2);
00375   delete[] tab;
00376   //joint2
00377   tab = new med_2_3::med_int[2*n2];
00378   med_2_3::MEDsubdomainCorrespondenceRd(fid2,meshname2,jn2,MED_NO_DT, MED_NO_IT,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist,tab);
00379 
00380   med_2_3::med_int tabreferencecell2[4] = {1,1,2,2};
00381   for (int i=0; i<n2; i++)
00382     CPPUNIT_ASSERT_EQUAL(tab[i],tabreferencecell2[i]);
00383 
00384   delete[]tab;
00385 
00386   //testing cells global numbering
00387   num = new med_2_3::med_int[2];
00388   MEDmeshGlobalNumberRd(fid1, meshname1, MED_NO_DT, MED_NO_IT, typ_ent_loc, typ_geo_loc, num);
00389   med_2_3::med_int* globcellref = new med_2_3::med_int[2];
00390   globcellref[0]=1;
00391   globcellref[1]=3;
00392 
00393   for (int i=0; i<2; i++)
00394     CPPUNIT_ASSERT_EQUAL(num[i],globcellref[i]);
00395   delete[] num;
00396 
00397   //testing cells global numbering
00398   num = new med_2_3::med_int[2];
00399   MEDmeshGlobalNumberRd(fid2, meshname2, MED_NO_DT, MED_NO_IT, typ_ent_loc, typ_geo_loc, num);
00400   globcellref[0]=2;
00401   globcellref[1]=4;
00402   for (int i=0; i<2; i++)
00403     CPPUNIT_ASSERT_EQUAL(num[i],globcellref[i]);
00404   delete[] num;
00405   delete[] globcellref;
00406   delete topo;
00407 }
00408 
00409 
00410 void MEDSPLITTERTest::testMESHCollection_square_with_faces()
00411 {
00412   string filename_rd   = MEDSPLITTERTest_Utils::getResourceFile("carre_en_quad4.med");
00413   string filename_wr   = MEDSPLITTERTest_Utils::makeTmpFile("carre_split_faces");
00414   string filename_wr_1 = MEDSPLITTERTest_Utils::makeTmpFile("carre_split_faces1.med");
00415   string filename_wr_2 = MEDSPLITTERTest_Utils::makeTmpFile("carre_split_faces2.med");
00416   
00417   // To remove tmp files from disk
00418   MEDSPLITTERTest_TmpFilesRemover aRemover;
00419   aRemover.Register(filename_wr);
00420   aRemover.Register(filename_wr+".xml");
00421   aRemover.Register(filename_wr_1);
00422   aRemover.Register(filename_wr_2);
00423   
00424   char meshname[20]  = "carre_en_quad4";
00425   char meshname1[20]  = "carre_en_quad4_1";
00426   char meshname2[20]  = "carre_en_quad4_2";
00427 
00428   /*
00429   MESHCollection collection(filename_rd,meshname);
00430   MEDSPLITTER::Topology* topo = collection.createPartition(2,Graph::METIS);
00431   MESHCollection new_collection(collection, topo);
00432   new_collection.setSubdomainBoundaryCreates(true);
00433 
00434   //collection.write("/export/home/test_splitter");
00435   new_collection.write(filename_wr);
00436   new_collection.castAllFields(collection);
00437   */
00438 
00439   MESHCollection* collection = new MESHCollection (filename_rd,meshname);
00440   MEDSPLITTER::Topology* topo = collection->createPartition(2,Graph::METIS);
00441   MESHCollection* new_collection = new MESHCollection (*collection, topo);
00442   new_collection->setSubdomainBoundaryCreates(true);
00443 
00444   //collection.write("/export/home/test_splitter");
00445   new_collection->write(filename_wr);
00446   new_collection->castAllFields(*collection);
00447 
00448   MEDMEM::MESH mesh1(MEDMEM::MED_DRIVER, filename_wr_1, meshname1);
00449   MEDMEM::MESH mesh2(MEDMEM::MED_DRIVER, filename_wr_2, meshname2);
00450 
00451   // testing number of elements for each partition
00452   int nbelem1=mesh1.getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS);
00453   int nbelem2=mesh2.getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS);
00454 
00455   CPPUNIT_ASSERT_EQUAL(nbelem1,2);
00456   CPPUNIT_ASSERT_EQUAL(nbelem2,2);
00457   
00458   
00459   //testing number of joints
00460   med_2_3::med_idt fid1 = med_2_3::MEDfileOpen(filename_wr_1.c_str(),med_2_3::MED_ACC_RDONLY);
00461   med_2_3::med_idt fid2 = med_2_3::MEDfileOpen(filename_wr_2.c_str(),med_2_3::MED_ACC_RDONLY);
00462   int nj1= med_2_3::MEDnSubdomainJoint(fid1, meshname1);
00463   int nj2= med_2_3::MEDnSubdomainJoint(fid2, meshname2);
00464   CPPUNIT_ASSERT_EQUAL(nj1,1);
00465   CPPUNIT_ASSERT_EQUAL(nj2,1);
00466        
00467   //testing distant domains
00468     
00469   char desc1[MED_COMMENT_SIZE+1];
00470   char maa_dist1[MED_NAME_SIZE+1], jn1[MED_NAME_SIZE+1];
00471   char desc2[MED_COMMENT_SIZE+1], maa_dist2[MED_NAME_SIZE+1], jn2[MED_NAME_SIZE+1];
00472   int dom1, dom2;
00473   int nstep,nocstp;
00474   med_2_3::MEDsubdomainJointInfo(fid1, meshname1, 1, jn1, desc1, &dom1, maa_dist1, &nstep, &nocstp);
00475   med_2_3::MEDsubdomainJointInfo(fid2, meshname2, 1, jn2, desc2, &dom2, maa_dist2, &nstep, &nocstp);
00476   CPPUNIT_ASSERT_EQUAL(dom1,1);
00477   CPPUNIT_ASSERT_EQUAL(dom2,0);
00478   
00479   // testing node-node correspondency
00480   med_2_3::med_entity_type typ_ent_loc=med_2_3::MED_NODE;
00481   med_2_3::med_entity_type typ_ent_dist=med_2_3::MED_NODE;
00482   med_2_3::med_geometry_type typ_geo_loc= MED_POINT1;
00483   med_2_3::med_geometry_type typ_geo_dist= MED_POINT1;
00484     
00485   int n1;
00486   med_2_3::MEDsubdomainCorrespondenceSize(fid1,meshname1,jn1, MED_NO_DT, MED_NO_IT, typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist, &n1);
00487   CPPUNIT_ASSERT_EQUAL(3,n1);
00488   med_2_3::med_int* tab = new med_2_3::med_int[2*n1];
00489    
00490   med_2_3::MEDsubdomainCorrespondenceRd(fid1,meshname1,jn1, MED_NO_DT, MED_NO_IT,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist, tab);
00491     
00492   med_2_3::med_int tabreference1[6] = {2,1,3,4,6,5};
00493   for (int i=0; i<2*n1; i++)
00494     CPPUNIT_ASSERT_EQUAL(tab[i],tabreference1[i]);
00495     
00496   delete[] tab;
00497 
00498   int n2;
00499   med_2_3::MEDsubdomainCorrespondenceSize(fid2,meshname2,jn2, MED_NO_DT, MED_NO_IT, typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist,&n2);
00500   tab = new med_2_3::med_int[2*n2];
00501     
00502   med_2_3::MEDsubdomainCorrespondenceRd(fid2,meshname2,jn2,MED_NO_DT, MED_NO_IT, typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist,tab);
00503     
00504   med_2_3::med_int tabreference2[]={1,2,4,3,5,6};
00505   for (int i=0; i<2*n1; i++)
00506     CPPUNIT_ASSERT_EQUAL(tab[i],tabreference2[i]);
00507   delete[] tab;
00508 
00509   //testing nodes global numbering
00510   med_2_3::med_int* num = new med_2_3::med_int[6];
00511   cout << "Reading global " << MEDmeshGlobalNumberRd(fid1, meshname1, MED_NO_DT, MED_NO_IT, typ_ent_loc, typ_geo_loc, num) << endl;
00512 
00513   med_2_3::med_int globnoderef1[]={4,5,2,1,7,8};
00514 
00515   for (int i=0; i<6; i++)
00516     CPPUNIT_ASSERT_EQUAL(num[i],globnoderef1[i]);
00517   delete[] num;
00518 
00519   //testing nodes global numbering
00520   num = new med_2_3::med_int[6];
00521   MEDmeshGlobalNumberRd(fid2, meshname2, MED_NO_DT, MED_NO_IT, typ_ent_loc, typ_geo_loc, num);
00522   med_2_3::med_int globnoderef2[]={5,6,3,2,8,9};
00523   for (int i=0; i<6; i++)
00524     CPPUNIT_ASSERT_EQUAL(num[i],globnoderef2[i]);
00525   delete[] num;
00526   
00527   //testing cell-cell correspondency
00528   typ_ent_loc=med_2_3::MED_CELL;
00529   typ_ent_dist=med_2_3::MED_CELL;
00530   typ_geo_loc= MED_QUAD4;
00531   typ_geo_dist= MED_QUAD4;
00532   //joint1
00533   med_2_3::MEDsubdomainCorrespondenceSize(fid1,meshname1,jn1,MED_NO_DT, MED_NO_IT,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist,&n1);
00534   CPPUNIT_ASSERT_EQUAL(n1,2);
00535   tab = new med_2_3::med_int[2*n1];
00536   med_2_3::MEDsubdomainCorrespondenceRd(fid1,meshname1,jn1,MED_NO_DT, MED_NO_IT,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist,tab);
00537     
00538   med_2_3::med_int tabreferencecell1[4]={1,1,2,2};
00539   for (int i=0; i<2*n1; i++)
00540     CPPUNIT_ASSERT_EQUAL(tab[i],tabreferencecell1[i]);
00541             
00542   med_2_3::MEDsubdomainCorrespondenceSize(fid2,meshname2,jn2,MED_NO_DT, MED_NO_IT,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist,&n2);
00543   CPPUNIT_ASSERT_EQUAL(n2,2);
00544   delete[] tab;
00545   //joint2
00546   tab = new med_2_3::med_int[2*n2];
00547   med_2_3::MEDsubdomainCorrespondenceRd(fid2,meshname2,jn2,MED_NO_DT, MED_NO_IT,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist,tab);
00548     
00549   med_2_3::med_int tabreferencecell2[4]={1,1,2,2};
00550   for (int i=0; i<n2; i++)
00551     CPPUNIT_ASSERT_EQUAL(tab[i],tabreferencecell2[i]);
00552             
00553   delete[]tab;
00554         
00555   //testing cells global numbering
00556   num = new med_2_3::med_int[2];
00557   MEDmeshGlobalNumberRd(fid1, meshname1, MED_NO_DT, MED_NO_IT, typ_ent_loc, typ_geo_loc,num);
00558   med_2_3::med_int* globcellref = new int[2];
00559   globcellref[0]=1;
00560   globcellref[1]=3;
00561   
00562   for (int i=0; i<2; i++)
00563     CPPUNIT_ASSERT_EQUAL(num[i],globcellref[i]);
00564   delete[] num;
00565     
00566   //testing cells global numbering
00567   num = new med_2_3::med_int[2];
00568   MEDmeshGlobalNumberRd(fid2, meshname2, MED_NO_DT, MED_NO_IT, typ_ent_loc, typ_geo_loc,num);
00569   globcellref[0]=2;
00570   globcellref[1]=4;
00571   for (int i=0; i<2; i++)
00572     CPPUNIT_ASSERT_EQUAL(num[i],globcellref[i]);
00573   delete[] num;
00574   
00575   //testing face/face/correspondency
00576   typ_ent_loc=med_2_3::MED_CELL;
00577   typ_ent_dist=med_2_3::MED_CELL;
00578   typ_geo_loc= MED_SEG2;
00579   typ_geo_dist= MED_SEG2;
00580   //joint1
00581   med_2_3::MEDsubdomainCorrespondenceSize(fid1,meshname1,jn1,MED_NO_DT, MED_NO_IT,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist, &n1);
00582   CPPUNIT_ASSERT_EQUAL(n1,2);
00583   tab = new med_2_3::med_int[2*n1];
00584   med_2_3::MEDsubdomainCorrespondenceRd(fid1,meshname1,jn1,MED_NO_DT, MED_NO_IT, typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist,tab);
00585     
00586   med_2_3::med_int tabreferencecell3[4]={1,1,2,2};
00587   for (int i=0; i<2*n1; i++)
00588     CPPUNIT_ASSERT_EQUAL(tab[i],tabreferencecell3[i]);
00589             
00590   med_2_3::MEDsubdomainCorrespondenceSize(fid2,meshname2,jn2,MED_NO_DT, MED_NO_IT,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist, &n2);
00591   CPPUNIT_ASSERT_EQUAL(n2,2);
00592   delete[] tab;
00593   //joint2
00594   tab = new med_2_3::med_int[2*n2];
00595   med_2_3::MEDsubdomainCorrespondenceRd(fid2,meshname2,jn2,MED_NO_DT, MED_NO_IT,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist,tab);
00596     
00597   med_2_3::med_int tabreferencecell4[4]={1,1,2,2};
00598   for (int i=0; i<n2; i++)
00599     CPPUNIT_ASSERT_EQUAL(tab[i],tabreferencecell4[i]);
00600             
00601   delete[]tab;
00602   
00603   delete[]globcellref;
00604   delete topo;   
00605 
00606   delete collection;       
00607   delete new_collection;       
00608 }
00609 
00610 /*
00611  * testing indivisibility functionality
00612  * 
00613  * computes a partitioning for the a geometry
00614  * with 8 TRIA3 and 4 QUAD4. A group containing the quads
00615  * is set to be indivisible. 
00616  * It is checked that on output, there is only one group 
00617  * containing quads.
00618  * SCOTCH is used for this partitioning.
00619  * */
00620 
00621 void MEDSPLITTERTest::testMESHCollection_indivisible()
00622 {
00623   string filename_rd     = MEDSPLITTERTest_Utils::getResourceFile("maill.00.med");
00624   string filename_wr     = MEDSPLITTERTest_Utils::makeTmpFile("carre_indivisible");
00625   string filename_wr_xml = MEDSPLITTERTest_Utils::makeTmpFile("carre_indivisible.xml");
00626   string filename_wr_1   = MEDSPLITTERTest_Utils::makeTmpFile("carre_indivisible1.med");
00627   string filename_wr_2   = MEDSPLITTERTest_Utils::makeTmpFile("carre_indivisible2.med");
00628   string filename_wr_3   = MEDSPLITTERTest_Utils::makeTmpFile("carre_indivisible3.med");
00629   string filename_wr_4   = MEDSPLITTERTest_Utils::makeTmpFile("carre_indivisible4.med");
00630   
00631         // To remove tmp files from disk
00632   MEDSPLITTERTest_TmpFilesRemover aRemover;
00633   aRemover.Register(filename_wr);
00634   aRemover.Register(filename_wr_xml);
00635   aRemover.Register(filename_wr_1);
00636   aRemover.Register(filename_wr_2);
00637   aRemover.Register(filename_wr_3);
00638   aRemover.Register(filename_wr_4);
00639   
00640   
00641   char meshname[20]  = "MAILTRQU";
00642   char family[MED_NAME_SIZE]="QUAD";
00643   MESHCollection collection(filename_rd,meshname);
00644   collection.setIndivisibleGroup(family);
00645   Topology* topo;
00646 #ifdef MED_ENABLE_SCOTCH
00647   CPPUNIT_ASSERT_NO_THROW(topo = collection.createPartition(4,Graph::SCOTCH));
00648 #else
00649   CPPUNIT_ASSERT_THROW(topo = collection.createPartition(4,Graph::SCOTCH), MEDEXCEPTION);
00650   CPPUNIT_FAIL("SCOTCH is not available, further test execution is not possible.");
00651 #endif
00652   MESHCollection new_collection(collection, topo);
00653   new_collection.write(filename_wr);
00654    
00655   char meshname1[20]="MAILTRQU_1";
00656   char meshname2[20]="MAILTRQU_2";
00657   char meshname3[20]="MAILTRQU_3";
00658   char meshname4[20]="MAILTRQU_4";
00659     
00660   MEDMEM::MESH mesh1(MEDMEM::MED_DRIVER, filename_wr_1, meshname1);
00661   MEDMEM::MESH mesh2(MEDMEM::MED_DRIVER, filename_wr_2, meshname2);
00662   MEDMEM::MESH mesh3(MEDMEM::MED_DRIVER, filename_wr_3, meshname3);
00663   MEDMEM::MESH mesh4(MEDMEM::MED_DRIVER, filename_wr_4, meshname4);
00664       
00665   // testing number of quads for each partition
00666   int nbquad1=    mesh1.getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_QUAD4);
00667   int nbquad2=    mesh2.getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_QUAD4);
00668   int nbquad3=    mesh3.getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_QUAD4);
00669   int nbquad4=    mesh4.getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_QUAD4);
00670   int nb_domain_with_quad=(nbquad1?1:0)+(nbquad2?1:0)+(nbquad3?1:0)+(nbquad4?1:0);
00671 
00672   CPPUNIT_ASSERT_EQUAL(nb_domain_with_quad,1);
00673   delete topo;  
00674 }
00675   
00676 /*
00677  * test_SPLITTER_user_partition
00678  * 
00679  * computes joints for the following geometry
00680  * with user specified partition
00681  * domain0: (1,4)/ domain1:(2,3)
00682  * 
00683  * 
00684  * 7------------8------------9
00685  * |            |            |
00686  * |            |            |
00687  * |     3      |     4      |
00688  * |            |            |
00689  * |            |            |
00690  * 4------------5------------6
00691  * |            |            |
00692  * |            |            |
00693  * |     1      |     2      |
00694  * |            |            |
00695  * |            |            |
00696  * 1------------2------------3 
00697  *
00698  * Result of the 2 domain split :
00699  *  
00700  * 5------------6 5------------6
00701  * |            | |            |
00702  * |            | |            |
00703  * |     2      | |     2      |
00704  * |            | |            |
00705  * |            | |            |
00706  * 7------------1 2------------7
00707  * 1------------2 1------------2
00708  * |            | |            |
00709  * |            | |            |
00710  * |     1      | |     1      |
00711  * |            | |            |
00712  * |            | |            |
00713  * 4------------3 4------------3 
00714  */
00715 
00716 
00717 void MEDSPLITTERTest::testMESHCollection_user_partition()
00718 {
00719   string filename_rd   = MEDSPLITTERTest_Utils::getResourceFile("carre_en_quad4.med");
00720   string filename_wr   = MEDSPLITTERTest_Utils::makeTmpFile("carre_split_user");
00721   string filename_wr_1 = MEDSPLITTERTest_Utils::makeTmpFile("carre_split_user1.med");
00722   string filename_wr_2 = MEDSPLITTERTest_Utils::makeTmpFile("carre_split_user2.med");
00723   
00724   // To remove tmp files from disk
00725   MEDSPLITTERTest_TmpFilesRemover aRemover;
00726   aRemover.Register(filename_wr);
00727   aRemover.Register(filename_wr+".xml");
00728   aRemover.Register(filename_wr_1);
00729   aRemover.Register(filename_wr_2);
00730 
00731   char meshname[20]  = "carre_en_quad4";
00732   char meshname1[20]  = "carre_en_quad4_1";
00733   char meshname2[20]  = "carre_en_quad4_2";
00734 
00735   //int partition[4]={0,1,1,0};
00736   int* partition=new int[4];
00737   partition[0]=0;
00738   partition[1]=1;
00739   partition[2]=1;
00740   partition[3]=0;
00741   //
00742   /*
00743   MESHCollection collection(filename_rd,meshname);
00744   Topology* topo = collection.createPartition(partition);
00745   MESHCollection new_collection(collection, topo);
00746 
00747   //collection.write("/export/home/test_splitter");
00748   new_collection.write(filename_wr);
00749   new_collection.castAllFields(collection);
00750   */
00751 
00752   MESHCollection* collection = new MESHCollection (filename_rd, meshname);
00753   Topology* topo = collection->createPartition(partition);
00754   MESHCollection* new_collection = new MESHCollection (*collection, topo);
00755   new_collection->write(filename_wr);
00756   new_collection->castAllFields(*collection);
00757 
00758   MEDMEM::MESH mesh1(MEDMEM::MED_DRIVER, filename_wr_1, meshname1);
00759   MEDMEM::MESH mesh2(MEDMEM::MED_DRIVER, filename_wr_2, meshname2);
00760 
00761   // testing number of elements for each partition
00762 
00763   int nbelem1=mesh1.getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS);
00764   int nbelem2=mesh2.getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS);
00765   CPPUNIT_ASSERT_EQUAL(nbelem1,2);
00766   CPPUNIT_ASSERT_EQUAL(nbelem2,2);
00767 
00768   //testing number of joints
00769   med_2_3::med_idt fid1 = med_2_3::MEDfileOpen(filename_wr_1.c_str(),med_2_3::MED_ACC_RDONLY);
00770   med_2_3::med_idt fid2 = med_2_3::MEDfileOpen(filename_wr_2.c_str(),med_2_3::MED_ACC_RDONLY);
00771 
00772   int nj1= med_2_3::MEDnSubdomainJoint(fid1, meshname1);
00773   int nj2= med_2_3::MEDnSubdomainJoint(fid2, meshname2);
00774   CPPUNIT_ASSERT_EQUAL(nj1,1);
00775   CPPUNIT_ASSERT_EQUAL(nj2,1);
00776 
00777   //testing distant domains
00778 
00779   char desc1[MED_COMMENT_SIZE+1];
00780   char maa_dist1[MED_NAME_SIZE+1], jn1[MED_NAME_SIZE+1];
00781   char desc2[MED_COMMENT_SIZE+1];
00782   char maa_dist2[MED_NAME_SIZE+1], jn2[MED_NAME_SIZE+1];
00783   //int dom1, dom2;
00784   med_2_3::med_int dom1, dom2;
00785   int nstep,nocstp;
00786   med_2_3::MEDsubdomainJointInfo(fid1, meshname1, 1, jn1, desc1, &dom1, maa_dist1, &nstep, &nocstp);
00787   med_2_3::MEDsubdomainJointInfo(fid2, meshname2, 1, jn2, desc2, &dom2, maa_dist2, &nstep, &nocstp);
00788   CPPUNIT_ASSERT_EQUAL(dom1,1);
00789   CPPUNIT_ASSERT_EQUAL(dom2,0);
00790 
00791   // testing node-node correspondency
00792   med_2_3::med_entity_type typ_ent_loc=med_2_3::MED_NODE;
00793   med_2_3::med_entity_type typ_ent_dist=med_2_3::MED_NODE;
00794   med_2_3::med_geometry_type typ_geo_loc= MED_POINT1;
00795   med_2_3::med_geometry_type typ_geo_dist= MED_POINT1;
00796 
00797   int n1;
00798   med_2_3::MEDsubdomainCorrespondenceSize(fid1,meshname1,jn1,MED_NO_DT, MED_NO_IT,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist,&n1);
00799   CPPUNIT_ASSERT_EQUAL(5,n1);
00800   med_2_3::med_int* tab = new med_2_3::med_int[2*n1];
00801 
00802   med_2_3::MEDsubdomainCorrespondenceRd(fid1,meshname1,jn1,MED_NO_DT, MED_NO_IT,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist,tab);
00803 
00804   med_2_3::med_int tabreference1[10] = {1,7,2,1,3,4,5,6,7,2};
00805   for (int i=0; i<2*n1; i++)
00806     CPPUNIT_ASSERT_EQUAL(tab[i],tabreference1[i]);
00807   delete[] tab;
00808   int n2;
00809   med_2_3::MEDsubdomainCorrespondenceSize(fid2,meshname2,jn2,MED_NO_DT, MED_NO_IT,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist,&n2);
00810   tab = new med_2_3::med_int[2*n2];
00811 
00812   med_2_3::MEDsubdomainCorrespondenceRd(fid2,meshname2,jn2,MED_NO_DT, MED_NO_IT,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist,tab);
00813 
00814   med_2_3::med_int tabreference2[10] = {1,2,2,7,4,3,6,5,7,1};
00815   for (int i=0; i<2*n2; i++)
00816                 CPPUNIT_ASSERT_EQUAL(tab[i],tabreference2[i]);
00817   delete[] tab;
00818 
00819   //testing nodes global numbering
00820   med_2_3::med_int* num = new med_2_3::med_int[7];
00821   cout << "Reading global " << MEDmeshGlobalNumberRd(fid1, meshname1, MED_NO_DT, MED_NO_IT, typ_ent_loc, typ_geo_loc, num) << endl;
00822   med_2_3::med_int globnoderef1[7] = {4,5,2,1,8,9,6};
00823 
00824   for (int i=0; i<7; i++)
00825                 CPPUNIT_ASSERT_EQUAL(num[i],globnoderef1[i]);
00826 
00827   delete[] num;
00828 
00829   //testing nodes global numbering
00830   num = new med_2_3::med_int[7];
00831   MEDmeshGlobalNumberRd(fid2, meshname2, MED_NO_DT, MED_NO_IT, typ_ent_loc, typ_geo_loc, num);
00832   med_2_3::med_int globnoderef2[7] = {5,6,3,2,7,8,4};
00833   for (int i=0; i<7; i++)
00834                 CPPUNIT_ASSERT_EQUAL(num[i],globnoderef2[i]);
00835   delete[] num;
00836 
00837   //testing cell-cell correspondency
00838   typ_ent_loc=med_2_3::MED_CELL;
00839   typ_ent_dist=med_2_3::MED_CELL;
00840   typ_geo_loc= MED_QUAD4;
00841   typ_geo_dist= MED_QUAD4;
00842   //joint1
00843   med_2_3::MEDsubdomainCorrespondenceSize(fid1,meshname1,jn1,MED_NO_DT, MED_NO_IT,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist, &n1);
00844   tab = new med_2_3::med_int[2*n1];
00845   med_2_3::MEDsubdomainCorrespondenceRd(fid1,meshname1,jn1,MED_NO_DT, MED_NO_IT,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist,tab);
00846 
00847   med_2_3::med_int tabreferencecell1[8] = {1,1,1,2,2,1,2,2};
00848   for (int i=0; i<2*n1; i++)
00849                 CPPUNIT_ASSERT_EQUAL(tab[i],tabreferencecell1[i]);
00850 
00851   med_2_3::MEDsubdomainCorrespondenceSize(fid1,meshname1,jn1,MED_NO_DT, MED_NO_IT,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist,&n2);
00852   delete[] tab;
00853   //joint2
00854   tab = new med_2_3::med_int[2*n2];
00855   med_2_3::MEDsubdomainCorrespondenceRd(fid2,meshname2,jn2,MED_NO_DT, MED_NO_IT,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist, tab);
00856 
00857   med_2_3::med_int tabreferencecell2[8] = {1,1,1,2,2,1,2,2};
00858   for (int i=0; i<n2; i++)
00859                 CPPUNIT_ASSERT_EQUAL(tab[i],tabreferencecell2[i]);
00860   delete[] tab;
00861 
00862   //testing cells global numbering
00863   num = new med_2_3::med_int[2];
00864   MEDmeshGlobalNumberRd(fid1, meshname1, MED_NO_DT, MED_NO_IT, typ_ent_loc, typ_geo_loc, num);
00865   med_2_3::med_int globcellref1[2] = {1,4};
00866   for (int i=0; i<2; i++)
00867     CPPUNIT_ASSERT_EQUAL(num[i],globcellref1[i]);
00868   delete[] num;
00869 
00870   //testing cells global numbering
00871   num = new med_2_3::med_int[2];
00872   MEDmeshGlobalNumberRd(fid2, meshname2, MED_NO_DT, MED_NO_IT, typ_ent_loc, typ_geo_loc, num);
00873   med_2_3::med_int globcellref2[2] = {2,3};
00874   for (int i=0; i<2; i++)
00875     CPPUNIT_ASSERT_EQUAL(num[i],globcellref2[i]);
00876 
00877   delete[] num;
00878   delete topo;
00879   delete[] partition;
00880   delete collection;
00881   delete new_collection;
00882 }
00883 
00884 
00889 void MEDSPLITTERTest::testMESHCollection_complete_sequence()
00890 {
00891   string filename_rd         = MEDSPLITTERTest_Utils::getResourceFile("pointe.med");
00892   string filename_para_wr    = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_para1_pointe22_");
00893   string filename_para_med1  = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_para1_pointe22_1.med");
00894   string filename_para_med2  = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_para1_pointe22_2.med");
00895   string filename_para2_wr   = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_para2_pointe22_");
00896   string filename_para2_med1 = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_para2_pointe22_1.med");
00897   string filename_para2_med2 = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_para2_pointe22_2.med");
00898   string filename_para2_med3 = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_para2_pointe22_3.med");
00899   string filename_seq_wr     = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_seq_pointe22_");
00900   string filename_seq_med    = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_seq_pointe22_1.med");
00901   
00902   
00903   // To remove tmp files from disk
00904   MEDSPLITTERTest_TmpFilesRemover aRemover;
00905   aRemover.Register(filename_para_wr);
00906   aRemover.Register(filename_para_med1);
00907   aRemover.Register(filename_para_med2);
00908   aRemover.Register(filename_para2_wr);
00909   aRemover.Register(filename_para2_med1);
00910   aRemover.Register(filename_para2_med2);
00911   aRemover.Register(filename_para2_med3);
00912   aRemover.Register(filename_seq_wr);
00913   aRemover.Register(filename_seq_wr+".xml");
00914   aRemover.Register(filename_seq_med);
00915   
00916   
00917   string meshname="maa1";
00918   MESHCollection collection(filename_rd,meshname);
00919   Topology* topo2;
00920 #ifdef MED_ENABLE_METIS
00921   CPPUNIT_ASSERT_NO_THROW(topo2 = collection.createPartition(2,Graph::METIS));
00922 #else
00923   CPPUNIT_ASSERT_THROW(topo2 = collection.createPartition(2,Graph::METIS), MEDEXCEPTION);
00924   CPPUNIT_FAIL("METIS is not available, further test execution is not possible.");
00925 #endif
00926   MESHCollection new_collection(collection, topo2);
00927         new_collection.setDriverType(MEDSPLITTER::MedAscii);
00928   new_collection.write(filename_para_wr);
00929     
00930   MESHCollection new_collection2(filename_para_wr);
00931   CPPUNIT_ASSERT_EQUAL(collection.getName(),new_collection2.getName());
00932   Topology* topo3;
00933 #ifdef MED_ENABLE_SCOTCH
00934   CPPUNIT_ASSERT_NO_THROW(topo3 = new_collection2.createPartition(3,Graph::SCOTCH));
00935 #else
00936   CPPUNIT_ASSERT_THROW(topo3 = new_collection2.createPartition(3,Graph::SCOTCH), MEDEXCEPTION);
00937   CPPUNIT_FAIL("SCOTCH is not available, further test execution is not possible.");
00938 #endif
00939   MESHCollection new_collection3(new_collection2,topo3);
00940   CPPUNIT_ASSERT_EQUAL(topo3->nbCells(),topo2->nbCells());
00941         new_collection3.setDriverType(MEDSPLITTER::MedAscii);
00942   new_collection3.write(filename_para2_wr);
00943 
00944   MESHCollection new_collection4(filename_para2_wr);
00945   Topology* topo1=new_collection4.createPartition(1,Graph::METIS);
00946 
00947   MESHCollection new_collection_seq(new_collection4,topo1);
00948   new_collection_seq.write(filename_seq_wr);
00949   MEDMEM::MESH* mesh_after = new_collection_seq.getMesh(0);
00950   MEDMEM::MESH* mesh_before = collection.getMesh(0);
00951   CPPUNIT_ASSERT_EQUAL(mesh_before->getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS), mesh_after->getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS));
00952   CPPUNIT_ASSERT_EQUAL(mesh_before->getNumberOfElements(MED_FACE, MED_ALL_ELEMENTS), mesh_after->getNumberOfElements(MED_FACE, MED_ALL_ELEMENTS));
00953   CPPUNIT_ASSERT_EQUAL(mesh_before->getNumberOfElements(MED_EDGE, MED_ALL_ELEMENTS), mesh_after->getNumberOfElements(MED_EDGE, MED_ALL_ELEMENTS));
00954   CPPUNIT_ASSERT_EQUAL(mesh_before->getNumberOfNodes(), mesh_after->getNumberOfNodes());
00955   delete topo2;
00956   delete topo3;
00957   delete topo1;
00958 }
00959 
00964 void MEDSPLITTERTest::testMESHCollection_complete_sequence_with_polygon()
00965 {
00966   string filename_rd         = MEDSPLITTERTest_Utils::getResourceFile("recoll_bord.med");
00967   string filename_para_wr    = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_para_recoll_");
00968   string filename_para_med1  = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_para_recoll_1.med");
00969   string filename_para_med2  = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_para_recoll_2.med");
00970   string filename_para2_wr   = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_para2_recoll_");
00971   string filename_para2_med1 = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_para2_recoll_1.med");
00972   string filename_para2_med2 = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_para2_recoll_2.med");
00973   string filename_para2_med3 = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_para2_recoll_3.med");
00974   string filename_seq_wr     = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_seq_recoll_");
00975   string filename_seq_med    = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_seq_recoll_1.med");
00976   
00977   
00978   // To remove tmp files from disk
00979   MEDSPLITTERTest_TmpFilesRemover aRemover;
00980         aRemover.Register(filename_para_wr);
00981   aRemover.Register(filename_para_med1);
00982   aRemover.Register(filename_para_med2);
00983   aRemover.Register(filename_para2_wr);
00984   aRemover.Register(filename_para2_med1);
00985   aRemover.Register(filename_para2_med2);
00986   aRemover.Register(filename_para2_med3);
00987   aRemover.Register(filename_seq_wr);
00988   aRemover.Register(filename_seq_wr+".xml");
00989   aRemover.Register(filename_seq_med);
00990   
00991   
00992   string meshname="Bord";
00993   MESHCollection collection(filename_rd,meshname);
00994   Topology* topo2=collection.createPartition(2,Graph::METIS);
00995   MESHCollection new_collection(collection, topo2);
00996   new_collection.setDriverType(MEDSPLITTER::MedAscii);
00997   new_collection.write(filename_para_wr);
00998     
00999   MESHCollection new_collection2(filename_para_wr);
01000   CPPUNIT_ASSERT_EQUAL(collection.getName(),new_collection2.getName());
01001   Topology* topo3=new_collection2.createPartition(3,Graph::SCOTCH);
01002   MESHCollection new_collection3(new_collection2,topo3);
01003   CPPUNIT_ASSERT_EQUAL(topo3->nbCells(),topo2->nbCells());
01004   new_collection3.setDriverType(MEDSPLITTER::MedAscii);
01005   new_collection3.write(filename_para2_wr);
01006 
01007   MESHCollection new_collection4(filename_para2_wr);
01008   Topology* topo1;
01009 #ifdef MED_ENABLE_METIS
01010   CPPUNIT_ASSERT_NO_THROW(topo1 = new_collection4.createPartition(1,Graph::METIS));
01011 #else
01012   CPPUNIT_ASSERT_THROW(topo1 = new_collection4.createPartition(1,Graph::METIS), MEDEXCEPTION);
01013   CPPUNIT_FAIL("METIS is not available, further test execution is not possible.");
01014 #endif
01015 
01016   MESHCollection new_collection_seq(new_collection4,topo1);
01017   new_collection_seq.write(filename_seq_wr);
01018   MEDMEM::MESH* mesh_after = new_collection_seq.getMesh(0);
01019   MEDMEM::MESH* mesh_before = collection.getMesh(0);
01020   CPPUNIT_ASSERT_EQUAL(mesh_before->getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS),
01021                        mesh_after->getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS));
01022   CPPUNIT_ASSERT_EQUAL(mesh_before->getNumberOfElements(MED_FACE, MED_ALL_ELEMENTS),
01023                        mesh_after->getNumberOfElements(MED_FACE, MED_ALL_ELEMENTS));
01024   CPPUNIT_ASSERT_EQUAL(mesh_before->getNumberOfElements(MED_EDGE, MED_ALL_ELEMENTS),
01025                        mesh_after->getNumberOfElements(MED_EDGE, MED_ALL_ELEMENTS));
01026   CPPUNIT_ASSERT_EQUAL(mesh_before->getNumberOfNodes(), mesh_after->getNumberOfNodes());
01027   delete topo2;
01028   delete topo3;
01029   delete topo1;
01030 }
01031 
01036 void MEDSPLITTERTest::testMESHCollection_complete_sequence_with_polyhedra()
01037 {
01038   string filename_rd         = MEDSPLITTERTest_Utils::getResourceFile("poly3D.med");
01039   string filename_para_wr    = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_para_poly3D_");
01040   string filename_para_med1  = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_para_poly3D_1.med");
01041   string filename_para_med2  = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_para_poly3D_2.med");
01042   string filename_para2_wr   = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_para2_poly3D_");
01043   string filename_para2_med1 = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_para2_poly3D_1.med");
01044   string filename_para2_med2 = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_para2_poly3D_2.med");
01045   string filename_para2_med3 = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_para2_poly3D_3.med");
01046   string filename_seq_wr     = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_seq_poly3D_");
01047   string filename_seq_med    = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_seq_poly3D_1.med");
01048   
01049   
01050   // To remove tmp files from disk
01051   MEDSPLITTERTest_TmpFilesRemover aRemover;
01052   aRemover.Register(filename_para_wr);
01053  aRemover.Register(filename_para_med1);
01054   aRemover.Register(filename_para_med2);
01055   aRemover.Register(filename_para2_wr);
01056   aRemover.Register(filename_para2_med1);
01057   aRemover.Register(filename_para2_med2);
01058   aRemover.Register(filename_para2_med3);
01059   aRemover.Register(filename_seq_wr);
01060   aRemover.Register(filename_seq_med);
01061   
01062   
01063   string meshname="poly3D";
01064   MESHCollection collection(filename_rd,meshname);
01065   Topology* topo2=collection.createPartition(2,Graph::METIS);
01066   MESHCollection new_collection(collection, topo2);
01067   new_collection.setDriverType(MEDSPLITTER::MedAscii);
01068   new_collection.write(filename_para_wr);
01069     
01070   MESHCollection new_collection2(filename_para_wr);
01071   CPPUNIT_ASSERT_EQUAL(collection.getName(),new_collection2.getName());
01072   Topology* topo3=new_collection2.createPartition(3,Graph::SCOTCH);
01073   MESHCollection new_collection3(new_collection2,topo3);
01074   CPPUNIT_ASSERT_EQUAL(topo3->nbCells(),topo2->nbCells());
01075   new_collection3.setDriverType(MEDSPLITTER::MedAscii);
01076   new_collection3.write(filename_para2_wr);
01077 
01078   MESHCollection new_collection4(filename_para2_wr);
01079   Topology* topo1=new_collection4.createPartition(1,Graph::METIS);
01080 
01081   MESHCollection new_collection_seq(new_collection4,topo1);
01082   new_collection_seq.write(filename_seq_wr);
01083   MEDMEM::MESH* mesh_after = new_collection_seq.getMesh(0);
01084   MEDMEM::MESH* mesh_before = collection.getMesh(0);
01085   CPPUNIT_ASSERT_EQUAL(mesh_before->getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS), mesh_after->getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS));
01086   CPPUNIT_ASSERT_EQUAL(mesh_before->getNumberOfElements(MED_FACE, MED_ALL_ELEMENTS), mesh_after->getNumberOfElements(MED_FACE, MED_ALL_ELEMENTS));
01087   CPPUNIT_ASSERT_EQUAL(mesh_before->getNumberOfElements(MED_EDGE, MED_ALL_ELEMENTS), mesh_after->getNumberOfElements(MED_EDGE, MED_ALL_ELEMENTS));
01088   CPPUNIT_ASSERT_EQUAL(mesh_before->getNumberOfNodes(), mesh_after->getNumberOfNodes());
01089   delete topo2;
01090   delete topo3;
01091   delete topo1;
01092 }
01093 
01099 void MEDSPLITTERTest::testMESHCollection_families()
01100 {
01101   string filename_rd   = MEDSPLITTERTest_Utils::getResourceFile("trio_2D.med");
01102   string filename_wr   = MEDSPLITTERTest_Utils::makeTmpFile("trio_split_faces");
01103   string filename_wr_1 = MEDSPLITTERTest_Utils::makeTmpFile("trio_split_faces1.med");
01104   string filename_wr_2 = MEDSPLITTERTest_Utils::makeTmpFile("trio_split_faces2.med");
01105   
01106   // To remove tmp files from disk
01107   MEDSPLITTERTest_TmpFilesRemover aRemover;
01108   aRemover.Register(filename_wr);
01109   aRemover.Register(filename_wr+".xml");
01110   aRemover.Register(filename_wr_1);
01111   aRemover.Register(filename_wr_2);
01112   
01113   char meshname[30]  = "dom";
01114   char meshname1[30]  = "dom_1";
01115   char meshname2[30]  = "dom_2";
01116 
01117 
01118   MESHCollection* collection = new MESHCollection (filename_rd,meshname);
01119   MEDSPLITTER::Topology* topo = collection->createPartition(2,Graph::METIS);
01120   MESHCollection* new_collection = new MESHCollection (*collection, topo, true, true);
01121   new_collection->setSubdomainBoundaryCreates(true);
01122   //collection.write("/export/home/test_splitter");
01123   new_collection->write(filename_wr);
01124   new_collection->castAllFields(*collection);
01125 
01126   delete topo;
01127   delete collection;       
01128   delete new_collection;
01129 
01130   MEDMEM::MESH mesh1(MEDMEM::MED_DRIVER, filename_wr_1, meshname1);
01131   MEDMEM::MESH mesh2(MEDMEM::MED_DRIVER, filename_wr_2, meshname2);
01132 
01133   // testing number of elements for each partition
01134   int nbelem1=mesh1.getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS);
01135   int nbelem2=mesh2.getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS);
01136 
01137   CPPUNIT_ASSERT_EQUAL(nbelem1+nbelem2,2020);
01138 
01139 
01140 
01141   //testing number of joints
01142   med_2_3::med_idt fid1 = med_2_3::MEDfileOpen(filename_wr_1.c_str(),med_2_3::MED_ACC_RDONLY);
01143   med_2_3::med_idt fid2 = med_2_3::MEDfileOpen(filename_wr_2.c_str(),med_2_3::MED_ACC_RDONLY);
01144   int nj1= med_2_3::MEDnSubdomainJoint(fid1, meshname1);
01145   int nj2= med_2_3::MEDnSubdomainJoint(fid2, meshname2);
01146   CPPUNIT_ASSERT_EQUAL(nj1,1);
01147   CPPUNIT_ASSERT_EQUAL(nj2,1);
01148 
01149   //testing distant domains
01150 
01151   char desc1[MED_COMMENT_SIZE+1];
01152   char maa_dist1[MED_NAME_SIZE+1], jn1[MED_NAME_SIZE+1];
01153   char desc2[MED_COMMENT_SIZE+1], maa_dist2[MED_NAME_SIZE+1], jn2[MED_NAME_SIZE+1];
01154   int dom1, dom2;
01155   int nstep,nocstp;
01156   med_2_3::MEDsubdomainJointInfo(fid1, meshname1, 1, jn1, desc1, &dom1, maa_dist1, &nstep, &nocstp);
01157   med_2_3::MEDsubdomainJointInfo(fid2, meshname2, 1, jn2, desc2, &dom2, maa_dist2, &nstep, &nocstp);
01158   CPPUNIT_ASSERT_EQUAL(dom1,1);
01159   CPPUNIT_ASSERT_EQUAL(dom2,0);
01160 
01161 
01162   int nbEdgesFamilies1= med_2_3::MEDnFamily(fid1, meshname1);
01163   int nbEdgesFamilies2= med_2_3::MEDnFamily(fid2, meshname2);
01164 
01165   CPPUNIT_ASSERT_EQUAL(nbEdgesFamilies1,7); // six initial families + a joint
01166   CPPUNIT_ASSERT_EQUAL(nbEdgesFamilies2,7); // six initial families + a joint
01167 
01168   // EAP 16 Apr 2012: order of families is actually unpredictable
01169   // string fam_name = mesh1.getFamily(MED_EN::MED_EDGE,1)->getName();
01170   // char test_name[MED_NAME_SIZE+1]="Sortie";
01171   // CPPUNIT_ASSERT(strcmp(fam_name.c_str(),test_name)==0);
01172 
01173 }