Generating 3D Geometry with SALOME and Python

Published by rupole1185 on

SALOME Platform is a powerful open-source software suite for pre- and post-processing in various engineering applications, including computational fluid dynamics (CFD) and finite element analysis (FEA). One of its key features is the ability to work with Python scripting for automated geometry creation and mesh generation.

In this post, we’ll demonstrate how to generate a simple 3D geometry using a Python script within the SALOME environment.

Prerequisites:

  • SALOME Platform: Install the latest version of SALOME from their official website.
  • Python: SALOME uses Python 2.7. Make sure you have a working Python environment.

Steps:

  1. Launch SALOME and Open a New Study:
  • Open the SALOME application.
  • Create a new study by clicking on “File” -> “New”.
  1. Import Necessary Modules:
  • In the Python scripting window (accessible by clicking on “Tools” -> “Python Scripting”), import the required modules:
    python import salome import GEOM from salome.geom import geompy
  1. Create a Basic Geometry:
  • Define the dimensions of your geometry. For this example, we’ll create a simple cube:
    python length = 1.0 width = 1.0 height = 1.0
  1. Create a Vertex:
  • Use the geompy.MakeVertex function to define a vertex at the origin:
    python vertex0 = geompy.MakeVertex(0, 0, 0)
  1. Create Edges:
  • Use the geompy.MakeLine function to create edges connecting vertices. For a cube, you’ll need 12 edges. Here’s an example for one edge:
    python edge0 = geompy.MakeLine(vertex0, geompy.MakeVertex(length, 0, 0))
  1. Create Faces:
  • Use the geompy.MakeFace function to create faces using the defined edges. For a cube, you’ll need 6 faces. For example:
    python face0 = geompy.MakeFace([edge0, edge1, edge2, edge3])
  1. Create a Solid:
  • Finally, use the geompy.MakeSolid function to create a solid object using all the defined faces:
    python cube = geompy.MakeSolid([face0, face1, face2, face3, face4, face5])
  1. Display the Geometry:
  • Use the geompy.addToStudy function to add the created solid to the SALOME study:
    python geompy.addToStudy(cube, "Cube")
  • You can now visualize the generated geometry in the SALOME GUI.

Complete Python Script:

import salome
import GEOM
from salome.geom import geompy

# Define dimensions
length = 1.0
width = 1.0
height = 1.0

# Create vertices
vertex0 = geompy.MakeVertex(0, 0, 0)
vertex1 = geompy.MakeVertex(length, 0, 0)
# ... (create other vertices)

# Create edges
edge0 = geompy.MakeLine(vertex0, vertex1)
# ... (create other edges)

# Create faces
face0 = geompy.MakeFace([edge0, edge1, edge2, edge3])
# ... (create other faces)

# Create solid
cube = geompy.MakeSolid([face0, face1, face2, face3, face4, face5])

# Add to study
geompy.addToStudy(cube, "Cube")

Running the Script:

  1. Paste the code into the Python scripting window in SALOME.
  2. Click “Run” to execute the script.

This will generate a simple cube geometry within your SALOME study. You can modify the script to create more complex geometries or utilize the Python scripting capabilities of SALOME to automate your pre-processing workflow.

Note: This is a basic example. For more complex geometries, you may need to use additional SALOME functions and features, such as creating volumes using Boolean operations or defining a mesh.


CloudHPC is a HPC provider to run engineering simulations on the cloud. CloudHPC provides from 1 to 224 vCPUs for each process in several configuration of HPC infrastructure - both multi-thread and multi-core. Current software ranges includes several CAE, CFD, FEA, FEM software among which OpenFOAM, FDS, Blender and several others.

New users benefit of a FREE trial of 300 vCPU/Hours to be used on the platform in order to test the platform, all each features and verify if it is suitable for their needs


Categories: SALOME

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *