Salome HOME
Update copyrights 2014.
[modules/med.git] / src / MEDOP / tut / projection / demomed / demo_createsource.py
1 # Copyright (C) 2012-2014  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 #
21 # Another possibility (to illustrate the creation of values) is to
22 # create the source field using the function fillFromAnalytic
23 #
24 from MEDLoader import *
25 from MEDCouplingRemapper import *
26
27 # Read the source mesh and create a field on it
28 msource  = MEDLoader.ReadUMeshFromFile("meshsource.med","meshsource",0)
29
30 equation = "319.*cos(((x)*(x)*3+(y-0.52)*(y-0.52)+(z-0.1)*(z-0.1))*7)"
31 fsource=msource.fillFromAnalytic(ON_CELLS,1,equation)
32 fsource.setName("Temperature")
33 fsource.setNature(ConservativeVolumic)
34
35 # Read the target mesh
36 mtarget = MEDLoader.ReadUMeshFromFile("meshtarget.med","meshtarget",0)
37
38 # Remapper of type P0P0 (interpolation from cells to cells)
39 remap = MEDCouplingRemapper()
40 remap.prepare(msource,mtarget,"P0P0")
41
42 defaultValue = 1e100
43 ftarget = remap.transferField(fsource,defaultValue)
44 ftarget.setName("Temperature")
45
46 outfilename = "createsource_fieldtarget.med"
47 MEDLoader.WriteField(outfilename,ftarget,True)
48