]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Extend IMesh condensation to 3D and 1D.
authorgeay <anthony.geay@cea.fr>
Mon, 19 May 2014 09:30:42 +0000 (11:30 +0200)
committergeay <anthony.geay@cea.fr>
Mon, 19 May 2014 09:30:42 +0000 (11:30 +0200)
src/MEDCoupling/MEDCouplingIMesh.cxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py
src/MEDCoupling_Swig/MEDCouplingRemapperTest.py

index 0f64ac2c6c29e7dbc2163162fcf4a0b032d4134f..b7f8e78cb050676c9ec4d01b3be3be4038533130 100644 (file)
@@ -230,11 +230,27 @@ void MEDCouplingIMesh::CondenseFineToCoarse(DataArrayDouble *coarseDA, const std
   double *outPtr(coarseDA->getPointer());
   const double *inPtr(fineDA->begin());
   //
+  std::vector<int> dims(MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(fineLocInCoarse));
   switch(meshDim)
   {
+    case 1:
+      {
+        int offset(fineLocInCoarse[0].first);
+        for(int i=0;i<dims[0];i++)
+          {
+            double *loc(outPtr+(offset+i)*nbCompo);
+            for(int ifact=0;ifact<fact;ifact++,inPtr+=nbCompo)
+              {
+                if(ifact!=0)
+                  std::transform(inPtr,inPtr+nbCompo,loc,loc,std::plus<double>());
+                else
+                  std::copy(inPtr,inPtr+nbCompo,loc);
+              }
+          }
+        break;
+      }
     case 2:
       {
-        std::vector<int> dims(MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(fineLocInCoarse));
         int kk(fineLocInCoarse[0].first+coarseSt[0]*fineLocInCoarse[1].first);
         for(int j=0;j<dims[1];j++)
           {
@@ -256,8 +272,37 @@ void MEDCouplingIMesh::CondenseFineToCoarse(DataArrayDouble *coarseDA, const std
           }
         break;
       }
+    case 3:
+      {
+        int kk(fineLocInCoarse[0].first+coarseSt[0]*fineLocInCoarse[1].first+coarseSt[0]*coarseSt[1]*fineLocInCoarse[2].first);
+        for(int k=0;k<dims[2];k++)
+          {
+            for(int kfact=0;kfact<fact;kfact++)
+              {
+                for(int j=0;j<dims[1];j++)
+                  {
+                    for(int jfact=0;jfact<fact;jfact++)
+                      {
+                        for(int i=0;i<dims[0];i++)
+                          {
+                            double *loc(outPtr+(kk+i+j*coarseSt[0])*nbCompo);
+                            for(int ifact=0;ifact<fact;ifact++,inPtr+=nbCompo)
+                              {
+                                if(kfact!=0 || jfact!=0 || ifact!=0)
+                                  std::transform(inPtr,inPtr+nbCompo,loc,loc,std::plus<double>());
+                                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;
index 25fe05512bc237adae02255148f5c3630ebe24c3..1cba4b50d96a4c9014f00f7778a9c1205d4d403d 100644 (file)
@@ -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):
index ab4e726b55c3d9816f5e14cff9ff95ba3a2d771f..9974af73dd45311db1b24e436cb2e656546f4e56 100644 (file)
@@ -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]