Back to index

salome-med  6.5.0
MEDMEMTest_Remapper.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
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 "MEDMEMTest.hxx"
00021 
00022 #include "MEDMEM_Remapper.hxx"
00023 #include "MEDMEM_Meshing.hxx"
00024 
00025 #include "MEDNormalizedUnstructuredMesh.txx"
00026 #include "Interpolation3D.txx"
00027 
00028 #include <cppunit/TestAssert.h>
00029 #include <iostream>
00030 //#include <vector>
00031 
00032 // namespace MEDMEMTest
00033 // {
00034 void MEDMEMTest::test_RemapperP0P0() 
00035 {
00036   std::string sourcename=getResourceFile("square1.med");
00037   MEDMEM::MESH *source_mesh=new MEDMEM::MESH (MED_DRIVER,sourcename,"Mesh_2");
00038 
00039   std::string targetname=getResourceFile("square2.med");
00040   MEDMEM::MESH *target_mesh=new MEDMEM::MESH (MED_DRIVER,targetname,"Mesh_3");
00041 
00042   int nbcomp=3;
00043 
00044   const MEDMEM::SUPPORT *source_support=source_mesh->getSupportOnAll( MED_EN::MED_CELL );
00045   MEDMEM::FIELD<double> *source_field=new MEDMEM::FIELD<double>(source_support,nbcomp);
00046   double* sourcevalue=const_cast<double*>(source_field->getValue());
00047   for (int i=0; i<source_support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)*nbcomp; i++)
00048     sourcevalue[i]=1.0;
00049 
00050   const MEDMEM::SUPPORT *target_support=target_mesh->getSupportOnAll( MED_EN::MED_CELL );
00051   MEDMEM::FIELD<double> *target_field=new MEDMEM::FIELD<double>(target_support,nbcomp);
00052   double* targetvalue=const_cast<double*>(target_field->getValue());
00053   for (int i=0; i<target_support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)*nbcomp; i++)
00054     targetvalue[i]=0.0;
00055 
00056 
00057   MEDMEM_REMAPPER remapper;
00058   const std::string intersectiontype = "IntersectionType";
00059   std::string convex = "Convex";
00060   remapper.setOptionDouble("Precision",1.e-8);
00061   remapper.setOptionString(intersectiontype,convex);
00062   remapper.setOptionInt("PrintLevel",1);
00063   remapper.prepare(*source_mesh,*target_mesh,"P0P0");
00064   remapper.transfer(*source_field,*target_field);
00065 
00066   //MN: Old tests
00067   MEDMEM::FIELD<double> *source_areas=source_mesh->getArea(source_support);
00068   MEDMEM::FIELD<double> *target_areas=target_mesh->getArea(target_support);
00069   //MEDMEMTest::absField(*source_areas); //absolute value
00070   //MEDMEMTest::absField(*target_areas); //absolute value
00071 
00072   //target square is in reverse order as compared to initial square
00073   double source_integral=source_field->normL2(nbcomp,source_areas);
00074   double target_integral=target_field->normL2(nbcomp,target_areas);
00075 
00076   CPPUNIT_ASSERT_DOUBLES_EQUAL(source_integral,target_integral,1e-10);
00077 
00078   //MN: Transfer test
00079   double max = -2;
00080   double min =  2;
00081   for(int i = 0; i<target_support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)*nbcomp; i++)
00082     {
00083       if( targetvalue[i] >max) max = targetvalue[i];
00084       if( targetvalue[i] <min) min = targetvalue[i];
00085     }
00086 
00087   CPPUNIT_ASSERT_DOUBLES_EQUAL(1,max,1e-10);
00088   CPPUNIT_ASSERT_DOUBLES_EQUAL(1,min,1e-10);
00089 
00090   //MN: Reverse transfer test
00091   remapper.reverseTransfer(*source_field,*target_field);
00092 
00093   max = -2;
00094   min =  2;
00095   for(int i = 0; i<source_support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)*nbcomp; i++)
00096     {
00097       if( sourcevalue[i] >max) max = sourcevalue[i];
00098       if( sourcevalue[i] <min) min = sourcevalue[i];
00099     }
00100 
00101   CPPUNIT_ASSERT_DOUBLES_EQUAL(1,max,1e-10);
00102   CPPUNIT_ASSERT_DOUBLES_EQUAL(1,min,1e-10);
00103 
00104   //MN: Hxx2salome transfer test
00105   MEDMEM::FIELD<double> *newTargetField =remapper.transferField(*source_field);
00106   MEDMEM::FIELD<double> *newSourceField =remapper.reverseTransferField(*target_field);
00107   sourcevalue=const_cast<double*>((*newSourceField).getValue());
00108   targetvalue=const_cast<double*>((*newTargetField).getValue());
00109   max = -2;
00110   min =  2;
00111   for(int i = 0; i<source_support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)*nbcomp; i++)
00112     {
00113       if( sourcevalue[i] >max) max = sourcevalue[i];
00114       if( sourcevalue[i] <min) min = sourcevalue[i];
00115     }
00116 
00117   CPPUNIT_ASSERT_DOUBLES_EQUAL(1,max,1e-10);
00118   CPPUNIT_ASSERT_DOUBLES_EQUAL(1,min,1e-10);    
00119   for(int i = 0; i<target_support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)*nbcomp; i++)
00120     {
00121       if( targetvalue[i] >max) max = targetvalue[i];
00122       if( targetvalue[i] <min) min = targetvalue[i];
00123     }
00124 
00125   CPPUNIT_ASSERT_DOUBLES_EQUAL(1,max,1e-10);
00126   CPPUNIT_ASSERT_DOUBLES_EQUAL(1,min,1e-10);
00127   source_field->removeReference();
00128   newSourceField->removeReference();
00129   newTargetField->removeReference();
00130   target_mesh->removeReference();
00131   source_areas->removeReference();
00132   target_areas->removeReference();
00133   target_field->removeReference();
00134   source_mesh->removeReference();
00135 }
00136 
00137 void  MEDMEMTest::test_RemapperP1P1() 
00138 {
00139   std::string sourcename=getResourceFile("square1.med");
00140   MEDMEM::MESH *source_mesh=new MEDMEM::MESH (MED_DRIVER,sourcename,"Mesh_2");
00141 
00142   std::string targetname=getResourceFile("square2.med");
00143   MEDMEM::MESH *target_mesh=new MEDMEM::MESH (MED_DRIVER,targetname,"Mesh_3");
00144 
00145   int nbcomp=2;
00146 
00147   const MEDMEM::SUPPORT *source_support=source_mesh->getSupportOnAll( MED_EN::MED_NODE );
00148   MEDMEM::FIELD<double> *source_field=new MEDMEM::FIELD<double>(source_support,nbcomp);
00149   double* sourcevalue=const_cast<double*>(source_field->getValue());
00150   for (int i=0; i<source_support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)*nbcomp; i++)
00151     sourcevalue[i]=1.0;
00152 
00153   const MEDMEM::SUPPORT *target_support=target_mesh->getSupportOnAll( MED_EN::MED_NODE );
00154   MEDMEM::FIELD<double> *target_field=new MEDMEM::FIELD<double>(target_support,nbcomp);
00155   double* targetvalue=const_cast<double*>(target_field->getValue());
00156   for (int i=0; i<target_support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)*nbcomp; i++)
00157     targetvalue[i]=-0.0001;
00158 
00159 
00160   MEDMEM_REMAPPER remapper;
00161   remapper.prepare(*source_mesh,*target_mesh,"P1P1");
00162   remapper.transfer(*source_field,*target_field);
00163 
00164   double max = -2;
00165   double min =  2;
00166   for(int i = 0; i<target_support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)*nbcomp; i++)
00167     {
00168       if( targetvalue[i] >max) max = targetvalue[i];
00169       if( targetvalue[i] <min) min = targetvalue[i];
00170     }
00171 
00172   CPPUNIT_ASSERT_DOUBLES_EQUAL(1,max,1e-10);
00173   CPPUNIT_ASSERT_DOUBLES_EQUAL(1,min,1e-10);
00174 
00175   remapper.reverseTransfer(*source_field,*target_field);
00176 
00177   max = -2;
00178   min =  2;
00179   for(int i = 0; i<source_support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)*nbcomp; i++)
00180     {
00181       if( sourcevalue[i] >max) max = sourcevalue[i];
00182       if( sourcevalue[i] <min) min = sourcevalue[i];
00183     }
00184   CPPUNIT_ASSERT_DOUBLES_EQUAL(1,max,1e-10);
00185   CPPUNIT_ASSERT_DOUBLES_EQUAL(1,min,1e-10);
00186   source_field->removeReference();
00187   source_mesh->removeReference();
00188   target_field->removeReference();
00189   target_mesh->removeReference();
00190 }
00191 
00192 
00193 void  MEDMEMTest::test_RemapperP1P0() 
00194 {
00195   std::string sourcename=getResourceFile("square1.med");
00196   MEDMEM::MESH *source_mesh=new MEDMEM::MESH (MED_DRIVER,sourcename,"Mesh_2");
00197 
00198   std::string targetname=getResourceFile("square2.med");
00199   MEDMEM::MESH *target_mesh=new MEDMEM::MESH (MED_DRIVER,targetname,"Mesh_3");
00200 
00201   int nbcomp=3;
00202   const MEDMEM::SUPPORT *source_support=source_mesh->getSupportOnAll( MED_EN::MED_NODE );
00203   MEDMEM::FIELD<double> *source_field=new MEDMEM::FIELD<double>(source_support,nbcomp);
00204   double* sourcevalue=const_cast<double*>(source_field->getValue());
00205   for (int i=0; i<source_support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)*nbcomp; i++)
00206     sourcevalue[i]=1.0;
00207 
00208   const MEDMEM::SUPPORT *target_support=target_mesh->getSupportOnAll( MED_EN::MED_CELL );
00209   MEDMEM::FIELD<double> *target_field=new MEDMEM::FIELD<double>(target_support,nbcomp);
00210   double* targetvalue=const_cast<double*>(target_field->getValue());
00211   for (int i=0; i<target_support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)*nbcomp; i++)
00212     targetvalue[i]=0.0;
00213 
00214 
00215   MEDMEM_REMAPPER remapper;
00216   remapper.prepare(*source_mesh,*target_mesh,"P1P0");
00217   target_mesh->removeReference();
00218   source_mesh->removeReference();
00219   remapper.transfer(*source_field,*target_field);
00220 
00221   double max = -2;
00222   double min =  2;
00223   for(int i = 0; i<target_support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)*nbcomp; i++)
00224     {
00225       if( targetvalue[i] >max) max = targetvalue[i];
00226       if( targetvalue[i] <min) min = targetvalue[i];
00227     }
00228 
00229   CPPUNIT_ASSERT_DOUBLES_EQUAL(1,max,1e-10);
00230   CPPUNIT_ASSERT_DOUBLES_EQUAL(1,min,1e-10);
00231 
00232   remapper.reverseTransfer(*source_field,*target_field);
00233   max = -2;
00234   min =  2;
00235   for(int i = 0; i<source_support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)*nbcomp; i++)
00236     {
00237       if( sourcevalue[i] >max) max = sourcevalue[i];
00238       if( sourcevalue[i] <min) min = sourcevalue[i];
00239     }
00240 
00241   CPPUNIT_ASSERT_DOUBLES_EQUAL(1,max,1e-10);
00242   CPPUNIT_ASSERT_DOUBLES_EQUAL(1,min,1e-10);
00243   source_field->removeReference();
00244   target_field->removeReference();
00245 }
00246 
00247 void  MEDMEMTest::test_RemapperP0P1() 
00248 {
00249   std::string sourcename=getResourceFile("square1.med");
00250   MEDMEM::MESH *source_mesh=new MEDMEM::MESH (MED_DRIVER,sourcename,"Mesh_2");
00251 
00252   std::string targetname=getResourceFile("square2.med");
00253   MEDMEM::MESH *target_mesh=new MEDMEM::MESH (MED_DRIVER,targetname,"Mesh_3");
00254 
00255   int nbcomp=4;
00256   const MEDMEM::SUPPORT *source_support=source_mesh->getSupportOnAll( MED_EN::MED_CELL );
00257   MEDMEM::FIELD<double> *source_field=new MEDMEM::FIELD<double>(source_support,nbcomp);
00258   double* sourcevalue=const_cast<double*>(source_field->getValue());
00259   for (int i=0; i<source_support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)*nbcomp; i++)
00260     sourcevalue[i]=1.0;
00261 
00262   const MEDMEM::SUPPORT *target_support=target_mesh->getSupportOnAll( MED_EN::MED_NODE );
00263   MEDMEM::FIELD<double> *target_field=new MEDMEM::FIELD<double>(target_support,nbcomp);
00264   double* targetvalue=const_cast<double*>(target_field->getValue());
00265   for (int i=0; i<target_support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)*nbcomp; i++)
00266     targetvalue[i]=0.0;
00267 
00268 
00269   MEDMEM_REMAPPER remapper;
00270   remapper.prepare(*source_mesh,*target_mesh,"P0P1");
00271   remapper.transfer(*source_field,*target_field);
00272 
00273   double max = -2;
00274   double min =  2;
00275   for(int i = 0; i<target_support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)*nbcomp; i++)
00276     {
00277       if( targetvalue[i] >max) max = targetvalue[i];
00278       if( targetvalue[i] <min) min = targetvalue[i];
00279     }
00280 
00281   CPPUNIT_ASSERT_DOUBLES_EQUAL(1,max,1e-10);
00282   CPPUNIT_ASSERT_DOUBLES_EQUAL(1,min,1e-10);
00283 
00284   remapper.reverseTransfer(*source_field,*target_field);
00285 
00286   max = -2;
00287   min =  2;
00288   for(int i = 0; i<source_support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)*nbcomp; i++)
00289     {
00290       if( sourcevalue[i] >max) max = sourcevalue[i];
00291       if( sourcevalue[i] <min) min = sourcevalue[i];
00292     }
00293 
00294   CPPUNIT_ASSERT_DOUBLES_EQUAL(1,max,1e-10);
00295   CPPUNIT_ASSERT_DOUBLES_EQUAL(1,min,1e-10);
00296   source_field->removeReference();
00297   target_field->removeReference();
00298   target_mesh->removeReference();
00299   source_mesh->removeReference();
00300 }
00301 
00302 namespace
00303 {
00304   MESH * build3DSourceMesh1()
00305   {
00306     const double coords[84]=
00307       {
00308         100.0, 100.0, 0.0, 100.0, 100.0, 100.0, 100.0, 0.0, 100.0, 100.0, 0.0, 0.0, 0.0, 100.0, 0.0,
00309         0.0, 100.0, 100.0, 0.0, 0.0, 100.0, 0.0, 0.0, 0.0, 100.0, 100.0, 200.0, 100.0, 0.0, 200.0,
00310         0.0, 100.0, 200.0, 0.0, 0.0, 200.0, 100.0, 200.0, 0.0, 100.0, 200.0, 100.0, 0.0, 200.0, 0.0,
00311         0.0, 200.0, 100.0, 100.0, 200.0, 200.0, 0.0, 200.0, 200.0, 200.0, 100.0, 0.0, 200.0, 100.00000000833332,
00312         100.00000000833332, 200.0, 0.0, 100.0, 200.0, 0.0, 0.0, 200.0, 100.0, 200.0, 200.0, 0.0, 200.0, 200.0,
00313         200.0, 0.0, 200.0, 200.0, 100.0, 200.0, 200.0, 200.0, 149.999999970343, 149.9999999874621, 49.999999881628682
00314       };
00315 
00316     const int conn[212]=
00317       {
00318         26, 28, 14, 20, 19, 4, 21, 22, 6, 11, 18, 2, 2, 4, 1, 8, 19, 2, 1, 28, 13, 28, 14, 25,
00319         26, 20, 17, 27, 2, 3, 7, 9, 16, 14, 13, 6, 25, 14, 26, 28, 11, 12, 10, 7, 20, 9, 24, 2,
00320         23, 9, 24, 20, 17, 14, 18, 2, 7, 10, 11, 9, 14, 18, 6, 16, 6, 5, 2, 13, 19, 1, 25, 28,
00321         20, 21, 19, 2, 8, 7, 6, 2, 5, 13, 16, 15, 26, 28, 20, 19, 2, 20, 17, 14, 21, 20, 24, 2,
00322         28, 13, 2, 1, 7, 6, 2, 11, 5, 6, 2, 8, 13, 28, 2, 14, 6, 16, 5, 13, 20, 17, 27, 23, 14,
00323         6, 18, 2, 2, 4, 8, 3, 14, 6, 2, 13, 19, 2, 4, 1, 9, 24, 3, 10, 4, 2, 19, 21, 2, 28, 20,
00324         14, 25, 26, 19, 28, 26, 17, 20, 14, 8, 2, 3, 7, 4, 2, 21, 3, 9, 17, 18, 2, 8, 5, 1, 2, 19,
00325         20, 2, 28, 28, 13, 1, 25, 10, 7, 3, 9, 2, 5, 1, 13, 20, 17, 23, 9, 9, 3, 24, 2, 2, 17, 20,
00326         9, 21, 3, 2, 24, 11, 2, 7, 9, 11, 9, 18, 2
00327       };
00328     MESHING* meshing = new MESHING;
00329     meshing->setName( "TESTMESH" );
00330     const int nNodes=28;
00331     meshing->setCoordinates(3, nNodes, coords, "CARTESIAN", MED_EN::MED_FULL_INTERLACE);
00332     std::string coordname[3] = { "x", "y", "z" };
00333     meshing->setCoordinatesNames(coordname);
00334     std::string coordunit[3] = 
00335       {
00336         "m", "m", "m" 
00337       };
00338     meshing->setCoordinatesUnits(coordunit);
00339     //Cell connectivity info for classical elts
00340     const MED_EN::medGeometryElement classicalTypesCell[1]={MED_EN::MED_TETRA4};
00341     const int nbOfCellElts[1]={53};
00342     meshing->setNumberOfTypes(1,MED_EN::MED_CELL);
00343     meshing->setTypes(classicalTypesCell,MED_EN::MED_CELL);
00344     meshing->setNumberOfElements(nbOfCellElts,MED_EN::MED_CELL);
00345     //All cell conn
00346     meshing->setConnectivity(MED_EN::MED_CELL,MED_EN::MED_TETRA4,conn);
00347     return meshing;
00348   }
00349 
00350   MESH * build3DTargetMesh1()
00351   {
00352     const double coords[24]=
00353       {
00354         200.0, 200.0, 0.0, 200.0, 200.0, 200.0, 200.0, 0.0, 0.0, 200.0, 0.0, 200.0,
00355         0.0, 200.0, 0.0, 0.0, 200.0, 200.0, 0.0, 0.0, 0.0, 0.0, 0.0, 200.0
00356       };
00357 
00358     const int conn[20]=
00359       {
00360         6, 7, 4, 1, 2, 4, 1, 6, 4, 7, 6, 8, 7, 5, 1, 6, 7, 4, 1, 3
00361       };
00362 
00363     MESHING* meshing = new MESHING;
00364     meshing->setName( "TESTMESH" );
00365     const int nNodes=8;
00366     meshing->setCoordinates(3, nNodes, coords, "CARTESIAN",MED_EN::MED_FULL_INTERLACE);
00367     std::string coordname[3] = { "x", "y", "z" };
00368     meshing->setCoordinatesNames(coordname);
00369     std::string coordunit[3] = 
00370       {
00371         "m", "m", "m" 
00372       };
00373     meshing->setCoordinatesUnits(coordunit);
00374     //Cell connectivity info for classical elts
00375     const MED_EN::medGeometryElement classicalTypesCell[1]={MED_EN::MED_TETRA4};
00376     const int nbOfCellElts[1]={5};
00377     meshing->setNumberOfTypes(1,MED_EN::MED_CELL);
00378     meshing->setTypes(classicalTypesCell,MED_EN::MED_CELL);
00379     meshing->setNumberOfElements(nbOfCellElts,MED_EN::MED_CELL);
00380     //All cell conn
00381     meshing->setConnectivity(MED_EN::MED_CELL,MED_EN::MED_TETRA4,conn);
00382     return meshing;
00383   }
00384 
00385   MESH * build1DTargetMesh1()
00386   {
00387     double coords[36]=
00388       {
00389         25.,25.,0., 25.,25.,50., 25.,25.,200., 75.,25.,0., 75.,25.,50., 75.,25.,200.,
00390         25.,125.,0., 25.,125.,50., 25.,125.,200., 125.,125.,0., 125.,125.,50., 125.,125.,200.
00391       };
00392     const int conn[16]=
00393       {
00394         1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 8, 9, 10, 11, 11, 12
00395       };
00396     MESHING* meshing = new MESHING;
00397     meshing->setName( "TESTMESH" );
00398     const int nNodes=12;
00399     meshing->setCoordinates(3, nNodes, coords, "CARTESIAN",MED_EN::MED_FULL_INTERLACE);
00400     string coordname[3] = { "x", "y", "z" };
00401     meshing->setCoordinatesNames(coordname);
00402     string coordunit[3] = 
00403       {
00404         "m", "m", "m" 
00405       };
00406     meshing->setCoordinatesUnits(coordunit);
00407     //Cell connectivity info for classical elts
00408     const MED_EN::medGeometryElement classicalTypesCell[1]={MED_EN::MED_SEG2};
00409     const int nbOfCellElts[1]={8};
00410     meshing->setNumberOfTypes(1,MED_EN::MED_CELL);
00411     meshing->setTypes(classicalTypesCell,MED_EN::MED_CELL);
00412     meshing->setNumberOfElements(nbOfCellElts,MED_EN::MED_CELL);
00413     //All cell conn
00414     meshing->setConnectivity(MED_EN::MED_CELL,MED_EN::MED_SEG2,conn);
00415     return meshing;
00416   }
00417 
00418   MESH * build3DSourceMesh2()
00419   {
00420     double coords[27]=
00421       {
00422         0.0, 0.0, 200.0, 0.0, 0.0, 0.0, 0.0, 200.0, 200.0, 0.0, 200.0, 0.0, 200.0, 0.0, 200.0,
00423         200.0, 0.0, 0.0, 200.0, 200.0, 200.0, 200.0, 200.0, 0.0, 100.0, 100.0, 100.0 
00424       };
00425     int conn[48]=
00426       {
00427         9, 2, 8, 4, 7, 1, 9, 3, 8, 5, 6, 9, 7, 9, 5, 8, 7, 9, 1, 5, 7, 9, 8, 4, 9, 2, 4, 1, 5, 2, 6, 9, 2, 8, 6, 9, 1, 4, 9, 3, 9, 2, 1, 5, 4, 7, 9, 3
00428       };
00429     MESHING* meshing = new MESHING;
00430     meshing->setName( "TESTMESH" );
00431     const int nNodes=9;
00432     meshing->setCoordinates(3, nNodes, coords, "CARTESIAN",MED_EN::MED_FULL_INTERLACE);
00433     string coordname[3] = { "x", "y", "z" };
00434     meshing->setCoordinatesNames(coordname);
00435     string coordunit[3] = 
00436       {
00437         "m", "m", "m" 
00438       };
00439     meshing->setCoordinatesUnits(coordunit);
00440     //Cell connectivity info for classical elts
00441     const MED_EN::medGeometryElement classicalTypesCell[1]={MED_EN::MED_TETRA4};
00442     const int nbOfCellElts[1]={12};
00443     meshing->setNumberOfTypes(1,MED_EN::MED_CELL);
00444     meshing->setTypes(classicalTypesCell,MED_EN::MED_CELL);
00445     meshing->setNumberOfElements(nbOfCellElts,MED_EN::MED_CELL);
00446     //
00447     const MED_EN::medGeometryElement classicalTypesFace[1]={MED_EN::MED_TRIA3};
00448     const int nbOfFaceElts[1]={1};
00449     meshing->setNumberOfTypes(1,MED_EN::MED_FACE);
00450     meshing->setTypes(classicalTypesFace,MED_EN::MED_FACE);
00451     meshing->setNumberOfElements(nbOfFaceElts,MED_EN::MED_FACE);
00452     //All cell conn
00453     meshing->setConnectivity(MED_EN::MED_CELL,MED_EN::MED_TETRA4,conn);
00454     meshing->setConnectivity(MED_EN::MED_FACE,MED_EN::MED_TRIA3,conn);
00455     return meshing;
00456   }
00457 
00458   MESH * build3DTargetMesh2()
00459   {
00460     double coords[81]=
00461       {
00462         0., 0., 0., 50., 0., 0. , 200., 0., 0.  , 0., 50., 0., 50., 50., 0. , 200., 50., 0.,   0., 200., 0., 50., 200., 0. , 200., 200., 0. ,
00463         0., 0., 50., 50., 0., 50. , 200., 0., 50.  , 0., 50., 50., 50., 50., 50. , 200., 50., 50.,   0., 200., 50., 50., 200., 50. , 200., 200., 50. ,
00464         0., 0., 200., 50., 0., 200. , 200., 0., 200.  , 0., 50., 200., 50., 50., 200. , 200., 50., 200.,   0., 200., 200., 50., 200., 200. , 200., 200., 200. 
00465       };
00466     int conn[64]=
00467       {
00468         1, 2, 5, 4, 10, 11, 14, 13, 2, 3, 6, 5, 11, 12, 15, 14, 4, 5, 8, 7, 13, 14, 17, 16, 5, 6, 9, 8, 14, 15, 18,
00469         17, 10, 11, 14, 13, 19, 20, 23, 22, 11, 12, 15, 14, 20, 21, 24, 23, 13, 14, 17, 16, 22, 23, 26, 25, 14, 15, 18, 17, 23, 24, 27, 26
00470       };
00471     MESHING* meshing = new MESHING;
00472     meshing->setName( "TESTMESH" );
00473     const int nNodes=27;
00474     meshing->setCoordinates(3, nNodes, coords, "CARTESIAN",MED_EN::MED_FULL_INTERLACE);
00475     string coordname[3] = { "x", "y", "z" };
00476     meshing->setCoordinatesNames(coordname);
00477     string coordunit[3] = 
00478       {
00479         "m", "m", "m" 
00480       };
00481     meshing->setCoordinatesUnits(coordunit);
00482     //Cell connectivity info for classical elts
00483     const MED_EN::medGeometryElement classicalTypesCell[1]={MED_EN::MED_HEXA8};
00484     const int nbOfCellElts[1]={8};
00485     meshing->setNumberOfTypes(1,MED_EN::MED_CELL);
00486     meshing->setTypes(classicalTypesCell,MED_EN::MED_CELL);
00487     meshing->setNumberOfElements(nbOfCellElts,MED_EN::MED_CELL);
00488     //
00489     const MED_EN::medGeometryElement classicalTypesFace[1]={MED_EN::MED_QUAD4};
00490     const int nbOfFaceElts[1]={1};
00491     meshing->setNumberOfTypes(1,MED_EN::MED_FACE);
00492     meshing->setTypes(classicalTypesFace,MED_EN::MED_FACE);
00493     meshing->setNumberOfElements(nbOfFaceElts,MED_EN::MED_FACE);
00494     //All cell conn
00495     meshing->setConnectivity(MED_EN::MED_CELL,MED_EN::MED_HEXA8,conn);
00496     meshing->setConnectivity(MED_EN::MED_FACE,MED_EN::MED_QUAD4,conn);
00497     return meshing;
00498   }
00499 
00500   MESH * build3DSourceMesh2Poly()
00501   {
00502     double coords[27]={ 0.0, 0.0, 200.0, 0.0, 0.0, 0.0, 0.0, 200.0, 200.0, 0.0, 200.0, 0.0, 200.0, 0.0, 200.0,
00503                             200.0, 0.0, 0.0, 200.0, 200.0, 200.0, 200.0, 200.0, 0.0, 100.0, 100.0, 100.0 };
00504     int conn[40]={9, 2, 8, 4, 7, 1, 9, 3, 8, 5, 6, 9, 7, 9, 5, 8, 7, 9, 1, 5, 7, 9, 8, 4, 9, 2, 4, 1, 5, 2, 6, 9, 2, 8, 6, 9, 1, 4, 9, 3};
00505     int connPoly1[3]={1,16,31};
00506     int connPoly2[30]={9, 2, 1, -1, 9, 5, 2, -1, 2, 5, 1, -1, 1, 5, 9,
00507                        4, 7, 9, -1, 4, 3, 7, -1, 7, 3, 9, -1, 9, 3, 4};
00508     MESHING* meshing = new MESHING;
00509     meshing->setName( "TESTMESH" );
00510     const int nNodes=9;
00511     meshing->setCoordinates(3, nNodes, coords, "CARTESIAN",MED_EN::MED_FULL_INTERLACE);
00512     string coordname[3] = { "x", "y", "z" };
00513     meshing->setCoordinatesNames(coordname);
00514     string coordunit[3] = 
00515       {
00516         "m", "m", "m" 
00517       };
00518     meshing->setCoordinatesUnits(coordunit);
00519     //Cell connectivity info for classical elts
00520     const MED_EN::medGeometryElement typesCell[2]={MED_EN::MED_TETRA4,MED_EN::MED_POLYHEDRA};
00521     const int nbOfCellElts[2]={10,2};
00522     meshing->setNumberOfTypes(2,MED_EN::MED_CELL);
00523     meshing->setTypes(typesCell,MED_EN::MED_CELL);
00524     meshing->setNumberOfElements(nbOfCellElts,MED_EN::MED_CELL);
00525     //All cell conn
00526     meshing->setConnectivity(MED_EN::MED_CELL,MED_EN::MED_TETRA4,conn);
00527     meshing->setConnectivity(MED_EN::MED_CELL,MED_EN::MED_POLYHEDRA,connPoly2,connPoly1);
00528     return meshing;
00529   }
00530 
00531   MESH * build3DTargetMesh2Poly()
00532   {
00533     double coords[81]={ 0., 0., 0., 50., 0., 0. , 200., 0., 0.  , 0., 50., 0., 50., 50., 0. , 200., 50., 0.,   0., 200., 0., 50., 200., 0. , 200., 200., 0. ,
00534                         0., 0., 50., 50., 0., 50. , 200., 0., 50.  , 0., 50., 50., 50., 50., 50. , 200., 50., 50.,   0., 200., 50., 50., 200., 50. , 200., 200., 50. ,
00535                         0., 0., 200., 50., 0., 200. , 200., 0., 200.  , 0., 50., 200., 50., 50., 200. , 200., 50., 200.,   0., 200., 200., 50., 200., 200. , 200., 200., 200. };
00536     int conn[56]={1, 2, 5, 4, 10, 11, 14, 13, 2, 3, 6, 5, 11, 12, 15, 14, 4, 5, 8, 7, 13, 14, 17, 16, 5, 6, 9, 8, 14, 15, 18,
00537                   17, 10, 11, 14, 13, 19, 20, 23, 22, 11, 12, 15, 14, 20, 21, 24, 23, 13, 14, 17, 16, 22, 23, 26, 25};
00538     int connPoly1[2]={1,30};
00539     int connPoly3[29]={ 14, 15, 18, 17, -1, 23, 26, 27, 24, -1, 14, 23, 24, 15, -1, 15, 24, 27, 18, -1, 18, 27, 26, 17, -1, 17, 26, 23, 14};
00540     MESHING* meshing = new MESHING;
00541     meshing->setName( "TESTMESH" );
00542     const int nNodes=27;
00543     meshing->setCoordinates(3, nNodes, coords, "CARTESIAN",MED_EN::MED_FULL_INTERLACE);
00544     string coordname[3] = { "x", "y", "z" };
00545     meshing->setCoordinatesNames(coordname);
00546     string coordunit[3] = 
00547       {
00548         "m", "m", "m" 
00549       };
00550     meshing->setCoordinatesUnits(coordunit);
00551     //Cell connectivity info for classical elts
00552     const MED_EN::medGeometryElement typesCell[2]={MED_EN::MED_HEXA8,MED_EN::MED_POLYHEDRA};
00553     const int nbOfCellElts[2]={7,1};
00554     meshing->setNumberOfTypes(2,MED_EN::MED_CELL);
00555     meshing->setTypes(typesCell,MED_EN::MED_CELL);
00556     meshing->setNumberOfElements(nbOfCellElts,MED_EN::MED_CELL);
00557     //All cell conn
00558     meshing->setConnectivity(MED_EN::MED_CELL,MED_EN::MED_HEXA8,conn);
00559     meshing->setConnectivity(MED_EN::MED_CELL,MED_EN::MED_POLYHEDRA,connPoly3,connPoly1);
00560     return meshing;
00561   }
00562 } // noname namespace
00563 
00564 void MEDMEMTest::test_remapper4()
00565 {
00566   const double valsSrc[28]=
00567     {
00568       1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.,25.,26.,27.,28.
00569     };
00570   const double targetExpected[8]= 
00571     {
00572       16.2061111122415724, 21.8916666665293072, 15.5833333333333321, 13.1613888888184309, 11.8583333333333361, 10.6969444444233712, 4.48388888888888815, 9.42500000000000071
00573     };
00574 
00575   MESH *source=build3DSourceMesh1();
00576   MESH *target=build3DTargetMesh1();
00577   const SUPPORT *supSrc=source->getSupportOnAll( MED_EN::MED_NODE );
00578   FIELD<double> *f1=new MEDMEM::FIELD<double>(supSrc,1);
00579   double *val=(double *)f1->getValue();
00580   std::copy(valsSrc,valsSrc+28,val);
00581   const SUPPORT *supTrg=target->getSupportOnAll( MED_EN::MED_NODE );
00582   FIELD<double> *f2=new FIELD<double>(supTrg,1);
00583   //
00584   MEDMEM_REMAPPER remap;
00585   remap.prepare(*source,*target,"P1P1");
00586   remap.transfer(*f1,*f2);
00587   const double *tmp=f2->getValue();
00588   for(int i=0;i<8;i++)
00589     CPPUNIT_ASSERT_DOUBLES_EQUAL(targetExpected[i],tmp[i],1e-12);
00590   //
00591   source->removeReference();
00592   target->removeReference();
00593   f1->removeReference();
00594   f2->removeReference();
00595 }
00596 
00597 void MEDMEMTest::test_remapper5()
00598 {
00599   MESH *sourceMesh=build3DSourceMesh2();
00600   MESH *targetMesh=build3DTargetMesh2();
00601   MEDNormalizedUnstructuredMesh<3,3> sourceWrapper(sourceMesh);
00602   MEDNormalizedUnstructuredMesh<3,3> targetWrapper(targetMesh);
00603   INTERP_KERNEL::Interpolation3D myInterpolator;
00604   vector<map<int,double> > res;
00605   myInterpolator.setPrecision(1e-12);
00606   myInterpolator.setIntersectionType(INTERP_KERNEL::PointLocator);
00607   myInterpolator.interpolateMeshes(sourceWrapper,targetWrapper,res,"P0P0");
00608   CPPUNIT_ASSERT_EQUAL(8,(int)res.size());
00609   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][1],1e-12);
00610   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][7],1e-12);
00611   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][8],1e-12);
00612   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][9],1e-12);
00613   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][11],1e-12);
00614   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[1][8],1e-12);
00615   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[1][9],1e-12);
00616   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[2][1],1e-12);
00617   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[2][7],1e-12);
00618   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[3][1],1e-12);
00619   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[3][9],1e-12);
00620   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[4][7],1e-12);
00621   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[4][11],1e-12);
00622   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[5][8],1e-12);
00623   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[5][11],1e-12);
00624   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[6][10],1e-12);
00625   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][2],1e-12);
00626   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][4],1e-12);
00627   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][5],1e-12);
00628   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][6],1e-12);
00629   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][12],1e-12);
00630   CPPUNIT_ASSERT_DOUBLES_EQUAL(21.,sumAll(res),1e-12);
00631   res.clear();
00632   //
00633   MEDNormalizedUnstructuredMesh<3,3> sourceWrapper2(targetMesh);
00634   MEDNormalizedUnstructuredMesh<3,3> targetWrapper2(sourceMesh);
00635   INTERP_KERNEL::Interpolation3D myInterpolator2;
00636   myInterpolator2.setPrecision(1e-12);
00637   myInterpolator2.setIntersectionType(INTERP_KERNEL::PointLocator);
00638   myInterpolator2.interpolateMeshes(sourceWrapper2,targetWrapper2,res,"P0P1");
00639   CPPUNIT_ASSERT_EQUAL(9,(int)res.size());
00640   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][5],1e-12);
00641   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[1][1],1e-12);
00642   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[2][7],1e-12);
00643   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[3][3],1e-12);
00644   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[4][6],1e-12);
00645   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[5][2],1e-12);
00646   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[6][8],1e-12);
00647   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][4],1e-12);
00648   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[8][8],1e-12);
00649   CPPUNIT_ASSERT_DOUBLES_EQUAL(9.,sumAll(res),1e-12);
00650   res.clear();
00651   //
00652   myInterpolator.setPrecision(1e-12);
00653   myInterpolator.setIntersectionType(INTERP_KERNEL::PointLocator);
00654   myInterpolator.interpolateMeshes(sourceWrapper,targetWrapper,res,"P1P0");
00655   CPPUNIT_ASSERT_EQUAL(8,(int)res.size());
00656   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.75,res[0][2],1e-12);
00657   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.25,res[0][9],1e-12);
00658   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,res[1][2],1e-12);
00659   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[1][6],1e-12);
00660   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,res[1][9],1e-12);
00661   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,res[2][2],1e-12);
00662   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[2][4],1e-12);
00663   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,res[2][9],1e-12);
00664   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,res[3][2],1e-12);
00665   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[3][8],1e-12);
00666   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,res[3][9],1e-12);
00667   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[4][1],1e-12);
00668   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,res[4][2],1e-12);
00669   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,res[4][9],1e-12);
00670   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,res[5][2],1e-12);
00671   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[5][5],1e-12);
00672   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,res[5][9],1e-12);
00673   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.25,res[6][1],1e-12);
00674   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.25,res[6][3],1e-12);
00675   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.25,res[6][4],1e-12);
00676   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.25,res[6][9],1e-12);
00677   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.25,res[7][7],1e-12);
00678   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.75,res[7][9],1e-12);
00679   CPPUNIT_ASSERT_DOUBLES_EQUAL(21.,sumAll(res),1e-12);
00680   //
00681   targetMesh->removeReference();
00682   sourceMesh->removeReference();
00683 }
00684 
00685 void MEDMEMTest::test_remapper6()
00686 {
00687   MESH *sourceMesh=build3DSourceMesh2Poly();
00688   MESH *targetMesh=build3DTargetMesh2Poly();
00689   MEDNormalizedUnstructuredMesh<3,3> sourceWrapper(sourceMesh);
00690   MEDNormalizedUnstructuredMesh<3,3> targetWrapper(targetMesh);
00691   INTERP_KERNEL::Interpolation3D myInterpolator;
00692   vector<map<int,double> > res;
00693   myInterpolator.setPrecision(1e-12);
00694   myInterpolator.setIntersectionType(INTERP_KERNEL::PointLocator);
00695   myInterpolator.interpolateMeshes(sourceWrapper,targetWrapper,res,"P0P0");
00696   CPPUNIT_ASSERT_EQUAL(8,(int)res.size());
00697   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][1],1e-12);
00698   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][7],1e-12);
00699   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][8],1e-12);
00700   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][9],1e-12);
00701   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][11],1e-12);
00702   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[1][8],1e-12);
00703   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[1][9],1e-12);
00704   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[2][1],1e-12);
00705   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[2][7],1e-12);
00706   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[3][1],1e-12);
00707   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[3][9],1e-12);
00708   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[4][7],1e-12);
00709   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[4][11],1e-12);
00710   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[5][8],1e-12);
00711   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[5][11],1e-12);
00712   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[6][10],1e-12);
00713   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][2],1e-12);
00714   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][4],1e-12);
00715   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][5],1e-12);
00716   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][6],1e-12);
00717   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][12],1e-12);
00718   CPPUNIT_ASSERT_DOUBLES_EQUAL(21.,sumAll(res),1e-12);
00719   targetMesh->removeReference();
00720   sourceMesh->removeReference();
00721 }
00722 
00723 void MEDMEMTest::test_remapper7()
00724 {
00725   MESH *sourceMesh=build3DSourceMesh2();
00726   MESH *targetMesh=build3DTargetMesh2();
00727   sourceMesh->convertToPoly();
00728   targetMesh->convertToPoly();
00729   MEDNormalizedUnstructuredMesh<3,3> sourceWrapper(sourceMesh);
00730   MEDNormalizedUnstructuredMesh<3,3> targetWrapper(targetMesh);
00731   INTERP_KERNEL::Interpolation3D myInterpolator;
00732   vector<map<int,double> > res;
00733   myInterpolator.setPrecision(1e-12);
00734   myInterpolator.setIntersectionType(INTERP_KERNEL::PointLocator);
00735   myInterpolator.interpolateMeshes(sourceWrapper,targetWrapper,res,"P0P0");
00736   CPPUNIT_ASSERT_EQUAL(8,(int)res.size());
00737   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][1],1e-12);
00738   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][7],1e-12);
00739   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][8],1e-12);
00740   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][9],1e-12);
00741   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][11],1e-12);
00742   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[1][8],1e-12);
00743   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[1][9],1e-12);
00744   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[2][1],1e-12);
00745   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[2][7],1e-12);
00746   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[3][1],1e-12);
00747   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[3][9],1e-12);
00748   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[4][7],1e-12);
00749   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[4][11],1e-12);
00750   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[5][8],1e-12);
00751   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[5][11],1e-12);
00752   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[6][10],1e-12);
00753   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][2],1e-12);
00754   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][4],1e-12);
00755   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][5],1e-12);
00756   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][6],1e-12);
00757   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][12],1e-12);
00758   CPPUNIT_ASSERT_DOUBLES_EQUAL(21.,sumAll(res),1e-12);
00759   targetMesh->removeReference();
00760   sourceMesh->removeReference();
00761 }
00762 
00763 void MEDMEMTest::test_remapper3DTo1D()
00764 {
00765   MESH *sourceMesh=build3DTargetMesh2();
00766   MESH *targetMesh=build1DTargetMesh1();
00767   MEDNormalizedUnstructuredMesh<3,3> sourceWrapper(sourceMesh);
00768   MEDNormalizedUnstructuredMesh<3,3> targetWrapper(targetMesh);
00769   INTERP_KERNEL::Interpolation3D myInterpolator;
00770   vector<map<int,double> > res;
00771   myInterpolator.setPrecision(1e-12);
00772   myInterpolator.setIntersectionType(INTERP_KERNEL::PointLocator);
00773   myInterpolator.interpolateMeshes(sourceWrapper,targetWrapper,res,"P0P0");
00774   CPPUNIT_ASSERT_EQUAL(8,(int)res.size());
00775   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][1],1e-12);
00776   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[1][5],1e-12);
00777   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[2][2],1e-12);
00778   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[3][6],1e-12);
00779   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[4][3],1e-12);
00780   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[5][7],1e-12);
00781   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[6][4],1e-12);
00782   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][8],1e-12);
00783   CPPUNIT_ASSERT_DOUBLES_EQUAL(8.,sumAll(res),1e-12);
00784   targetMesh->removeReference();
00785   sourceMesh->removeReference();
00786 }
00787 
00788 double MEDMEMTest::sumAll(const std::vector< std::map<int,double> >& matrix)
00789 {
00790   double ret=0.;
00791   for(std::vector< std::map<int,double> >::const_iterator iter=matrix.begin();iter!=matrix.end();iter++)
00792     for(std::map<int,double>::const_iterator iter2=(*iter).begin();iter2!=(*iter).end();iter2++)
00793       ret+=(*iter2).second;
00794   return ret;
00795 }
00796 
00797 void MEDMEMTest::absField(MEDMEM::FIELD<double>& field)
00798 {
00799   double* areas=const_cast<double*>(field.getValue());
00800   for (int i=0; i< field.getNumberOfValues();i++)
00801     {
00802       areas[i]=fabs(areas[i]);
00803     }
00804 }
00805 
00806 // }