mirror of
https://git.salome-platform.org/gitpub/modules/smesh.git
synced 2025-01-28 00:40:32 +05:00
Removin argument from ParallelMesh init
This commit is contained in:
parent
1835ca6ea1
commit
9299033da1
@ -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,62 +7539,66 @@ 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())
|
||||||
|
|
||||||
|
def _split_geom(geompyD, geom):
|
||||||
|
"""
|
||||||
|
Splitting geometry into n solids and a 2D/1D compound
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
geompyD: geomBuilder instance
|
||||||
|
geom: geometrical object for meshing
|
||||||
|
|
||||||
|
"""
|
||||||
|
# Splitting geometry into 3D elements and all the 2D/1D into one compound
|
||||||
|
object_solids = geompyD.ExtractShapes(geom, geompyD.ShapeType["SOLID"],
|
||||||
|
True)
|
||||||
|
|
||||||
|
solids = []
|
||||||
|
isolid = 0
|
||||||
|
for solid in object_solids:
|
||||||
|
isolid += 1
|
||||||
|
geompyD.addToStudyInFather( geom, solid, 'Solid_{}'.format(isolid) )
|
||||||
|
solids.append(solid)
|
||||||
|
# If geom is a solid ExtractShapes will return nothin in that case geom is the solids
|
||||||
|
if isolid == 0:
|
||||||
|
solids = [geom]
|
||||||
|
|
||||||
|
faces = []
|
||||||
|
iface = 0
|
||||||
|
for isolid, solid in enumerate(solids):
|
||||||
|
solid_faces = geompyD.ExtractShapes(solid, geompyD.ShapeType["FACE"],
|
||||||
|
True)
|
||||||
|
for face in solid_faces:
|
||||||
|
faces.append(face)
|
||||||
|
iface += 1
|
||||||
|
geompyD.addToStudyInFather(solid, face,
|
||||||
|
'Face_{}'.format(iface))
|
||||||
|
|
||||||
|
# Creating submesh for edges 1D/2D part
|
||||||
|
|
||||||
|
all_faces = geompyD.MakeCompound(faces)
|
||||||
|
geompyD.addToStudy(all_faces, 'Compound_1')
|
||||||
|
all_faces = geompyD.MakeGlueEdges(all_faces, 1e-07)
|
||||||
|
all_faces = geompyD.MakeGlueFaces(all_faces, 1e-07)
|
||||||
|
geompyD.addToStudy(all_faces, 'global2D')
|
||||||
|
|
||||||
|
return all_faces, solids
|
||||||
|
|
||||||
class ParallelMesh(Mesh):
|
class ParallelMesh(Mesh):
|
||||||
"""
|
"""
|
||||||
Surcharge on Mesh for parallel computation of a mesh
|
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
|
|
||||||
|
|
||||||
Parameters:
|
def __init__(self, smeshpyD, geompyD, geom, split_geom=True, name=0):
|
||||||
geom: geometrical object for meshing
|
|
||||||
|
|
||||||
"""
|
|
||||||
# Splitting geometry into 3D elements and all the 2D/1D into one compound
|
|
||||||
object_solids = geompyD.ExtractShapes(geom, geompyD.ShapeType["SOLID"],
|
|
||||||
True)
|
|
||||||
|
|
||||||
solids = []
|
|
||||||
isolid = 0
|
|
||||||
for solid in object_solids:
|
|
||||||
isolid += 1
|
|
||||||
geompyD.addToStudyInFather( geom, solid, 'Solid_{}'.format(isolid) )
|
|
||||||
solids.append(solid)
|
|
||||||
# If geom is a solid ExtractShapes will return nothin in that case geom is the solids
|
|
||||||
if isolid == 0:
|
|
||||||
solids = [geom]
|
|
||||||
|
|
||||||
faces = []
|
|
||||||
iface = 0
|
|
||||||
for isolid, solid in enumerate(solids):
|
|
||||||
solid_faces = geompyD.ExtractShapes(solid, geompyD.ShapeType["FACE"],
|
|
||||||
True)
|
|
||||||
for face in solid_faces:
|
|
||||||
faces.append(face)
|
|
||||||
iface += 1
|
|
||||||
geompyD.addToStudyInFather(solid, face,
|
|
||||||
'Face_{}'.format(iface))
|
|
||||||
|
|
||||||
# Creating submesh for edges 1D/2D part
|
|
||||||
|
|
||||||
all_faces = geompyD.MakeCompound(faces)
|
|
||||||
geompyD.addToStudy(all_faces, 'Compound_1')
|
|
||||||
all_faces = geompyD.MakeGlueEdges(all_faces, 1e-07)
|
|
||||||
all_faces = geompyD.MakeGlueFaces(all_faces, 1e-07)
|
|
||||||
geompyD.addToStudy(all_faces, 'global2D')
|
|
||||||
|
|
||||||
return all_faces, solids
|
|
||||||
|
|
||||||
def __init__(self, smeshpyD, geompyD, geom, param, nbThreads, 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,36 +7608,59 @@ 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
|
||||||
|
# list of 3D elements
|
||||||
|
super(ParallelMesh, self).__init__(smeshpyD, geompyD, geom, name, parallel=True)
|
||||||
|
|
||||||
|
if split_geom:
|
||||||
|
self._all_faces, self._solids = _split_geom(geompyD, geom)
|
||||||
|
|
||||||
|
self.UseExistingSegments()
|
||||||
|
self.UseExistingFaces()
|
||||||
|
|
||||||
|
self._algo2d = self.Triangle(geom=self._all_faces, algo="NETGEN_2D")
|
||||||
|
self._algo3d = []
|
||||||
|
|
||||||
|
for solid_id, solid in enumerate(self._solids):
|
||||||
|
name = "Solid_{}".format(solid_id)
|
||||||
|
self.UseExistingSegments(geom=solid)
|
||||||
|
self.UseExistingFaces(geom=solid)
|
||||||
|
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")
|
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()
|
||||||
|
_copy_netgen_param(3, param3d, hyp)
|
||||||
|
|
||||||
|
def SetNbThreads(self, nbThreads):
|
||||||
|
"""
|
||||||
|
Define the number of threads for meshing
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
nbThreads: Number of threads
|
||||||
|
"""
|
||||||
|
|
||||||
if nbThreads < 1:
|
if nbThreads < 1:
|
||||||
raise ValueError("Number of threads must be stricly greater than 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)
|
|
||||||
|
|
||||||
self.mesh.SetNbThreads(nbThreads)
|
self.mesh.SetNbThreads(nbThreads)
|
||||||
|
|
||||||
self.UseExistingSegments()
|
|
||||||
self.UseExistingFaces()
|
|
||||||
|
|
||||||
algo2d = self.Triangle(geom=all_faces, algo="NETGEN_2D")
|
|
||||||
param2d = algo2d.Parameters()
|
|
||||||
|
|
||||||
_copy_netgen_param(2, param2d, param)
|
|
||||||
|
|
||||||
for solid_id, solid in enumerate(solids):
|
|
||||||
name = "Solid_{}".format(solid_id)
|
|
||||||
self.UseExistingSegments(geom=solid)
|
|
||||||
self.UseExistingFaces(geom=solid)
|
|
||||||
algo3d = self.Tetrahedron(geom=solid, algo="NETGEN_3D_Remote")
|
|
||||||
|
|
||||||
param3d = algo3d.Parameters()
|
|
||||||
|
|
||||||
_copy_netgen_param(3, param3d, param)
|
|
||||||
|
|
||||||
pass # End of ParallelMesh
|
pass # End of ParallelMesh
|
||||||
|
|
||||||
|
|
||||||
|
@ -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()
|
||||||
|
Loading…
Reference in New Issue
Block a user