-// Copyright (C) 2007-2015 CEA/DEN, EDF R&D
+// Copyright (C) 2007-2016 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
using namespace std;
-#include "MEDCouplingAutoRefCountObjectPtr.hxx"
+#include "MCAuto.hxx"
#include "MEDLoader.hxx"
#include "MEDLoaderBase.hxx"
#include "MEDCouplingFieldDouble.hxx"
#include "MEDCouplingMemArray.hxx"
#include "MEDCouplingRemapper.hxx"
-using namespace ParaMEDMEM;
+using namespace MEDCoupling;
-typedef MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> MUMesh;
-typedef MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> MFDouble;
-typedef MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> DADouble;
+typedef MCAuto<MEDCouplingUMesh> MUMesh;
+typedef MCAuto<MEDCouplingFieldDouble> MFDouble;
+typedef MCAuto<DataArrayDouble> DADouble;
//void ParaMEDMEMTest::testOverlapDEC_LMEC_seq()
//{
// string tgt_mesh_nam(rep + string("T_SC_Trio_dst.med"));
//// string src_mesh_nam(rep + string("h_TH_Trio_src.med"));
//// string tgt_mesh_nam(rep + string("h_TH_Trio_dst.med"));
-// MUMesh src_mesh=MEDLoader::ReadUMeshFromFile(src_mesh_nam,"SupportOf_",0);
-// MUMesh tgt_mesh=MEDLoader::ReadUMeshFromFile(tgt_mesh_nam,"SupportOf_T_SC_Trio",0);
-//// MUMesh tgt_mesh=MEDLoader::ReadUMeshFromFile(tgt_mesh_nam,"SupportOf_h_TH_Trio",0);
+// MUMesh src_mesh=ReadUMeshFromFile(src_mesh_nam,"SupportOf_",0);
+// MUMesh tgt_mesh=ReadUMeshFromFile(tgt_mesh_nam,"SupportOf_T_SC_Trio",0);
+//// MUMesh tgt_mesh=ReadUMeshFromFile(tgt_mesh_nam,"SupportOf_h_TH_Trio",0);
//
// MFDouble srcField = MEDCouplingFieldDouble::New(ON_CELLS, ONE_TIME);
// srcField->setMesh(src_mesh);
// DataArrayDouble * dad = DataArrayDouble::New(); dad->alloc(src_mesh->getNumberOfCells(),1);
// dad->fillWithValue(1.0);
// srcField->setArray(dad);
-// srcField->setNature(ConservativeVolumic);
+// srcField->setNature(IntensiveMaximum);
//
// MEDCouplingRemapper remap;
// remap.setOrientation(2); // always consider surface intersections as absolute areas.
// MFDouble tgtField = remap.transferField(srcField, 1.0e+300);
// tgtField->setName("result");
// string out_nam(rep + string("adrien.med"));
-// MEDLoader::WriteField(out_nam,tgtField, true);
+// WriteField(out_nam,tgtField, true);
// cout << "wrote: " << out_nam << "\n";
// double integ1 = 0.0, integ2 = 0.0;
// srcField->integral(true, &integ1);
//
//void ParaMEDMEMTest::testOverlapDEC_LMEC_para()
//{
-// using namespace ParaMEDMEM;
+// using namespace MEDCoupling;
//
// int size;
// int rank;
// {
// // string src_mesh_nam(rep + string("h_TH_Trio_src.med"));
// // string tgt_mesh_nam(rep + string("h_TH_Trio_dst.med"));
-// MUMesh src_mesh=MEDLoader::ReadUMeshFromFile(src_mesh_nam,"SupportOf_",0);
-// MUMesh tgt_mesh=MEDLoader::ReadUMeshFromFile(tgt_mesh_nam,"SupportOf_T_SC_Trio",0);
-// // MUMesh tgt_mesh=MEDLoader::ReadUMeshFromFile(tgt_mesh_nam,"SupportOf_h_TH_Trio",0);
+// MUMesh src_mesh=ReadUMeshFromFile(src_mesh_nam,"SupportOf_",0);
+// MUMesh tgt_mesh=ReadUMeshFromFile(tgt_mesh_nam,"SupportOf_T_SC_Trio",0);
+// // MUMesh tgt_mesh=ReadUMeshFromFile(tgt_mesh_nam,"SupportOf_h_TH_Trio",0);
//
// // **** SOURCE
// srcField = MEDCouplingFieldDouble::New(ON_CELLS, ONE_TIME);
// DataArrayDouble * dad = DataArrayDouble::New(); dad->alloc(src_mesh->getNumberOfCells(),1);
// dad->fillWithValue(1.0);
// srcField->setArray(dad);
-// srcField->setNature(ConservativeVolumic);
+// srcField->setNature(IntensiveMaximum);
//
// ComponentTopology comptopo;
// parameshS = new ParaMESH(src_mesh,*dec.getGroup(),"source mesh");
// parafieldS = new ParaFIELD(ON_CELLS,ONE_TIME,parameshS,comptopo);
-// parafieldS->getField()->setNature(ConservativeVolumic);//IntegralGlobConstraint
+// parafieldS->getField()->setNature(IntensiveMaximum);//ExtensiveConservation
// parafieldS->getField()->setArray(dad);
//
// // **** TARGET
// parameshT=new ParaMESH(tgt_mesh,*dec.getGroup(),"target mesh");
// parafieldT=new ParaFIELD(ON_CELLS,ONE_TIME,parameshT,comptopo);
-// parafieldT->getField()->setNature(ConservativeVolumic);//IntegralGlobConstraint
+// parafieldT->getField()->setNature(IntensiveMaximum);//ExtensiveConservation
// parafieldT->getField()->getArray()->fillWithValue(1.0e300);
//// valsT[0]=7.;
// }
// tgtField->integral(true, &integ2);
// tgtField->setName("result");
// string out_nam(rep + string("adrien_para.med"));
-// MEDLoader::WriteField(out_nam,tgtField, true);
+// WriteField(out_nam,tgtField, true);
// cout << "wrote: " << out_nam << "\n";
// CPPUNIT_ASSERT_DOUBLES_EQUAL(integ1,integ2,1e-8);
// }
}
}
-/*! Test case from the official doc of the OverlapDEC.
- * WARNING: bounding boxes are tweaked here to make the case more interesting (i.e. to avoid an all to all exchange
- * between all procs).
- */
-void ParaMEDMEMTest::testOverlapDEC1()
-{
- int size, rank;
- MPI_Comm_size(MPI_COMM_WORLD,&size);
- MPI_Comm_rank(MPI_COMM_WORLD,&rank);
- // char hostname[256];
- // printf("(%d) PID %d on localhost ready for attach\n", rank, getpid());
- // fflush(stdout);
-
-// if (rank == 1)
-// {
-// int i=1, j=0;
-// while (i!=0)
-// j=2;
-// }
-
- if (size != 3) return ;
- int nproc = 3;
- std::set<int> procs;
- for (int i=0; i<nproc; i++)
- procs.insert(i);
-
- CommInterface interface;
- OverlapDEC dec(procs);
- MEDCouplingFieldDouble * mcfieldS=0, *mcfieldT=0;
-
- prepareData1(rank, ConservativeVolumic, mcfieldS, mcfieldT);
-
- /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- * HACK ON BOUNDING BOX TO MAKE THIS CASE SIMPLE AND USABLE IN DEBUG
- * Bounding boxes are slightly smaller than should be, thus localizing the work to be done
- * and avoiding every proc talking to everyone else.
- * Obviously this is NOT a good idea to do this in production code :-)
- * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- */
- dec.setBoundingBoxAdjustmentAbs(-1.0e-12);
-
- 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,mcfieldT->getArray()->getIJ(0,0),1e-12);
- }
- if(rank==1)
- {
- CPPUNIT_ASSERT_DOUBLES_EQUAL(8.5,mcfieldT->getArray()->getIJ(0,0),1e-12);
- }
- if(rank==2)
- {
- CPPUNIT_ASSERT_DOUBLES_EQUAL(10.5,mcfieldT->getArray()->getIJ(0,0),1e-12);
- }
-
- mcfieldS->decrRef();
- mcfieldT->decrRef();
-
- MPI_Barrier(MPI_COMM_WORLD);
-}
-
-/*!
- * Same as testOverlapDEC1() but with regular bounding boxes. If you're looking for a nice debug case,
- * testOverlapDEC1() is identical in terms of geometry and field values, and more appropriate.
- */
-void ParaMEDMEMTest::testOverlapDEC2()
-{
- int size, rank;
- MPI_Comm_size(MPI_COMM_WORLD,&size);
- MPI_Comm_rank(MPI_COMM_WORLD,&rank);
-
- if (size != 3) return ;
- int nproc = 3;
- std::set<int> procs;
- for (int i=0; i<nproc; i++)
- procs.insert(i);
-
-// if (rank == 0)
-// {
-// int i=1, j=0;
-// while (i!=0)
-// j=2;
-// }
-
-
- CommInterface interface;
- OverlapDEC dec(procs);
- MEDCouplingFieldDouble * mcfieldS=0, *mcfieldT=0;
- prepareData1(rank, ConservativeVolumic, mcfieldS, mcfieldT);
-
- /* Normal bounding boxes here: */
- dec.setBoundingBoxAdjustmentAbs(+1.0e-12);
-
- dec.attachSourceLocalField(mcfieldS);
- dec.attachTargetLocalField(mcfieldT);
- dec.synchronize();
- dec.sendRecvData(true);
- //
- if(rank==0)
- {
- CPPUNIT_ASSERT_DOUBLES_EQUAL(8.75,mcfieldT->getArray()->getIJ(0,0),1e-12);
- }
- if(rank==1)
- {
- CPPUNIT_ASSERT_DOUBLES_EQUAL(8.5,mcfieldT->getArray()->getIJ(0,0),1e-12);
- }
- if(rank==2)
- {
- CPPUNIT_ASSERT_DOUBLES_EQUAL(10.5,mcfieldT->getArray()->getIJ(0,0),1e-12);
- }
-
- mcfieldS->decrRef();
- mcfieldT->decrRef();
-
- MPI_Barrier(MPI_COMM_WORLD);
-}
-
void prepareData2_buildOneSquare(MEDCouplingUMesh* & meshS_0, MEDCouplingUMesh* & meshT_0)
{
const double coords[10] = {0.0,0.0, 0.0,1.0, 1.0,1.0, 1.0,0.0, 0.5,0.5};
meshT_0->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,connT+3);
meshT_0->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,connT+6);
meshT_0->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,connT+9);
-
}
/**
if(rank==0)
{
const double tr1[] = {1.5, 0.0};
- MEDCouplingUMesh *meshS_1 = static_cast<MEDCouplingUMesh*>(meshS_0->deepCpy());
+ MEDCouplingUMesh *meshS_1 = static_cast<MEDCouplingUMesh*>(meshS_0->deepCopy());
meshS_1->translate(tr1);
const double tr2[] = {3.0, 0.0};
- MEDCouplingUMesh *meshS_2 = static_cast<MEDCouplingUMesh*>(meshS_0->deepCpy());
+ MEDCouplingUMesh *meshS_2 = static_cast<MEDCouplingUMesh*>(meshS_0->deepCopy());
meshS_2->translate(tr2);
std::vector<const MEDCouplingUMesh*> vec;
//
const double tr3[] = {0.0, -1.5};
- MEDCouplingUMesh *meshT_3 = static_cast<MEDCouplingUMesh*>(meshT_0->deepCpy());
+ MEDCouplingUMesh *meshT_3 = static_cast<MEDCouplingUMesh*>(meshT_0->deepCopy());
meshT_3->translate(tr3);
vec.clear();
vec.push_back(meshT_0);vec.push_back(meshT_3);
if(rank==1)
{
const double tr3[] = {0.0, -1.5};
- MEDCouplingUMesh *meshS_3 = static_cast<MEDCouplingUMesh*>(meshS_0->deepCpy());
+ MEDCouplingUMesh *meshS_3 = static_cast<MEDCouplingUMesh*>(meshS_0->deepCopy());
meshS_3->translate(tr3);
const double tr4[] = {1.5, -1.5};
- MEDCouplingUMesh *meshS_4 = static_cast<MEDCouplingUMesh*>(meshS_0->deepCpy());
+ MEDCouplingUMesh *meshS_4 = static_cast<MEDCouplingUMesh*>(meshS_0->deepCopy());
meshS_4->translate(tr4);
std::vector<const MEDCouplingUMesh*> vec;
//
const double tr5[] = {1.5, 0.0};
- MEDCouplingUMesh *meshT_1 = static_cast<MEDCouplingUMesh*>(meshT_0->deepCpy());
+ MEDCouplingUMesh *meshT_1 = static_cast<MEDCouplingUMesh*>(meshT_0->deepCopy());
meshT_1->translate(tr5);
const double tr6[] = {3.0, 0.0};
- MEDCouplingUMesh *meshT_2 = static_cast<MEDCouplingUMesh*>(meshT_0->deepCpy());
+ MEDCouplingUMesh *meshT_2 = static_cast<MEDCouplingUMesh*>(meshT_0->deepCopy());
meshT_2->translate(tr6);
const double tr7[] = {1.5, -1.5};
- MEDCouplingUMesh *meshT_4 = static_cast<MEDCouplingUMesh*>(meshT_0->deepCpy());
+ MEDCouplingUMesh *meshT_4 = static_cast<MEDCouplingUMesh*>(meshT_0->deepCopy());
meshT_4->translate(tr7);
vec.clear();
meshT_0->decrRef();
}
+/*! Test case from the official doc of the OverlapDEC.
+ * WARNING: bounding boxes might be tweaked here to make the case more interesting (i.e. to avoid an all to all exchange
+ * between all procs).
+ */
+void testOverlapDEC_generic(int workSharingAlgo, double bbAdj)
+{
+ int size, rank;
+ MPI_Comm_size(MPI_COMM_WORLD,&size);
+ MPI_Comm_rank(MPI_COMM_WORLD,&rank);
+ // char hostname[256];
+ // printf("(%d) PID %d on localhost ready for attach\n", rank, getpid());
+ // fflush(stdout);
+
+// if (rank == 0)
+// {
+// int i=1, j=0;
+// while (i!=0)
+// j=2;
+// }
+
+ if (size != 3) return ;
+ int nproc = 3;
+ std::set<int> procs;
+ for (int i=0; i<nproc; i++)
+ procs.insert(i);
+
+ CommInterface interface;
+ OverlapDEC dec(procs);
+ MEDCouplingFieldDouble * mcfieldS=0, *mcfieldT=0;
+
+ prepareData1(rank, IntensiveMaximum, mcfieldS, mcfieldT);
+
+ // See comment in the caller:
+ dec.setBoundingBoxAdjustmentAbs(bbAdj);
+ dec.setWorkSharingAlgo(workSharingAlgo); // just to ease debugging
+
+ dec.attachSourceLocalField(mcfieldS);
+ dec.attachTargetLocalField(mcfieldT);
+ dec.synchronize();
+// dec.debugPrintWorkSharing(std::cout);
+ dec.sendRecvData(true);
+ //
+ MPI_Barrier(MPI_COMM_WORLD);
+ if(rank==0)
+ {
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(8.75,mcfieldT->getArray()->getIJ(0,0),1e-12);
+ }
+ if(rank==1)
+ {
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(8.5,mcfieldT->getArray()->getIJ(0,0),1e-12);
+ }
+ if(rank==2)
+ {
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(10.5,mcfieldT->getArray()->getIJ(0,0),1e-12);
+ }
+
+ mcfieldS->decrRef();
+ mcfieldT->decrRef();
+
+ MPI_Barrier(MPI_COMM_WORLD);
+}
+
+void ParaMEDMEMTest::testOverlapDEC1()
+{
+ /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ * HACK ON BOUNDING BOX TO MAKE THIS CASE SIMPLE AND USABLE IN DEBUG
+ * Bounding boxes are slightly smaller than should be, thus localizing the work to be done
+ * and avoiding every proc talking to everyone else.
+ * Obviously this is NOT a good idea to do this in production code :-)
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ */
+ testOverlapDEC_generic(0,-1.0e-12);
+}
+
+void ParaMEDMEMTest::testOverlapDEC1_bis()
+{
+ // Same BB hack as above
+ testOverlapDEC_generic(1,-1.0e-12);
+}
+
+void ParaMEDMEMTest::testOverlapDEC1_ter()
+{
+ // Same BB hack as above
+ testOverlapDEC_generic(2, -1.0e-12);
+}
+
+
+/*!
+ * Same as testOverlapDEC1() but with regular bounding boxes. If you're looking for a nice debug case,
+ * testOverlapDEC1() is identical in terms of geometry and field values, and more appropriate.
+ */
+void ParaMEDMEMTest::testOverlapDEC2()
+{
+ testOverlapDEC_generic(0,1.0e-12);
+}
+
+void ParaMEDMEMTest::testOverlapDEC2_bis()
+{
+ testOverlapDEC_generic(1,1.0e-12);
+}
+
+void ParaMEDMEMTest::testOverlapDEC2_ter()
+{
+ testOverlapDEC_generic(2,1.0e-12);
+}
+
+
/*! Test focused on the mapping of cell IDs.
* (i.e. when only part of the source/target mesh is transmitted)
*/
ParaMESH* parameshS=0, *parameshT=0;
ParaFIELD* parafieldS=0, *parafieldT=0;
- prepareData2(rank, grp, ConservativeVolumic, meshS, meshT, parameshS, parameshT, parafieldS, parafieldT);
+ prepareData2(rank, grp, IntensiveMaximum, meshS, meshT, parameshS, parameshT, parafieldS, parafieldT);
dec.attachSourceLocalField(parafieldS);
dec.attachTargetLocalField(parafieldT);
ParaFIELD* parafieldS=0, *parafieldT=0;
// As before, except than one of the source cell is removed, and that the field now has 2 components
- prepareData2(rank, grp, ConservativeVolumic, meshS, meshT, parameshS, parameshT, parafieldS, parafieldT,
+ prepareData2(rank, grp, IntensiveMaximum, meshS, meshT, parameshS, parameshT, parafieldS, parafieldT,
true, 2);
// if (rank == 1)
// {
meshT->decrRef();
MPI_Barrier(MPI_COMM_WORLD);
-
}