]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Adding prepare with FieldTemplate as input.
authorageay <ageay>
Thu, 31 Mar 2011 10:15:13 +0000 (10:15 +0000)
committerageay <ageay>
Thu, 31 Mar 2011 10:15:13 +0000 (10:15 +0000)
src/MEDCoupling_Swig/MEDCoupling.i
src/MEDCoupling_Swig/MEDCouplingRemapperTest.py

index 978c99579775851a19388bf05c645b2f91adaac8..33a267735d9e6925488b3b618338b23fe9a40ba0 100644 (file)
@@ -2278,6 +2278,7 @@ namespace ParaMEDMEM
   {
   public:
     static MEDCouplingFieldTemplate *New(const MEDCouplingFieldDouble *f) throw(INTERP_KERNEL::Exception);
+    static MEDCouplingFieldTemplate *New(TypeOfField type);
     std::string simpleRepr() const;
     std::string advancedRepr() const;
     %extend
index 4f38166b5ad9bbbea4fe27ce405f0133cd2c86ef..df7f5c5ca044dae3f26996c4eabf28b1b0a014e7 100644 (file)
@@ -48,6 +48,38 @@ class MEDCouplingBasicsTest(unittest.TestCase):
             pass
         self.failUnless(1==trgfield.getArray().getNumberOfComponents());
         pass
+
+    def testPrepareEx1(self):
+        sourceMesh=self.build2DSourceMesh_1();
+        targetMesh=self.build2DTargetMesh_3();
+        #
+        remapper=MEDCouplingRemapper();
+        remapper.setPrecision(1e-12);
+        remapper.setIntersectionType(Triangulation);
+        srcFt=MEDCouplingFieldTemplate.New(ON_CELLS);
+        trgFt=MEDCouplingFieldTemplate.New(ON_CELLS);
+        srcFt.setMesh(sourceMesh);
+        trgFt.setMesh(targetMesh);
+        self.assertEqual(1,remapper.prepareEx(srcFt,trgFt));
+        srcField=MEDCouplingFieldDouble.New(ON_CELLS);
+        srcField.setNature(ConservativeVolumic);
+        srcField.setMesh(sourceMesh);
+        array=DataArrayDouble.New();
+        ptr=sourceMesh.getNumberOfCells()*[None]
+        for i in xrange(sourceMesh.getNumberOfCells()):
+            ptr[i]=float(i+7);
+            pass
+        array.setValues(ptr,sourceMesh.getNumberOfCells(),1);
+        srcField.setArray(array);
+        trgfield=remapper.transferField(srcField,4.220173);
+        values=trgfield.getArray().getValues();
+        valuesExpected=[7.75, 7.0625, 4.220173,8.0]
+        self.assertEqual(4,trgfield.getArray().getNumberOfTuples());
+        self.assertEqual(1,trgfield.getArray().getNumberOfComponents());
+        for i0 in xrange(4):
+            self.assertAlmostEqual(valuesExpected[i0],values[i0],12);
+            pass
+        pass
     
     def build2DSourceMesh_1(self):
         sourceCoords=[-0.3,-0.3, 0.7,-0.3, -0.3,0.7, 0.7,0.7]
@@ -78,6 +110,22 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         myCoords.setValues(targetCoords,9,2);
         targetMesh.setCoords(myCoords);
         return targetMesh;
+
+    def build2DTargetMesh_3(self):
+        targetCoords=[-0.6,-0.4, -0.1,-0.4, 1.1,-0.4, 2.1,-0.4, -0.6,0.1,  -0.1,0.1,  1.1,0.1,  2.1,0.1, -0.6,1.1,  -0.1,1.1]
+        targetConn=[0,4,5,1, 1,5,6,2, 2,6,7,3, 4,8,9,5]
+        targetMesh=MEDCouplingUMesh.New();
+        targetMesh.setMeshDimension(2);
+        targetMesh.allocateCells(4);
+        for i in xrange(4):
+            targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[4*i:4*(i+1)])
+            pass
+        targetMesh.finishInsertingCells();
+        myCoords=DataArrayDouble.New();
+        myCoords.setValues(targetCoords,10,2);
+        targetMesh.setCoords(myCoords);
+        return targetMesh;
+        pass
     
     def setUp(self):
         pass