Salome HOME
updated copyright message
[modules/med.git] / doc / tut / medloader / testamel.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2012-2023  CEA, EDF
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 # This illustrates the use of getValueOn in the case of hexahedron
22 # meshes (for which a temporary limitation implies the usage of the
23 # method simplexize that split the hexahedron into simplex,
24 # i.e. triangles and tetrahedrons).
25 #
26 # (gboulant, nov. 2012)
27 from MEDLoader import *
28 from medcoupling import *
29
30 import os
31 filename = "timeseries.med"
32 filepath = os.path.join(os.path.abspath(os.path.dirname(__file__)),filename)
33
34 rmedfilename = filepath
35
36 # Load the mesh data
37 meshname = "Grid_80x80"
38 fieldname = "Pulse"
39 dimrestriction = 0 # no restriction
40 msource = MEDLoader.ReadUMeshFromFile(rmedfilename,meshname,dimrestriction)
41
42 # WARN: In the current version of MEDCoupling, the getValueOn works
43 # only with simplex cells (triangles, tetrahedron). This is not a
44 # technical problem, but a question of specification of the
45 # interpolation to be performed in the case of other cells, in
46 # particular in the case of hexahedron meshes.
47 #
48 # A temporary solution (with good numerical results) is to split
49 # hexahedrons into simplex (before the association of the mesh to the
50 # field) using the method simplexize.
51 policy = 0
52 msource.simplexize(policy)
53
54 # Load the field data at iteration 0
55 iteration = 0
56 order = -1
57 fieldOnNodes = MEDLoader.ReadField(ON_NODES,rmedfilename,
58                                    meshname,dimrestriction,
59                                    fieldname,iteration,order)
60
61
62 fieldOnNodes.setMesh(msource)
63
64 # Get the value of field at coordinates x,y
65 x=0.5
66 y=0.5
67 fieldValue = fieldOnNodes.getValueOn([x,y])
68 print(fieldValue)