Salome HOME
7e86a47a3d32745a34f6262e406a48d94ebc4385
[modules/med.git] / doc / tut / medloader / cmesh.py
1 #!/usr/bin/env python3
2 # Copyright (C) 2012-2021  CEA/DEN, EDF R&D
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 from MEDLoader import MEDLoader
22
23 import os
24 filename = "madnex_field.med"
25 filepath = os.path.join(os.path.abspath(os.path.dirname(__file__)),filename)
26
27 meshName="my_field_RG"
28 fieldName="my_field"
29 itNumber=0
30 itOrder=0
31
32 # Load as an unstructured mesh
33 meshDimRelToMax = 0 # 0 = no restriction
34 umesh = MEDLoader.ReadUMeshFromFile(filepath,meshName,meshDimRelToMax)
35 print("umesh is structured: %s"%umesh.isStructured())
36
37 # Load as a structured mesh explicitly
38 # _T2A
39 from MEDLoader import MEDFileCMesh
40 medfile = MEDFileCMesh.New(filepath,meshName)
41 cmesh = medfile.getMesh()
42 # Note that the getMesh method is a short way to the method:
43 #cmesh = medfile.getGenMeshAtLevel(0,False)
44 print("cmesh is structured: %s"%cmesh.isStructured())
45 # _T2B
46
47 # Load and let MEDLoader decide what is nature of the mesh
48 # _T1A
49 from MEDLoader import MEDFileMesh
50 medfile = MEDFileMesh.New(filepath,meshName)
51 print(medfile.advancedRepr())
52 meshDimRelToMax = 0 # 0 = no restriction
53 mesh = medfile.getGenMeshAtLevel(meshDimRelToMax)
54 print("mesh is structured: %s"%mesh.isStructured())
55 # _T1B
56
57
58 # Write the mesh to another file
59 # _T3A
60 outputfilepath="output.med"
61 mode=0
62 medfile.write(outputfilepath,mode)
63 # _T3B
64
65 # test to reload the mesh
66 medfile = MEDFileCMesh.New(outputfilepath,meshName)
67 cmesh = medfile.getMesh()
68 print("cmesh is structured: %s"%cmesh.isStructured())
69
70 # Q: Is it possible to know if a mesh is structured or unstructured
71 # without loading the mesh.