]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
OverlapDEC: adding attach*LocalField(MEDCouplingFieldDouble *) methods
authorabn <adrien.bruneton@cea.fr>
Mon, 30 Nov 2015 13:34:33 +0000 (14:34 +0100)
committerabn <adrien.bruneton@cea.fr>
Mon, 30 Nov 2015 13:34:33 +0000 (14:34 +0100)
src/ParaMEDMEM/OverlapDEC.cxx
src/ParaMEDMEM/OverlapDEC.hxx
src/ParaMEDMEMTest/ParaMEDMEMTest.hxx
src/ParaMEDMEMTest/ParaMEDMEMTest_OverlapDEC.cxx

index 12374f9122d85ec36a835ff7321975f2673dbbdd..4fcfdc49f66b23f0d29f7ab173ce3a6a403523b0 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "OverlapDEC.hxx"
 #include "CommInterface.hxx"
+#include "ParaMESH.hxx"
 #include "ParaFIELD.hxx"
 #include "MPIProcessorGroup.hxx"
 #include "OverlapElementLocator.hxx"
@@ -322,6 +323,30 @@ namespace ParaMEDMEM
     _own_target_field=ownPt;
   }
 
+  void OverlapDEC::attachSourceLocalField(MEDCouplingFieldDouble *field)
+  {
+    if(!isInGroup())
+      return ;
+
+    ParaMESH *paramesh = new ParaMESH(static_cast<MEDCouplingPointSet *>(const_cast<MEDCouplingMesh *>(field->getMesh())),
+                                      *_group,field->getMesh()->getName());
+    ParaFIELD *tmpField=new ParaFIELD(field, paramesh, *_group);
+    tmpField->setOwnSupport(true);
+    attachSourceLocalField(tmpField,true);
+  }
+
+  void OverlapDEC::attachTargetLocalField(MEDCouplingFieldDouble *field)
+  {
+    if(!isInGroup())
+      return ;
+
+    ParaMESH *paramesh = new ParaMESH(static_cast<MEDCouplingPointSet *>(const_cast<MEDCouplingMesh *>(field->getMesh())),
+                                      *_group,field->getMesh()->getName());
+    ParaFIELD *tmpField=new ParaFIELD(field, paramesh, *_group);
+    tmpField->setOwnSupport(true);
+    attachTargetLocalField(tmpField,true);
+  }
+
   bool OverlapDEC::isInGroup() const
   {
     if(!_group)
index 871cdc6e6c8e5d0705d8072ee7bda8277f6b18ef..0fcba097140bc07e5ddfc0049e6f0bbc7e7dbde4 100644 (file)
@@ -44,6 +44,8 @@ namespace ParaMEDMEM
     void synchronize();
     void attachSourceLocalField(ParaFIELD *field, bool ownPt=false);
     void attachTargetLocalField(ParaFIELD *field, bool ownPt=false);
+    void attachSourceLocalField(MEDCouplingFieldDouble *field);
+    void attachTargetLocalField(MEDCouplingFieldDouble *field);
     ProcessorGroup *getGroup() { return _group; }
     bool isInGroup() const;
 
index b15b53fd1291ddeaca8383333fb01068136f4431..9d6d1f141b561f80f94d753cbebec06b631af310 100644 (file)
@@ -64,11 +64,11 @@ class ParaMEDMEMTest : public CppUnit::TestFixture
   CPPUNIT_TEST(testAsynchronousSlowerSourceInterpKernelDEC_2D);           // 5 procs
   CPPUNIT_TEST(testAsynchronousSlowSourceInterpKernelDEC_2D);             // 5 procs
   CPPUNIT_TEST(testAsynchronousFastSourceInterpKernelDEC_2D);             // 5 procs
-//#ifdef MED_ENABLE_FVM
-//  //can be added again after FVM correction for 2D
-//  //  CPPUNIT_TEST(testNonCoincidentDEC_2D);
-//  CPPUNIT_TEST(testNonCoincidentDEC_3D);
-//#endif
+#ifdef MED_ENABLE_FVM
+  //can be added again after FVM correction for 2D
+  //  CPPUNIT_TEST(testNonCoincidentDEC_2D);
+  CPPUNIT_TEST(testNonCoincidentDEC_3D);
+#endif
   CPPUNIT_TEST(testStructuredCoincidentDEC);     // 5 procs
   CPPUNIT_TEST(testICoco1);           // 2 procs
   CPPUNIT_TEST(testGauthier1);        // 4 procs
index 63bfc9f9be256db379f92d31d348609848ad66df..187d3df3fbe64ce50c9ec02b331f6ce2996a22e8 100644 (file)
@@ -46,6 +46,7 @@ using namespace ParaMEDMEM;
 
 typedef  MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> MUMesh;
 typedef  MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> MFDouble;
+typedef  MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> DADouble;
 
 //void ParaMEDMEMTest::testOverlapDEC_LMEC_seq()
 //{
@@ -180,17 +181,15 @@ typedef  MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> MFDouble;
 //
 //  MPI_Barrier(MPI_COMM_WORLD);
 //}
-
-void prepareData1(int rank, ProcessorGroup * grp, NatureOfField nature,
-                                  MEDCouplingUMesh *& meshS, MEDCouplingUMesh *& meshT,
-                                  ParaMESH*& parameshS, ParaMESH*& parameshT,
-                                  ParaFIELD*& parafieldS, ParaFIELD*& parafieldT)
+//
+void prepareData1(int rank, NatureOfField nature,
+                  MEDCouplingFieldDouble *& fieldS, MEDCouplingFieldDouble *& fieldT)
 {
   if(rank==0)
     {
       const double coordsS[10]={0.,0.,0.5,0.,1.,0.,0.,0.5,0.5,0.5};
       const double coordsT[6]={0.,0.,1.,0.,1.,1.};
-      meshS=MEDCouplingUMesh::New();
+      MUMesh meshS=MEDCouplingUMesh::New();
       meshS->setMeshDimension(2);
       DataArrayDouble *myCoords=DataArrayDouble::New();
       myCoords->alloc(5,2);
@@ -202,14 +201,14 @@ void prepareData1(int rank, ProcessorGroup * grp, NatureOfField nature,
       meshS->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,connS);
       meshS->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,connS+4);
       meshS->finishInsertingCells();
-      ComponentTopology comptopo;
-      parameshS=new ParaMESH(meshS, *grp,"source mesh");
-      parafieldS=new ParaFIELD(ON_CELLS,NO_TIME,parameshS,comptopo);
-      parafieldS->getField()->setNature(nature);
-      double *valsS=parafieldS->getField()->getArray()->getPointer();
+      fieldS = MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
+      DADouble arr = DataArrayDouble::New(); arr->alloc(meshS->getNumberOfCells(), 1);
+      fieldS->setMesh(meshS); fieldS->setArray(arr);
+      fieldS->setNature(nature);
+      double *valsS=fieldS->getArray()->getPointer();
       valsS[0]=7.; valsS[1]=8.;
       //
-      meshT=MEDCouplingUMesh::New();
+      MUMesh meshT=MEDCouplingUMesh::New();
       meshT->setMeshDimension(2);
       myCoords=DataArrayDouble::New();
       myCoords->alloc(3,2);
@@ -220,10 +219,11 @@ void prepareData1(int rank, ProcessorGroup * grp, NatureOfField nature,
       meshT->allocateCells(1);
       meshT->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,connT);
       meshT->finishInsertingCells();
-      parameshT=new ParaMESH(meshT,*grp,"target mesh");
-      parafieldT=new ParaFIELD(ON_CELLS,NO_TIME,parameshT,comptopo);
-      parafieldT->getField()->setNature(nature);
-      double *valsT=parafieldT->getField()->getArray()->getPointer();
+      fieldT = MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
+      DADouble arr2 = DataArrayDouble::New(); arr2->alloc(meshT->getNumberOfCells(), 1);
+      fieldT->setMesh(meshT);  fieldT->setArray(arr2);
+      fieldT->setNature(nature);
+      double *valsT=fieldT->getArray()->getPointer();
       valsT[0]=7.;
     }
   //
@@ -231,7 +231,7 @@ void prepareData1(int rank, ProcessorGroup * grp, NatureOfField nature,
     {
       const double coordsS[10]={1.,0.,0.5,0.5,1.,0.5,0.5,1.,1.,1.};
       const double coordsT[6]={0.,0.,0.5,0.5,0.,1.};
-      meshS=MEDCouplingUMesh::New();
+      MUMesh meshS=MEDCouplingUMesh::New();
       meshS->setMeshDimension(2);
       DataArrayDouble *myCoords=DataArrayDouble::New();
       myCoords->alloc(5,2);
@@ -243,15 +243,14 @@ void prepareData1(int rank, ProcessorGroup * grp, NatureOfField nature,
       meshS->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,connS);
       meshS->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,connS+3);
       meshS->finishInsertingCells();
-      ComponentTopology comptopo;
-      parameshS=new ParaMESH(meshS,*grp,"source mesh");
-      parafieldS=new ParaFIELD(ON_CELLS,NO_TIME,parameshS,comptopo);
-      parafieldS->getField()->setNature(nature);
-      double *valsS=parafieldS->getField()->getArray()->getPointer();
-      valsS[0]=9.;
-      valsS[1]=11.;
+      fieldS = MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
+      DADouble arr = DataArrayDouble::New(); arr->alloc(meshS->getNumberOfCells(), 1);
+      fieldS->setMesh(meshS); fieldS->setArray(arr);
+      fieldS->setNature(nature);
+      double *valsS=fieldS->getArray()->getPointer();
+      valsS[0]=9.; valsS[1]=11.;
       //
-      meshT=MEDCouplingUMesh::New();
+      MUMesh meshT=MEDCouplingUMesh::New();
       meshT->setMeshDimension(2);
       myCoords=DataArrayDouble::New();
       myCoords->alloc(3,2);
@@ -262,10 +261,11 @@ void prepareData1(int rank, ProcessorGroup * grp, NatureOfField nature,
       meshT->allocateCells(1);
       meshT->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,connT);
       meshT->finishInsertingCells();
-      parameshT=new ParaMESH(meshT,*grp,"target mesh");
-      parafieldT=new ParaFIELD(ON_CELLS,NO_TIME,parameshT,comptopo);
-      parafieldT->getField()->setNature(nature);
-      double *valsT=parafieldT->getField()->getArray()->getPointer();
+      fieldT = MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
+      DADouble arr2 = DataArrayDouble::New(); arr2->alloc(meshT->getNumberOfCells(), 1);
+      fieldT->setMesh(meshT);  fieldT->setArray(arr2);
+      fieldT->setNature(nature);
+      double *valsT=fieldT->getArray()->getPointer();
       valsT[0]=8.;
     }
   //
@@ -273,7 +273,7 @@ void prepareData1(int rank, ProcessorGroup * grp, NatureOfField nature,
     {
       const double coordsS[8]={0.,0.5, 0.5,0.5, 0.,1., 0.5,1.};
       const double coordsT[6]={0.5,0.5,0.,1.,1.,1.};
-      meshS=MEDCouplingUMesh::New();
+      MUMesh meshS=MEDCouplingUMesh::New();
       meshS->setMeshDimension(2);
       DataArrayDouble *myCoords=DataArrayDouble::New();
       myCoords->alloc(4,2);
@@ -284,14 +284,14 @@ void prepareData1(int rank, ProcessorGroup * grp, NatureOfField nature,
       meshS->allocateCells(1);
       meshS->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,connS);
       meshS->finishInsertingCells();
-      ComponentTopology comptopo;
-      parameshS=new ParaMESH(meshS,*grp,"source mesh");
-      parafieldS=new ParaFIELD(ON_CELLS,NO_TIME,parameshS,comptopo);
-      parafieldS->getField()->setNature(nature);
-      double *valsS=parafieldS->getField()->getArray()->getPointer();
+      fieldS = MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
+      DADouble arr = DataArrayDouble::New(); arr->alloc(meshS->getNumberOfCells(), 1);
+      fieldS->setMesh(meshS); fieldS->setArray(arr);
+      fieldS->setNature(nature);
+      double *valsS=fieldS->getArray()->getPointer();
       valsS[0]=10.;
       //
-      meshT=MEDCouplingUMesh::New();
+      MUMesh meshT=MEDCouplingUMesh::New();
       meshT->setMeshDimension(2);
       myCoords=DataArrayDouble::New();
       myCoords->alloc(3,2);
@@ -302,10 +302,11 @@ void prepareData1(int rank, ProcessorGroup * grp, NatureOfField nature,
       meshT->allocateCells(1);
       meshT->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,connT);
       meshT->finishInsertingCells();
-      parameshT=new ParaMESH(meshT,*grp,"target mesh");
-      parafieldT=new ParaFIELD(ON_CELLS,NO_TIME,parameshT,comptopo);
-      parafieldT->getField()->setNature(nature);
-      double *valsT=parafieldT->getField()->getArray()->getPointer();
+      fieldT = MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
+      DADouble arr2 = DataArrayDouble::New(); arr2->alloc(meshT->getNumberOfCells(), 1);
+      fieldT->setMesh(meshT); fieldT->setArray(arr2);
+      fieldT->setNature(nature);
+      double *valsT=fieldT->getArray()->getPointer();
       valsT[0]=9.;
     }
 }
@@ -338,13 +339,9 @@ void ParaMEDMEMTest::testOverlapDEC1()
 
   CommInterface interface;
   OverlapDEC dec(procs);
-  ProcessorGroup * grp = dec.getGroup();
-  MEDCouplingUMesh* meshS=0, *meshT=0;
-  ParaMESH* parameshS=0, *parameshT=0;
-  ParaFIELD* parafieldS=0, *parafieldT=0;
+  MEDCouplingFieldDouble * mcfieldS=0, *mcfieldT=0;
 
-  MPI_Barrier(MPI_COMM_WORLD);
-  prepareData1(rank, grp, ConservativeVolumic, meshS, meshT, parameshS, parameshT, parafieldS, parafieldT);
+  prepareData1(rank, ConservativeVolumic, mcfieldS, mcfieldT);
 
   /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    *  HACK ON BOUNDING BOX TO MAKE THIS CASE SIMPLE AND USABLE IN DEBUG
@@ -355,31 +352,27 @@ void ParaMEDMEMTest::testOverlapDEC1()
    */
   dec.setBoundingBoxAdjustmentAbs(-1.0e-12);
 
-  dec.attachSourceLocalField(parafieldS);
-  dec.attachTargetLocalField(parafieldT);
+  dec.attachSourceLocalField(mcfieldS);
+  dec.attachTargetLocalField(mcfieldT);
   dec.synchronize();
   dec.sendRecvData(true);
   //
   MPI_Barrier(MPI_COMM_WORLD);
   if(rank==0)
     {
-      CPPUNIT_ASSERT_DOUBLES_EQUAL(8.75,parafieldT->getField()->getArray()->getIJ(0,0),1e-12);
+      CPPUNIT_ASSERT_DOUBLES_EQUAL(8.75,mcfieldT->getArray()->getIJ(0,0),1e-12);
     }
   if(rank==1)
     {
-      CPPUNIT_ASSERT_DOUBLES_EQUAL(8.5,parafieldT->getField()->getArray()->getIJ(0,0),1e-12);
+      CPPUNIT_ASSERT_DOUBLES_EQUAL(8.5,mcfieldT->getArray()->getIJ(0,0),1e-12);
     }
   if(rank==2)
     {
-      CPPUNIT_ASSERT_DOUBLES_EQUAL(10.5,parafieldT->getField()->getArray()->getIJ(0,0),1e-12);
+      CPPUNIT_ASSERT_DOUBLES_EQUAL(10.5,mcfieldT->getArray()->getIJ(0,0),1e-12);
     }
 
-  delete parafieldS;
-  delete parafieldT;
-  delete parameshS;
-  delete parameshT;
-  meshS->decrRef();
-  meshT->decrRef();
+  mcfieldS->decrRef();
+  mcfieldT->decrRef();
 
   MPI_Barrier(MPI_COMM_WORLD);
 }
@@ -410,40 +403,32 @@ void ParaMEDMEMTest::testOverlapDEC2()
 
   CommInterface interface;
   OverlapDEC dec(procs);
-  ProcessorGroup * grp = dec.getGroup();
-  MEDCouplingUMesh* meshS=0, *meshT=0;
-  ParaMESH* parameshS=0, *parameshT=0;
-  ParaFIELD* parafieldS=0, *parafieldT=0;
-
-  MPI_Barrier(MPI_COMM_WORLD);
-  prepareData1(rank, grp, ConservativeVolumic,meshS, meshT, parameshS, parameshT, parafieldS, parafieldT);
+  MEDCouplingFieldDouble * mcfieldS=0, *mcfieldT=0;
+  prepareData1(rank, ConservativeVolumic, mcfieldS, mcfieldT);
 
   /* Normal bounding boxes here: */
   dec.setBoundingBoxAdjustmentAbs(+1.0e-12);
 
-  dec.attachSourceLocalField(parafieldS);
-  dec.attachTargetLocalField(parafieldT);
+  dec.attachSourceLocalField(mcfieldS);
+  dec.attachTargetLocalField(mcfieldT);
   dec.synchronize();
   dec.sendRecvData(true);
   //
   if(rank==0)
     {
-      CPPUNIT_ASSERT_DOUBLES_EQUAL(8.75,parafieldT->getField()->getArray()->getIJ(0,0),1e-12);
+      CPPUNIT_ASSERT_DOUBLES_EQUAL(8.75,mcfieldT->getArray()->getIJ(0,0),1e-12);
     }
   if(rank==1)
     {
-      CPPUNIT_ASSERT_DOUBLES_EQUAL(8.5,parafieldT->getField()->getArray()->getIJ(0,0),1e-12);
+      CPPUNIT_ASSERT_DOUBLES_EQUAL(8.5,mcfieldT->getArray()->getIJ(0,0),1e-12);
     }
   if(rank==2)
     {
-      CPPUNIT_ASSERT_DOUBLES_EQUAL(10.5,parafieldT->getField()->getArray()->getIJ(0,0),1e-12);
+      CPPUNIT_ASSERT_DOUBLES_EQUAL(10.5,mcfieldT->getArray()->getIJ(0,0),1e-12);
     }
-  delete parafieldS;
-  delete parafieldT;
-  delete parameshS;
-  delete parameshT;
-  meshS->decrRef();
-  meshT->decrRef();
+
+  mcfieldS->decrRef();
+  mcfieldT->decrRef();
 
   MPI_Barrier(MPI_COMM_WORLD);
 }