1 # Copyright (C) 2014-2023 CEA/DEN, EDF R&D
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 def __select_data(reader, dataname=None):
21 keys = reader.GetProperty("FieldsTreeInfo")[::2]
22 # list all the names of arrays that can be seen (including their spatial discretization)
23 arr_name_with_dis = [elt.split("/")[-1] for elt in keys]
24 # list all the names of arrays (Equal to those in the MED File)
25 separator = reader.GetProperty("Separator").GetData()
26 arr_name = [elt.split(separator)[0] for elt in arr_name_with_dis]
27 for idx in range(len(keys)):
28 if arr_name[idx] == dataname:
29 reader.FieldsStatus = keys[idx]
35 def get_element_type(reader):
36 # Return 'P0', 'P1'...
37 separator = reader.GetProperty("Separator").GetData()
38 return reader.FieldsStatus[0].split(separator)[1]
41 def get_element_name(reader):
42 separator = reader.GetProperty("Separator").GetData()
43 return reader.FieldsStatus[0].split(separator)[0].split("/")[-1]
46 def load_mesh(med_filename, mesh_name=None):
48 reader = pvsimple.MEDReader(FileNames=med_filename)
49 return __select_data(reader, mesh_name)
52 def load_field(med_filename, field_name=None):
54 reader = pvsimple.MEDReader(FileNames=med_filename)
55 return __select_data(reader, field_name)