Back to index

salome-med  6.5.0
MEDCouplingRemapperTest.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 "MEDCouplingRemapperTest.hxx"
00021 #include "MEDCouplingUMesh.hxx"
00022 #include "MEDCouplingExtrudedMesh.hxx"
00023 #include "MEDCouplingFieldDouble.hxx"
00024 #include "MEDCouplingFieldTemplate.hxx"
00025 #include "MEDCouplingMemArray.hxx"
00026 #include "MEDCouplingRemapper.hxx"
00027 
00028 #include "MEDCouplingBasicsTest.hxx"
00029 
00030 #include <cmath>
00031 #include <numeric>
00032 
00033 using namespace ParaMEDMEM;
00034 
00035 void MEDCouplingRemapperTest::test2DInterpP0P0_1()
00036 {
00037   MEDCouplingUMesh *sourceMesh=MEDCouplingBasicsTest::build2DSourceMesh_1();
00038   MEDCouplingUMesh *targetMesh=MEDCouplingBasicsTest::build2DTargetMesh_1();
00039   //
00040   MEDCouplingRemapper remapper;
00041   remapper.setPrecision(1e-12);
00042   remapper.setIntersectionType(INTERP_KERNEL::Triangulation);
00043   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(sourceMesh,targetMesh,"P0P0"));
00044   
00045   MEDCouplingFieldDouble *srcField=MEDCouplingFieldDouble::New(ON_CELLS);
00046   srcField->setNature(ConservativeVolumic);
00047   srcField->setMesh(sourceMesh);
00048   DataArrayDouble *array=DataArrayDouble::New();
00049   array->alloc(sourceMesh->getNumberOfCells(),1);
00050   srcField->setArray(array);
00051   double *ptr=array->getPointer();
00052   for(int i=0;i<sourceMesh->getNumberOfCells();i++)
00053     ptr[i]=(double)(i+7);
00054   array->decrRef();
00055   MEDCouplingFieldDouble *trgfield=remapper.transferField(srcField,4.57);
00056   const double *values=trgfield->getArray()->getConstPointer();
00057   const double valuesExpected[5]={7.5 ,7. ,7.,8.,7.5};
00058   CPPUNIT_ASSERT_EQUAL(5,trgfield->getArray()->getNumberOfTuples());
00059   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00060   for(int i0=0;i0<5;i0++)
00061     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected[i0],values[i0],1e-12);
00062   trgfield->decrRef();
00063   //
00064   srcField->setNature(IntegralGlobConstraint);
00065   trgfield=remapper.transferField(srcField,4.57);
00066   values=trgfield->getArray()->getConstPointer();
00067   const double valuesExpected2[5]={3.75 ,1.75 ,1.75,4.,3.75};
00068   CPPUNIT_ASSERT_EQUAL(5,trgfield->getArray()->getNumberOfTuples());
00069   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00070   for(int i0=0;i0<5;i0++)
00071     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected2[i0],values[i0],1e-12);
00072   trgfield->decrRef();
00073   //
00074   srcField->setNature(ConservativeVolumic);
00075   trgfield=remapper.transferField(srcField,4.57);
00076   values=trgfield->getArray()->getConstPointer();
00077   CPPUNIT_ASSERT_EQUAL(5,trgfield->getArray()->getNumberOfTuples());
00078   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00079   for(int i0=0;i0<5;i0++)
00080     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected[i0],values[i0],1e-12);
00081   trgfield->decrRef();
00082   //
00083   srcField->setNature(IntegralGlobConstraint);
00084   trgfield=remapper.transferField(srcField,4.57);
00085   values=trgfield->getArray()->getConstPointer();
00086   CPPUNIT_ASSERT_EQUAL(5,trgfield->getArray()->getNumberOfTuples());
00087   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00088   for(int i0=0;i0<5;i0++)
00089     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected2[i0],values[i0],1e-12);
00090   trgfield->decrRef();
00091   //
00092   srcField->setNature(Integral);
00093   trgfield=remapper.transferField(srcField,4.57);
00094   values=trgfield->getArray()->getConstPointer();
00095   CPPUNIT_ASSERT_EQUAL(5,trgfield->getArray()->getNumberOfTuples());
00096   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00097   for(int i0=0;i0<5;i0++)
00098     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected2[i0],values[i0],1e-12);
00099   trgfield->decrRef();
00100   //
00101   srcField->setNature(RevIntegral);
00102   trgfield=remapper.transferField(srcField,4.57);
00103   values=trgfield->getArray()->getConstPointer();
00104   CPPUNIT_ASSERT_EQUAL(5,trgfield->getArray()->getNumberOfTuples());
00105   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00106   for(int i0=0;i0<5;i0++)
00107     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected[i0],values[i0],1e-12);
00108   trgfield->decrRef();
00109   //
00110   srcField->decrRef();
00111   //clean up
00112   sourceMesh->decrRef();
00113   targetMesh->decrRef();
00114 }
00115 
00116 void MEDCouplingRemapperTest::test2DInterpP0P0R_1()
00117 {
00118   MEDCouplingUMesh *sourceMesh=MEDCouplingBasicsTest::build2DSourceMesh_1();
00119   MEDCouplingUMesh *targetMesh=MEDCouplingBasicsTest::build2DTargetMesh_1();
00120   //
00121   MEDCouplingRemapper remapper;
00122   remapper.setPrecision(1e-12);
00123   remapper.setIntersectionType(INTERP_KERNEL::Triangulation);
00124   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(sourceMesh,targetMesh,"P0P0"));
00125   
00126   MEDCouplingFieldDouble *targetField=MEDCouplingFieldDouble::New(ON_CELLS);
00127   targetField->setNature(ConservativeVolumic);
00128   targetField->setMesh(sourceMesh);
00129   DataArrayDouble *array=DataArrayDouble::New();
00130   array->alloc(targetMesh->getNumberOfCells(),1);
00131   targetField->setArray(array);
00132   double *ptr=array->getPointer();
00133   for(int i=0;i<targetMesh->getNumberOfCells();i++)
00134     ptr[i]=(double)(i+7);
00135   array->decrRef();
00136   //
00137   MEDCouplingFieldDouble *srcfield=remapper.reverseTransferField(targetField,4.57);
00138   const double *values=srcfield->getArray()->getConstPointer();
00139   const double valuesExpected[2]={8.75 ,9.5};
00140   CPPUNIT_ASSERT_EQUAL(2,srcfield->getArray()->getNumberOfTuples());
00141   CPPUNIT_ASSERT_EQUAL(1,srcfield->getArray()->getNumberOfComponents());
00142   for(int i0=0;i0<2;i0++)
00143     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected[i0],values[i0],1e-12);
00144   srcfield->decrRef();
00145   //
00146   targetField->setNature(IntegralGlobConstraint);
00147   srcfield=remapper.reverseTransferField(targetField,4.57);
00148   values=srcfield->getArray()->getConstPointer();
00149   const double valuesExpected2[2]={26., 19.};
00150   CPPUNIT_ASSERT_EQUAL(2,srcfield->getArray()->getNumberOfTuples());
00151   CPPUNIT_ASSERT_EQUAL(1,srcfield->getArray()->getNumberOfComponents());
00152   for(int i0=0;i0<2;i0++)
00153     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected2[i0],values[i0],1e-12);
00154   srcfield->decrRef();
00155   //
00156   targetField->decrRef();
00157   //clean up
00158   sourceMesh->decrRef();
00159   targetMesh->decrRef();
00160 }
00161 
00162 void MEDCouplingRemapperTest::test1DInterp_1()
00163 {
00164   MEDCouplingUMesh *sourceMesh=MEDCouplingBasicsTest::build1DSourceMesh_2();
00165   MEDCouplingUMesh *targetMesh=MEDCouplingBasicsTest::build1DTargetMesh_2();
00166   //
00167   MEDCouplingRemapper remapper;
00168   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(sourceMesh,targetMesh,"P0P0"));
00169   MEDCouplingFieldDouble *srcField=MEDCouplingFieldDouble::New(ON_CELLS);
00170   srcField->setNature(ConservativeVolumic);
00171   srcField->setMesh(sourceMesh);
00172   DataArrayDouble *array=DataArrayDouble::New();
00173   array->alloc(sourceMesh->getNumberOfCells(),1);
00174   srcField->setArray(array);
00175   double *ptr=array->getPointer();
00176   for(int i=0;i<sourceMesh->getNumberOfCells();i++)
00177     ptr[i]=(double)(i+7);
00178   array->decrRef();
00179   //
00180   MEDCouplingFieldDouble *trgfield=remapper.transferField(srcField,4.57);
00181   const double *values=trgfield->getArray()->getConstPointer();
00182   const double valuesExpected1[2]={9.0540540540540526,7.4};
00183   CPPUNIT_ASSERT_EQUAL(2,trgfield->getArray()->getNumberOfTuples());
00184   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00185   for(int i0=0;i0<2;i0++)
00186     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected1[i0],values[i0],1e-12);
00187   trgfield->decrRef();
00188   const double valuesExpected2[2]={24.75,5.75};
00189   srcField->setNature(Integral);
00190   trgfield=remapper.transferField(srcField,4.57);
00191   values=trgfield->getArray()->getConstPointer();
00192   CPPUNIT_ASSERT_EQUAL(2,trgfield->getArray()->getNumberOfTuples());
00193   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00194   for(int i0=0;i0<2;i0++)
00195     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected2[i0],values[i0],1e-12);
00196   trgfield->decrRef();
00197   //
00198   const double valuesExpected3[2]={24.75,9.25};
00199   srcField->setNature(IntegralGlobConstraint);
00200   trgfield=remapper.transferField(srcField,4.57);
00201   values=trgfield->getArray()->getConstPointer();
00202   CPPUNIT_ASSERT_EQUAL(2,trgfield->getArray()->getNumberOfTuples());
00203   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00204   for(int i0=0;i0<2;i0++)
00205     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected3[i0],values[i0],1e-12);
00206   trgfield->decrRef();
00207   //
00208   const double valuesExpected4[2]={7.4444444444444446,7.4};
00209   srcField->setNature(RevIntegral);
00210   trgfield=remapper.transferField(srcField,4.57);
00211   values=trgfield->getArray()->getConstPointer();
00212   CPPUNIT_ASSERT_EQUAL(2,trgfield->getArray()->getNumberOfTuples());
00213   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00214   for(int i0=0;i0<2;i0++)
00215     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected4[i0],values[i0],1e-12);
00216   trgfield->decrRef();
00217   //
00218   srcField->decrRef();
00219   sourceMesh->decrRef();
00220   targetMesh->decrRef();
00221   //2D Curve
00222   sourceMesh=MEDCouplingBasicsTest::build2DCurveSourceMesh_2();
00223   targetMesh=MEDCouplingBasicsTest::build2DCurveTargetMesh_2();
00224   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(sourceMesh,targetMesh,"P0P0"));
00225   srcField=MEDCouplingFieldDouble::New(ON_CELLS);
00226   srcField->setNature(ConservativeVolumic);
00227   srcField->setMesh(sourceMesh);
00228   array=DataArrayDouble::New();
00229   array->alloc(sourceMesh->getNumberOfCells(),1);
00230   srcField->setArray(array);
00231   ptr=array->getPointer();
00232   for(int i=0;i<sourceMesh->getNumberOfCells();i++)
00233     ptr[i]=(double)(i+7);
00234   array->decrRef();
00235   //
00236   trgfield=remapper.transferField(srcField,4.57);
00237   values=trgfield->getArray()->getConstPointer();
00238   CPPUNIT_ASSERT_EQUAL(2,trgfield->getArray()->getNumberOfTuples());
00239   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00240   for(int i0=0;i0<2;i0++)
00241     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected1[i0],values[i0],1e-12);
00242   trgfield->decrRef();
00243   srcField->setNature(Integral);
00244   trgfield=remapper.transferField(srcField,4.57);
00245   values=trgfield->getArray()->getConstPointer();
00246   CPPUNIT_ASSERT_EQUAL(2,trgfield->getArray()->getNumberOfTuples());
00247   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00248   for(int i0=0;i0<2;i0++)
00249     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected2[i0],values[i0],1e-12);
00250   trgfield->decrRef();
00251   //
00252   srcField->setNature(IntegralGlobConstraint);
00253   trgfield=remapper.transferField(srcField,4.57);
00254   values=trgfield->getArray()->getConstPointer();
00255   CPPUNIT_ASSERT_EQUAL(2,trgfield->getArray()->getNumberOfTuples());
00256   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00257   for(int i0=0;i0<2;i0++)
00258     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected3[i0],values[i0],1e-12);
00259   trgfield->decrRef();
00260   //
00261   srcField->setNature(RevIntegral);
00262   trgfield=remapper.transferField(srcField,4.57);
00263   values=trgfield->getArray()->getConstPointer();
00264   CPPUNIT_ASSERT_EQUAL(2,trgfield->getArray()->getNumberOfTuples());
00265   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00266   for(int i0=0;i0<2;i0++)
00267     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected4[i0],values[i0],1e-12);
00268   trgfield->decrRef();
00269   //
00270   srcField->decrRef();
00271   sourceMesh->decrRef();
00272   targetMesh->decrRef();
00273 }
00274 
00275 void MEDCouplingRemapperTest::test2DInterpMultiMethods()
00276 {
00277   MEDCouplingUMesh *sourceMesh=MEDCouplingBasicsTest::build2DSourceMesh_1();
00278   MEDCouplingUMesh *targetMesh=MEDCouplingBasicsTest::build2DTargetMesh_1();
00279   //
00280   MEDCouplingRemapper remapper;
00281   remapper.setPrecision(1e-12);
00282   remapper.setIntersectionType(INTERP_KERNEL::Triangulation);
00283   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(sourceMesh,targetMesh,"P0P0"));
00284   
00285   MEDCouplingFieldDouble *srcField=MEDCouplingFieldDouble::New(ON_CELLS);
00286   srcField->setNature(ConservativeVolumic);
00287   srcField->setMesh(sourceMesh);
00288   DataArrayDouble *array=DataArrayDouble::New();
00289   array->alloc(sourceMesh->getNumberOfCells(),1);
00290   srcField->setArray(array);
00291   double *ptr=array->getPointer();
00292   for(int i=0;i<sourceMesh->getNumberOfCells();i++)
00293     ptr[i]=(double)(i+7);
00294   array->decrRef();
00295   MEDCouplingFieldDouble *trgfield=remapper.transferField(srcField,4.57);
00296   const double *values=trgfield->getArray()->getConstPointer();
00297   const double valuesExpected[5]={7.5 ,7. ,7.,8.,7.5};
00298   CPPUNIT_ASSERT_EQUAL(5,trgfield->getArray()->getNumberOfTuples());
00299   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00300   for(int i0=0;i0<5;i0++)
00301     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected[i0],values[i0],1e-12);
00302   trgfield->decrRef();
00303   srcField->decrRef();
00304   //
00305   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(sourceMesh,targetMesh,"P1P0"));
00306   srcField=MEDCouplingFieldDouble::New(ON_NODES);
00307   srcField->setNature(ConservativeVolumic);
00308   srcField->setMesh(sourceMesh);
00309   array=DataArrayDouble::New();
00310   array->alloc(sourceMesh->getNumberOfNodes(),1);
00311   srcField->setArray(array);
00312   ptr=array->getPointer();
00313   for(int i=0;i<sourceMesh->getNumberOfNodes();i++)
00314     ptr[i]=(double)(i+7);
00315   array->decrRef();
00316   trgfield=remapper.transferField(srcField,4.57);
00317   values=trgfield->getArray()->getConstPointer();
00318   const double valuesExpected2[5]={7.,7.666666666666667,8.6666666666666661,8.8333333333333339,10.};
00319   CPPUNIT_ASSERT_EQUAL(5,trgfield->getArray()->getNumberOfTuples());
00320   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00321   for(int i0=0;i0<5;i0++)
00322     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected2[i0],values[i0],1e-12);
00323   trgfield->decrRef();
00324   srcField->decrRef();
00325   //
00326   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(targetMesh,sourceMesh,"P0P1"));
00327   srcField=MEDCouplingFieldDouble::New(ON_CELLS);
00328   srcField->setNature(ConservativeVolumic);
00329   srcField->setMesh(targetMesh);
00330   array=DataArrayDouble::New();
00331   array->alloc(targetMesh->getNumberOfCells(),1);
00332   srcField->setArray(array);
00333   ptr=array->getPointer();
00334   for(int i=0;i<targetMesh->getNumberOfCells();i++)
00335     ptr[i]=(double)(i+7);
00336   array->decrRef();
00337   trgfield=remapper.transferField(srcField,4.57);
00338   values=trgfield->getArray()->getConstPointer();
00339   const double valuesExpected3[4]={7.5,8.5,10.,10.625};
00340   CPPUNIT_ASSERT_EQUAL(4,trgfield->getArray()->getNumberOfTuples());
00341   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00342   for(int i0=0;i0<4;i0++)
00343     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected3[i0],values[i0],1e-12);
00344   trgfield->decrRef();
00345   srcField->decrRef();
00346   //clean up
00347   sourceMesh->decrRef();
00348   targetMesh->decrRef();
00349   //
00350   sourceMesh=MEDCouplingBasicsTest::build2DSourceMesh_1();
00351   targetMesh=MEDCouplingBasicsTest::build2DTargetMesh_2();
00352   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(sourceMesh,targetMesh,"P1P1"));
00353   srcField=MEDCouplingFieldDouble::New(ON_NODES);
00354   srcField->setNature(ConservativeVolumic);
00355   srcField->setMesh(sourceMesh);
00356   array=DataArrayDouble::New();
00357   array->alloc(sourceMesh->getNumberOfNodes(),1);
00358   srcField->setArray(array);
00359   ptr=array->getPointer();
00360   for(int i=0;i<sourceMesh->getNumberOfNodes();i++)
00361     ptr[i]=(double)(i+7);
00362   array->decrRef();
00363   trgfield=remapper.transferField(srcField,4.57);
00364   values=trgfield->getArray()->getConstPointer();
00365   const double valuesExpected4[9]={ 7.,7.35,8.,7.7,8.2857142857142865,
00366                                     9.5333333333333332,9.,9.7666666666666657,10.};
00367   CPPUNIT_ASSERT_EQUAL(9,trgfield->getArray()->getNumberOfTuples());
00368   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00369   for(int i0=0;i0<9;i0++)
00370     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected4[i0],values[i0],1e-12);
00371   trgfield->decrRef();
00372   srcField->decrRef();
00373   //clean up
00374   sourceMesh->decrRef();
00375   targetMesh->decrRef();
00376 }
00377 
00378 void MEDCouplingRemapperTest::testMultiDimCombi()
00379 {
00380   // ------------- 2D
00381   MEDCouplingUMesh *sourceMesh=MEDCouplingBasicsTest::build2DSourceMesh_1();
00382   MEDCouplingUMesh *targetMesh=MEDCouplingBasicsTest::build2DTargetMesh_1();
00383   //
00384   MEDCouplingRemapper remapper;
00385   remapper.setPrecision(1e-12);
00386   remapper.setIntersectionType(INTERP_KERNEL::Triangulation);
00387   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(sourceMesh,targetMesh,"P0P0"));
00388   MEDCouplingFieldDouble *srcField=MEDCouplingFieldDouble::New(ON_CELLS);
00389   srcField->setNature(ConservativeVolumic);
00390   srcField->setMesh(sourceMesh);
00391   DataArrayDouble *array=DataArrayDouble::New();
00392   array->alloc(sourceMesh->getNumberOfCells(),1);
00393   srcField->setArray(array);
00394   double *ptr=array->getPointer();
00395   for(int i=0;i<sourceMesh->getNumberOfCells();i++)
00396     ptr[i]=(double)(i+7);
00397   array->decrRef();
00398   MEDCouplingFieldDouble *trgField=remapper.transferField(srcField,4.57);
00399   const double *values=trgField->getArray()->getConstPointer();
00400   const double valuesExpected[5]={7.5 ,7. ,7.,8.,7.5};
00401   CPPUNIT_ASSERT_EQUAL(5,trgField->getArray()->getNumberOfTuples());
00402   CPPUNIT_ASSERT_EQUAL(1,trgField->getArray()->getNumberOfComponents());
00403   for(int i0=0;i0<5;i0++)
00404     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected[i0],values[i0],1e-12);
00405   trgField->decrRef();
00406   srcField->decrRef();
00407   sourceMesh->decrRef();
00408   targetMesh->decrRef();
00409   // ------------- 3D Surf
00410   sourceMesh=MEDCouplingBasicsTest::build3DSurfSourceMesh_1();
00411   targetMesh=MEDCouplingBasicsTest::build3DSurfTargetMesh_1();
00412   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(sourceMesh,targetMesh,"P0P0"));
00413   srcField=MEDCouplingFieldDouble::New(ON_CELLS);
00414   srcField->setNature(ConservativeVolumic);
00415   srcField->setMesh(sourceMesh);
00416   array=DataArrayDouble::New();
00417   array->alloc(sourceMesh->getNumberOfCells(),1);
00418   srcField->setArray(array);
00419   ptr=array->getPointer();
00420   for(int i=0;i<sourceMesh->getNumberOfCells();i++)
00421     ptr[i]=(double)(i+8);
00422   array->decrRef();
00423   trgField=remapper.transferField(srcField,4.57);
00424   CPPUNIT_ASSERT_EQUAL(5,trgField->getArray()->getNumberOfTuples());
00425   CPPUNIT_ASSERT_EQUAL(1,trgField->getArray()->getNumberOfComponents());
00426   const double valuesExpected2[5]={8.5,8.,8.,9.,8.5};
00427   values=trgField->getArray()->getConstPointer();
00428   for(int i0=0;i0<5;i0++)
00429     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected2[i0],values[i0],1e-12);
00430   trgField->decrRef();
00431   srcField->decrRef();
00432   sourceMesh->decrRef();
00433   targetMesh->decrRef();
00434   // ------------- 3D
00435   sourceMesh=MEDCouplingBasicsTest::build3DSourceMesh_1();
00436   targetMesh=MEDCouplingBasicsTest::build3DTargetMesh_1();
00437   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(sourceMesh,targetMesh,"P0P0"));
00438   srcField=MEDCouplingFieldDouble::New(ON_CELLS);
00439   srcField->setNature(ConservativeVolumic);
00440   srcField->setMesh(sourceMesh);
00441   array=DataArrayDouble::New();
00442   array->alloc(sourceMesh->getNumberOfCells(),1);
00443   srcField->setArray(array);
00444   ptr=array->getPointer();
00445   for(int i=0;i<sourceMesh->getNumberOfCells();i++)
00446     ptr[i]=(double)(i+7);
00447   array->decrRef();
00448   trgField=remapper.transferField(srcField,4.57);
00449   CPPUNIT_ASSERT_EQUAL(8,trgField->getArray()->getNumberOfTuples());
00450   CPPUNIT_ASSERT_EQUAL(1,trgField->getArray()->getNumberOfComponents());
00451   const double valuesExpected3[8]={13.166666666666668, 13.888888888888888, 10.722222222222223, 10.870370370370372,
00452                                    14.555555555555555, 13.888888888888889, 14.444444444444443, 11.72222222222222};
00453   values=trgField->getArray()->getConstPointer();
00454   for(int i0=0;i0<8;i0++)
00455     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected3[i0],values[i0],1e-12);
00456   trgField->decrRef();
00457   srcField->decrRef();
00458   sourceMesh->decrRef();
00459   targetMesh->decrRef();
00460   // ------------- 3D -> 1D
00461   sourceMesh=MEDCouplingBasicsTest::build3DTargetMesh_1();
00462   targetMesh=MEDCouplingBasicsTest::build1DTargetMesh_1();
00463   remapper.setIntersectionType(INTERP_KERNEL::PointLocator);
00464   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(sourceMesh,targetMesh,"P0P0"));
00465   srcField=MEDCouplingFieldDouble::New(ON_CELLS);
00466   srcField->setNature(ConservativeVolumic);
00467   srcField->setMesh(sourceMesh);
00468   array=DataArrayDouble::New();
00469   array->alloc(sourceMesh->getNumberOfCells(),1);
00470   srcField->setArray(array);
00471   ptr=array->getPointer();
00472   for(int i=0;i<sourceMesh->getNumberOfCells();i++)
00473     ptr[i]=(double)(i+7);
00474   array->decrRef();
00475   trgField=remapper.transferField(srcField,4.57);
00476   CPPUNIT_ASSERT_EQUAL(8,trgField->getArray()->getNumberOfTuples());
00477   CPPUNIT_ASSERT_EQUAL(1,trgField->getArray()->getNumberOfComponents());
00478   const double valuesExpected4[8]={7.,11.,8.,12.,9.,13.,10.,14.};
00479   values=trgField->getArray()->getConstPointer();
00480   for(int i0=0;i0<8;i0++)
00481     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected4[i0],values[i0],1e-12);
00482   trgField->decrRef();
00483   srcField->decrRef();
00484   sourceMesh->decrRef();
00485   targetMesh->decrRef();
00486   // ------------- 1D -> 3D
00487   sourceMesh=MEDCouplingBasicsTest::build1DTargetMesh_1();
00488   targetMesh=MEDCouplingBasicsTest::build3DTargetMesh_1();
00489   remapper.setIntersectionType(INTERP_KERNEL::PointLocator);
00490   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(sourceMesh,targetMesh,"P0P0"));
00491   srcField=MEDCouplingFieldDouble::New(ON_CELLS);
00492   srcField->setNature(ConservativeVolumic);
00493   srcField->setMesh(sourceMesh);
00494   array=DataArrayDouble::New();
00495   array->alloc(sourceMesh->getNumberOfCells(),1);
00496   srcField->setArray(array);
00497   ptr=array->getPointer();
00498   for(int i=0;i<sourceMesh->getNumberOfCells();i++)
00499     ptr[i]=(double)(i+7);
00500   array->decrRef();
00501   trgField=remapper.transferField(srcField,4.57);
00502   CPPUNIT_ASSERT_EQUAL(8,trgField->getArray()->getNumberOfTuples());
00503   CPPUNIT_ASSERT_EQUAL(1,trgField->getArray()->getNumberOfComponents());
00504   const double valuesExpected5[8]={7.,9.,11.,13.,8.,10.,12.,14.};
00505   values=trgField->getArray()->getConstPointer();
00506   for(int i0=0;i0<8;i0++)
00507     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected5[i0],values[i0],1e-12);
00508   trgField->decrRef();
00509   srcField->decrRef();
00510   sourceMesh->decrRef();
00511   targetMesh->decrRef();
00512   // ------------- 2D -> 1D
00513   sourceMesh=MEDCouplingBasicsTest::build2DTargetMesh_1();
00514   targetMesh=build1DTargetMesh_2();
00515   remapper.setIntersectionType(INTERP_KERNEL::PointLocator);
00516   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(sourceMesh,targetMesh,"P0P0"));
00517   srcField=MEDCouplingFieldDouble::New(ON_CELLS);
00518   srcField->setNature(ConservativeVolumic);
00519   srcField->setMesh(sourceMesh);
00520   array=DataArrayDouble::New();
00521   array->alloc(sourceMesh->getNumberOfCells(),1);
00522   srcField->setArray(array);
00523   ptr=array->getPointer();
00524   for(int i=0;i<sourceMesh->getNumberOfCells();i++)
00525     ptr[i]=(double)(i+7);
00526   array->decrRef();
00527   trgField=remapper.transferField(srcField,4.57);
00528   const double valuesExpected8[5]={9.,8.,11.,7.,11.};
00529   values=trgField->getArray()->getConstPointer();
00530   for(int i0=0;i0<5;i0++)
00531     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected8[i0],values[i0],1e-12);
00532   trgField->decrRef();
00533   srcField->decrRef();
00534   sourceMesh->decrRef();
00535   targetMesh->decrRef();
00536   // ------------- 1D -> 2D
00537   sourceMesh=build1DTargetMesh_2();
00538   targetMesh=MEDCouplingBasicsTest::build2DTargetMesh_1();
00539   remapper.setIntersectionType(INTERP_KERNEL::PointLocator);
00540   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(sourceMesh,targetMesh,"P0P0"));
00541   srcField=MEDCouplingFieldDouble::New(ON_CELLS);
00542   srcField->setNature(ConservativeVolumic);
00543   srcField->setMesh(sourceMesh);
00544   array=DataArrayDouble::New();
00545   array->alloc(sourceMesh->getNumberOfCells(),1);
00546   srcField->setArray(array);
00547   ptr=array->getPointer();
00548   for(int i=0;i<sourceMesh->getNumberOfCells();i++)
00549     ptr[i]=(double)(i+7);
00550   array->decrRef();
00551   trgField=remapper.transferField(srcField,4.57);
00552   const double valuesExpected9[5]={10.,8.,7.,4.57,10.};
00553   values=trgField->getArray()->getConstPointer();
00554   for(int i0=0;i0<5;i0++)
00555     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected9[i0],values[i0],1e-12);
00556   trgField->decrRef();
00557   srcField->decrRef();
00558   sourceMesh->decrRef();
00559   targetMesh->decrRef();
00560   // ------------- 2D -> -1D
00561   sourceMesh=MEDCouplingBasicsTest::build2DTargetMesh_1();
00562   targetMesh=MEDCouplingUMesh::New("an example of -1 D mesh",-1);
00563   srcField=MEDCouplingFieldDouble::New(ON_CELLS);
00564   srcField->setNature(ConservativeVolumic);
00565   srcField->setMesh(sourceMesh);
00566   array=DataArrayDouble::New();
00567   array->alloc(sourceMesh->getNumberOfCells(),1);
00568   srcField->setArray(array);
00569   ptr=array->getPointer();
00570   for(int i=0;i<sourceMesh->getNumberOfCells();i++)
00571     ptr[i]=(double)(i+7);
00572   array->decrRef();
00573   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(sourceMesh,targetMesh,"P0P0"));
00574   trgField=remapper.transferField(srcField,4.57);
00575   values=trgField->getArray()->getConstPointer();
00576   CPPUNIT_ASSERT_EQUAL(1,trgField->getNumberOfTuples());
00577   CPPUNIT_ASSERT_EQUAL(1,trgField->getNumberOfComponents());
00578   CPPUNIT_ASSERT_DOUBLES_EQUAL(9.125,values[0],1e-14);
00579   srcField->decrRef();
00580   srcField=remapper.reverseTransferField(trgField,4.220173);
00581   CPPUNIT_ASSERT_EQUAL(5,srcField->getNumberOfTuples());
00582   CPPUNIT_ASSERT_EQUAL(1,srcField->getNumberOfComponents());
00583   values=srcField->getArray()->getConstPointer();
00584   for(int i0=0;i0<5;i0++)
00585     CPPUNIT_ASSERT_DOUBLES_EQUAL(9.125,values[i0],1e-14);
00586   srcField->decrRef();
00587   trgField->setNature(Integral);
00588   srcField=remapper.reverseTransferField(trgField,4.220173);
00589   CPPUNIT_ASSERT_EQUAL(5,srcField->getNumberOfTuples());
00590   CPPUNIT_ASSERT_EQUAL(1,srcField->getNumberOfComponents());
00591   values=srcField->getArray()->getConstPointer();
00592   const double valuesExpected6[5]={2.28125,1.140625,1.140625,2.28125,2.28125};
00593   for(int i0=0;i0<5;i0++)
00594     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected6[i0],values[i0],1e-14);
00595   srcField->decrRef();
00596   trgField->decrRef();
00597   // ------------- -1D -> 2D
00598   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(targetMesh,sourceMesh,"P0P0"));
00599   trgField=MEDCouplingFieldDouble::New(ON_CELLS);
00600   trgField->setNature(ConservativeVolumic);
00601   trgField->setMesh(targetMesh);
00602   array=DataArrayDouble::New();
00603   array->alloc(targetMesh->getNumberOfCells(),1);
00604   trgField->setArray(array);
00605   ptr=array->getPointer();
00606   ptr[0]=7.;
00607   array->decrRef();
00608   srcField=remapper.transferField(trgField,4.221073);
00609   values=srcField->getArray()->getConstPointer();
00610   for(int i0=0;i0<5;i0++)
00611     CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,values[i0],1e-14);
00612   srcField->decrRef();
00613   trgField->setNature(IntegralGlobConstraint);
00614   srcField=remapper.transferField(trgField,4.221073);
00615   values=srcField->getArray()->getConstPointer();
00616   const double valuesExpected7[5]={1.75,0.875,0.875,1.75,1.75};
00617   for(int i0=0;i0<5;i0++)
00618     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected7[i0],values[i0],1e-14);
00619   srcField->decrRef();
00620   trgField->setNature(Integral);
00621   srcField=remapper.transferField(trgField,4.221073);
00622   values=srcField->getArray()->getConstPointer();
00623   for(int i0=0;i0<5;i0++)
00624     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected7[i0],values[i0],1e-14);
00625   srcField->decrRef();
00626   trgField->decrRef();
00627   sourceMesh->decrRef();
00628   targetMesh->decrRef();
00629   //------------- 1D -> 2D
00630   const int conn[8]={0,1,1,2,2,3,3,0};
00631   const int conn2[12]={6,7,5,4,2,7,6,3,0,4,5,1};
00632   const double coords1[]={0.17,0.93,0.56,0.93,0.56,0.25,0.17,0.52};
00633   const double coords2[]={0.,0.,1.,0.,1.,1.,0.,1.,0.,0.5,1.,0.5,0.,0.8,1.,0.8};
00634   sourceMesh=MEDCouplingUMesh::New("src1D",1);
00635   sourceMesh->allocateCells(4);
00636   sourceMesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn);
00637   sourceMesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+2);
00638   sourceMesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+4);
00639   sourceMesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+6);
00640   sourceMesh->finishInsertingCells();
00641   array=DataArrayDouble::New(); array->alloc(4,2);
00642   std::copy(coords1,coords1+8,array->getPointer());
00643   sourceMesh->setCoords(array); array->decrRef();
00644   targetMesh=MEDCouplingUMesh::New("trg2D",2);
00645   targetMesh->allocateCells(3);
00646   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn2);
00647   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn2+4);
00648   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn2+8);
00649   targetMesh->finishInsertingCells();
00650   array=DataArrayDouble::New(); array->alloc(8,2);
00651   std::copy(coords2,coords2+16,array->getPointer());
00652   targetMesh->setCoords(array); array->decrRef();
00653   remapper.setPrecision(1e-12);
00654   remapper.setIntersectionType(INTERP_KERNEL::Geometric2D);
00655   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(sourceMesh,targetMesh,"P0P0"));
00656   srcField=MEDCouplingFieldDouble::New(ON_CELLS);
00657   srcField->setNature(ConservativeVolumic);
00658   srcField->setMesh(sourceMesh);
00659   array=DataArrayDouble::New();
00660   array->alloc(4,1); array->iota(2.);
00661   srcField->setArray(array); array->decrRef();
00662   trgField=remapper.transferField(srcField,4.57);
00663   const double valuesExpected10[3]={3.9674868868103834, 2.8, 3.6372633449255796};
00664   CPPUNIT_ASSERT_EQUAL(3,trgField->getNumberOfTuples());
00665   CPPUNIT_ASSERT_EQUAL(1,trgField->getNumberOfComponents());
00666   for(int i=0;i<3;i++)
00667     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected10[i],trgField->getIJ(i,0),1e-13);
00668   srcField->decrRef();
00669   trgField->decrRef();
00670   //------------- 2D -> 1D
00671   remapper.setPrecision(1e-12);
00672   remapper.setIntersectionType(INTERP_KERNEL::Geometric2D);
00673   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(targetMesh,sourceMesh,"P0P0"));
00674   srcField=MEDCouplingFieldDouble::New(ON_CELLS);
00675   srcField->setNature(ConservativeVolumic);
00676   srcField->setMesh(targetMesh);
00677   array=DataArrayDouble::New();
00678   array->alloc(3,1); array->iota(2.);
00679   srcField->setArray(array); array->decrRef();
00680   trgField=remapper.transferField(srcField,4.57);
00681   const double valuesExpected11[4]={3., 2.9264705882352944, 3.8518518518518516, 2.3170731707317076};
00682   CPPUNIT_ASSERT_EQUAL(4,trgField->getNumberOfTuples());
00683   CPPUNIT_ASSERT_EQUAL(1,trgField->getNumberOfComponents());
00684   for(int i=0;i<4;i++)
00685     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected11[i],trgField->getIJ(i,0),1e-13);
00686   srcField->decrRef();
00687   trgField->decrRef();
00688   sourceMesh->decrRef();
00689   targetMesh->decrRef();
00690   //------------- 2D -> 3D
00691   sourceMesh=MEDCouplingBasicsTest::build3D2DSourceMesh();
00692   targetMesh=MEDCouplingBasicsTest::build3D2DTargetMesh();
00693   remapper.setIntersectionType(INTERP_KERNEL::Triangulation);
00694   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(sourceMesh,targetMesh,"P0P0"));
00695   srcField=MEDCouplingFieldDouble::New(ON_CELLS);
00696   srcField->setNature(ConservativeVolumic);
00697   srcField->setMesh(sourceMesh);
00698   array=DataArrayDouble::New();
00699   array->alloc(7,1); array->iota(2.);
00700   srcField->setArray(array); array->decrRef();
00701   trgField=remapper.transferField(srcField,4.57);
00702   const double valuesExpected12[3]={5.70909090909091, 6.08362715128042, 6.92857142857143};
00703   CPPUNIT_ASSERT_EQUAL(3,trgField->getNumberOfTuples());
00704   CPPUNIT_ASSERT_EQUAL(1,trgField->getNumberOfComponents());
00705   for(int i=0;i<3;i++)
00706     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected12[i],trgField->getIJ(i,0),1e-13);
00707   srcField->decrRef();
00708   trgField->decrRef();
00709   //------------- 3D -> 2D
00710   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(targetMesh,sourceMesh,"P0P0"));
00711   srcField=MEDCouplingFieldDouble::New(ON_CELLS);
00712   srcField->setNature(ConservativeVolumic);
00713   srcField->setMesh(targetMesh);
00714   array=DataArrayDouble::New();
00715   array->alloc(3,1); array->iota(2.);
00716   srcField->setArray(array); array->decrRef();
00717   trgField=remapper.transferField(srcField,4.57);
00718   const double valuesExpected13[7]={3., 4., 2.5, 2.909090909090909, 2., 3.5, 3.3571428571428572};
00719   CPPUNIT_ASSERT_EQUAL(7,trgField->getNumberOfTuples());
00720   CPPUNIT_ASSERT_EQUAL(1,trgField->getNumberOfComponents());
00721   for(int i=0;i<7;i++)
00722     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected13[i],trgField->getIJ(i,0),1e-13);
00723   srcField->decrRef();
00724   trgField->decrRef();
00725   sourceMesh->decrRef();
00726   targetMesh->decrRef();
00727 }
00728 
00729 void MEDCouplingRemapperTest::testNatureOfField()
00730 {
00731   MEDCouplingUMesh *sourceMesh=MEDCouplingBasicsTest::build2DSourceMesh_1();
00732   MEDCouplingUMesh *targetMesh=build2DTargetMesh_3();
00733   //
00734   MEDCouplingRemapper remapper;
00735   remapper.setPrecision(1e-12);
00736   remapper.setIntersectionType(INTERP_KERNEL::Triangulation);
00737   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(sourceMesh,targetMesh,"P0P0"));
00738   MEDCouplingFieldDouble *srcField=MEDCouplingFieldDouble::New(ON_CELLS);
00739   srcField->setNature(ConservativeVolumic);
00740   srcField->setMesh(sourceMesh);
00741   DataArrayDouble *array=DataArrayDouble::New();
00742   array->alloc(sourceMesh->getNumberOfCells(),1);
00743   srcField->setArray(array);
00744   double *ptr=array->getPointer();
00745   for(int i=0;i<sourceMesh->getNumberOfCells();i++)
00746     ptr[i]=(double)(i+7);
00747   array->decrRef();
00748   MEDCouplingFieldDouble *trgfield=remapper.transferField(srcField,4.220173);
00749   const double *values=trgfield->getArray()->getConstPointer();
00750   const double valuesExpected[4]={7.75, 7.0625, 4.220173,8.0};
00751   CPPUNIT_ASSERT_EQUAL(4,trgfield->getArray()->getNumberOfTuples());
00752   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00753   for(int i0=0;i0<4;i0++)
00754     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected[i0],values[i0],1e-12);
00755   trgfield->decrRef();
00756   //
00757   srcField->setNature(IntegralGlobConstraint);
00758   trgfield=remapper.transferField(srcField,4.220173);
00759   values=trgfield->getArray()->getConstPointer();
00760   const double valuesExpected2[4]={2.8374999999999999, 7.3624999999999998, 4.220173, 4.7999999999999998};
00761   CPPUNIT_ASSERT_EQUAL(4,trgfield->getArray()->getNumberOfTuples());
00762   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00763   for(int i0=0;i0<4;i0++)
00764     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected2[i0],values[i0],1e-12);
00765   trgfield->decrRef();
00766   //
00767   srcField->setNature(Integral);
00768   trgfield=remapper.transferField(srcField,4.220173);
00769   values=trgfield->getArray()->getConstPointer();
00770   const double valuesExpected3[4]={1.24, 4.5199999999999996, 4.220173, 1.9199999999999999};
00771   CPPUNIT_ASSERT_EQUAL(4,trgfield->getArray()->getNumberOfTuples());
00772   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00773   for(int i0=0;i0<4;i0++)
00774     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected3[i0],values[i0],1e-12);
00775   trgfield->decrRef();
00776   //
00777   srcField->setNature(RevIntegral);
00778   trgfield=remapper.transferField(srcField,4.220173);
00779   values=trgfield->getArray()->getConstPointer();
00780   const double valuesExpected9[4]={2.48, 3.766666666666666, 4.220173, 1.9199999999999999};
00781   CPPUNIT_ASSERT_EQUAL(4,trgfield->getArray()->getNumberOfTuples());
00782   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00783   for(int i0=0;i0<4;i0++)
00784     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected9[i0],values[i0],1e-12);
00785   trgfield->decrRef();
00786   //
00787   srcField->decrRef();
00788   // REVERSE ***********
00789   trgfield=MEDCouplingFieldDouble::New(ON_CELLS);
00790   trgfield->setNature(ConservativeVolumic);
00791   trgfield->setMesh(targetMesh);
00792   array=DataArrayDouble::New();
00793   array->alloc(targetMesh->getNumberOfCells(),1);
00794   trgfield->setArray(array);
00795   ptr=array->getPointer();
00796   for(int i=0;i<targetMesh->getNumberOfCells();i++)
00797     ptr[i]=(double)(i+7);
00798   array->decrRef();
00799   srcField=remapper.reverseTransferField(trgfield,4.220173);
00800   values=srcField->getArray()->getConstPointer();
00801   const double valuesExpected4[2]={7.9375, 8.9};
00802   CPPUNIT_ASSERT_EQUAL(2,srcField->getArray()->getNumberOfTuples());
00803   CPPUNIT_ASSERT_EQUAL(1,srcField->getArray()->getNumberOfComponents());
00804   for(int i0=0;i0<2;i0++)
00805     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected4[i0],values[i0],1e-12);
00806   srcField->decrRef();
00807   //
00808   trgfield->decrRef();
00809   //
00810   sourceMesh->decrRef();
00811   targetMesh->decrRef();
00812   // REVERSE ALL
00813   sourceMesh=build2DTargetMesh_3();
00814   targetMesh=MEDCouplingBasicsTest::build2DSourceMesh_1();
00815   //
00816   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(sourceMesh,targetMesh,"P0P0"));
00817   srcField=MEDCouplingFieldDouble::New(ON_CELLS);
00818   srcField->setNature(ConservativeVolumic);
00819   srcField->setMesh(sourceMesh);
00820   array=DataArrayDouble::New();
00821   array->alloc(sourceMesh->getNumberOfCells(),1);
00822   srcField->setArray(array);
00823   ptr=array->getPointer();
00824   for(int i=0;i<sourceMesh->getNumberOfCells();i++)
00825     ptr[i]=(double)(i+7);
00826   array->decrRef();
00827   trgfield=remapper.transferField(srcField,4.220173);
00828   values=trgfield->getArray()->getConstPointer();
00829   const double valuesExpected5[2]={7.9375, 8.9};
00830   CPPUNIT_ASSERT_EQUAL(2,trgfield->getArray()->getNumberOfTuples());
00831   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00832   for(int i0=0;i0<2;i0++)
00833     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected5[i0],values[i0],1e-12);
00834   trgfield->decrRef();
00835   //
00836   srcField->setNature(IntegralGlobConstraint);
00837   trgfield=remapper.transferField(srcField,4.220173);
00838   values=trgfield->getArray()->getConstPointer();
00839   const double valuesExpected6[4]={9.25, 15.75};
00840   CPPUNIT_ASSERT_EQUAL(2,trgfield->getArray()->getNumberOfTuples());
00841   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00842   for(int i0=0;i0<2;i0++)
00843     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected6[i0],values[i0],1e-12);
00844   trgfield->decrRef();
00845   //
00846   srcField->setNature(Integral);
00847   trgfield=remapper.transferField(srcField,4.220173);
00848   values=trgfield->getArray()->getConstPointer();
00849   const double valuesExpected7[2]={4.56, 4.3466666666666667};
00850   CPPUNIT_ASSERT_EQUAL(2,trgfield->getArray()->getNumberOfTuples());
00851   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00852   for(int i0=0;i0<2;i0++)
00853     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected7[i0],values[i0],1e-12);
00854   trgfield->decrRef();
00855   //
00856   srcField->setNature(RevIntegral);
00857   trgfield=remapper.transferField(srcField,4.220173);
00858   values=trgfield->getArray()->getConstPointer();
00859   const double valuesExpected10[2]={5.08, 3.56};
00860   CPPUNIT_ASSERT_EQUAL(2,trgfield->getArray()->getNumberOfTuples());
00861   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
00862   for(int i0=0;i0<2;i0++)
00863     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected10[i0],values[i0],1e-12);
00864   trgfield->decrRef();
00865   //
00866   srcField->decrRef();
00867   // REVERSE ***********
00868   trgfield=MEDCouplingFieldDouble::New(ON_CELLS);
00869   trgfield->setNature(ConservativeVolumic);
00870   trgfield->setMesh(targetMesh);
00871   array=DataArrayDouble::New();
00872   array->alloc(targetMesh->getNumberOfCells(),1);
00873   trgfield->setArray(array);
00874   ptr=array->getPointer();
00875   for(int i=0;i<targetMesh->getNumberOfCells();i++)
00876     ptr[i]=(double)(i+7);
00877   array->decrRef();
00878   srcField=remapper.reverseTransferField(trgfield,4.220173);
00879   values=srcField->getArray()->getConstPointer();
00880   const double valuesExpected8[4]={7.75, 7.0625,4.220173, 8.0};
00881   CPPUNIT_ASSERT_EQUAL(4,srcField->getArray()->getNumberOfTuples());
00882   CPPUNIT_ASSERT_EQUAL(1,srcField->getArray()->getNumberOfComponents());
00883   for(int i0=0;i0<4;i0++)
00884     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected8[i0],values[i0],1e-12);
00885   srcField->decrRef();
00886   //
00887   trgfield->decrRef();
00888   //
00889   sourceMesh->decrRef();
00890   targetMesh->decrRef();
00891 }
00892 
00893 void MEDCouplingRemapperTest::testExtruded()
00894 {
00895   MEDCouplingUMesh *mesh2DS=0;
00896   MEDCouplingUMesh *mesh3DS=build3DExtrudedUMesh_1(mesh2DS);
00897   MEDCouplingExtrudedMesh *extS=MEDCouplingExtrudedMesh::New(mesh3DS,mesh2DS,1);
00898   mesh3DS->decrRef();
00899   mesh2DS->decrRef();
00900   MEDCouplingUMesh *mesh2DT=0;
00901   MEDCouplingUMesh *mesh3DT=build3DExtrudedUMesh_1(mesh2DT);
00902   MEDCouplingExtrudedMesh *extT=MEDCouplingExtrudedMesh::New(mesh3DT,mesh2DT,1);
00903   //
00904   //
00905   mesh3DT->decrRef();
00906   mesh2DT->decrRef();
00907   //
00908   extS->decrRef();
00909   extT->decrRef();
00910 }
00911 
00912 void MEDCouplingRemapperTest::testExtruded2()
00913 {
00914   MEDCouplingUMesh *meshN,*meshTT,*meshTF;
00915   MEDCouplingBasicsTest::build3DExtrudedUMesh_2(meshN,meshTT,meshTF);
00916   std::vector<int> n;
00917   double pt[3]={300.,300.,0.};
00918   double v[3]={0.,0.,2.};
00919   meshN->findNodesOnPlane(pt,v,1e-12,n);
00920   MEDCouplingUMesh *meshN2D=(MEDCouplingUMesh *)meshN->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
00921   n.clear();
00922   bool b=false;
00923   int newNbOfNodes;
00924   DataArrayInt *da=meshTT->mergeNodes(1e-12,b,newNbOfNodes);
00925   CPPUNIT_ASSERT(b);
00926   da->decrRef();
00927   meshTT->findNodesOnPlane(pt,v,1e-12,n);
00928   MEDCouplingUMesh *meshTT2D=(MEDCouplingUMesh *)meshTT->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
00929   n.clear();
00930   meshTF->findNodesOnPlane(pt,v,1e-12,n);
00931   MEDCouplingUMesh *meshTF2D=(MEDCouplingUMesh *)meshTF->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
00932   n.clear();
00933   //
00934   MEDCouplingExtrudedMesh *meshNE=MEDCouplingExtrudedMesh::New(meshN,meshN2D,0);
00935   MEDCouplingExtrudedMesh *meshTTE=MEDCouplingExtrudedMesh::New(meshTT,meshTT2D,0);
00936   MEDCouplingExtrudedMesh *meshTFE=MEDCouplingExtrudedMesh::New(meshTF,meshTF2D,0);
00937   //
00938   MEDCouplingRemapper remapper;
00939   remapper.setPrecision(1e-12);
00940   remapper.setIntersectionType(INTERP_KERNEL::Geometric2D);
00941   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(meshNE,meshTTE,"P0P0"));
00942   MEDCouplingFieldDouble *srcField=MEDCouplingFieldDouble::New(ON_CELLS);
00943   srcField->setNature(IntegralGlobConstraint);
00944   srcField->setMesh(meshNE);
00945   DataArrayDouble *array=DataArrayDouble::New();
00946   array->alloc(meshNE->getNumberOfCells(),1);
00947   srcField->setArray(array);
00948   double vals1[40]={
00949     1000.,1000.,1020.,1030.,1040.,1000.,1000.,1070.,1080.,1090.,1000.,1000.,1120.,1130.,1140.,1000.,1000.,1170.,1180.,1190.,
00950     2000.,2000.,2020.,2030.,2040.,2000.,2000.,2070.,2080.,2090.,2000.,2000.,2120.,2130.,2140.,2000.,2000.,2170.,2180.,2190.,
00951   };
00952   CPPUNIT_ASSERT_EQUAL((int)(sizeof(vals1)/sizeof(double)),meshNE->getNumberOfCells());
00953   std::copy(vals1,vals1+meshNE->getNumberOfCells(),array->getPointer());
00954   array->decrRef();
00955   MEDCouplingFieldDouble *trgField=remapper.transferField(srcField,4.220173);
00956   double expected1[200]={
00957     800.,800.,800.,800.,800.,800.,800.,800.,800.,800.,1600.,1600.,1600.,1600.,1600.,1600.,1600.,1600.,1600.,1600.,
00958     102.,102.,102.,102.,102.,102.,102.,102.,102.,102.,202.,202.,202.,202.,202.,202.,202.,202.,202.,202.,
00959     103.,103.,103.,103.,103.,103.,103.,103.,103.,103.,203.,203.,203.,203.,203.,203.,203.,203.,203.,203.,
00960     104.,104.,104.,104.,104.,104.,104.,104.,104.,104.,204.,204.,204.,204.,204.,204.,204.,204.,204.,204.,
00961     219.,219.,219.,219.,219.,219.,219.,219.,219.,219.,419.,419.,419.,419.,419.,419.,419.,419.,419.,419.,
00962     221.,221.,221.,221.,221.,221.,221.,221.,221.,221.,421.,421.,421.,421.,421.,421.,421.,421.,421.,421.,
00963     223.,223.,223.,223.,223.,223.,223.,223.,223.,223.,423.,423.,423.,423.,423.,423.,423.,423.,423.,423.,
00964     117.,117.,117.,117.,117.,117.,117.,117.,117.,117.,217.,217.,217.,217.,217.,217.,217.,217.,217.,217.,
00965     118.,118.,118.,118.,118.,118.,118.,118.,118.,118.,218.,218.,218.,218.,218.,218.,218.,218.,218.,218.,
00966     119.,119.,119.,119.,119.,119.,119.,119.,119.,119.,219.,219.,219.,219.,219.,219.,219.,219.,219.,219.
00967     };
00968   for(int i=0;i<200;i++)
00969     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],trgField->getArray()->getConstPointer()[i],1e-3);//1e-3 precision due to non coincidence in 1D mesh
00970   CPPUNIT_ASSERT_DOUBLES_EQUAL(std::accumulate(expected1,expected1+200,0.),std::accumulate(vals1,vals1+40,0.),1e-10);
00971   CPPUNIT_ASSERT_DOUBLES_EQUAL(std::accumulate(expected1,expected1+200,0.),std::accumulate(trgField->getArray()->getConstPointer(),trgField->getArray()->getConstPointer()+200,0.),1e-10);
00972   trgField->decrRef();
00973   //
00974   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(meshNE,meshTFE,"P0P0"));
00975   trgField=remapper.transferField(srcField,4.220173);
00976   double expected2[340]={25.5, 51.25, 51.75, 26., 79., 158.75, 160.25, 80.5, 85.25, 171.25, 172.75, 86.75, 29.25, 58.75, 59.25, 29.75, 25.5, 51.25, 51.75, 26., 79., 158.75,
00977                          160.25, 80.5, 85.25, 171.25, 172.75, 86.75, 29.25, 58.75, 59.25, 29.75, 25.5, 51.25, 51.75, 26., 79., 158.75, 160.25, 80.5, 85.25, 171.25, 172.75, 86.75,
00978                          29.25, 58.75, 59.25, 29.75, 25.5, 51.25, 51.75, 26., 79., 158.75, 160.25, 80.5, 85.25, 171.25, 172.75, 86.75, 29.25, 58.75, 59.25, 29.75, 25.5, 51.25, 51.75,
00979                          26., 79., 158.75, 160.25, 80.5, 85.25, 171.25, 172.75, 86.75, 29.25, 58.75, 59.25, 29.75, 25.5, 51.25, 51.75, 26., 79., 158.75, 160.25, 80.5, 85.25, 171.25,
00980                          172.75, 86.75, 29.25, 58.75, 59.25, 29.75, 25.5, 51.25, 51.75, 26., 79., 158.75, 160.25, 80.5, 85.25, 171.25, 172.75, 86.75, 29.25, 58.75, 59.25, 29.75, 25.5,
00981                          51.25, 51.75, 26., 79., 158.75, 160.25, 80.5, 85.25, 171.25, 172.75, 86.75, 29.25, 58.75, 59.25, 29.75, 25.5, 51.25, 51.75, 26., 79., 158.75, 160.25, 80.5,
00982                          85.25, 171.25, 172.75, 86.75, 29.25, 58.75, 59.25, 29.75, 25.5, 51.25, 51.75, 26., 79., 158.75, 160.25, 80.5, 85.25, 171.25, 172.75, 86.75, 29.25, 58.75, 59.25,
00983                          29.75, 50.5, 101.25, 101.75, 51., 154., 308.75, 310.25, 155.5, 160.25, 321.25, 322.75, 161.75, 54.25, 108.75, 109.25, 54.75, 50.5, 101.25, 101.75, 51., 154.,
00984                          308.75, 310.25, 155.5, 160.25, 321.25, 322.75, 161.75, 54.25, 108.75, 109.25, 54.75, 50.5, 101.25, 101.75, 51., 154., 308.75, 310.25, 155.5, 160.25, 321.25, 322.75,
00985                          161.75, 54.25, 108.75, 109.25, 54.75, 50.5, 101.25, 101.75, 51., 154., 308.75, 310.25, 155.5, 160.25, 321.25, 322.75, 161.75, 54.25, 108.75, 109.25, 54.75, 50.5,
00986                          101.25, 101.75, 51., 154., 308.75, 310.25, 155.5, 160.25, 321.25, 322.75, 161.75, 54.25, 108.75, 109.25, 54.75, 50.5, 101.25, 101.75, 51., 154., 308.75, 310.25,
00987                          155.5, 160.25, 321.25, 322.75, 161.75, 54.25, 108.75, 109.25, 54.75, 50.5, 101.25, 101.75, 51., 154., 308.75, 310.25, 155.5, 160.25, 321.25, 322.75, 161.75, 54.25,
00988                          108.75, 109.25, 54.75, 50.5, 101.25, 101.75, 51., 154., 308.75, 310.25, 155.5, 160.25, 321.25, 322.75, 161.75, 54.25, 108.75, 109.25, 54.75, 50.5, 101.25, 101.75,
00989                          51., 154., 308.75, 310.25, 155.5, 160.25, 321.25, 322.75, 161.75, 54.25, 108.75, 109.25, 54.75, 50.5, 101.25, 101.75, 51., 154., 308.75, 310.25, 155.5, 160.25, 321.25,
00990                          322.75, 161.75, 54.25, 108.75, 109.25, 54.75, 800., 800., 800., 800., 800., 800., 800., 800., 800., 800., 1600., 1600., 1600., 1600., 1600., 1600., 1600.,
00991                          1600., 1600., 1600.};
00992   for(int i=0;i<340;i++)
00993     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],trgField->getArray()->getConstPointer()[i],1e-3);//1e-3 precision due to non coincidence in 1D mesh
00994   CPPUNIT_ASSERT_DOUBLES_EQUAL(std::accumulate(expected2,expected2+340,0.),std::accumulate(vals1,vals1+40,0.),1e-10);
00995   CPPUNIT_ASSERT_DOUBLES_EQUAL(std::accumulate(expected2,expected2+340,0.),std::accumulate(trgField->getArray()->getConstPointer(),trgField->getArray()->getConstPointer()+340,0.),1e-10);
00996   trgField->decrRef();
00997   srcField->decrRef();
00998   //
00999   double vals2[200]={
01000     100., 200., 300., 400., 500., 600., 700., 800., 900., 1000., 1100., 1200., 1300., 1400., 1500., 1600., 1700., 1800., 1900., 2000,
01001     101., 201., 301., 401., 501., 601., 701., 801., 901., 1001., 1101., 1201., 1301., 1401., 1501., 1601., 1701., 1801., 1901., 2001,
01002     102., 202., 302., 402., 502., 602., 702., 802., 902., 1002., 1102., 1202., 1302., 1402., 1502., 1602., 1702., 1802., 1902., 2002,
01003     103., 203., 303., 403., 503., 603., 703., 803., 903., 1003., 1103., 1203., 1303., 1403., 1503., 1603., 1703., 1803., 1903., 2003,
01004     104., 204., 304., 404., 504., 604., 704., 804., 904., 1004., 1104., 1204., 1304., 1404., 1504., 1604., 1704., 1804., 1904., 2004,
01005     105., 205., 305., 405., 505., 605., 705., 805., 905., 1005., 1105., 1205., 1305., 1405., 1505., 1605., 1705., 1805., 1905., 2005,
01006     106., 206., 306., 406., 506., 606., 706., 806., 906., 1006., 1106., 1206., 1306., 1406., 1506., 1606., 1706., 1806., 1906., 2006,
01007     107., 207., 307., 407., 507., 607., 707., 807., 907., 1007., 1107., 1207., 1307., 1407., 1507., 1607., 1707., 1807., 1907., 2007,
01008     108., 208., 308., 408., 508., 608., 708., 808., 908., 1008., 1108., 1208., 1308., 1408., 1508., 1608., 1708., 1808., 1908., 2008,
01009     109., 209., 309., 409., 509., 609., 709., 809., 909., 1009., 1109., 1209., 1309., 1409., 1509., 1609., 1709., 1809., 1909., 2009.
01010   };
01011   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(meshNE,meshTTE,"P0P0"));
01012   trgField=MEDCouplingFieldDouble::New(ON_CELLS);
01013   trgField->setNature(ConservativeVolumic);
01014   trgField->setMesh(meshTTE);
01015   array=DataArrayDouble::New();
01016   array->alloc(meshTTE->getNumberOfCells(),1);
01017   trgField->setArray(array);
01018   std::copy(vals2,vals2+meshTTE->getNumberOfCells(),array->getPointer());
01019   array->decrRef();
01020   srcField=remapper.reverseTransferField(trgField,4.220173);
01021   double expected3[40]={
01022     550.,550.,551.,552.,553.,550.,550.,554.,555.,556.,550.,550.,554.,555.,556.,550.,550.,557.,558.,559.,
01023     1550.,1550.,1551.,1552.,1553.,1550.,1550.,1554.,1555.,1556.,1550.,1550.,1554.,1555.,1556.,1550.,1550.,1557.,1558.,1559.
01024   };
01025   for(int i=0;i<40;i++)
01026     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],srcField->getArray()->getConstPointer()[i],1e-3);//1e-3 precision due to non coincidence in 1D mesh
01027   srcField->decrRef();
01028   trgField->decrRef();
01029   //
01030   double vals3[340]={
01031     100., 101., 102., 103., 104., 105., 106., 107., 108., 109., 110., 111., 112., 113., 114., 115.,
01032     200., 201., 202., 203., 204., 205., 206., 207., 208., 209., 210., 211., 212., 213., 214., 215.,
01033     300., 301., 302., 303., 304., 305., 306., 307., 308., 309., 310., 311., 312., 313., 314., 315.,
01034     400., 401., 402., 403., 404., 405., 406., 407., 408., 409., 410., 411., 412., 413., 414., 415.,
01035     500., 501., 502., 503., 504., 505., 506., 507., 508., 509., 510., 511., 512., 513., 514., 515.,
01036     600., 601., 602., 603., 604., 605., 606., 607., 608., 609., 610., 611., 612., 613., 614., 615.,
01037     700., 701., 702., 703., 704., 705., 706., 707., 708., 709., 710., 711., 712., 713., 714., 715.,
01038     800., 801., 802., 803., 804., 805., 806., 807., 808., 809., 810., 811., 812., 813., 814., 815.,
01039     900., 901., 902., 903., 904., 905., 906., 907., 908., 909., 910., 911., 912., 913., 914., 915.,
01040     1000., 1001., 1002., 1003., 1004., 1005., 1006., 1007., 1008., 1009., 1010., 1011., 1012., 1013., 1014., 1015.,
01041     1100., 1101., 1102., 1103., 1104., 1105., 1106., 1107., 1108., 1109., 1110., 1111., 1112., 1113., 1114., 1115.,
01042     1200., 1201., 1202., 1203., 1204., 1205., 1206., 1207., 1208., 1209., 1210., 1211., 1212., 1213., 1214., 1215.,
01043     1300., 1301., 1302., 1303., 1304., 1305., 1306., 1307., 1308., 1309., 1310., 1311., 1312., 1313., 1314., 1315.,
01044     1400., 1401., 1402., 1403., 1404., 1405., 1406., 1407., 1408., 1409., 1410., 1411., 1412., 1413., 1414., 1415.,
01045     1500., 1501., 1502., 1503., 1504., 1505., 1506., 1507., 1508., 1509., 1510., 1511., 1512., 1513., 1514., 1515.,
01046     1600., 1601., 1602., 1603., 1604., 1605., 1606., 1607., 1608., 1609., 1610., 1611., 1612., 1613., 1614., 1615.,
01047     1700., 1701., 1702., 1703., 1704., 1705., 1706., 1707., 1708., 1709., 1710., 1711., 1712., 1713., 1714., 1715.,
01048     1800., 1801., 1802., 1803., 1804., 1805., 1806., 1807., 1808., 1809., 1810., 1811., 1812., 1813., 1814., 1815.,
01049     1900., 1901., 1902., 1903., 1904., 1905., 1906., 1907., 1908., 1909., 1910., 1911., 1912., 1913., 1914., 1915.,
01050     2000., 2001., 2002., 2003., 2004., 2005., 2006., 2007., 2008., 2009., 2010., 2011., 2012., 2013., 2014., 2015.,
01051     116.,216.,316.,416.,516.,616.,716.,816.,916.,1016.,1116.,1216.,1316.,1416.,1516.,1616.,1716.,1816.,1916.,2016.
01052   };
01053   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(meshNE,meshTFE,"P0P0"));
01054   trgField=MEDCouplingFieldDouble::New(ON_CELLS);
01055   trgField->setNature(ConservativeVolumic);
01056   trgField->setMesh(meshTFE);
01057   array=DataArrayDouble::New();
01058   array->alloc(meshTFE->getNumberOfCells(),1);
01059   trgField->setArray(array);
01060   std::copy(vals3,vals3+meshTFE->getNumberOfCells(),array->getPointer());
01061   array->decrRef();
01062   srcField=remapper.reverseTransferField(trgField,4.220173);
01063   double expected4[40]={
01064     566.,566.,552.5,553.5,554.5,566.,566.,554.5,555.5,556.5,566.,566.,558.5,559.5,560.5,566.,566.,560.5,561.5,562.5,
01065     1566.,1566.,1552.5,1553.5,1554.5,1566.,1566.,1554.5,1555.5,1556.5,1566.,1566.,1558.5,1559.5,1560.5,1566.,1566.,1560.5,1561.5,1562.5
01066   };
01067   for(int i=0;i<40;i++)
01068     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected4[i],srcField->getArray()->getConstPointer()[i],1e-3);//1e-3 precision due to non coincidence in 1D mesh
01069   srcField->decrRef();
01070   trgField->decrRef();
01071   //
01072   meshN2D->decrRef();
01073   meshTT2D->decrRef();
01074   meshTF2D->decrRef();
01075   meshNE->decrRef();
01076   meshTTE->decrRef();
01077   meshTFE->decrRef();
01078   meshN->decrRef();
01079   meshTT->decrRef();
01080   meshTF->decrRef();
01081 }
01082 
01083 void MEDCouplingRemapperTest::testPrepareEx1()
01084 {
01085   MEDCouplingUMesh *sourceMesh=MEDCouplingBasicsTest::build2DSourceMesh_1();
01086   MEDCouplingUMesh *targetMesh=build2DTargetMesh_3();
01087   //
01088   MEDCouplingRemapper remapper;
01089   remapper.setPrecision(1e-12);
01090   remapper.setIntersectionType(INTERP_KERNEL::Triangulation);
01091   MEDCouplingFieldTemplate *srcFt=MEDCouplingFieldTemplate::New(ON_CELLS);
01092   MEDCouplingFieldTemplate *trgFt=MEDCouplingFieldTemplate::New(ON_CELLS);
01093   srcFt->setMesh(sourceMesh);
01094   trgFt->setMesh(targetMesh);
01095   CPPUNIT_ASSERT_EQUAL(1,remapper.prepareEx(srcFt,trgFt));
01096   srcFt->decrRef();
01097   trgFt->decrRef();
01098   MEDCouplingFieldDouble *srcField=MEDCouplingFieldDouble::New(ON_CELLS);
01099   srcField->setNature(ConservativeVolumic);
01100   srcField->setMesh(sourceMesh);
01101   DataArrayDouble *array=DataArrayDouble::New();
01102   array->alloc(sourceMesh->getNumberOfCells(),1);
01103   srcField->setArray(array);
01104   double *ptr=array->getPointer();
01105   for(int i=0;i<sourceMesh->getNumberOfCells();i++)
01106     ptr[i]=(double)(i+7);
01107   array->decrRef();
01108   MEDCouplingFieldDouble *trgfield=remapper.transferField(srcField,4.220173);
01109   const double *values=trgfield->getArray()->getConstPointer();
01110   const double valuesExpected[4]={7.75, 7.0625, 4.220173,8.0};
01111   CPPUNIT_ASSERT_EQUAL(4,trgfield->getArray()->getNumberOfTuples());
01112   CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents());
01113   for(int i0=0;i0<4;i0++)
01114     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected[i0],values[i0],1e-12);
01115   trgfield->decrRef();
01116   srcField->decrRef();
01117   sourceMesh->decrRef();
01118   targetMesh->decrRef();
01119 }
01120 
01121 MEDCouplingUMesh *MEDCouplingRemapperTest::build1DTargetMesh_2()
01122 {
01123   double targetCoords[20]={
01124     0.59,0.09, 0.69,0.19, 0.21,-0.29,0.31,-0.19, 0.45,0.25,0.65,0.45,
01125     -0.2,-0.2,0.11,0.11, 0.25,0.25, 0.45,0.45
01126   };
01127   int targetConn[10]={0,1, 2,3, 4,5, 6,7, 8,9};
01128 
01129   MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New("my name of mesh 1D 2",1);
01130   targetMesh->allocateCells(5);
01131   for(int i=0;i<5;i++)
01132     targetMesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,targetConn+2*i);
01133   targetMesh->finishInsertingCells();
01134   DataArrayDouble *myCoords=DataArrayDouble::New();
01135   myCoords->alloc(10,2);
01136   std::copy(targetCoords,targetCoords+20,myCoords->getPointer());
01137   targetMesh->setCoords(myCoords);
01138   myCoords->decrRef();
01139   return targetMesh;
01140 }
01141 
01142 MEDCouplingUMesh *MEDCouplingRemapperTest::build2DTargetMesh_3()
01143 {
01144   double targetCoords[20]={-0.6,-0.4, -0.1,-0.4, 1.1,-0.4, 2.1,-0.4,
01145                            -0.6,0.1,  -0.1,0.1,  1.1,0.1,  2.1,0.1,
01146                            -0.6,1.1,  -0.1,1.1};
01147   int targetConn[16]={0,4,5,1, 1,5,6,2, 2,6,7,3, 4,8,9,5};
01148   MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
01149   targetMesh->setMeshDimension(2);
01150   targetMesh->allocateCells(4);
01151   for(int i=0;i<4;i++)
01152     targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+4*i);
01153   targetMesh->finishInsertingCells();
01154   DataArrayDouble *myCoords=DataArrayDouble::New();
01155   myCoords->alloc(10,2);
01156   std::copy(targetCoords,targetCoords+20,myCoords->getPointer());
01157   targetMesh->setCoords(myCoords);
01158   myCoords->decrRef();
01159   return targetMesh;
01160 }
01161 
01162 MEDCouplingUMesh *MEDCouplingRemapperTest::build3DExtrudedUMesh_1(MEDCouplingUMesh *&mesh2D)
01163 {
01164   double coords[180]={
01165     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.,
01166     3.,2.,0., 0.,1.,0., 1.,3.,0., 2.,2.,0., 2.,3.,0.,
01167     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.,
01168     3.,2.,1., 0.,1.,1., 1.,3.,1., 2.,2.,1., 2.,3.,1.,
01169     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.,
01170     3.,2.,2., 0.,1.,2., 1.,3.,2., 2.,2.,2., 2.,3.,2.,
01171     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.,
01172     3.,2.,3., 0.,1.,3., 1.,3.,3., 2.,2.,3., 2.,3.,3.};
01173 
01174   int conn[354]={
01175     // 0
01176     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,
01177     1,6,5,3,16,21,20,18,   13,10,9,6,28,25,24,21,
01178     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,
01179     7,12,14,13,22,27,29,28,
01180     // 1
01181     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,
01182     16,21,20,18,31,36,35,33,   28,25,24,21,43,40,39,36,
01183     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,
01184     22,27,29,28,37,42,44,43,
01185     // 2
01186     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,
01187     31,36,35,33,46,51,50,48,  43,40,39,36,58,55,54,51,
01188     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,
01189     37,42,44,43,52,57,59,58
01190   };
01191   int conn2[28]={7,12,14,13, 11,8,7,4,2,1, 13,10,9,6, 1,6,5,3, 1,2,4,7,13,6, 0,11,1,3};
01192   //
01193   MEDCouplingUMesh *ret=MEDCouplingUMesh::New();
01194   ret->setMeshDimension(3);
01195   ret->allocateCells(18);
01196   //
01197   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn);
01198   ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+8);
01199   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+51);
01200   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+59);
01201   ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+67);
01202   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+110);
01203   //
01204   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+118);
01205   ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+126);
01206   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+169);
01207   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+177);
01208   ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+185);
01209   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+228);
01210   //
01211   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+236);
01212   ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+244);
01213   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+287);
01214   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+295);
01215   ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+303);
01216   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+346);
01217   //
01218   ret->finishInsertingCells();
01219   DataArrayDouble *myCoords=DataArrayDouble::New();
01220   myCoords->alloc(60,3);
01221   std::copy(coords,coords+180,myCoords->getPointer());
01222   ret->setCoords(myCoords);
01223   //
01224   mesh2D=MEDCouplingUMesh::New();
01225   mesh2D->setMeshDimension(2);
01226   mesh2D->allocateCells(6);
01227   mesh2D->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn2);
01228   mesh2D->insertNextCell(INTERP_KERNEL::NORM_POLYGON,6,conn2+4);
01229   mesh2D->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn2+10);
01230   mesh2D->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn2+14);
01231   mesh2D->insertNextCell(INTERP_KERNEL::NORM_POLYGON,6,conn2+18);
01232   mesh2D->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn2+24);
01233   mesh2D->setCoords(myCoords);
01234   myCoords->decrRef();
01235   return ret;
01236 }
01237 
01238 void MEDCouplingRemapperTest::testPartialTransfer1()
01239 {
01240   MEDCouplingRemapper remapper;
01241   MEDCouplingUMesh *sourceMesh=build1DTargetMesh_2();
01242   MEDCouplingUMesh *targetMesh=MEDCouplingBasicsTest::build2DTargetMesh_1();
01243   remapper.setIntersectionType(INTERP_KERNEL::PointLocator);
01244   CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(sourceMesh,targetMesh,"P0P0"));
01245   MEDCouplingFieldDouble *srcField=MEDCouplingFieldDouble::New(ON_CELLS);
01246   srcField->setNature(ConservativeVolumic);
01247   srcField->setMesh(sourceMesh);
01248   DataArrayDouble *array=DataArrayDouble::New();
01249   array->alloc(sourceMesh->getNumberOfCells(),1);
01250   srcField->setArray(array);
01251   double *ptr=array->getPointer();
01252   for(int i=0;i<sourceMesh->getNumberOfCells();i++)
01253     ptr[i]=(double)(i+7);
01254   array->decrRef();
01255   MEDCouplingFieldDouble *trgField=MEDCouplingFieldDouble::New(ON_CELLS);
01256   trgField->setNature(ConservativeVolumic);
01257   trgField->setMesh(targetMesh);
01258   array=DataArrayDouble::New();
01259   array->alloc(targetMesh->getNumberOfCells(),1);
01260   ptr=array->getPointer();
01261   std::fill(ptr,ptr+targetMesh->getNumberOfCells(),96.3);
01262   trgField->setArray(array);
01263   array->decrRef();
01264   remapper.partialTransfer(srcField,trgField);
01265   const double valuesExpected9[5]={10.,8.,7.,96.3,10.};
01266   const double *values=trgField->getArray()->getConstPointer();
01267   for(int i0=0;i0<5;i0++)
01268     CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected9[i0],values[i0],1e-12);
01269   trgField->decrRef();
01270   srcField->decrRef();
01271   sourceMesh->decrRef();
01272   targetMesh->decrRef();
01273 }