That’s a really neat implementation! Thanks franco. Indeed franco, the scripting is really a great feature, but somewhat difficult to learn.
I like the GUI / selection implementation, I was writing a function, (didn’t test it extensively so still wip):
import sys
import salome
import GEOM
from salome.geom import geomBuilder
import math
import SMESH, SALOMEDS
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
def flattenToPlane( meshName = None, geoGroupName = None, plane = ["Y"] ):
"""
Description:
Flatten the nodes on a given geometrical entity (X, Y or Z coordinates) to 0.
Example:
flattenToPlane( "Mesh_2", "Symmetry", "X" )
flattenToPlane( "Mesh_2", "Symmetry", "Y" )
Arguments:
# meshName
Description: The mesh object to be modified.
Type: String
Default value: None
# geoGroupName
Description: The list of names of groups to export, excluding the others.
Type: String
Default value: None
# plane
Description: The coordinate to operate on, either X, Y or Z.
Type: String
Default value: "Y"
Conditions of use:
The mesh has to be computed and to contain groups describing the desired boundary conditions (inlet, outlet, wall, farfield, etc.).
"""
# Checking that user provided an input
if not meshName:
print("Incorrect input provided. meshName must be defined")
return
# Checking that user provided an input
if not geoGroupName:
print("Incorrect input provided. geoGroup must be defined")
return
# Checking that user provided an input that is actually available in the hdf
try:
meshProxy = salome.myStudy.FindObjectByName(meshName, "SMESH")[0].GetObject()
except:
print("The specified input for meshName can not be found")
return
# Checking that user provided an input that is actually available in the hdf
try:
geoGroup = salome.myStudy.FindObjectByName(geoGroupName, "GEOM")[0].GetObject()
except:
print("The specified input for geoGroupName can not be found")
return
groups = meshProxy.GetGroups()
# Convert MeshProxy into mesh class
mesh=smesh.Mesh(meshProxy)
# Retrieves the nodes group if it is already there
try:
SymNodes = salome.myStudy.FindObjectByName(geoGroup, "SMESH")[0].GetObject()
# Create one otherwise
except:
SymNodes = mesh.GroupOnGeom(geoGroup,'SymNodes',SMESH.NODE)
# Get all the ids of the nodes that belong to the groupGeom geometric entity
nodeIDs = SymNodes.GetIDs()
# Get the nodes position
positions=[mesh.GetNodeXYZ(nodeID) for nodeID in nodeIDs]
# Retrieve X, Z from nodes, and set Y to 0 on each node laying on symmetry
if plane == "X" :
[mesh.MoveNode(nodeID,0,positions[n][1],positions[n][2]) for n,nodeID in enumerate(nodeIDs)]
elif plane == "Y" :
[mesh.MoveNode(nodeID,positions[n][0],0,positions[n][2]) for n,nodeID in enumerate(nodeIDs)]
elif plane == "Z" :
[mesh.MoveNode(nodeID,positions[n][0],positions[n][1],0) for n,nodeID in enumerate(nodeIDs)]
else :
print("Incorrect plane input provided. plane input must be either X, Y, or Z")
return
The control on the inputs is a bit more extensive when dealing with functions, but it opens the door to specify other inputs as well (the plane on which to proceed, for example), but the GUI selection is really cool to have a macro like function.