From f1d6e5ac6e52d8d826ccbef46316dffe7efe35ba Mon Sep 17 00:00:00 2001 From: geay Date: Thu, 22 May 2014 14:39:14 +0200 Subject: [PATCH] some improvements and on the road of 3D manangement --- .../MEDCouplingCartesianAMRMesh.cxx | 45 +++++----- src/MEDCoupling/MEDCouplingStructuredMesh.cxx | 89 ++++++++++--------- src/MEDCoupling/MEDCouplingStructuredMesh.hxx | 1 - src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 4 + 4 files changed, 70 insertions(+), 69 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingCartesianAMRMesh.cxx b/src/MEDCoupling/MEDCouplingCartesianAMRMesh.cxx index d97d294cf..b73244d43 100644 --- a/src/MEDCoupling/MEDCouplingCartesianAMRMesh.cxx +++ b/src/MEDCoupling/MEDCouplingCartesianAMRMesh.cxx @@ -177,6 +177,7 @@ class InternalPatch : public RefCountObjectOnly { public: InternalPatch():_nb_of_true(0) { } + int getDimension() const { return (int)_part.size(); } double getEfficiency() const { return (double)_nb_of_true/(double)_crit.size(); } int getNumberOfCells() const { return (int)_crit.size(); } void setNumberOfTrue(int nboft) { _nb_of_true=nboft; } @@ -261,7 +262,7 @@ void DissectBigPatch(const INTERP_KERNEL::BoxSplittingOptions& bso, const Intern } int minCellDirection(bso.getMinCellDirection()),indexMin(-1); int dimRatioInner(rangeOfAxisId-1-2*(minCellDirection-1)); - std::vector ratio_inner(dimRatioInner); + std::vector ratio_inner(dimRatioInner); double minRatio(1.e10); for(int i=0; igetConstPart()[axisId].first-1; } -void FindHole(const INTERP_KERNEL::BoxSplittingOptions& bso, const InternalPatch *patchToBeSplit, const int axisId, bool& cutFound, int& cutPlace) +void FindHole(const INTERP_KERNEL::BoxSplittingOptions& bso, const InternalPatch *patchToBeSplit, int& axisId, bool& cutFound, int& cutPlace) { cutPlace=-1; cutFound=false; int minCellDirection(bso.getMinCellDirection()); - - int sortedDims[2]; - sortedDims[0]=axisId==0?1:0; - sortedDims[1]=axisId==0?0:1; - static const int dim(2); + const int dim(patchToBeSplit->getDimension()); std::vector< std::vector > signatures(patchToBeSplit->computeSignature()); for(int id=0;id& signature(signatures[sortedDims[id]]); + const std::vector& signature(signatures[id]); std::vector hole; - std::vector distance ; + std::vector distance; int len((int)signature.size()); for(int i=0;i0) { - double center(((double)len/2.)+0.5); + double center(((double)len/2.)); for(std::size_t i=0;igetConstPart()[axisId].first+1; return ; } @@ -312,14 +309,14 @@ void FindHole(const INTERP_KERNEL::BoxSplittingOptions& bso, const InternalPatch void FindInflection(const INTERP_KERNEL::BoxSplittingOptions& bso, const InternalPatch *patchToBeSplit, bool& cutFound, int& cutPlace, int& axisId) { - cutFound=false; cutPlace=-1; axisId=-1; + cutFound=false; cutPlace=-1;// do not set axisId before to be sure that cutFound was set to true const std::vector< std::pair >& part(patchToBeSplit->getConstPart()); int sign,minCellDirection(bso.getMinCellDirection()); - static const int dim = 2 ; + const int dim(patchToBeSplit->getDimension()); - std::vector zeroCrossDims(2,-1); - std::vector zeroCrossVals(2,-1); + std::vector zeroCrossDims(dim,-1); + std::vector zeroCrossVals(dim,-1); std::vector< std::vector > signatures(patchToBeSplit->computeSignature()); for (int id=0;idgetEfficiency() <= bso.getEffeciencySnd()) + if(patchToBeSplit->getEfficiency()<=bso.getEffeciencySnd()) { if(rangeOfAxisId>=2*bso.getMinCellDirection()) { @@ -469,19 +466,19 @@ void MEDCouplingCartesianAMRMesh::createPatchesFromCriterion(const INTERP_KERNEL for(std::vector< MEDCouplingAutoRefCountObjectPtr >::iterator it=listOfPatches.begin();it!=listOfPatches.end();it++) { // - int axisId,rangeOfAxisId; + int axisId,rangeOfAxisId,cutPlace; bool cutFound; - int cutPlace; MEDCouplingStructuredMesh::FindTheWidestAxisOfGivenRangeInCompactFrmt((*it)->getConstPart(),axisId,rangeOfAxisId); if((*it)->getEfficiency()>=bso.getEffeciency() && (*it)->getNumberOfCells() >::const_iterator it=listOfPatchesOK.begin();it!=listOfPatchesOK.end();it++) - { - addPatch((*it)->getConstPart(),factors); - } + addPatch((*it)->getConstPart(),factors); } void MEDCouplingCartesianAMRMesh::removePatch(int patchId) diff --git a/src/MEDCoupling/MEDCouplingStructuredMesh.cxx b/src/MEDCoupling/MEDCouplingStructuredMesh.cxx index 19c054b6e..8db11f5a8 100644 --- a/src/MEDCoupling/MEDCouplingStructuredMesh.cxx +++ b/src/MEDCoupling/MEDCouplingStructuredMesh.cxx @@ -808,8 +808,53 @@ std::vector< std::vector > MEDCouplingStructuredMesh::ComputeSignaturePerAx } break; } + case 3: + { + int nx(st[0]),ny(st[1]),nz(st[2]); + ret[0].resize(nx); ret[1].resize(ny); ret[2].resize(nz); + std::vector& retX(ret[0]); + for(int i=0;i& retY(ret[1]); + for(int j=0;j& retZ(ret[2]); + for(int k=0;k& st, c return ret; } -void MEDCouplingStructuredMesh::ExtractVecOfBool(const std::vector& st, const std::vector& crit, const std::vector< std::pair >& partCompactFormat, std::vector& reducedCrit) -{ - int nbt(DeduceNumberOfGivenRangeInCompactFrmt(partCompactFormat)); - std::vector dims(GetDimensionsFromCompactFrmt(partCompactFormat)); - reducedCrit.resize(nbt); - switch((int)st.size()) - { - case 1: - { - int nx(dims[0]); - int kk(partCompactFormat[0].first); - for(int i=0;i& st, const std::vector& crit, std::vector< std::pair >& partCompactFormat); static int FindMinimalPartOf2D(const std::vector& st, const std::vector& crit, std::vector< std::pair >& partCompactFormat); static int FindMinimalPartOf3D(const std::vector& st, const std::vector& crit, std::vector< std::pair >& partCompactFormat); - static void ExtractVecOfBool(const std::vector& st, const std::vector& crit, const std::vector< std::pair >& partCompactFormat, std::vector& reducedCrit); protected: static int ZipNodeStructure(const int *nodeStBg, const int *nodeStEnd, int zipNodeSt[3]); protected: diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 530995096..3a0d610bb 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -15136,6 +15136,10 @@ class MEDCouplingBasicsTest(unittest.TestCase): # self.assertEqual(MEDCouplingStructuredMesh.ChangeReferenceToGlobalOfCompactFrmt([(8,32),(4,17)],[(0,24),(2,12)]),[(8,32),(6,16)]) self.assertEqual(MEDCouplingStructuredMesh.ChangeReferenceFromGlobalOfCompactFrmt([(8,32),(4,17)],[(8,32),(6,16)]),[(0,24),(2,12)]) + self.assertTrue(amr.getImageMesh().isEqual(im,1e-12)) + m=amr.getImageMesh().asSingleCell().build1SGTUnstructured() + self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([1,0,2,3]))) + self.assertTrue(m.getCoords().isEqualWithoutConsideringStr(DataArrayDouble([(0,0),(2,0),(0,2),(2,2)]),1e-12)) pass def setUp(self): -- 2.39.2