Salome HOME
79f9bd4c1d2b1368ce687c4bc6df304914b9da2f
[modules/med.git] / doc / tut / projection / demovtu / projection.py
1 # Copyright (C) 2012-2020  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 from MEDLoader import *
21 from MEDCouplingRemapper import *
22
23 ms=MEDFileMesh.New("MeshSource.med") ; ms=ms.getMeshAtLevel(0)
24 mt=MEDFileMesh.New("MeshTarget.med") ; mt=mt.getMeshAtLevel(0)
25 fs=ms.fillFromAnalytic(ON_CELLS,1,"319.*cos(((x)*(x)*3+(y-0.52)*(y-0.52)+(z-0.1)*(z-0.1))*7)")
26 fs.setNature(IntensiveMaximum)
27 fs.setName("Temperature")
28 MEDCouplingFieldDouble.WriteVTK("MeshSource.vtu",[fs])
29
30 mt2=mt.deepCopy()
31 mt2.translate([0.4,0.,0.])
32 mt2.writeVTK("MeshTarget.vtu")
33 #
34 remap=MEDCouplingRemapper()
35 remap.prepare(ms,mt,"P0P0")
36 ft=remap.transferField(fs,1e100)
37 ft.setName("Temperature")
38 ft.getMesh().translate([0.4,0.,0.])
39 MEDCouplingFieldDouble.WriteVTK("FieldTarget.vtu",[ft])
40
41
42 # Image illustrating the starting point:
43 # - load MeshSource.vtu (contains mesh+field)
44 # - load MeshTarget.vtu (contains only the mesh with translation)
45 #
46 # Image illustrating the result point:
47 # - load MeshSource.vtu
48 # - load FieldTarget.vtu
49