From 8c2c4768ed5bfb8a198ff86da93b76b6bb6d5686 Mon Sep 17 00:00:00 2001 From: Jon Shimwell Date: Mon, 27 Jan 2025 18:38:23 +0100 Subject: [PATCH 1/5] working for 2d, with volume tags --- src/cad_to_dagmc/core.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/cad_to_dagmc/core.py b/src/cad_to_dagmc/core.py index cb117f7..867d2d5 100644 --- a/src/cad_to_dagmc/core.py +++ b/src/cad_to_dagmc/core.py @@ -239,6 +239,7 @@ def _mesh_brep( max_mesh_size: float = 10, mesh_algorithm: int = 1, dimensions: int = 2, + set_size: dict[int, float] | None = None, ): """Creates a conformal surface meshes of the volumes in a Brep file using Gmsh. @@ -261,7 +262,28 @@ def _mesh_brep( gmsh.option.setNumber("Mesh.MeshSizeMin", min_mesh_size) gmsh.option.setNumber("Mesh.MeshSizeMax", max_mesh_size) gmsh.option.setNumber("General.NumThreads", 0) # Use all available cores + + + if dimensions == 2: + set_size={1: 1, 2: 0.5} + volumes = gmsh.model.getEntities(3) + print('volumes', volumes) + if set_size: + for (_, volume) in volumes: + if volume in set_size.keys(): + size=set_size[volume] + if isinstance(size, dict): + pass + else: + boundaries = gmsh.model.getBoundary([(3,volume)], recursive=True) # dim must be set to 3 + print('boundaries',boundaries) + gmsh.model.mesh.setSize(boundaries, size) + print(f"Set size of {size} for volume {volume}") + else: + raise ValueError(f'volume ID of {volume} set in set_sizes but not found in available volumes {volumes}') + gmsh.model.mesh.generate(dimensions) + gmsh.write("mesh2.msh") return gmsh @@ -669,6 +691,7 @@ def export_dagmc_h5m_file( method: str = "file", scale_factor: float = 1.0, imprint: bool = True, + set_size: dict[int, float] | None = None, ) -> str: """Saves a DAGMC h5m file of the geometry @@ -695,6 +718,8 @@ def export_dagmc_h5m_file( normally needed to ensure the geometry is meshed correctly. However if you know your geometry does not need imprinting you can set this to False and this can save time. + set_size: a dictionary of volume ids and target mesh sizes to set for each + volume, passed to gmsh.model.mesh.setSize after min and max sizes are set. Returns: str: the DAGMC filename saved @@ -739,6 +764,7 @@ def export_dagmc_h5m_file( min_mesh_size=min_mesh_size, max_mesh_size=max_mesh_size, mesh_algorithm=mesh_algorithm, + set_size=set_size, ) dims_and_vol_ids = volumes From 78b9d23fd780696dc2f94810a956fda996407c43 Mon Sep 17 00:00:00 2001 From: jon-proximafusion <174589458+jon-proximafusion@users.noreply.github.com> Date: Tue, 28 Jan 2025 12:51:21 +0000 Subject: [PATCH 2/5] [skip ci] Apply formatting changes --- src/cad_to_dagmc/core.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/cad_to_dagmc/core.py b/src/cad_to_dagmc/core.py index 867d2d5..b4cc1b2 100644 --- a/src/cad_to_dagmc/core.py +++ b/src/cad_to_dagmc/core.py @@ -263,24 +263,27 @@ def _mesh_brep( gmsh.option.setNumber("Mesh.MeshSizeMax", max_mesh_size) gmsh.option.setNumber("General.NumThreads", 0) # Use all available cores - if dimensions == 2: - set_size={1: 1, 2: 0.5} + set_size = {1: 1, 2: 0.5} volumes = gmsh.model.getEntities(3) - print('volumes', volumes) + print("volumes", volumes) if set_size: - for (_, volume) in volumes: + for _, volume in volumes: if volume in set_size.keys(): - size=set_size[volume] + size = set_size[volume] if isinstance(size, dict): pass else: - boundaries = gmsh.model.getBoundary([(3,volume)], recursive=True) # dim must be set to 3 - print('boundaries',boundaries) + boundaries = gmsh.model.getBoundary( + [(3, volume)], recursive=True + ) # dim must be set to 3 + print("boundaries", boundaries) gmsh.model.mesh.setSize(boundaries, size) print(f"Set size of {size} for volume {volume}") else: - raise ValueError(f'volume ID of {volume} set in set_sizes but not found in available volumes {volumes}') + raise ValueError( + f"volume ID of {volume} set in set_sizes but not found in available volumes {volumes}" + ) gmsh.model.mesh.generate(dimensions) gmsh.write("mesh2.msh") From 3a75bd85cbcba80a6e0270a4b85f06a2c01bac13 Mon Sep 17 00:00:00 2001 From: shimwell Date: Tue, 28 Jan 2025 15:00:57 +0100 Subject: [PATCH 3/5] min max mesh sizes defualt to None --- src/cad_to_dagmc/core.py | 41 +++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/cad_to_dagmc/core.py b/src/cad_to_dagmc/core.py index b4cc1b2..6f4096f 100644 --- a/src/cad_to_dagmc/core.py +++ b/src/cad_to_dagmc/core.py @@ -235,8 +235,8 @@ def init_gmsh(): def _mesh_brep( gmsh, - min_mesh_size: float = 1, - max_mesh_size: float = 10, + min_mesh_size: float | None = None, + max_mesh_size: float | None = None, mesh_algorithm: int = 1, dimensions: int = 2, set_size: dict[int, float] | None = None, @@ -253,25 +253,36 @@ def _mesh_brep( gmsh.option.setNumber("Mesh.Algorithm", mesh_algorithm) dimensions: The number of dimensions, 2 for a surface mesh 3 for a volume mesh. Passed to gmsh.model.mesh.generate() + set_size: a dictionary of volume ids (int) and target mesh sizes + (floats) to set for each volume, passed to gmsh.model.mesh.setSize. Returns: The resulting gmsh object and volumes """ + if min_mesh_size and max_mesh_size: + if min_mesh_size > max_mesh_size: + raise ValueError( + f"min_mesh_size must be less than or equal to max_mesh_size. Currently min_mesh_size is set to {min_mesh_size} and max_mesh_size is set to {max_mesh_size}" + ) + + if min_mesh_size: + gmsh.option.setNumber("Mesh.MeshSizeMin", min_mesh_size) + + if max_mesh_size: + gmsh.option.setNumber("Mesh.MeshSizeMax", max_mesh_size) gmsh.option.setNumber("Mesh.Algorithm", mesh_algorithm) - gmsh.option.setNumber("Mesh.MeshSizeMin", min_mesh_size) - gmsh.option.setNumber("Mesh.MeshSizeMax", max_mesh_size) gmsh.option.setNumber("General.NumThreads", 0) # Use all available cores if dimensions == 2: - set_size = {1: 1, 2: 0.5} - volumes = gmsh.model.getEntities(3) - print("volumes", volumes) if set_size: + volumes = gmsh.model.getEntities(3) + print("volumes", volumes) for _, volume in volumes: if volume in set_size.keys(): size = set_size[volume] if isinstance(size, dict): + # TODO face specific mesh sizes pass else: boundaries = gmsh.model.getBoundary( @@ -614,13 +625,14 @@ def export_unstructured_mesh_file( def export_gmsh_mesh_file( self, filename: str = "mesh.msh", - min_mesh_size: float = 1, - max_mesh_size: float = 5, + min_mesh_size: float | None = None, + max_mesh_size: float | None = None, mesh_algorithm: int = 1, dimensions: int = 2, method: str = "file", scale_factor: float = 1.0, imprint: bool = True, + set_size: dict[int, float] | None = None, ): """Saves a GMesh msh file of the geometry in either 2D surface mesh or 3D volume mesh. @@ -647,6 +659,8 @@ def export_gmsh_mesh_file( normally needed to ensure the geometry is meshed correctly. However if you know your geometry does not need imprinting you can set this to False and this can save time. + set_size: a dictionary of volume ids (int) and target mesh sizes + (floats) to set for each volume, passed to gmsh.model.mesh.setSize. """ assembly = cq.Assembly() @@ -668,6 +682,7 @@ def export_gmsh_mesh_file( max_mesh_size=max_mesh_size, mesh_algorithm=mesh_algorithm, dimensions=dimensions, + set_size=set_size, ) # makes the folder if it does not exist @@ -687,8 +702,8 @@ def export_gmsh_mesh_file( def export_dagmc_h5m_file( self, filename: str = "dagmc.h5m", - min_mesh_size: float = 1, - max_mesh_size: float = 5, + min_mesh_size: float | None = None, + max_mesh_size: float | None = None, mesh_algorithm: int = 1, implicit_complement_material_tag: str | None = None, method: str = "file", @@ -721,8 +736,8 @@ def export_dagmc_h5m_file( normally needed to ensure the geometry is meshed correctly. However if you know your geometry does not need imprinting you can set this to False and this can save time. - set_size: a dictionary of volume ids and target mesh sizes to set for each - volume, passed to gmsh.model.mesh.setSize after min and max sizes are set. + set_size: a dictionary of volume ids (int) and target mesh sizes + (floats) to set for each volume, passed to gmsh.model.mesh.setSize. Returns: str: the DAGMC filename saved From 4f03ec71a4a35b63b87e58c1d658c82c5af5f4a7 Mon Sep 17 00:00:00 2001 From: shimwell Date: Tue, 28 Jan 2025 16:25:06 +0100 Subject: [PATCH 4/5] update readme --- .github/workflows/ci_with_conda_install.yml | 3 ++ .github/workflows/ci_with_pip_install.yml | 2 + README.md | 29 +++++++---- .../different_resolution_meshes.py | 38 +++++++++++++++ .../different_resolution_meshes.py | 38 +++++++++++++++ src/cad_to_dagmc/core.py | 48 ++++++++++--------- 6 files changed, 127 insertions(+), 31 deletions(-) create mode 100644 examples/surface_mesh/different_resolution_meshes.py create mode 100644 examples/unstrucutred_volume_mesh/different_resolution_meshes.py diff --git a/.github/workflows/ci_with_conda_install.yml b/.github/workflows/ci_with_conda_install.yml index 9b9ce84..1b2de5f 100644 --- a/.github/workflows/ci_with_conda_install.yml +++ b/.github/workflows/ci_with_conda_install.yml @@ -72,3 +72,6 @@ jobs: python examples/surface_mesh/single_stp_file.py python examples/unstrucutred_volume_mesh/curved_cadquery_object_to_dagmc_volume_mesh.py python examples/unstrucutred_volume_mesh/simulate_unstrucutred_volume_mesh_with_openmc.py + python examples/unstrucutred_volume_mesh/different_resolution_meshes.py + python examples/surface_mesh/different_resolution_meshes.py + python examples/surface_mesh/cadquery_assembly_with_scaled_geometry.py diff --git a/.github/workflows/ci_with_pip_install.yml b/.github/workflows/ci_with_pip_install.yml index 820866f..9defe9b 100644 --- a/.github/workflows/ci_with_pip_install.yml +++ b/.github/workflows/ci_with_pip_install.yml @@ -58,4 +58,6 @@ jobs: python examples/surface_mesh/from_gmsh_mesh_file.py python examples/unstrucutred_volume_mesh/curved_cadquery_object_to_dagmc_volume_mesh.py python examples/unstrucutred_volume_mesh/simulate_unstrucutred_volume_mesh_with_openmc.py + python examples/unstrucutred_volume_mesh/different_resolution_meshes.py + python examples/surface_mesh/different_resolution_meshes.py python examples/surface_mesh/cadquery_assembly_with_scaled_geometry.py \ No newline at end of file diff --git a/README.md b/README.md index 0eb644d..571e4cc 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ [![PyPI](https://img.shields.io/pypi/v/cad_to_dagmc?color=brightgreen&label=pypi&logo=grebrightgreenen&logoColor=green)](https://pypi.org/project/cad_to_dagmc/) -A minimal package that converts CAD geometry to [DAGMC](https://github.com/svalinn/DAGMC/) h5m files +A minimal package that converts CAD geometry to [DAGMC](https://github.com/svalinn/DAGMC/) (h5m) files, [unstructured mesh](https://docs.openmc.org/en/latest/pythonapi/generated/openmc.UnstructuredMesh.html) files (vtk) and Gmsh (msh) files ready for use in neutronics simulations. cad-to-dagmc can create: - surface meshes / faceted geometry / triangular meshes @@ -21,14 +21,21 @@ cad-to-dagmc can create: cad-to-dagmc can convert: - STEP files - CadQuery objects (in memory) - -cad-to-dagmc aims to produce DAGMC compatible h5m files from CAD geometry is intended to convert [STEP](http://www.steptools.com/stds/step/) files or [CadQuery](https://cadquery.readthedocs.io) objects to a [DAGMC](https://github.com/svalinn/DAGMC/) compatible h5m file. - -The resulting DAGMC geometry can then be used for simulations in [OpenMC](https://github.com/openmc-dev/openmc/) or [other supported codes](https://svalinn.github.io/DAGMC/). - -This package is tested with [pytest tests](https://github.com/fusion-energy/cad_to_dagmc/tree/main/tests) and also the DAGMC geometry made with this package is compared to simulation carried out with native constructive solid geometry, see [Model Benchmark Zoo](https://github.com/fusion-energy/model_benchmark_zoo) for more details. - -Also checkout these other software projects that also create DAGMC geometry [CAD-to-OpenMC](https://github.com/openmsr/CAD_to_OpenMC), [Stellarmesh](https://github.com/Thea-Energy/stellarmesh) and [Coreform Cubit](https://coreform.com/products/coreform-cubit/) +- Gmsh meshes + +Cad-to-dagmc is offers a wide range of features including. +- Geometry scaling with ```scale_factor``` argument +- Model wide mesh size parameters with ```min_mesh_size``` and ```max_mesh_size``` arguments +- Volume specific mesh sizing parameters with the ```set_size``` argument +- Parallel meshing to quickly mesh the geometry using multiple CPU cores +- Imprint and merging of CAD geometry, or disable with the ```imprint``` argument +- Add geometry from multiple sources ([STEP](http://www.steptools.com/stds/step/) files, [CadQuery](https://cadquery.readthedocs.io) objects and [Gmsh](https://gmsh.info/) meshes) +- Ability to tag the DAGMC implicit complement material using the ```implicit_complement_material_tag``` argument +- Selected different Gmesh mesh algorithms (defaults to 1) using the ```mesh_algorithm``` argument +- Pass CadQuery objects in memory for fast transfer of geometry using the ```method``` argument +- Easy to install with [pip](https://pypi.org/project/cad-to-dagmc/) and [Conda/Mamba](https://anaconda.org/conda-forge/cad_to_dagmc) +- Well tested both with [CI unit tests](https://github.com/fusion-energy/cad_to_dagmc/tree/main/tests), integration tests and the CSG [Model Benchmark Zoo](https://github.com/fusion-energy/model_benchmark_zoo). +- Compatible with [Paramak](https://github.com/fusion-energy/paramak) geometry for fusion simulations. # Installation options @@ -149,3 +156,7 @@ For examples see the [examples folder](https://github.com/fusion-energy/cad_to_d For examples see the [examples folder](https://github.com/fusion-energy/cad_to_dagmc/tree/main/examples) For more examples see the CAD tasks in the [neutronics-workshop](https://github.com/fusion-energy/neutronics-workshop) and [model benchmark zoo](https://github.com/fusion-energy/model_benchmark_zoo) + +# Related software + +Also checkout these other software projects that also create DAGMC geometry [CAD-to-OpenMC](https://github.com/openmsr/CAD_to_OpenMC), [Stellarmesh](https://github.com/Thea-Energy/stellarmesh) and [Coreform Cubit](https://coreform.com/products/coreform-cubit/). diff --git a/examples/surface_mesh/different_resolution_meshes.py b/examples/surface_mesh/different_resolution_meshes.py new file mode 100644 index 0000000..eb5e097 --- /dev/null +++ b/examples/surface_mesh/different_resolution_meshes.py @@ -0,0 +1,38 @@ +# This example makes 3 CAD boxes +# Meshes the 3 volumes with different resolutions +# exports the mesh to a DAGMC h5m file and GMsh msh file +import cadquery as cq +from cad_to_dagmc import CadToDagmc + +box_set_size_course_mesh = cq.Workplane().box(1, 1, 2) +box_set_size_fine_mesh = cq.Workplane().moveTo(1,0.5).box(1, 1, 1.5) +box_set_global_mesh = cq.Workplane().moveTo(2,1).box(1, 1, 1) + +assembly = cq.Assembly() +assembly.add(box_set_size_course_mesh, color=cq.Color(0, 0, 1)) +assembly.add(box_set_size_fine_mesh,color=cq.Color(0, 1, 0)) +assembly.add(box_set_global_mesh, color=cq.Color(1, 0, 0)) + +assembly.export('different_resolution_meshes.step') + +# uncomment to see the assembly in a pop up vtk viewer +# from cadquery import vis +# vis.show(assembly) + +model = CadToDagmc() +model.add_cadquery_object(assembly, material_tags=["mat1", "mat2", "mat3"]) + +model.export_dagmc_h5m_file( + filename="different_resolution_meshes.h5m", + min_mesh_size=0.01, + max_mesh_size=10, + set_size= {1: 0.9, 2: 0.1} # not volume 3 is not specified in the set_size so it uses only the min max mesh sizes +) + +model.export_gmsh_mesh_file( + filename="different_resolution_meshes.msh", + dimensions=2, + min_mesh_size=0.01, + max_mesh_size=10, + set_size= {1: 0.9, 2: 0.1} # not volume 3 is not specified in the set_size so it uses only the min max mesh sizes +) diff --git a/examples/unstrucutred_volume_mesh/different_resolution_meshes.py b/examples/unstrucutred_volume_mesh/different_resolution_meshes.py new file mode 100644 index 0000000..7c8c9d5 --- /dev/null +++ b/examples/unstrucutred_volume_mesh/different_resolution_meshes.py @@ -0,0 +1,38 @@ +# This example makes 3 CAD boxes +# Meshes the 3 volumes with different resolutions +# exports the mesh to a DAGMC unstructured VTK file and Gmsh msh file +import cadquery as cq +from cad_to_dagmc import CadToDagmc + +box_set_size_course_mesh = cq.Workplane().box(1, 1, 2) +box_set_size_fine_mesh = cq.Workplane().moveTo(1,0.5).box(1, 1, 1.5) +box_set_global_mesh = cq.Workplane().moveTo(2,1).box(1, 1, 1) + +assembly = cq.Assembly() +assembly.add(box_set_size_course_mesh, color=cq.Color(0, 0, 1)) +assembly.add(box_set_size_fine_mesh,color=cq.Color(0, 1, 0)) +assembly.add(box_set_global_mesh, color=cq.Color(1, 0, 0)) + +assembly.export('different_resolution_meshes.step') + +# uncomment to see the assembly in a pop up vtk viewer +# from cadquery import vis +# vis.show(assembly) + +model = CadToDagmc() +model.add_cadquery_object(assembly, material_tags=["mat1", "mat2", "mat3"]) + +model.export_gmsh_mesh_file( + filename="different_resolution_meshes.msh", + dimensions=3, + min_mesh_size=0.01, + max_mesh_size=10, + set_size= {1: 0.9, 2: 0.1} # not volume 3 is not specified in the set_size so it uses only the min max mesh sizes +) + +model.export_unstructured_mesh_file( + filename="different_resolution_meshes.vtk", + min_mesh_size=0.01, + max_mesh_size=10, + set_size= {1: 0.9, 2: 0.1} # not volume 3 is not specified in the set_size so it uses only the min max mesh sizes +) diff --git a/src/cad_to_dagmc/core.py b/src/cad_to_dagmc/core.py index 6f4096f..af14193 100644 --- a/src/cad_to_dagmc/core.py +++ b/src/cad_to_dagmc/core.py @@ -254,7 +254,7 @@ def _mesh_brep( dimensions: The number of dimensions, 2 for a surface mesh 3 for a volume mesh. Passed to gmsh.model.mesh.generate() set_size: a dictionary of volume ids (int) and target mesh sizes - (floats) to set for each volume, passed to gmsh.model.mesh.setSize. + (floats) to set for each volume, passed to gmsh.model.mesh.setSize. Returns: The resulting gmsh object and volumes @@ -274,30 +274,29 @@ def _mesh_brep( gmsh.option.setNumber("Mesh.Algorithm", mesh_algorithm) gmsh.option.setNumber("General.NumThreads", 0) # Use all available cores - if dimensions == 2: - if set_size: - volumes = gmsh.model.getEntities(3) - print("volumes", volumes) - for _, volume in volumes: - if volume in set_size.keys(): - size = set_size[volume] - if isinstance(size, dict): - # TODO face specific mesh sizes - pass - else: - boundaries = gmsh.model.getBoundary( - [(3, volume)], recursive=True - ) # dim must be set to 3 - print("boundaries", boundaries) - gmsh.model.mesh.setSize(boundaries, size) - print(f"Set size of {size} for volume {volume}") + if set_size: + volumes = gmsh.model.getEntities(3) + available_volumes = [volume[1] for volume in volumes] + print("volumes", volumes) + for volume_id, size in set_size.items(): + if volume_id in available_volumes: + size = set_size[volume_id] + if isinstance(size, dict): + # TODO face specific mesh sizes + pass else: - raise ValueError( - f"volume ID of {volume} set in set_sizes but not found in available volumes {volumes}" - ) + boundaries = gmsh.model.getBoundary( + [(3, volume_id)], recursive=True + ) # dim must be set to 3 + print("boundaries", boundaries) + gmsh.model.mesh.setSize(boundaries, size) + print(f"Set size of {size} for volume {volume_id}") + else: + raise ValueError( + f"volume ID of {volume_id} set in set_sizes but not found in available volumes {volumes}" + ) gmsh.model.mesh.generate(dimensions) - gmsh.write("mesh2.msh") return gmsh @@ -544,6 +543,7 @@ def export_unstructured_mesh_file( method: str = "file", scale_factor: float = 1.0, imprint: bool = True, + set_size: dict[int, float] | None = None, ): """ Exports an unstructured mesh file in VTK format for use with openmc.UnstructuredMesh. @@ -575,6 +575,9 @@ def export_unstructured_mesh_file( normally needed to ensure the geometry is meshed correctly. However if you know your geometry does not need imprinting you can set this to False and this can save time. + set_size: a dictionary of volume ids (int) and target mesh sizes + (floats) to set for each volume, passed to gmsh.model.mesh.setSize. + Returns: -------- @@ -606,6 +609,7 @@ def export_unstructured_mesh_file( max_mesh_size=max_mesh_size, mesh_algorithm=mesh_algorithm, dimensions=3, + set_size=set_size, ) # makes the folder if it does not exist From 579591a7f3aeef7672326d2a93a72423e070aa1a Mon Sep 17 00:00:00 2001 From: shimwell <8583900+shimwell@users.noreply.github.com> Date: Tue, 28 Jan 2025 15:25:30 +0000 Subject: [PATCH 5/5] [skip ci] Apply formatting changes --- .../different_resolution_meshes.py | 18 ++++++++++++------ .../different_resolution_meshes.py | 18 ++++++++++++------ src/cad_to_dagmc/core.py | 2 +- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/examples/surface_mesh/different_resolution_meshes.py b/examples/surface_mesh/different_resolution_meshes.py index eb5e097..be3ab25 100644 --- a/examples/surface_mesh/different_resolution_meshes.py +++ b/examples/surface_mesh/different_resolution_meshes.py @@ -5,15 +5,15 @@ from cad_to_dagmc import CadToDagmc box_set_size_course_mesh = cq.Workplane().box(1, 1, 2) -box_set_size_fine_mesh = cq.Workplane().moveTo(1,0.5).box(1, 1, 1.5) -box_set_global_mesh = cq.Workplane().moveTo(2,1).box(1, 1, 1) +box_set_size_fine_mesh = cq.Workplane().moveTo(1, 0.5).box(1, 1, 1.5) +box_set_global_mesh = cq.Workplane().moveTo(2, 1).box(1, 1, 1) assembly = cq.Assembly() assembly.add(box_set_size_course_mesh, color=cq.Color(0, 0, 1)) -assembly.add(box_set_size_fine_mesh,color=cq.Color(0, 1, 0)) +assembly.add(box_set_size_fine_mesh, color=cq.Color(0, 1, 0)) assembly.add(box_set_global_mesh, color=cq.Color(1, 0, 0)) -assembly.export('different_resolution_meshes.step') +assembly.export("different_resolution_meshes.step") # uncomment to see the assembly in a pop up vtk viewer # from cadquery import vis @@ -26,7 +26,10 @@ filename="different_resolution_meshes.h5m", min_mesh_size=0.01, max_mesh_size=10, - set_size= {1: 0.9, 2: 0.1} # not volume 3 is not specified in the set_size so it uses only the min max mesh sizes + set_size={ + 1: 0.9, + 2: 0.1, + }, # not volume 3 is not specified in the set_size so it uses only the min max mesh sizes ) model.export_gmsh_mesh_file( @@ -34,5 +37,8 @@ dimensions=2, min_mesh_size=0.01, max_mesh_size=10, - set_size= {1: 0.9, 2: 0.1} # not volume 3 is not specified in the set_size so it uses only the min max mesh sizes + set_size={ + 1: 0.9, + 2: 0.1, + }, # not volume 3 is not specified in the set_size so it uses only the min max mesh sizes ) diff --git a/examples/unstrucutred_volume_mesh/different_resolution_meshes.py b/examples/unstrucutred_volume_mesh/different_resolution_meshes.py index 7c8c9d5..e98c22d 100644 --- a/examples/unstrucutred_volume_mesh/different_resolution_meshes.py +++ b/examples/unstrucutred_volume_mesh/different_resolution_meshes.py @@ -5,15 +5,15 @@ from cad_to_dagmc import CadToDagmc box_set_size_course_mesh = cq.Workplane().box(1, 1, 2) -box_set_size_fine_mesh = cq.Workplane().moveTo(1,0.5).box(1, 1, 1.5) -box_set_global_mesh = cq.Workplane().moveTo(2,1).box(1, 1, 1) +box_set_size_fine_mesh = cq.Workplane().moveTo(1, 0.5).box(1, 1, 1.5) +box_set_global_mesh = cq.Workplane().moveTo(2, 1).box(1, 1, 1) assembly = cq.Assembly() assembly.add(box_set_size_course_mesh, color=cq.Color(0, 0, 1)) -assembly.add(box_set_size_fine_mesh,color=cq.Color(0, 1, 0)) +assembly.add(box_set_size_fine_mesh, color=cq.Color(0, 1, 0)) assembly.add(box_set_global_mesh, color=cq.Color(1, 0, 0)) -assembly.export('different_resolution_meshes.step') +assembly.export("different_resolution_meshes.step") # uncomment to see the assembly in a pop up vtk viewer # from cadquery import vis @@ -27,12 +27,18 @@ dimensions=3, min_mesh_size=0.01, max_mesh_size=10, - set_size= {1: 0.9, 2: 0.1} # not volume 3 is not specified in the set_size so it uses only the min max mesh sizes + set_size={ + 1: 0.9, + 2: 0.1, + }, # not volume 3 is not specified in the set_size so it uses only the min max mesh sizes ) model.export_unstructured_mesh_file( filename="different_resolution_meshes.vtk", min_mesh_size=0.01, max_mesh_size=10, - set_size= {1: 0.9, 2: 0.1} # not volume 3 is not specified in the set_size so it uses only the min max mesh sizes + set_size={ + 1: 0.9, + 2: 0.1, + }, # not volume 3 is not specified in the set_size so it uses only the min max mesh sizes ) diff --git a/src/cad_to_dagmc/core.py b/src/cad_to_dagmc/core.py index af14193..8f93284 100644 --- a/src/cad_to_dagmc/core.py +++ b/src/cad_to_dagmc/core.py @@ -577,7 +577,7 @@ def export_unstructured_mesh_file( and this can save time. set_size: a dictionary of volume ids (int) and target mesh sizes (floats) to set for each volume, passed to gmsh.model.mesh.setSize. - + Returns: --------