Salome HOME
Copyright update 2022
[modules/paravis.git] / examples / command_line / dataset.py
1 # Copyright (C) 2014-2022  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 def create_geometry(out_filename=None):
20   import GEOM
21   import salome
22   from salome.geom import geomBuilder
23   geompy = geomBuilder.New()
24
25   # create a cloud of points
26   points = [
27     geompy.MakeVertex(0,0,0),
28     geompy.MakeVertex(9,0,0),
29     geompy.MakeVertex(0,9,0),
30     geompy.MakeVertex(9,9,0),
31     geompy.MakeVertex(3,3,1),
32     geompy.MakeVertex(6,6,2)]
33
34   # create SmoothingSurface object
35   smoothingsurface = geompy.MakeSmoothingSurface(points)
36   if out_filename:
37     geompy.ExportBREP(smoothingsurface, out_filename)
38
39   # add object in the study
40   id_smoothingsurface = geompy.addToStudy(smoothingsurface,"SmoothingSurface")
41
42   return smoothingsurface
43 #
44
45 def create_meshes(geometry, out_filename=None):
46   import SMESH
47   import salome
48   from salome.smesh import smeshBuilder
49
50   smesh = smeshBuilder.New()
51   Mesh_tri = smesh.Mesh(geometry)
52
53   Regular_1D = Mesh_tri.Segment()
54   Max_Size_1 = Regular_1D.MaxSize(1.28993)
55
56   MEFISTO_2D = Mesh_tri.Triangle(algo=smeshBuilder.MEFISTO)
57   Nb_Segments_1 = smesh.CreateHypothesis('NumberOfSegments')
58   Nb_Segments_1.SetNumberOfSegments( 15 )
59   Nb_Segments_1.SetDistrType( 0 )
60
61   Mesh_quad = smesh.Mesh(geometry)
62   status = Mesh_quad.AddHypothesis(Nb_Segments_1)
63   status = Mesh_quad.AddHypothesis(Regular_1D)
64
65   Quadrangle_2D = Mesh_quad.Quadrangle(algo=smeshBuilder.QUADRANGLE)
66   isDone = Mesh_tri.Compute()
67   isDone = Mesh_quad.Compute()
68   smesh.SetName(Mesh_tri, 'Mesh_tri')
69   if out_filename:
70     Mesh_tri.ExportMED(out_filename, overwrite=True)
71   smesh.SetName(Mesh_quad, 'Mesh_quad')
72   if out_filename:
73     Mesh_quad.ExportMED(out_filename, overwrite=False)
74
75   # Set names of Mesh objects
76   smesh.SetName(Regular_1D.GetAlgorithm(), 'Regular_1D')
77   smesh.SetName(Quadrangle_2D.GetAlgorithm(), 'Quadrangle_2D')
78   smesh.SetName(MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D')
79   smesh.SetName(Nb_Segments_1, 'Nb. Segments_1')
80   smesh.SetName(Max_Size_1, 'Max Size_1')
81   smesh.SetName(Mesh_tri.GetMesh(), 'Mesh_tri')
82   smesh.SetName(Mesh_quad.GetMesh(), 'Mesh_quad')
83
84   return Mesh_tri, Mesh_quad
85 #
86
87 from MEDLoader import *
88
89 def create_field(mesh_filename, mesh_name, field_name, out_filename=None):
90   mesh = MEDLoader.ReadUMeshFromFile(mesh_filename, mesh_name)
91   src_field = mesh.fillFromAnalytic(ON_CELLS, 1, "7-sqrt((x-5.)*(x-5.)+(y-5.)*(y-5.)+(z-5.)*(z-5.))")
92   src_field.setName(field_name)
93   if out_filename:
94     MEDLoader.WriteField(out_filename, src_field, True)
95   return src_field
96 #