2 # Copyright (C) 2012-2022 CEA/DEN, EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # This script illustrates the basic usage of MEDCoupling and MEDLoader
22 # to read fields in a med file and make basics operation on the values
23 # (gboulant - 11/07/2011)
27 medfilename = "timeseries.med" # med source filename
28 meshName = "Grid_80x80" # name of the support mesh
29 dimrestriction = 0 # 0=no restriction
30 fieldName = "Pulse" # name of the field series
33 # ==============================================================
34 # Make a scaling. This does not require the loading of the mesh
36 from MEDLoader import MEDLoader, ON_NODES
38 iteration, order = (3,-1) # timestamps to consider
39 field=MEDLoader.ReadField(ON_NODES,
40 medfilename, meshName, dimrestriction,
41 fieldName, iteration, order)
43 field.applyFunc("f*3")
44 outfilename = "scaling.med"
45 MEDLoader.WriteField(outfilename,field,True)
49 # ==============================================================
50 # Make an addition. This requires to load first the mesh
53 # Load the support mesh
54 mesh = MEDLoader.ReadUMeshFromFile(medfilename, meshName, dimrestriction)
56 # Load the field at timestamps 3
57 iteration, order = (3,-1)
58 p3=MEDLoader.ReadField(ON_NODES,
59 medfilename,meshName,dimrestriction,
60 fieldName,iteration,order)
64 # Load the field at timestamps 4
65 iteration, order = (4,-1)
66 p4=MEDLoader.ReadField(ON_NODES,
67 medfilename, meshName, dimrestriction,
68 fieldName, iteration, order)
74 result.setName("p3+p4")
76 # We can finally save the result together with the operands fields
77 outfilename = "addition.med"
78 MEDLoader.WriteField(outfilename,result,True)
79 MEDLoader.WriteField(outfilename,p3,False)
80 MEDLoader.WriteField(outfilename,p4,False)
83 # ==============================================================
84 # Make an addition. A different way that loads fields all at once
85 mesh = MEDLoader.ReadUMeshFromFile(medfilename, meshName, dimrestriction)
86 timestamps = [(3,-1),(4,-1)]
87 p3,p4 = MEDLoader.ReadFieldsOnSameMesh(ON_NODES,medfilename,
88 meshName,dimrestriction,
93 result.setName("p3+p4")
95 outfilename = "addition_01.med"
96 MEDLoader.WriteField(outfilename,result,True)