EDF Exercise 11
Work with scripts only
This sample is known to work on the latest SALOME release.
The compatibility with previous versions of SALOME is not guaranteed, though the sample can work on old versions also.
The objective of this exercise is to learn working with Python scripts in SALOME. The scripts allow to parameterize studies and to limit the disk space for the storage.
The attached sample Python SALOME script can be the base for all your future studies. To practice in the usage of the scripts, it is suggested to construct a parameterized cube in 3 different ways and to learn some elementary geometric Python functions. Then we are going to mesh the cube with increased precision around a given point.Copyright © EDF R&D 2009.
This tutorial is a part of the EDF internal training course; it does not describe a real use case.
Sample start Python scriptCreate a new script (*.py) and initialize the SALOME modules GEOM and SMESH
import smesh, SMESH
The script is executed with command File > Load Script, the objects are displayed in the GUI.
The TUI documentation of GEOM module is available in SALOME via the menu Help -> Module help -> Geometry Help. The section « Python Interface geompy.py » describes all functions available from Python, the section «TUI Scripts» provides examples of these functions usage and some practical use cases.
We are going to parameterize the box using only its edge (Python Variable Python Arete)
As described in the SALOME documentation, execute the following operations using only scripts:
- Create Arete Variable = 100
Create 8 points corresponding to the box vertices and its centre (Origine = (0,0,0), Diag=(Arete,Arete,Arete,))
Create 4 edges which form a face
Create the 1st box by 2 points
Create the 2nd box by extrusion of the reference face.
Create 2 other faces of the box with 2 rotations of the reference face.
Use central symmetry on 3 created faces to build 6 faces of the 3rd box
Create the shell from 6 faces
Create the 3rd box from shell
Explode the 1rd box to reconstruct Edges.
Create group of edges to build SubMesh.
pnt1 = geompy.MakeVertex (0,0,0)
line1 = geompy.MakeEdge(pnt1, pnt2)
box1 = geompy.MakeBoxTwoPnt(pnt1, pnt5)
box2 = geompy.MakePrism(face1, pnt1, pnt7)
angle = 90 * math.pi / 180
face4 = geompy.MakeMirrorByPoint(face1, pnt_center)
Shell = geompy.MakeShell([face1, face2, face3,
box3 = geompy.MakeSolid([Shell])
edge1 = salome.myStudy.FindObjectByPath
MeshThe TUI documentation of SMESH module is available in SALOME via the menu Help -> Module help -> Mesh Help.
The section « Python Interface smesh.py » describes all functions available from Python, the section «TUI Scripts» provides examples of these functions and some practical use cases.
Start with the parameterization of the mesh with a 1D hypothesis Wire Discretisation.The standard script procedure of meshing is as follows:
Mesh_1 = smesh.Mesh(box1)
Regular_1D = Mesh_1.Segment()
isDone = Mesh_1.Compute()
Nb_Segments_2 = smesh.smesh.CreateHypothesis