From bfbb6e70ca65979e36c85d2960fe5d230cc3ff32 Mon Sep 17 00:00:00 2001 From: abn Date: Mon, 30 Nov 2015 14:34:33 +0100 Subject: [PATCH] OverlapDEC: adding attach*LocalField(MEDCouplingFieldDouble *) methods --- src/ParaMEDMEM/OverlapDEC.cxx | 25 ++++ src/ParaMEDMEM/OverlapDEC.hxx | 2 + src/ParaMEDMEMTest/ParaMEDMEMTest.hxx | 10 +- .../ParaMEDMEMTest_OverlapDEC.cxx | 135 ++++++++---------- 4 files changed, 92 insertions(+), 80 deletions(-) diff --git a/src/ParaMEDMEM/OverlapDEC.cxx b/src/ParaMEDMEM/OverlapDEC.cxx index 12374f912..4fcfdc49f 100644 --- a/src/ParaMEDMEM/OverlapDEC.cxx +++ b/src/ParaMEDMEM/OverlapDEC.cxx @@ -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(const_cast(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(const_cast(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) diff --git a/src/ParaMEDMEM/OverlapDEC.hxx b/src/ParaMEDMEM/OverlapDEC.hxx index 871cdc6e6..0fcba0971 100644 --- a/src/ParaMEDMEM/OverlapDEC.hxx +++ b/src/ParaMEDMEM/OverlapDEC.hxx @@ -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; diff --git a/src/ParaMEDMEMTest/ParaMEDMEMTest.hxx b/src/ParaMEDMEMTest/ParaMEDMEMTest.hxx index b15b53fd1..9d6d1f141 100644 --- a/src/ParaMEDMEMTest/ParaMEDMEMTest.hxx +++ b/src/ParaMEDMEMTest/ParaMEDMEMTest.hxx @@ -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 diff --git a/src/ParaMEDMEMTest/ParaMEDMEMTest_OverlapDEC.cxx b/src/ParaMEDMEMTest/ParaMEDMEMTest_OverlapDEC.cxx index 63bfc9f9b..187d3df3f 100644 --- a/src/ParaMEDMEMTest/ParaMEDMEMTest_OverlapDEC.cxx +++ b/src/ParaMEDMEMTest/ParaMEDMEMTest_OverlapDEC.cxx @@ -46,6 +46,7 @@ using namespace ParaMEDMEM; typedef MEDCouplingAutoRefCountObjectPtr MUMesh; typedef MEDCouplingAutoRefCountObjectPtr MFDouble; +typedef MEDCouplingAutoRefCountObjectPtr DADouble; //void ParaMEDMEMTest::testOverlapDEC_LMEC_seq() //{ @@ -180,17 +181,15 @@ typedef MEDCouplingAutoRefCountObjectPtr 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); } -- 2.39.2