1 # Copyright (C) 2014-2019 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 create_geometry(out_filename=None):
22 from salome.geom import geomBuilder
23 geompy = geomBuilder.New()
25 # create a cloud of 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)]
34 # create SmoothingSurface object
35 smoothingsurface = geompy.MakeSmoothingSurface(points)
37 geompy.ExportBREP(smoothingsurface, out_filename)
39 # add object in the study
40 id_smoothingsurface = geompy.addToStudy(smoothingsurface,"SmoothingSurface")
42 return smoothingsurface
45 def create_meshes(geometry, out_filename=None):
48 from salome.smesh import smeshBuilder
50 smesh = smeshBuilder.New()
51 Mesh_tri = smesh.Mesh(geometry)
53 Regular_1D = Mesh_tri.Segment()
54 Max_Size_1 = Regular_1D.MaxSize(1.28993)
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 )
61 Mesh_quad = smesh.Mesh(geometry)
62 status = Mesh_quad.AddHypothesis(Nb_Segments_1)
63 status = Mesh_quad.AddHypothesis(Regular_1D)
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')
70 Mesh_tri.ExportMED(out_filename, overwrite=True)
71 smesh.SetName(Mesh_quad, 'Mesh_quad')
73 Mesh_quad.ExportMED(out_filename, overwrite=False)
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')
84 return Mesh_tri, Mesh_quad
87 from MEDLoader import *
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)
94 MEDLoader.WriteField(out_filename, src_field, True)