Esempio n. 1
0
 def testRemapper1(self):
     sourceMesh = self.build2DSourceMesh_1()
     targetMesh = self.build2DTargetMesh_1()
     remapper = MEDCouplingRemapper()
     remapper.setPrecision(1e-12)
     remapper.setIntersectionType(Triangulation)
     self.failUnless(remapper.prepare(sourceMesh, targetMesh, "P0P0") == 1)
     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.57)
     values = trgfield.getArray().getValues()
     valuesExpected = [7.5, 7., 7., 8., 7.5]
     for i in xrange(targetMesh.getNumberOfCells()):
         self.failUnless(abs(values[i] - valuesExpected[i]) < 1e-12)
         pass
     self.failUnless(1 == trgfield.getArray().getNumberOfComponents())
     pass
Esempio n. 2
0
 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 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 testRemapper1(self):
     sourceMesh = self.build2DSourceMesh_1()
     targetMesh = self.build2DTargetMesh_1()
     remapper = MEDCouplingRemapper()
     remapper.setPrecision(1e-12)
     remapper.setIntersectionType(Triangulation)
     self.failUnless(remapper.prepare(sourceMesh, targetMesh, "P0P0") == 1)
     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.57)
     values = trgfield.getArray().getValues()
     valuesExpected = [7.5, 7.0, 7.0, 8.0, 7.5]
     for i in xrange(targetMesh.getNumberOfCells()):
         self.failUnless(abs(values[i] - valuesExpected[i]) < 1e-12)
         pass
     self.failUnless(1 == trgfield.getArray().getNumberOfComponents())
     pass
    pass
mergeMLMesh.write("merge.med",2)
mergeMLFields.write("merge.med",0)

#####

arr=DataArrayDouble(11) ; arr.iota(0)
trgMesh=MEDCouplingCMesh() ; trgMesh.setCoords(arr,arr) ; trgMesh=trgMesh.buildUnstructured()
#
arr=DataArrayDouble(21) ; arr.iota(0) ; arr*=0.5
srcMesh=MEDCouplingCMesh() ; srcMesh.setCoords(arr,arr) ; srcMesh=srcMesh.buildUnstructured()
#
tmp=srcMesh[:20] ; tmp.simplexize(0)
srcMesh=MEDCouplingUMesh.MergeUMeshes([tmp,srcMesh[20:]])
#
remap=MEDCouplingRemapper()
remap.prepare(srcMesh,trgMesh,"P0P0")
#
myMatrix=remap.getCrudeMatrix()
print(myMatrix) # pour voir a quoi elle ressemble
sumByRows=DataArrayDouble(len(myMatrix))
for i,wIt in enumerate(sumByRows):
  su=0.
  for it in myMatrix[i]:
    su+=myMatrix[i][it]
  wIt[0]=su
print("Does interpolation look OK ? %s"%(str(sumByRows.isUniform(1.,1e-12)))) ; assert sumByRows.isUniform(1.,1e-12)
#
srcField=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; srcField.setMesh(srcMesh)
srcField.fillFromAnalytic(1,"7-sqrt((x-5.)*(x-5.)+(y-5.)*(y-5.))") ; CellField.getArray().setInfoOnComponent(0,"powercell [W]")
#
#
# Another possibility (to illustrate the creation of values) is to
# create the source field using the function fillFromAnalytic
#
from MEDLoader import *
from MEDCouplingRemapper import *

# Read the source mesh and create a field on it
msource  = MEDLoader.ReadUMeshFromFile("meshsource.med","meshsource",0)

equation = "319.*cos(((x)*(x)*3+(y-0.52)*(y-0.52)+(z-0.1)*(z-0.1))*7)"
fsource=msource.fillFromAnalytic(ON_CELLS,1,equation)
fsource.setName("Temperature")
fsource.setNature(ConservativeVolumic)

# Read the target mesh
mtarget = MEDLoader.ReadUMeshFromFile("meshtarget.med","meshtarget",0)

# Remapper of type P0P0 (interpolation from cells to cells)
remap = MEDCouplingRemapper()
remap.prepare(msource,mtarget,"P0P0")

defaultValue = 1e100
ftarget = remap.transferField(fsource,defaultValue)
ftarget.setName("Temperature")

outfilename = "createsource_fieldtarget.med"
MEDLoader.WriteField(outfilename,ftarget,True)

Esempio n. 7
0
trgMesh = MEDCouplingCMesh()
trgMesh.setCoords(arr, arr)
trgMesh = trgMesh.buildUnstructured()
#
arr = DataArrayDouble(21)
arr.iota(0)
arr *= 0.5
srcMesh = MEDCouplingCMesh()
srcMesh.setCoords(arr, arr)
srcMesh = srcMesh.buildUnstructured()
#
tmp = srcMesh[:20]
tmp.simplexize(0)
srcMesh = MEDCouplingUMesh.MergeUMeshes([tmp, srcMesh[20:]])
#
remap = MEDCouplingRemapper()
remap.prepare(srcMesh, trgMesh, "P0P0")
#
myMatrix = remap.getCrudeMatrix()
print myMatrix  # pour voir a quoi elle ressemble
sumByRows = DataArrayDouble(len(myMatrix))
for i, wIt in enumerate(sumByRows):
    su = 0.
    for it in myMatrix[i]:
        su += myMatrix[i][it]
    wIt[0] = su
print "Does interpolation look OK ? %s" % (str(sumByRows.isUniform(1., 1e-12)))
assert sumByRows.isUniform(1., 1e-12)
#
srcField = MEDCouplingFieldDouble(ON_CELLS, ONE_TIME)
srcField.setMesh(srcMesh)
Esempio n. 8
0
from MEDLoader import *
from MEDCouplingRemapper import *

ms=MEDFileMesh.New("MeshSource.med") ; ms=ms.getMeshAtLevel(0)
mt=MEDFileMesh.New("MeshTarget.med") ; mt=mt.getMeshAtLevel(0)
fs=ms.fillFromAnalytic(ON_CELLS,1,"319.*cos(((x)*(x)*3+(y-0.52)*(y-0.52)+(z-0.1)*(z-0.1))*7)")
fs.setNature(ConservativeVolumic)
fs.setName("Temperature")
MEDCouplingFieldDouble.WriteVTK("MeshSource.vtu",[fs])

mt2=mt.deepCpy()
mt2.translate([0.4,0.,0.])
mt2.writeVTK("MeshTarget.vtu")
#
remap=MEDCouplingRemapper()
remap.prepare(ms,mt,"P0P0")
ft=remap.transferField(fs,1e100)
ft.setName("Temperature")
ft.getMesh().translate([0.4,0.,0.])
MEDCouplingFieldDouble.WriteVTK("FieldTarget.vtu",[ft])


# Image illustrating the starting point:
# - load MeshSource.vtu (contains mesh+field)
# - load MeshTarget.vtu (contains only the mesh with translation)
#
# Image illustrating the result point:
# - load MeshSource.vtu
# - load FieldTarget.vtu
 
Esempio n. 9
0
from MEDCouplingRemapper import *

ms = MEDFileMesh.New("MeshSource.med")
ms = ms.getMeshAtLevel(0)
mt = MEDFileMesh.New("MeshTarget.med")
mt = mt.getMeshAtLevel(0)
fs = ms.fillFromAnalytic(
    ON_CELLS, 1, "319.*cos(((x)*(x)*3+(y-0.52)*(y-0.52)+(z-0.1)*(z-0.1))*7)")
fs.setNature(ConservativeVolumic)
fs.setName("Temperature")
MEDCouplingFieldDouble.WriteVTK("MeshSource.vtu", [fs])

mt2 = mt.deepCpy()
mt2.translate([0.4, 0., 0.])
mt2.writeVTK("MeshTarget.vtu")
#
remap = MEDCouplingRemapper()
remap.prepare(ms, mt, "P0P0")
ft = remap.transferField(fs, 1e100)
ft.setName("Temperature")
ft.getMesh().translate([0.4, 0., 0.])
MEDCouplingFieldDouble.WriteVTK("FieldTarget.vtu", [ft])

# Image illustrating the starting point:
# - load MeshSource.vtu (contains mesh+field)
# - load MeshTarget.vtu (contains only the mesh with translation)
#
# Image illustrating the result point:
# - load MeshSource.vtu
# - load FieldTarget.vtu
Esempio n. 10
0
 def testPrepareCC(self):
     # 1D
     src = MEDCouplingCMesh()
     arr = DataArrayDouble([-0.7, -0.1, 0.2, 0.7, 2., 2.3])
     src.setCoordsAt(0, arr)
     trg = MEDCouplingCMesh()
     arr = DataArrayDouble([-0.9, -0.1, 0.15])
     trg.setCoordsAt(0, arr)
     fieldSrc = MEDCouplingFieldDouble(ON_CELLS, NO_TIME)
     fieldSrc.setMesh(src)
     arrTrg = DataArrayDouble([10., 30., 40., 70., 80.])
     fieldSrc.setNature(Integral)
     fieldSrc.setArray(arrTrg)
     rem = MEDCouplingRemapper()
     rem.prepare(src, trg, "P0P0")
     trgField = rem.transferField(fieldSrc, -7.)
     expected1 = [10., 25.]
     self.assertEqual(2., trgField.getArray().getNumberOfTuples())
     self.assertEqual(2, len(expected1))
     for i, val in enumerate(expected1):
         self.assertAlmostEqual(expected1[i],
                                trgField.getArray().getIJ(i, 0), 12)
         pass
     # 2D
     src = MEDCouplingCMesh()
     arr = DataArrayDouble([-0.7, -0.1, 0.2, 0.7, 2., 2.3])
     src.setCoordsAt(0, arr)
     src.setCoordsAt(1, arr)
     trg = MEDCouplingCMesh()
     arr = DataArrayDouble([-0.9, -0.1, 0.15])
     trg.setCoordsAt(0, arr)
     trg.setCoordsAt(1, arr)
     fieldSrc = MEDCouplingFieldDouble(ON_CELLS, NO_TIME)
     fieldSrc.setMesh(src)
     arrSrc = DataArrayDouble([
         10., 30., 40., 70., 80., 110., 130., 140., 170., 180., 210., 230.,
         240., 270., 280., 310., 330., 340., 370., 380., 410., 430., 440.,
         470., 480.
     ])
     fieldSrc.setNature(Integral)
     fieldSrc.setArray(arrSrc)
     rem = MEDCouplingRemapper()
     rem.prepare(src, trg, "P0P0")
     trgField = rem.transferField(fieldSrc, -7.)
     expected2 = [10., 25., 91.66666666666666, 90.27777777777777]
     self.assertEqual(4, trgField.getArray().getNumberOfTuples())
     self.assertEqual(4, len(expected2))
     for i, val in enumerate(expected2):
         self.assertAlmostEqual(expected2[i],
                                trgField.getArray().getIJ(i, 0), 12)
         pass
     # 3D
     src = MEDCouplingCMesh()
     arr = DataArrayDouble([-0.7, -0.1, 0.2, 0.7, 2., 2.3])
     src.setCoordsAt(0, arr)
     src.setCoordsAt(1, arr)
     src.setCoordsAt(2, arr)
     trg = MEDCouplingCMesh()
     arr = DataArrayDouble([-0.9, -0.1, 0.15])
     trg.setCoordsAt(0, arr)
     trg.setCoordsAt(1, arr)
     trg.setCoordsAt(2, arr)
     fieldSrc = MEDCouplingFieldDouble(ON_CELLS, NO_TIME)
     fieldSrc.setMesh(src)
     arrSrc = DataArrayDouble(125)
     arrSrc.iota(7.7)
     fieldSrc.setNature(Integral)
     fieldSrc.setArray(arrSrc)
     fieldSrc.checkCoherency()
     rem = MEDCouplingRemapper()
     rem.prepare(src, trg, "P0P0")
     trgField = rem.transferField(fieldSrc, -7.)
     expected3 = [
         7.7, 7.249999999999999, 10.583333333333332, 9.513888888888886,
         27.25, 23.40277777777777, 26.180555555555546, 22.39583333333333
     ]
     self.assertEqual(8, trgField.getArray().getNumberOfTuples())
     self.assertEqual(8, len(expected3))
     for i, val in enumerate(expected3):
         self.assertAlmostEqual(expected3[i],
                                trgField.getArray().getIJ(i, 0), 12)
         pass
     pass
Esempio n. 11
0
 def testPrepareCU(self):
     # 1D
     coords = DataArrayDouble([0., 0.5, 0.7])
     trg = MEDCouplingUMesh("", 1)
     trg.setCoords(coords)
     trg.allocateCells(2)
     trg.insertNextCell(NORM_SEG2, [0, 1])
     trg.insertNextCell(NORM_SEG2, [1, 2])
     trg.finishInsertingCells()
     src = MEDCouplingCMesh()
     arr = DataArrayDouble([-0.7, -0.1, 0.2, 0.7, 2., 2.3])
     src.setCoordsAt(0, arr)
     fieldSrc = MEDCouplingFieldDouble(ON_CELLS, NO_TIME)
     fieldSrc.setMesh(src)
     arrTrg = DataArrayDouble([10., 30., 40., 70., 80.])
     fieldSrc.setNature(Integral)
     fieldSrc.setArray(arrTrg)
     rem = MEDCouplingRemapper()
     rem.prepare(src, trg, "P0P0")
     trgField = rem.transferField(fieldSrc, -7.)
     expected1 = [44., 16.]
     self.assertEqual(2., trgField.getArray().getNumberOfTuples())
     self.assertEqual(2, len(expected1))
     for i, val in enumerate(expected1):
         self.assertAlmostEqual(expected1[i],
                                trgField.getArray().getIJ(i, 0), 12)
         pass
     # 2D
     coords = DataArrayDouble([0., 0., 0., 1., 1., 1., 1., 0., 0.5, -0.2],
                              5, 2)
     trg = MEDCouplingUMesh("", 2)
     trg.setCoords(coords)
     trg.allocateCells(2)
     trg.insertNextCell(NORM_TRI3, [0, 1, 2])
     trg.insertNextCell(NORM_TRI3, [3, 4, 0])
     trg.finishInsertingCells()
     src = MEDCouplingCMesh()
     arr = DataArrayDouble([-0.7, -0.1, 0.2, 0.7, 2., 2.3])
     src.setCoordsAt(0, arr)
     src.setCoordsAt(1, arr)
     fieldSrc = MEDCouplingFieldDouble(ON_CELLS, NO_TIME)
     fieldSrc.setMesh(src)
     arrSrc = DataArrayDouble([
         10., 30., 40., 70., 80., 110., 130., 140., 170., 180., 210., 230.,
         240., 270., 280., 310., 330., 340., 370., 380., 410., 430., 440.,
         470., 480.
     ])
     fieldSrc.setNature(Integral)
     fieldSrc.setArray(arrSrc)
     rem = MEDCouplingRemapper()
     rem.prepare(src, trg, "P0P0")
     trgField = rem.transferField(fieldSrc, -7.)
     expected2 = [441.3050624589086, 68.69529914529915]
     self.assertEqual(2, trgField.getArray().getNumberOfTuples())
     self.assertEqual(2, len(expected2))
     for i, val in enumerate(expected2):
         self.assertAlmostEqual(expected2[i],
                                trgField.getArray().getIJ(i, 0), 12)
         pass
     # 3D
     coords = DataArrayDouble([
         0., 0., 0., 0., 1., 0., 1., 1., 0., 1., 0., 0., 0.5, -0.2, 0., 0.1,
         0.8, 1., 0.5, 0., 1.
     ], 7, 3)
     trg = MEDCouplingUMesh("", 3)
     trg.setCoords(coords)
     trg.allocateCells(2)
     trg.insertNextCell(NORM_TETRA4, [0, 1, 2, 5])
     trg.insertNextCell(NORM_TETRA4, [3, 4, 0, 6])
     trg.finishInsertingCells()
     src = MEDCouplingCMesh()
     arr = DataArrayDouble([-0.7, -0.1, 0.2, 0.7, 2., 2.3])
     arr2 = DataArrayDouble([-0.7, 0.2, 0.6, 1.2, 2.])
     src.setCoordsAt(0, arr)
     src.setCoordsAt(1, arr)
     src.setCoordsAt(2, arr2)
     trg.checkCoherency2(1e-10)
     src.checkCoherency()
     fieldSrc = MEDCouplingFieldDouble(ON_CELLS, NO_TIME)
     fieldSrc.setMesh(src)
     arrSrc = DataArrayDouble(100)
     arrSrc.iota(7.7)
     fieldSrc.setNature(Integral)
     fieldSrc.setArray(arrSrc)
     rem = MEDCouplingRemapper()
     rem.prepare(src, trg, "P0P0")
     trgField = rem.transferField(fieldSrc, -7.)
     expected3 = [39.635196634558845, 12.13422356758468]
     self.assertEqual(2, trgField.getArray().getNumberOfTuples())
     self.assertEqual(2, len(expected3))
     for i, val in enumerate(expected3):
         self.assertAlmostEqual(expected3[i],
                                trgField.getArray().getIJ(i, 0), 12)
         pass
     pass
Esempio n. 12
0
 def testPrepareUC(self):
     # 1D
     coords = DataArrayDouble([0., 0.5, 0.7])
     src = MEDCouplingUMesh("", 1)
     src.setCoords(coords)
     src.allocateCells(2)
     src.insertNextCell(NORM_SEG2, [0, 1])
     src.insertNextCell(NORM_SEG2, [1, 2])
     src.finishInsertingCells()
     trg = MEDCouplingCMesh()
     arr = DataArrayDouble([-0.7, -0.1, 0.2, 0.7, 2., 2.3])
     trg.setCoordsAt(0, arr)
     fieldSrc = MEDCouplingFieldDouble(ON_CELLS, NO_TIME)
     fieldSrc.setMesh(src)
     arrSrc = DataArrayDouble([10., 30.])
     fieldSrc.setNature(Integral)
     fieldSrc.setArray(arrSrc)
     rem = MEDCouplingRemapper()
     rem.prepare(src, trg, "P0P0")
     trgField = rem.transferField(fieldSrc, -7.)
     expected1 = [-7., 4., 36., -7., -7.]
     self.assertEqual(5, trgField.getArray().getNumberOfTuples())
     self.assertEqual(5, len(expected1))
     for i, val in enumerate(expected1):
         self.assertAlmostEqual(expected1[i],
                                trgField.getArray().getIJ(i, 0), 12)
         pass
     # 2D
     coords = DataArrayDouble([0., 0., 0., 1., 1., 1., 1., 0., 0.5, -0.2],
                              5, 2)
     src = MEDCouplingUMesh("", 2)
     src.setCoords(coords)
     src.allocateCells(2)
     src.insertNextCell(NORM_TRI3, [0, 1, 2])
     src.insertNextCell(NORM_TRI3, [3, 4, 0])
     src.finishInsertingCells()
     trg = MEDCouplingCMesh()
     arr = DataArrayDouble([-0.7, -0.1, 0.2, 0.7, 2., 2.3])
     trg.setCoordsAt(0, arr)
     trg.setCoordsAt(1, arr)
     fieldSrc = MEDCouplingFieldDouble(ON_CELLS, NO_TIME)
     fieldSrc.setMesh(src)
     arrSrc = DataArrayDouble([10., 30.])
     fieldSrc.setNature(Integral)
     fieldSrc.setArray(arrSrc)
     rem = MEDCouplingRemapper()
     rem.prepare(src, trg, "P0P0")
     trgField = rem.transferField(fieldSrc, -7.)
     expected2 = [
         -7., -7., 7.35, 0.15, -7., -7., 2.8, 14.85, 5.25, -7., -7., 2.,
         2.5, -7., -7., -7., 1.2, 3., 0.9, -7., -7., -7., -7., -7., -7.
     ]
     self.assertEqual(25, trgField.getArray().getNumberOfTuples())
     self.assertEqual(25, len(expected2))
     for i, val in enumerate(expected2):
         self.assertAlmostEqual(expected2[i],
                                trgField.getArray().getIJ(i, 0), 12)
         pass
     # 3D
     coords = DataArrayDouble([
         0., 0., 0., 0., 1., 0., 1., 1., 0., 1., 0., 0., 0.5, -0.2, 0., 0.1,
         0.8, 1., 0.5, 0., 1.
     ], 7, 3)
     src = MEDCouplingUMesh("", 3)
     src.setCoords(coords)
     src.allocateCells(2)
     src.insertNextCell(NORM_TETRA4, [0, 1, 2, 5])
     src.insertNextCell(NORM_TETRA4, [3, 4, 0, 6])
     src.finishInsertingCells()
     trg = MEDCouplingCMesh()
     arr = DataArrayDouble([-0.7, -0.1, 0.2, 0.7, 2., 2.3])
     arr2 = DataArrayDouble([-0.7, 0.2, 0.6, 1.2, 2.])
     trg.setCoordsAt(0, arr)
     trg.setCoordsAt(1, arr)
     trg.setCoordsAt(2, arr2)
     src.checkCoherency2(1e-10)
     trg.checkCoherency()
     fieldSrc = MEDCouplingFieldDouble(ON_CELLS, NO_TIME)
     fieldSrc.setMesh(src)
     arrSrc = DataArrayDouble([10., 30.])
     fieldSrc.setNature(Integral)
     fieldSrc.setArray(arrSrc)
     rem = MEDCouplingRemapper()
     rem.prepare(src, trg, "P0P0")
     trgField = rem.transferField(fieldSrc, -7.)
     expected3 = [
         -7., -7., 2.925, 0.015, -7., -7., 0.9392, 8.595, 2.265, -7., -7.,
         1.1008, 1.1192, -7., -7., -7., 0.6392, 1.6408, 0.2808, -7., -7.,
         -7., -7., -7., -7., -7., -7., 0.81, -7., -7., -7., 0.1208, 11.55,
         0.96, -7., -7., 1.1752, 0.6592, -7., -7., -7., 0.8512, 1.7744,
         0.0192, -7., -7., -7., -7., -7., -7., -7., -7., -7., -7., -7., -7.,
         -7., 1.92, -7., -7., -7., 0.12578571428571422,
         0.007314285714285673, -7., -7., -7., 0.3189253968253971,
         0.1879746031746033, -7., -7., -7., -7., -7., -7., -7., -7., -7.,
         -7., -7., -7., -7., -7., -7., -7., -7., -7., -7., -7., -7., -7.,
         -7., -7., -7., -7., -7., -7., -7., -7., -7., -7.
     ]
     self.assertEqual(100, trgField.getArray().getNumberOfTuples())
     self.assertEqual(100, len(expected3))
     for i, val in enumerate(expected3):
         self.assertAlmostEqual(expected3[i],
                                trgField.getArray().getIJ(i, 0), 12)
         pass
     pass
Esempio n. 13
0
#

#
# Another possibility (to illustrate the creation of values) is to
# create the source field using the function fillFromAnalytic
#
from MEDLoader import *
from MEDCouplingRemapper import *

# Read the source mesh and create a field on it
msource = MEDLoader.ReadUMeshFromFile("meshsource.med", "meshsource", 0)

equation = "319.*cos(((x)*(x)*3+(y-0.52)*(y-0.52)+(z-0.1)*(z-0.1))*7)"
fsource = msource.fillFromAnalytic(ON_CELLS, 1, equation)
fsource.setName("Temperature")
fsource.setNature(IntensiveMaximum)

# Read the target mesh
mtarget = MEDLoader.ReadUMeshFromFile("meshtarget.med", "meshtarget", 0)

# Remapper of type P0P0 (interpolation from cells to cells)
remap = MEDCouplingRemapper()
remap.prepare(msource, mtarget, "P0P0")

defaultValue = 1e100
ftarget = remap.transferField(fsource, defaultValue)
ftarget.setName("Temperature")

outfilename = "createsource_fieldtarget.med"
MEDLoader.WriteField(outfilename, ftarget, True)
 def testPrepareCC(self):
     # 1D
     src = MEDCouplingCMesh()
     arr = DataArrayDouble([-0.7, -0.1, 0.2, 0.7, 2.0, 2.3])
     src.setCoordsAt(0, arr)
     trg = MEDCouplingCMesh()
     arr = DataArrayDouble([-0.9, -0.1, 0.15])
     trg.setCoordsAt(0, arr)
     fieldSrc = MEDCouplingFieldDouble(ON_CELLS, NO_TIME)
     fieldSrc.setMesh(src)
     arrTrg = DataArrayDouble([10.0, 30.0, 40.0, 70.0, 80.0])
     fieldSrc.setNature(Integral)
     fieldSrc.setArray(arrTrg)
     rem = MEDCouplingRemapper()
     rem.prepare(src, trg, "P0P0")
     trgField = rem.transferField(fieldSrc, -7.0)
     expected1 = [10.0, 25.0]
     self.assertEqual(2.0, trgField.getArray().getNumberOfTuples())
     self.assertEqual(2, len(expected1))
     for i, val in enumerate(expected1):
         self.assertAlmostEqual(expected1[i], trgField.getArray().getIJ(i, 0), 12)
         pass
     # 2D
     src = MEDCouplingCMesh()
     arr = DataArrayDouble([-0.7, -0.1, 0.2, 0.7, 2.0, 2.3])
     src.setCoordsAt(0, arr)
     src.setCoordsAt(1, arr)
     trg = MEDCouplingCMesh()
     arr = DataArrayDouble([-0.9, -0.1, 0.15])
     trg.setCoordsAt(0, arr)
     trg.setCoordsAt(1, arr)
     fieldSrc = MEDCouplingFieldDouble(ON_CELLS, NO_TIME)
     fieldSrc.setMesh(src)
     arrSrc = DataArrayDouble(
         [
             10.0,
             30.0,
             40.0,
             70.0,
             80.0,
             110.0,
             130.0,
             140.0,
             170.0,
             180.0,
             210.0,
             230.0,
             240.0,
             270.0,
             280.0,
             310.0,
             330.0,
             340.0,
             370.0,
             380.0,
             410.0,
             430.0,
             440.0,
             470.0,
             480.0,
         ]
     )
     fieldSrc.setNature(Integral)
     fieldSrc.setArray(arrSrc)
     rem = MEDCouplingRemapper()
     rem.prepare(src, trg, "P0P0")
     trgField = rem.transferField(fieldSrc, -7.0)
     expected2 = [10.0, 25.0, 91.66666666666666, 90.27777777777777]
     self.assertEqual(4, trgField.getArray().getNumberOfTuples())
     self.assertEqual(4, len(expected2))
     for i, val in enumerate(expected2):
         self.assertAlmostEqual(expected2[i], trgField.getArray().getIJ(i, 0), 12)
         pass
     # 3D
     src = MEDCouplingCMesh()
     arr = DataArrayDouble([-0.7, -0.1, 0.2, 0.7, 2.0, 2.3])
     src.setCoordsAt(0, arr)
     src.setCoordsAt(1, arr)
     src.setCoordsAt(2, arr)
     trg = MEDCouplingCMesh()
     arr = DataArrayDouble([-0.9, -0.1, 0.15])
     trg.setCoordsAt(0, arr)
     trg.setCoordsAt(1, arr)
     trg.setCoordsAt(2, arr)
     fieldSrc = MEDCouplingFieldDouble(ON_CELLS, NO_TIME)
     fieldSrc.setMesh(src)
     arrSrc = DataArrayDouble(125)
     arrSrc.iota(7.7)
     fieldSrc.setNature(Integral)
     fieldSrc.setArray(arrSrc)
     fieldSrc.checkCoherency()
     rem = MEDCouplingRemapper()
     rem.prepare(src, trg, "P0P0")
     trgField = rem.transferField(fieldSrc, -7.0)
     expected3 = [
         7.7,
         7.249999999999999,
         10.583333333333332,
         9.513888888888886,
         27.25,
         23.40277777777777,
         26.180555555555546,
         22.39583333333333,
     ]
     self.assertEqual(8, trgField.getArray().getNumberOfTuples())
     self.assertEqual(8, len(expected3))
     for i, val in enumerate(expected3):
         self.assertAlmostEqual(expected3[i], trgField.getArray().getIJ(i, 0), 12)
         pass
     pass
 def testPrepareCU(self):
     # 1D
     coords = DataArrayDouble([0.0, 0.5, 0.7])
     trg = MEDCouplingUMesh("", 1)
     trg.setCoords(coords)
     trg.allocateCells(2)
     trg.insertNextCell(NORM_SEG2, [0, 1])
     trg.insertNextCell(NORM_SEG2, [1, 2])
     trg.finishInsertingCells()
     src = MEDCouplingCMesh()
     arr = DataArrayDouble([-0.7, -0.1, 0.2, 0.7, 2.0, 2.3])
     src.setCoordsAt(0, arr)
     fieldSrc = MEDCouplingFieldDouble(ON_CELLS, NO_TIME)
     fieldSrc.setMesh(src)
     arrTrg = DataArrayDouble([10.0, 30.0, 40.0, 70.0, 80.0])
     fieldSrc.setNature(Integral)
     fieldSrc.setArray(arrTrg)
     rem = MEDCouplingRemapper()
     rem.prepare(src, trg, "P0P0")
     trgField = rem.transferField(fieldSrc, -7.0)
     expected1 = [44.0, 16.0]
     self.assertEqual(2.0, trgField.getArray().getNumberOfTuples())
     self.assertEqual(2, len(expected1))
     for i, val in enumerate(expected1):
         self.assertAlmostEqual(expected1[i], trgField.getArray().getIJ(i, 0), 12)
         pass
     # 2D
     coords = DataArrayDouble([0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.5, -0.2], 5, 2)
     trg = MEDCouplingUMesh("", 2)
     trg.setCoords(coords)
     trg.allocateCells(2)
     trg.insertNextCell(NORM_TRI3, [0, 1, 2])
     trg.insertNextCell(NORM_TRI3, [3, 4, 0])
     trg.finishInsertingCells()
     src = MEDCouplingCMesh()
     arr = DataArrayDouble([-0.7, -0.1, 0.2, 0.7, 2.0, 2.3])
     src.setCoordsAt(0, arr)
     src.setCoordsAt(1, arr)
     fieldSrc = MEDCouplingFieldDouble(ON_CELLS, NO_TIME)
     fieldSrc.setMesh(src)
     arrSrc = DataArrayDouble(
         [
             10.0,
             30.0,
             40.0,
             70.0,
             80.0,
             110.0,
             130.0,
             140.0,
             170.0,
             180.0,
             210.0,
             230.0,
             240.0,
             270.0,
             280.0,
             310.0,
             330.0,
             340.0,
             370.0,
             380.0,
             410.0,
             430.0,
             440.0,
             470.0,
             480.0,
         ]
     )
     fieldSrc.setNature(Integral)
     fieldSrc.setArray(arrSrc)
     rem = MEDCouplingRemapper()
     rem.prepare(src, trg, "P0P0")
     trgField = rem.transferField(fieldSrc, -7.0)
     expected2 = [441.3050624589086, 68.69529914529915]
     self.assertEqual(2, trgField.getArray().getNumberOfTuples())
     self.assertEqual(2, len(expected2))
     for i, val in enumerate(expected2):
         self.assertAlmostEqual(expected2[i], trgField.getArray().getIJ(i, 0), 12)
         pass
     # 3D
     coords = DataArrayDouble(
         [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.5, -0.2, 0.0, 0.1, 0.8, 1.0, 0.5, 0.0, 1.0],
         7,
         3,
     )
     trg = MEDCouplingUMesh("", 3)
     trg.setCoords(coords)
     trg.allocateCells(2)
     trg.insertNextCell(NORM_TETRA4, [0, 1, 2, 5])
     trg.insertNextCell(NORM_TETRA4, [3, 4, 0, 6])
     trg.finishInsertingCells()
     src = MEDCouplingCMesh()
     arr = DataArrayDouble([-0.7, -0.1, 0.2, 0.7, 2.0, 2.3])
     arr2 = DataArrayDouble([-0.7, 0.2, 0.6, 1.2, 2.0])
     src.setCoordsAt(0, arr)
     src.setCoordsAt(1, arr)
     src.setCoordsAt(2, arr2)
     trg.checkCoherency2(1e-10)
     src.checkCoherency()
     fieldSrc = MEDCouplingFieldDouble(ON_CELLS, NO_TIME)
     fieldSrc.setMesh(src)
     arrSrc = DataArrayDouble(100)
     arrSrc.iota(7.7)
     fieldSrc.setNature(Integral)
     fieldSrc.setArray(arrSrc)
     rem = MEDCouplingRemapper()
     rem.prepare(src, trg, "P0P0")
     trgField = rem.transferField(fieldSrc, -7.0)
     expected3 = [39.635196634558845, 12.13422356758468]
     self.assertEqual(2, trgField.getArray().getNumberOfTuples())
     self.assertEqual(2, len(expected3))
     for i, val in enumerate(expected3):
         self.assertAlmostEqual(expected3[i], trgField.getArray().getIJ(i, 0), 12)
         pass
     pass
 def testPrepareUC(self):
     # 1D
     coords = DataArrayDouble([0.0, 0.5, 0.7])
     src = MEDCouplingUMesh("", 1)
     src.setCoords(coords)
     src.allocateCells(2)
     src.insertNextCell(NORM_SEG2, [0, 1])
     src.insertNextCell(NORM_SEG2, [1, 2])
     src.finishInsertingCells()
     trg = MEDCouplingCMesh()
     arr = DataArrayDouble([-0.7, -0.1, 0.2, 0.7, 2.0, 2.3])
     trg.setCoordsAt(0, arr)
     fieldSrc = MEDCouplingFieldDouble(ON_CELLS, NO_TIME)
     fieldSrc.setMesh(src)
     arrSrc = DataArrayDouble([10.0, 30.0])
     fieldSrc.setNature(Integral)
     fieldSrc.setArray(arrSrc)
     rem = MEDCouplingRemapper()
     rem.prepare(src, trg, "P0P0")
     trgField = rem.transferField(fieldSrc, -7.0)
     expected1 = [-7.0, 4.0, 36.0, -7.0, -7.0]
     self.assertEqual(5, trgField.getArray().getNumberOfTuples())
     self.assertEqual(5, len(expected1))
     for i, val in enumerate(expected1):
         self.assertAlmostEqual(expected1[i], trgField.getArray().getIJ(i, 0), 12)
         pass
     # 2D
     coords = DataArrayDouble([0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.5, -0.2], 5, 2)
     src = MEDCouplingUMesh("", 2)
     src.setCoords(coords)
     src.allocateCells(2)
     src.insertNextCell(NORM_TRI3, [0, 1, 2])
     src.insertNextCell(NORM_TRI3, [3, 4, 0])
     src.finishInsertingCells()
     trg = MEDCouplingCMesh()
     arr = DataArrayDouble([-0.7, -0.1, 0.2, 0.7, 2.0, 2.3])
     trg.setCoordsAt(0, arr)
     trg.setCoordsAt(1, arr)
     fieldSrc = MEDCouplingFieldDouble(ON_CELLS, NO_TIME)
     fieldSrc.setMesh(src)
     arrSrc = DataArrayDouble([10.0, 30.0])
     fieldSrc.setNature(Integral)
     fieldSrc.setArray(arrSrc)
     rem = MEDCouplingRemapper()
     rem.prepare(src, trg, "P0P0")
     trgField = rem.transferField(fieldSrc, -7.0)
     expected2 = [
         -7.0,
         -7.0,
         7.35,
         0.15,
         -7.0,
         -7.0,
         2.8,
         14.85,
         5.25,
         -7.0,
         -7.0,
         2.0,
         2.5,
         -7.0,
         -7.0,
         -7.0,
         1.2,
         3.0,
         0.9,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
     ]
     self.assertEqual(25, trgField.getArray().getNumberOfTuples())
     self.assertEqual(25, len(expected2))
     for i, val in enumerate(expected2):
         self.assertAlmostEqual(expected2[i], trgField.getArray().getIJ(i, 0), 12)
         pass
     # 3D
     coords = DataArrayDouble(
         [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.5, -0.2, 0.0, 0.1, 0.8, 1.0, 0.5, 0.0, 1.0],
         7,
         3,
     )
     src = MEDCouplingUMesh("", 3)
     src.setCoords(coords)
     src.allocateCells(2)
     src.insertNextCell(NORM_TETRA4, [0, 1, 2, 5])
     src.insertNextCell(NORM_TETRA4, [3, 4, 0, 6])
     src.finishInsertingCells()
     trg = MEDCouplingCMesh()
     arr = DataArrayDouble([-0.7, -0.1, 0.2, 0.7, 2.0, 2.3])
     arr2 = DataArrayDouble([-0.7, 0.2, 0.6, 1.2, 2.0])
     trg.setCoordsAt(0, arr)
     trg.setCoordsAt(1, arr)
     trg.setCoordsAt(2, arr2)
     src.checkCoherency2(1e-10)
     trg.checkCoherency()
     fieldSrc = MEDCouplingFieldDouble(ON_CELLS, NO_TIME)
     fieldSrc.setMesh(src)
     arrSrc = DataArrayDouble([10.0, 30.0])
     fieldSrc.setNature(Integral)
     fieldSrc.setArray(arrSrc)
     rem = MEDCouplingRemapper()
     rem.prepare(src, trg, "P0P0")
     trgField = rem.transferField(fieldSrc, -7.0)
     expected3 = [
         -7.0,
         -7.0,
         2.925,
         0.015,
         -7.0,
         -7.0,
         0.9392,
         8.595,
         2.265,
         -7.0,
         -7.0,
         1.1008,
         1.1192,
         -7.0,
         -7.0,
         -7.0,
         0.6392,
         1.6408,
         0.2808,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         0.81,
         -7.0,
         -7.0,
         -7.0,
         0.1208,
         11.55,
         0.96,
         -7.0,
         -7.0,
         1.1752,
         0.6592,
         -7.0,
         -7.0,
         -7.0,
         0.8512,
         1.7744,
         0.0192,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         1.92,
         -7.0,
         -7.0,
         -7.0,
         0.12578571428571422,
         0.007314285714285673,
         -7.0,
         -7.0,
         -7.0,
         0.3189253968253971,
         0.1879746031746033,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
         -7.0,
     ]
     self.assertEqual(100, trgField.getArray().getNumberOfTuples())
     self.assertEqual(100, len(expected3))
     for i, val in enumerate(expected3):
         self.assertAlmostEqual(expected3[i], trgField.getArray().getIJ(i, 0), 12)
         pass
     pass