From b0b5c3242d8bd2485bb138ef3a9b93b6521b7e60 Mon Sep 17 00:00:00 2001 From: "yoann.audouin" Date: Tue, 2 Jan 2024 09:53:50 +0100 Subject: [PATCH 1/1] Handling gmsh global parameter for a gmsh ParallelMesh --- doc/examples/creating_parallel_gmsh_mesh.py | 18 ++---- src/SMESH_SWIG/mesher_launcher.py | 3 - src/SMESH_SWIG/smeshBuilder.py | 72 +++++++++++++++------ 3 files changed, 57 insertions(+), 36 deletions(-) diff --git a/doc/examples/creating_parallel_gmsh_mesh.py b/doc/examples/creating_parallel_gmsh_mesh.py index 8b30c841e..a028f6525 100644 --- a/doc/examples/creating_parallel_gmsh_mesh.py +++ b/doc/examples/creating_parallel_gmsh_mesh.py @@ -60,19 +60,13 @@ smesh = smeshBuilder.New() print("Creating Parallel Mesh") par_mesh = smesh.ParallelMesh(rubik_cube, name="par_mesh", mesher3D="GMSH") -print("Creating hypoehtesis for netgen") -NETGEN_3D_Parameters_1 = smesh.CreateHypothesisByAverageLength( 'NETGEN_Parameters', - 'NETGENEngine', 34.641, 0 ) +print("Creating hypoehtesis for gmsh") +GMSH_3D_Parameters_1 = smesh.CreateHypothesis( 'GMSH_Parameters', + 'libGMSHEngine.so' ) +GMSH_3D_Parameters_1.SetMaxSize(10) +GMSH_3D_Parameters_1.SetMinSize(0.141421) print("Adding hypothesis") -par_mesh.AddGlobalHypothesis(NETGEN_3D_Parameters_1, mesher="GMSH" ) - -#Set here particular mesh parameters in 3D -for algo3d in par_mesh._algo3d: - param3d = algo3d.Parameters() - param3d.Set2DAlgo(0) - param3d.Set3DAlgo(0) - param3d.SetSmouthSteps(2) - param3d.SetSizeFactor(1.1) +par_mesh.AddGlobalHypothesis(GMSH_3D_Parameters_1) print("Setting parallelism method") par_mesh.SetParallelismMethod(smeshBuilder.MULTITHREAD) diff --git a/src/SMESH_SWIG/mesher_launcher.py b/src/SMESH_SWIG/mesher_launcher.py index 8ca70494c..0e07ffd72 100644 --- a/src/SMESH_SWIG/mesher_launcher.py +++ b/src/SMESH_SWIG/mesher_launcher.py @@ -111,7 +111,6 @@ def get_runner(mesher): def run_local(args): """ Simple Local run """ - #TODO: Check on how to handle log for windows (through sp.check_output) cmd = CMD_TEMPLATE.format(\ runner=get_runner(args.mesher), mesher=args.mesher, @@ -122,8 +121,6 @@ def run_local(args): new_element_file=args.new_element_file, log_file=path.join(path.dirname(args.shape_file), "run.log"), output_mesh_file=args.output_mesh_file) - print("Executing:") - print(cmd) sp.check_output(cmd, shell=True, cwd=path.dirname(args.shape_file)) def run_pylauncher(args): diff --git a/src/SMESH_SWIG/smeshBuilder.py b/src/SMESH_SWIG/smeshBuilder.py index 0bd3de6a4..cfeda1a3a 100644 --- a/src/SMESH_SWIG/smeshBuilder.py +++ b/src/SMESH_SWIG/smeshBuilder.py @@ -462,7 +462,7 @@ class smeshBuilder( SMESH._objref_SMESH_Gen, object ): obj,name = name,obj return Mesh(self, self.geompyD, obj, name) - def ParallelMesh(self, obj, name=0, split_geom=True, mesher2D="NETGEN", mesher3D="NETGEN"): + def ParallelMesh(self, obj, name=0, split_geom=True, mesher2D=None, mesher3D="NETGEN"): """ Create a parallel mesh. @@ -7549,7 +7549,33 @@ class Mesh(metaclass = MeshMeta): def _copy_gmsh_param(dim, local_param, global_param): if dim==3: local_param.SetMaxSize(global_param.GetMaxSize()) - local_param.SetMinSize(global_param.GetMinSize()) + local_param.SetMinSize(global_param.GetMinSize()) + local_param.Set3DAlgo(global_param.Get3DAlgo()) + local_param.SetRecombineAll(global_param.GetRecombineAll()) + local_param.SetSubdivAlgo(global_param.GetSubdivAlgo()) + local_param.SetRemeshAlgo(global_param.GetRemeshAlgo()) + local_param.SetRemeshPara(global_param.GetRemeshPara()) + local_param.SetSmouthSteps(global_param.GetSmouthSteps()) + local_param.SetSizeFactor(global_param.GetSizeFactor()) + local_param.SetUseIncomplElem(global_param.GetUseIncomplElem()) + local_param.SetMeshCurvatureSize(global_param.GetMeshCurvatureSize()) + local_param.SetSecondOrder(global_param.GetSecondOrder()) + local_param.SetIs2d(global_param.GetIs2d()) + elif dim==2: + local_param.SetMaxSize(global_param.GetMaxSize()) + local_param.SetMinSize(global_param.GetMinSize()) + local_param.Set2DAlgo(global_param.Get2DAlgo()) + local_param.SetRecomb2DAlgo(global_param.GetRecomb2DAlgo()) + local_param.SetRecombineAll(global_param.GetRecombineAll()) + local_param.SetSubdivAlgo(global_param.GetSubdivAlgo()) + local_param.SetRemeshAlgo(global_param.GetRemeshAlgo()) + local_param.SetRemeshPara(global_param.GetRemeshPara()) + local_param.SetSmouthSteps(global_param.GetSmouthSteps()) + local_param.SetSizeFactor(global_param.GetSizeFactor()) + local_param.SetUseIncomplElem(global_param.GetUseIncomplElem()) + local_param.SetMeshCurvatureSize(global_param.GetMeshCurvatureSize()) + local_param.SetSecondOrder(global_param.GetSecondOrder()) + local_param.SetIs2d(global_param.GetIs2d()) def _copy_netgen_param(dim, local_param, global_param): """ @@ -7784,7 +7810,7 @@ class ParallelMesh(Mesh): """ Surcharge on Mesh for parallel computation of a mesh """ - def __init__(self, smeshpyD, geompyD, geom, split_geom=True, name=0, mesher2D="NETGEN", mesher3D="NETGEN"): + def __init__(self, smeshpyD, geompyD, geom, split_geom=True, name=0, mesher2D=None, mesher3D="NETGEN"): """ Create a parallel mesh. @@ -7818,13 +7844,17 @@ class ParallelMesh(Mesh): if split_geom: self._all_faces, self._solids = _split_geom(geompyD, geom_obj) - order = [] + if mesher3D == "NETGEN": + self._algo2d = self.Triangle(geom=geom_obj, algo="NETGEN_2D") + elif mesher3D == "GMSH": + self._algo2d = self.Triangle(geom=geom_obj, algo="GMSH_2D") + else: + raise ValueError("mesher3D should be either NETGEN or GMSH") - if ( mesher2D == "NETGEN" ): #Default 2D mesher - self._algo2d = self.Triangle(geom=geom_obj, algo="NETGEN_2D") - if ( mesher2D != "NETGEN" ): - #Means that we want to mesh face of solids in parallel and not the volume + if mesher2D is not None: + #Means that we want to mesh face of solids in parallel and not + #the volume self._algo2d = [] #For the moment use AutomaticLength based on finesse self._algo1d = self.Segment().AutomaticLength(0.1) @@ -7843,9 +7873,8 @@ class ParallelMesh(Mesh): elif ( mesher3D == "GMSH" ): algo3d = self.Tetrahedron(geom=solid, algo="GMSH_3D_Remote") self._algo3d.append(algo3d) - - self._param = None + self._param = None def GetNbSolids(self): """ @@ -7877,7 +7906,7 @@ class ParallelMesh(Mesh): raise Exception("You need to set Parallelism method first (SetParallelismMethod)") return self._param - def AddGlobalHypothesis(self, hyp, mesher="NETGEN"): + def AddGlobalHypothesis(self, hyp): """ Split hypothesis to apply it to all the submeshes: - the 1D+2D @@ -7887,18 +7916,19 @@ class ParallelMesh(Mesh): 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) - + if isinstance(hyp, NETGENPlugin._objref_NETGENPlugin_Hypothesis): + copy_param = _copy_netgen_param + elif isinstance(hyp, GMSHPlugin._objref_GMSHPlugin_Hypothesis): + copy_param = _copy_gmsh_param + else: + raise ValueError("param must come from NETGENPlugin or GMSHPlugin") + + param2d = self._algo2d.Parameters() + copy_param(2, param2d, hyp) + for algo3d in self._algo3d: param3d = algo3d.Parameters() - if ( mesher == "NETGEN" ): - _copy_netgen_param(3, param3d, hyp) - elif( mesher == "GMSH" ): - _copy_gmsh_param(3, param3d, hyp) + copy_param(3, param3d, hyp) pass # End of ParallelMesh -- 2.30.2