Removin argument from ParallelMesh init

This commit is contained in:
Yoann Audouin 2023-01-11 16:47:11 +01:00
parent 1835ca6ea1
commit 9299033da1
2 changed files with 106 additions and 73 deletions

View File

@ -462,20 +462,21 @@ class smeshBuilder( SMESH._objref_SMESH_Gen, object ):
obj,name = name,obj obj,name = name,obj
return Mesh(self, self.geompyD, obj, name) return Mesh(self, self.geompyD, obj, name)
def ParallelMesh(self, obj, param, nbThreads, name=0): def ParallelMesh(self, obj, name=0, split_geom=True):
""" """
Create a parallel mesh. Create a parallel mesh.
Parameters: Parameters:
obj: geometrical object for meshing obj: geometrical object for meshing
name: the name for the new mesh. name: the name for the new mesh.
param: full mesh parameters split_geom: If True split the geometry and create the assoicated
nbThreads: Number of threads for parallelisation. sub meshes
Returns: Returns:
an instance of class :class:`ParallelMesh`. an instance of class :class:`ParallelMesh`.
""" """
return ParallelMesh(self, self.geompyD, obj, param, nbThreads, name) return ParallelMesh(self, self.geompyD, obj,
split_geom=split_geom, name=name)
def RemoveMesh( self, mesh ): def RemoveMesh( self, mesh ):
""" """
@ -7504,6 +7505,9 @@ class Mesh(metaclass = MeshMeta):
def _copy_netgen_param(dim, local_param, global_param): def _copy_netgen_param(dim, local_param, global_param):
"""
Create 1D/2D/3D netgen parameters from a NETGEN 1D2D3D parameter
"""
if dim==1: if dim==1:
#TODO: Try to identify why we need to substract 1 #TODO: Try to identify why we need to substract 1
local_param.NumberOfSegments(int(global_param.GetNbSegPerEdge())-1) local_param.NumberOfSegments(int(global_param.GetNbSegPerEdge())-1)
@ -7535,16 +7539,12 @@ def _copy_netgen_param(dim, local_param, global_param):
local_param.SetGrowthRate(global_param.GetGrowthRate()) local_param.SetGrowthRate(global_param.GetGrowthRate())
local_param.SetNbThreads(global_param.GetNbThreads()) local_param.SetNbThreads(global_param.GetNbThreads())
class ParallelMesh(Mesh): def _split_geom(geompyD, geom):
"""
Surcharge on Mesh for parallel computation of a mesh
"""
def __split_geom(self, geompyD, geom):
""" """
Splitting geometry into n solids and a 2D/1D compound Splitting geometry into n solids and a 2D/1D compound
Parameters: Parameters:
geompyD: geomBuilder instance
geom: geometrical object for meshing geom: geometrical object for meshing
""" """
@ -7583,14 +7583,22 @@ class ParallelMesh(Mesh):
return all_faces, solids return all_faces, solids
def __init__(self, smeshpyD, geompyD, geom, param, nbThreads, name=0): class ParallelMesh(Mesh):
"""
Surcharge on Mesh for parallel computation of a mesh
"""
def __init__(self, smeshpyD, geompyD, geom, split_geom=True, name=0):
""" """
Create a parallel mesh. Create a parallel mesh.
Parameters: Parameters:
smeshpyD: instance of smeshBuilder
geompyD: instance of geomBuilder
geom: geometrical object for meshing geom: geometrical object for meshing
param: full mesh parameters split_geom: If true will divide geometry on solids and 1D/2D
nbThreads: Number of threads for parallelisation. coumpund and create the associated submeshes
name: the name for the new mesh. name: the name for the new mesh.
Returns: Returns:
@ -7600,35 +7608,58 @@ class ParallelMesh(Mesh):
if not isinstance(geom, geomBuilder.GEOM._objref_GEOM_Object): if not isinstance(geom, geomBuilder.GEOM._objref_GEOM_Object):
raise ValueError("geom argument must be a geometry") raise ValueError("geom argument must be a geometry")
if not isinstance(param, NETGENPlugin._objref_NETGENPlugin_Hypothesis): # Splitting geometry into one geom containing 1D and 2D elements and a
raise ValueError("param must come from NETGENPlugin") # list of 3D elements
if nbThreads < 1:
raise ValueError("Number of threads must be stricly greater than 1")
all_faces, solids = self.__split_geom(geompyD, geom)
super(ParallelMesh, self).__init__(smeshpyD, geompyD, geom, name, parallel=True) super(ParallelMesh, self).__init__(smeshpyD, geompyD, geom, name, parallel=True)
self.mesh.SetNbThreads(nbThreads) if split_geom:
self._all_faces, self._solids = _split_geom(geompyD, geom)
self.UseExistingSegments() self.UseExistingSegments()
self.UseExistingFaces() self.UseExistingFaces()
algo2d = self.Triangle(geom=all_faces, algo="NETGEN_2D") self._algo2d = self.Triangle(geom=self._all_faces, algo="NETGEN_2D")
param2d = algo2d.Parameters() self._algo3d = []
_copy_netgen_param(2, param2d, param) for solid_id, solid in enumerate(self._solids):
for solid_id, solid in enumerate(solids):
name = "Solid_{}".format(solid_id) name = "Solid_{}".format(solid_id)
self.UseExistingSegments(geom=solid) self.UseExistingSegments(geom=solid)
self.UseExistingFaces(geom=solid) self.UseExistingFaces(geom=solid)
algo3d = self.Tetrahedron(geom=solid, algo="NETGEN_3D_Remote") algo3d = self.Tetrahedron(geom=solid, algo="NETGEN_3D_Remote")
self._algo3d.append(algo3d)
def AddGlobalHypothesis(self, hyp):
"""
Assign a hypothesis
Parameters:
hyp: a hypothesis to assign
"""
if not isinstance(hyp, NETGENPlugin._objref_NETGENPlugin_Hypothesis):
raise ValueError("param must come from NETGENPlugin")
param2d = self._algo2d.Parameters()
_copy_netgen_param(2, param2d, hyp)
for algo3d in self._algo3d:
param3d = algo3d.Parameters() param3d = algo3d.Parameters()
_copy_netgen_param(3, param3d, hyp)
_copy_netgen_param(3, param3d, param) def SetNbThreads(self, nbThreads):
"""
Define the number of threads for meshing
Parameters:
nbThreads: Number of threads
"""
if nbThreads < 1:
raise ValueError("Number of threads must be stricly greater than 1")
self.mesh.SetNbThreads(nbThreads)
pass # End of ParallelMesh pass # End of ParallelMesh

View File

@ -98,7 +98,9 @@ def run_test(nbox=2, boxsize=100):
""" """
geom, seq_mesh, netgen_parameters = build_seq_mesh(nbox, boxsize, 0) geom, seq_mesh, netgen_parameters = build_seq_mesh(nbox, boxsize, 0)
par_mesh = smesh.ParallelMesh(geom, netgen_parameters, 6, name="par_mesh") par_mesh = smesh.ParallelMesh(geom, name="par_mesh")
par_mesh.AddGlobalHypothesis(netgen_parameters)
par_mesh.SetNbThreads(6)
start = time.monotonic() start = time.monotonic()
is_done = seq_mesh.Compute() is_done = seq_mesh.Compute()