From: geay Date: Mon, 19 May 2014 09:30:42 +0000 (+0200) Subject: Extend IMesh condensation to 3D and 1D. X-Git-Tag: V7_5_0a1~2^2~32^2~43 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=836815c1784ddbce4a677797639c407c243c6ccf;p=tools%2Fmedcoupling.git Extend IMesh condensation to 3D and 1D. --- diff --git a/src/MEDCoupling/MEDCouplingIMesh.cxx b/src/MEDCoupling/MEDCouplingIMesh.cxx index 0f64ac2c6..b7f8e78cb 100644 --- a/src/MEDCoupling/MEDCouplingIMesh.cxx +++ b/src/MEDCoupling/MEDCouplingIMesh.cxx @@ -230,11 +230,27 @@ void MEDCouplingIMesh::CondenseFineToCoarse(DataArrayDouble *coarseDA, const std double *outPtr(coarseDA->getPointer()); const double *inPtr(fineDA->begin()); // + std::vector dims(MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(fineLocInCoarse)); switch(meshDim) { + case 1: + { + int offset(fineLocInCoarse[0].first); + for(int i=0;i()); + else + std::copy(inPtr,inPtr+nbCompo,loc); + } + } + break; + } case 2: { - std::vector dims(MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(fineLocInCoarse)); int kk(fineLocInCoarse[0].first+coarseSt[0]*fineLocInCoarse[1].first); for(int j=0;j()); + else + std::copy(inPtr,inPtr+nbCompo,loc); + } + } + } + } + } + kk+=coarseSt[0]*coarseSt[1]; + } + break; + } default: - throw INTERP_KERNEL::Exception("MEDCouplingIMesh::CondenseFineToCoarse : only dimensions 2 supported !"); + throw INTERP_KERNEL::Exception("MEDCouplingIMesh::CondenseFineToCoarse : only dimensions 1, 2 and 3 supported !"); } } @@ -837,7 +882,7 @@ int MEDCouplingIMesh::FindIntRoot(int val, int order) { double retf(std::pow(val,0.3333333333333333)); int ret((int)retf),ret2(ret+1); - if(ret*ret*ret!=val || ret2*ret2*ret2!=val) + if(ret*ret*ret!=val && ret2*ret2*ret2!=val) throw INTERP_KERNEL::Exception("MEDCouplingIMesh::FindIntRoot : the input val is not a perfect cublic root !"); if(ret*ret*ret==val) return ret; diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 25fe05512..1cba4b50d 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -15082,6 +15082,16 @@ class MEDCouplingBasicsTest(unittest.TestCase): fine=DataArrayDouble(3*2*4*4) ; fine.iota(0) #X=3,Y=2 refined by 4 MEDCouplingIMesh.CondenseFineToCoarse(coarse,[5,7],fine,[(1,4),(2,4)]) self.assertTrue(coarse.isEqual(DataArrayDouble([0,1,2,3,4,5,6,7,8,9,10,312,376,440,14,15,1080,1144,1208,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34]),1e-12)) + # 3D + coarse=DataArrayDouble(175) ; coarse.iota(0) #X=5,Y=7,Z=5 + fine=DataArrayDouble(3*2*3*4*4*4) ; fine.iota(0) #X=3,Y=2,Z=3 refined by 4 + MEDCouplingIMesh.CondenseFineToCoarse(coarse,[5,7,5],fine,[(1,4),(2,4),(1,4)]) + self.assertTrue(coarse.isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.,25.,26.,27.,28.,29.,30.,31.,32.,33.,34.,35.,36.,37.,38.,39.,40.,41.,42.,43.,44.,45.,10464.,10720.,10976.,49.,50.,13536.,13792.,14048.,54.,55.,56.,57.,58.,59.,60.,61.,62.,63.,64.,65.,66.,67.,68.,69.,70.,71.,72.,73.,74.,75.,76.,77.,78.,79.,80.,35040.,35296.,35552.,84.,85.,38112.,38368.,38624.,89.,90.,91.,92.,93.,94.,95.,96.,97.,98.,99.,100.,101.,102.,103.,104.,105.,106.,107.,108.,109.,110.,111.,112.,113.,114.,115.,59616.,59872.,60128.,119.,120.,62688.,62944.,63200.,124.,125.,126.,127.,128.,129.,130.,131.,132.,133.,134.,135.,136.,137.,138.,139.,140.,141.,142.,143.,144.,145.,146.,147.,148.,149.,150.,151.,152.,153.,154.,155.,156.,157.,158.,159.,160.,161.,162.,163.,164.,165.,166.,167.,168.,169.,170.,171.,172.,173.,174.]),1e-12)) + # 1D + coarse=DataArrayDouble(5) ; coarse.iota(0) #X=5 + fine=DataArrayDouble(3*4) ; fine.iota(0) #X=3 refined by 4 + MEDCouplingIMesh.CondenseFineToCoarse(coarse,[5],fine,[(1,4)]) + self.assertTrue(coarse.isEqual(DataArrayDouble([0,6,22,38,4]),1e-12)) pass def setUp(self): diff --git a/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py b/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py index ab4e726b5..9974af73d 100644 --- a/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py @@ -760,6 +760,31 @@ class MEDCouplingBasicsTest(unittest.TestCase): expArr2=DataArrayDouble([0.49,7.956666666666667,7.956666666666667,7.956666666666667,27.29,27.29,59.95666666666667,59.95666666666667,59.95666666666667,94.09,125.69,125.69,202.89,202.89,202.89,202.89,296.09,296.09,-36.]) self.assertTrue(f2Test.getArray().isEqual(expArr2,1e-12)) pass + + def testRemapperAMR1(self): + """ This test is the origin of the ref values for MEDCouplingBasicsTest.testAMR2""" + coarse=DataArrayDouble(35) ; coarse.iota(0) #X=5,Y=7 + fine=DataArrayDouble(3*2*4*4) ; fine.iota(0) #X=3,Y=2 refined by 4 + MEDCouplingIMesh.CondenseFineToCoarse(coarse,[5,7],fine,[(1,4),(2,4)]) + # + m=MEDCouplingCartesianAMRMesh("mesh",2,[6,8],[0.,0.],[1.,1.]) + trgMesh=m.buildUnstructured() + m.addPatch([(1,4),(2,4)],4) + srcMesh=m[0].getMesh().buildUnstructured() + srcField=MEDCouplingFieldDouble(ON_CELLS) + fine2=DataArrayDouble(3*2*4*4) ; fine2.iota(0) ; srcField.setArray(fine2) + srcField.setMesh(srcMesh) ; srcField.setNature(Integral) + # + trgField=MEDCouplingFieldDouble(ON_CELLS) + coarse2=DataArrayDouble(35) ; coarse2.iota(0) ; trgField.setArray(coarse2) + trgField.setMesh(trgMesh) ; trgField.setNature(Integral) + # + rem=MEDCouplingRemapper() + rem.prepare(srcMesh,trgMesh,"P0P0") + rem.partialTransfer(srcField,trgField) + # + self.assertTrue(coarse.isEqual(trgField.getArray(),1e-12)) + pass def build2DSourceMesh_1(self): sourceCoords=[-0.3,-0.3, 0.7,-0.3, -0.3,0.7, 0.7,0.7]