From f29cfeee23f594c263f83ee524244829eae8c1cf Mon Sep 17 00:00:00 2001 From: geay Date: Tue, 27 May 2014 15:11:36 +0200 Subject: [PATCH] on the road of full remapper fine to fine + debug on MEDCouplingIMesh::getBoundingBox --- .../MEDCouplingCartesianAMRMesh.cxx | 73 +++++++++++++++---- .../MEDCouplingCartesianAMRMesh.hxx | 2 + src/MEDCoupling/MEDCouplingIMesh.cxx | 10 ++- src/MEDCoupling/MEDCouplingStructuredMesh.cxx | 62 +++++++++------- src/MEDCoupling/MEDCouplingStructuredMesh.hxx | 4 +- src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 1 + src/MEDCoupling_Swig/MEDCouplingCommon.i | 17 ++++- 7 files changed, 122 insertions(+), 47 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingCartesianAMRMesh.cxx b/src/MEDCoupling/MEDCouplingCartesianAMRMesh.cxx index 3d872445d..62055571b 100644 --- a/src/MEDCoupling/MEDCouplingCartesianAMRMesh.cxx +++ b/src/MEDCoupling/MEDCouplingCartesianAMRMesh.cxx @@ -106,7 +106,9 @@ bool MEDCouplingCartesianAMRPatch::isInMyNeighborhood(const MEDCouplingCartesian continue; if(otherpp.second+ghostLev-1==thispp.first) continue; - return false; + int start(std::max(thispp.first,otherpp.first)),end(std::min(thispp.second,otherpp.second)); + if(endisInMyNeighborhood(p2,ghostLevInPatchRef); } @@ -686,11 +688,11 @@ void MEDCouplingCartesianAMRMesh::fillCellFieldOnPatchGhostAdv(int patchId, cons fillCellFieldOnPatchGhost(patchId,cellFieldOnThis,theFieldToFill,ghostLev); // all reference patch stuff const MEDCouplingCartesianAMRPatch *refP(getPatch(patchId)); - const std::vector< std::pair >& refBLTR(refP->getBLTRRange()); - std::vector dimsCoarse(MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(refBLTR)); - std::transform(dimsCoarse.begin(),dimsCoarse.end(),_factors.begin(),dimsCoarse.begin(),std::multiplies()); - std::transform(dimsCoarse.begin(),dimsCoarse.end(),dimsCoarse.begin(),std::bind2nd(std::plus(),2*ghostLev)); - std::vector< std::pair > rangeCoarse(MEDCouplingStructuredMesh::GetCompactFrmtFromDimensions(dimsCoarse)); + const std::vector< std::pair >& refBLTR(refP->getBLTRRange());//[(1,4),(2,4)] + std::vector dimsCoarse(MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(refBLTR));//[3,2] + std::transform(dimsCoarse.begin(),dimsCoarse.end(),_factors.begin(),dimsCoarse.begin(),std::multiplies());//[12,8] + std::transform(dimsCoarse.begin(),dimsCoarse.end(),dimsCoarse.begin(),std::bind2nd(std::plus(),2*ghostLev));//[14,10] + std::vector< std::pair > rangeCoarse(MEDCouplingStructuredMesh::GetCompactFrmtFromDimensions(dimsCoarse));//[(0,14),(0,10)] std::vector fakeFactors(dim,1); // for(int i=0;i >& otherBLTR(otherP->getBLTRRange()); - std::vector< std::pair > tmp0; - MEDCouplingStructuredMesh::ChangeReferenceFromGlobalOfCompactFrmt(refBLTR,otherBLTR,tmp0); - ApplyFactorsOnCompactFrmt(tmp0,_factors); - ApplyGhostOnCompactFrmt(tmp0,ghostLev); - std::vector dimsFine(MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(otherBLTR)); - MEDCouplingAutoRefCountObjectPtr ghostVals;//(MEDCouplingStructuredMesh::ExtractFieldOfDoubleFrom(dimsFine,arrsOnPatches[i],)); - std::vector< std::pair > interstRange(MEDCouplingStructuredMesh::IntersectRanges(tmp0,rangeCoarse)); + const std::vector< std::pair >& otherBLTR(otherP->getBLTRRange());//[(4,5),(3,4)] + std::vector< std::pair > tmp0,tmp1,tmp2; + MEDCouplingStructuredMesh::ChangeReferenceFromGlobalOfCompactFrmt(refBLTR,otherBLTR,tmp0,false);//tmp0=[(3,4),(1,2)] + ApplyFactorsOnCompactFrmt(tmp0,_factors);//tmp0=[(12,16),(4,8)] + ApplyGhostOnCompactFrmt(tmp0,ghostLev);//tmp0=[(13,17),(5,9)] + std::vector< std::pair > interstRange(MEDCouplingStructuredMesh::IntersectRanges(tmp0,rangeCoarse));//interstRange=[(13,14),(5,9)] + MEDCouplingStructuredMesh::ChangeReferenceFromGlobalOfCompactFrmt(otherBLTR,refBLTR,tmp1,false);//tmp1=[(-3,0),(-1,1)] + ApplyFactorsOnCompactFrmt(tmp1,_factors);//tmp1=[(-12,-4),(-4,0)] + MEDCouplingStructuredMesh::ChangeReferenceToGlobalOfCompactFrmt(tmp1,interstRange,tmp2,false);//tmp2=[(1,2),(1,5)] + // + std::vector< std::pair > dimsFine(otherBLTR); + ApplyFactorsOnCompactFrmt(dimsFine,_factors); + ApplyAllGhostOnCompactFrmt(dimsFine,ghostLev); + // + MEDCouplingAutoRefCountObjectPtr ghostVals(MEDCouplingStructuredMesh::ExtractFieldOfDoubleFrom(MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(dimsFine),arrsOnPatches[i],tmp2)); MEDCouplingIMesh::CondenseFineToCoarse(dimsCoarse,ghostVals,interstRange,fakeFactors,theFieldToFill); } } @@ -816,6 +825,22 @@ MEDCoupling1SGTUMesh *MEDCouplingCartesianAMRMesh::buildMeshFromPatchEnvelop() c return MEDCoupling1SGTUMesh::Merge1SGTUMeshes(cells); } +MEDCoupling1SGTUMesh *MEDCouplingCartesianAMRMesh::buildMeshOfDirectChildrenOnly() const +{ + std::vector patches; + std::vector< MEDCouplingAutoRefCountObjectPtr > patchesSafe; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_patches.begin();it!=_patches.end();it++) + { + const MEDCouplingCartesianAMRPatch *patch(*it); + if(patch) + { + MEDCouplingAutoRefCountObjectPtr patchMesh(patch->getMesh()->getImageMesh()->build1SGTUnstructured()); + patchesSafe.push_back(patchMesh); patches.push_back(patchMesh); + } + } + return MEDCoupling1SGTUMesh::Merge1SGTUMeshes(patches); +} + MEDCouplingCartesianAMRMesh::MEDCouplingCartesianAMRMesh(const std::string& meshName, int spaceDim, const int *nodeStrctStart, const int *nodeStrctStop, const double *originStart, const double *originStop, const double *dxyzStart, const double *dxyzStop):_father(0) { @@ -889,6 +914,24 @@ void MEDCouplingCartesianAMRMesh::ApplyGhostOnCompactFrmt(std::vector< std::pair } } +/*! + * This method is different than ApplyGhostOnCompactFrmt + * + * \param [in,out] partBeforeFact - the part of a image mesh in compact format that will be put in ghost reference. + * \param [in] ghostSize - the ghost size of zone for all axis. + */ +void MEDCouplingCartesianAMRMesh::ApplyAllGhostOnCompactFrmt(std::vector< std::pair >& partBeforeFact, int ghostSize) +{ + if(ghostSize<0) + throw INTERP_KERNEL::Exception("MEDCouplingCartesianAMRMesh::ApplyAllGhostOnCompactFrmt : ghost size must be >= 0 !"); + std::size_t sz(partBeforeFact.size()); + for(std::size_t i=0;i& factors); static void ApplyFactorsOnCompactFrmt(std::vector< std::pair >& partBeforeFact, const std::vector& factors); static void ApplyGhostOnCompactFrmt(std::vector< std::pair >& partBeforeFact, int ghostSize); + static void ApplyAllGhostOnCompactFrmt(std::vector< std::pair >& partBeforeFact, int ghostSize); protected: MEDCOUPLING_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const; MEDCOUPLING_EXPORT std::vector getDirectChildren() const; diff --git a/src/MEDCoupling/MEDCouplingIMesh.cxx b/src/MEDCoupling/MEDCouplingIMesh.cxx index 969e36489..6ec8c5839 100644 --- a/src/MEDCoupling/MEDCouplingIMesh.cxx +++ b/src/MEDCoupling/MEDCouplingIMesh.cxx @@ -951,7 +951,15 @@ void MEDCouplingIMesh::getBoundingBox(double *bbox) const for(int idim=0; idim1) + coeff=_structure[idim]-1; + bbox[2*idim+1]=_origin[idim]+_dxyz[idim]*coeff; } } diff --git a/src/MEDCoupling/MEDCouplingStructuredMesh.cxx b/src/MEDCoupling/MEDCouplingStructuredMesh.cxx index 9b213d795..d079e8288 100644 --- a/src/MEDCoupling/MEDCouplingStructuredMesh.cxx +++ b/src/MEDCoupling/MEDCouplingStructuredMesh.cxx @@ -1528,12 +1528,12 @@ DataArrayDouble *MEDCouplingStructuredMesh::ExtractFieldOfDoubleFrom(const std:: /*! * This method changes the reference of a part of structured mesh \a partOfBigInAbs define in absolute reference to a new reference \a bigInAbs. * So this method only performs a translation by doing \a partOfBigRelativeToBig = \a partOfBigInAbs - \a bigInAbs - * This method also checks that \a partOfBigInAbs is included in \a bigInAbs. + * This method also checks (if \a check=true) that \a partOfBigInAbs is included in \a bigInAbs. * This method is useful to extract a part from a field lying on a big mesh. * * \sa ChangeReferenceToGlobalOfCompactFrmt, BuildExplicitIdsFrom, SwitchOnIdsFrom, ExtractFieldOfBoolFrom, ExtractFieldOfDoubleFrom */ -void MEDCouplingStructuredMesh::ChangeReferenceFromGlobalOfCompactFrmt(const std::vector< std::pair >& bigInAbs, const std::vector< std::pair >& partOfBigInAbs, std::vector< std::pair >& partOfBigRelativeToBig) +void MEDCouplingStructuredMesh::ChangeReferenceFromGlobalOfCompactFrmt(const std::vector< std::pair >& bigInAbs, const std::vector< std::pair >& partOfBigInAbs, std::vector< std::pair >& partOfBigRelativeToBig, bool check) { std::size_t dim(bigInAbs.size()); if(dim!=partOfBigInAbs.size()) @@ -1541,21 +1541,27 @@ void MEDCouplingStructuredMesh::ChangeReferenceFromGlobalOfCompactFrmt(const std partOfBigRelativeToBig.resize(dim); for(std::size_t i=0;ibigInAbs[i].second) + if(check) { - std::ostringstream oss; oss << "MEDCouplingStructuredMesh::ChangeReferenceFromGlobalOfCompactFrmt : Error at axis #" << i << " the input big part invalid, end before start !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - if(partOfBigInAbs[i].first=bigInAbs[i].second) - { - std::ostringstream oss; oss << "MEDCouplingStructuredMesh::ChangeReferenceFromGlobalOfCompactFrmt : Error at axis #" << i << " the part is not included in the big one (start) !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + if(bigInAbs[i].first>bigInAbs[i].second) + { + std::ostringstream oss; oss << "MEDCouplingStructuredMesh::ChangeReferenceFromGlobalOfCompactFrmt : Error at axis #" << i << " the input big part invalid, end before start !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(partOfBigInAbs[i].first=bigInAbs[i].second) + { + std::ostringstream oss; oss << "MEDCouplingStructuredMesh::ChangeReferenceFromGlobalOfCompactFrmt : Error at axis #" << i << " the part is not included in the big one (start) !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } } partOfBigRelativeToBig[i].first=partOfBigInAbs[i].first-bigInAbs[i].first; - if(partOfBigInAbs[i].secondbigInAbs[i].second) + if(check) { - std::ostringstream oss; oss << "MEDCouplingStructuredMesh::ChangeReferenceFromGlobalOfCompactFrmt : Error at axis #" << i << " the part is not included in the big one (end) !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + if(partOfBigInAbs[i].secondbigInAbs[i].second) + { + std::ostringstream oss; oss << "MEDCouplingStructuredMesh::ChangeReferenceFromGlobalOfCompactFrmt : Error at axis #" << i << " the part is not included in the big one (end) !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } } partOfBigRelativeToBig[i].second=partOfBigInAbs[i].second-bigInAbs[i].first; } @@ -1566,7 +1572,7 @@ void MEDCouplingStructuredMesh::ChangeReferenceFromGlobalOfCompactFrmt(const std * * \sa ChangeReferenceFromGlobalOfCompactFrmt */ -void MEDCouplingStructuredMesh::ChangeReferenceToGlobalOfCompactFrmt(const std::vector< std::pair >& bigInAbs, const std::vector< std::pair >& partOfBigRelativeToBig, std::vector< std::pair >& partOfBigInAbs) +void MEDCouplingStructuredMesh::ChangeReferenceToGlobalOfCompactFrmt(const std::vector< std::pair >& bigInAbs, const std::vector< std::pair >& partOfBigRelativeToBig, std::vector< std::pair >& partOfBigInAbs, bool check) { std::size_t dim(bigInAbs.size()); if(dim!=partOfBigRelativeToBig.size()) @@ -1574,21 +1580,27 @@ void MEDCouplingStructuredMesh::ChangeReferenceToGlobalOfCompactFrmt(const std:: partOfBigInAbs.resize(dim); for(std::size_t i=0;ibigInAbs[i].second) + if(check) { - std::ostringstream oss; oss << "MEDCouplingStructuredMesh::ChangeReferenceToGlobalOfCompactFrmt : Error at axis #" << i << " the input big part invalid, end before start !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - if(partOfBigRelativeToBig[i].first<0 || partOfBigRelativeToBig[i].first>=bigInAbs[i].second-bigInAbs[i].first) - { - std::ostringstream oss; oss << "MEDCouplingStructuredMesh::ChangeReferenceToGlobalOfCompactFrmt : Error at axis #" << i << " the start of part is not in the big one !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + if(bigInAbs[i].first>bigInAbs[i].second) + { + std::ostringstream oss; oss << "MEDCouplingStructuredMesh::ChangeReferenceToGlobalOfCompactFrmt : Error at axis #" << i << " the input big part invalid, end before start !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(partOfBigRelativeToBig[i].first<0 || partOfBigRelativeToBig[i].first>=bigInAbs[i].second-bigInAbs[i].first) + { + std::ostringstream oss; oss << "MEDCouplingStructuredMesh::ChangeReferenceToGlobalOfCompactFrmt : Error at axis #" << i << " the start of part is not in the big one !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } } partOfBigInAbs[i].first=partOfBigRelativeToBig[i].first+bigInAbs[i].first; - if(partOfBigRelativeToBig[i].secondbigInAbs[i].second-bigInAbs[i].first) + if(check) { - std::ostringstream oss; oss << "MEDCouplingStructuredMesh::ChangeReferenceToGlobalOfCompactFrmt : Error at axis #" << i << " the end of part is not in the big one !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + if(partOfBigRelativeToBig[i].secondbigInAbs[i].second-bigInAbs[i].first) + { + std::ostringstream oss; oss << "MEDCouplingStructuredMesh::ChangeReferenceToGlobalOfCompactFrmt : Error at axis #" << i << " the end of part is not in the big one !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } } partOfBigInAbs[i].second=partOfBigRelativeToBig[i].second+bigInAbs[i].first; } diff --git a/src/MEDCoupling/MEDCouplingStructuredMesh.hxx b/src/MEDCoupling/MEDCouplingStructuredMesh.hxx index b669deafd..18b8eb552 100644 --- a/src/MEDCoupling/MEDCouplingStructuredMesh.hxx +++ b/src/MEDCoupling/MEDCouplingStructuredMesh.hxx @@ -78,8 +78,8 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT static void SwitchOnIdsFrom(const std::vector& st, const std::vector< std::pair >& partCompactFormat, std::vector& vectToSwitchOn); MEDCOUPLING_EXPORT static void ExtractFieldOfBoolFrom(const std::vector& st, const std::vector& fieldOfBool, const std::vector< std::pair >& partCompactFormat, std::vector& fieldOut); MEDCOUPLING_EXPORT static DataArrayDouble *ExtractFieldOfDoubleFrom(const std::vector& st, const DataArrayDouble *fieldOfDbl, const std::vector< std::pair >& partCompactFormat); - MEDCOUPLING_EXPORT static void ChangeReferenceFromGlobalOfCompactFrmt(const std::vector< std::pair >& bigInAbs, const std::vector< std::pair >& partOfBigInAbs, std::vector< std::pair >& partOfBigRelativeToBig); - MEDCOUPLING_EXPORT static void ChangeReferenceToGlobalOfCompactFrmt(const std::vector< std::pair >& bigInAbs, const std::vector< std::pair >& partOfBigRelativeToBig, std::vector< std::pair >& partOfBigInAbs); + MEDCOUPLING_EXPORT static void ChangeReferenceFromGlobalOfCompactFrmt(const std::vector< std::pair >& bigInAbs, const std::vector< std::pair >& partOfBigInAbs, std::vector< std::pair >& partOfBigRelativeToBig, bool check=true); + MEDCOUPLING_EXPORT static void ChangeReferenceToGlobalOfCompactFrmt(const std::vector< std::pair >& bigInAbs, const std::vector< std::pair >& partOfBigRelativeToBig, std::vector< std::pair >& partOfBigInAbs, bool check=true); MEDCOUPLING_EXPORT static DataArrayInt *BuildExplicitIdsFrom(const std::vector& st, const std::vector< std::pair >& partCompactFormat); MEDCOUPLING_EXPORT static DataArrayInt *Build1GTNodalConnectivity(const int *nodeStBg, const int *nodeStEnd); MEDCOUPLING_EXPORT static DataArrayInt *Build1GTNodalConnectivityOfSubLevelMesh(const int *nodeStBg, const int *nodeStEnd); diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index f1f81259c..518be3669 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -14922,6 +14922,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertEqual((1.,0.5,2.),m3.getDXYZ()) # now playing with 3D surf m4=MEDCouplingIMesh("",3,DataArrayInt([3,1,4]),DataArrayDouble([1.5,2.5,3.5]),DataArrayDouble((0.5,1.,0.25))) ; m4.setAxisUnit("km") + self.assertEqual([(1.5,2.5),(2.5,3.5),(3.5,4.25)],m4.getBoundingBox()) self.assertEqual(3,m4.getSpaceDimension()) self.assertEqual(2,m4.getMeshDimension()) self.assertEqual(12,m4.getNumberOfNodes()) diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index ea847d73e..7755bc2db 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -321,6 +321,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingCartesianAMRMesh::New; %newobject ParaMEDMEM::MEDCouplingCartesianAMRMesh::buildUnstructured; %newobject ParaMEDMEM::MEDCouplingCartesianAMRMesh::buildMeshFromPatchEnvelop; +%newobject ParaMEDMEM::MEDCouplingCartesianAMRMesh::buildMeshOfDirectChildrenOnly; %newobject ParaMEDMEM::MEDCouplingCartesianAMRMesh::getImageMesh; %newobject ParaMEDMEM::MEDCouplingCartesianAMRMesh::getGodFather; %newobject ParaMEDMEM::MEDCouplingCartesianAMRMesh::getFather; @@ -2964,12 +2965,12 @@ namespace ParaMEDMEM return ret; } - static PyObject *ChangeReferenceFromGlobalOfCompactFrmt(PyObject *bigInAbs, PyObject *partOfBigInAbs) throw(INTERP_KERNEL::Exception) + static PyObject *ChangeReferenceFromGlobalOfCompactFrmt(PyObject *bigInAbs, PyObject *partOfBigInAbs, bool check=true) throw(INTERP_KERNEL::Exception) { std::vector< std::pair > param0,param1,ret; convertPyToVectorPairInt(bigInAbs,param0); convertPyToVectorPairInt(partOfBigInAbs,param1); - MEDCouplingStructuredMesh::ChangeReferenceFromGlobalOfCompactFrmt(param0,param1,ret); + MEDCouplingStructuredMesh::ChangeReferenceFromGlobalOfCompactFrmt(param0,param1,ret,check); PyObject *retPy(PyList_New(ret.size())); for(std::size_t i=0;i > param0,param1,ret; convertPyToVectorPairInt(bigInAbs,param0); convertPyToVectorPairInt(partOfBigRelativeToBig,param1); - MEDCouplingStructuredMesh::ChangeReferenceToGlobalOfCompactFrmt(param0,param1,ret); + MEDCouplingStructuredMesh::ChangeReferenceToGlobalOfCompactFrmt(param0,param1,ret,check); PyObject *retPy(PyList_New(ret.size())); for(std::size_t i=0;i arrsOnPatches2; + convertFromPyObjVectorOfObj(arrsOnPatches,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,"DataArrayDouble",arrsOnPatches2); + self->fillCellFieldOnPatchGhostAdv(patchId,cellFieldOnThis,ghostLev,arrsOnPatches2); + } + void __delitem__(int patchId) throw(INTERP_KERNEL::Exception) { self->removePatch(patchId); -- 2.39.2