cad-to-dagmc 0.7.7__py3-none-any.whl → 0.8.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of cad-to-dagmc might be problematic. Click here for more details.

_version.py CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.7.7'
16
- __version_tuple__ = version_tuple = (0, 7, 7)
15
+ __version__ = version = '0.8.0'
16
+ __version_tuple__ = version_tuple = (0, 8, 0)
cad_to_dagmc/core.py CHANGED
@@ -235,10 +235,11 @@ def init_gmsh():
235
235
 
236
236
  def _mesh_brep(
237
237
  gmsh,
238
- min_mesh_size: float = 1,
239
- max_mesh_size: float = 10,
238
+ min_mesh_size: float | None = None,
239
+ max_mesh_size: float | None = None,
240
240
  mesh_algorithm: int = 1,
241
241
  dimensions: int = 2,
242
+ set_size: dict[int, float] | None = None,
242
243
  ):
243
244
  """Creates a conformal surface meshes of the volumes in a Brep file using Gmsh.
244
245
 
@@ -252,15 +253,49 @@ def _mesh_brep(
252
253
  gmsh.option.setNumber("Mesh.Algorithm", mesh_algorithm)
253
254
  dimensions: The number of dimensions, 2 for a surface mesh 3 for a
254
255
  volume mesh. Passed to gmsh.model.mesh.generate()
256
+ set_size: a dictionary of volume ids (int) and target mesh sizes
257
+ (floats) to set for each volume, passed to gmsh.model.mesh.setSize.
255
258
 
256
259
  Returns:
257
260
  The resulting gmsh object and volumes
258
261
  """
262
+ if min_mesh_size and max_mesh_size:
263
+ if min_mesh_size > max_mesh_size:
264
+ raise ValueError(
265
+ 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}"
266
+ )
267
+
268
+ if min_mesh_size:
269
+ gmsh.option.setNumber("Mesh.MeshSizeMin", min_mesh_size)
270
+
271
+ if max_mesh_size:
272
+ gmsh.option.setNumber("Mesh.MeshSizeMax", max_mesh_size)
259
273
 
260
274
  gmsh.option.setNumber("Mesh.Algorithm", mesh_algorithm)
261
- gmsh.option.setNumber("Mesh.MeshSizeMin", min_mesh_size)
262
- gmsh.option.setNumber("Mesh.MeshSizeMax", max_mesh_size)
263
275
  gmsh.option.setNumber("General.NumThreads", 0) # Use all available cores
276
+
277
+ if set_size:
278
+ volumes = gmsh.model.getEntities(3)
279
+ available_volumes = [volume[1] for volume in volumes]
280
+ print("volumes", volumes)
281
+ for volume_id, size in set_size.items():
282
+ if volume_id in available_volumes:
283
+ size = set_size[volume_id]
284
+ if isinstance(size, dict):
285
+ # TODO face specific mesh sizes
286
+ pass
287
+ else:
288
+ boundaries = gmsh.model.getBoundary(
289
+ [(3, volume_id)], recursive=True
290
+ ) # dim must be set to 3
291
+ print("boundaries", boundaries)
292
+ gmsh.model.mesh.setSize(boundaries, size)
293
+ print(f"Set size of {size} for volume {volume_id}")
294
+ else:
295
+ raise ValueError(
296
+ f"volume ID of {volume_id} set in set_sizes but not found in available volumes {volumes}"
297
+ )
298
+
264
299
  gmsh.model.mesh.generate(dimensions)
265
300
 
266
301
  return gmsh
@@ -508,6 +543,7 @@ class CadToDagmc:
508
543
  method: str = "file",
509
544
  scale_factor: float = 1.0,
510
545
  imprint: bool = True,
546
+ set_size: dict[int, float] | None = None,
511
547
  ):
512
548
  """
513
549
  Exports an unstructured mesh file in VTK format for use with openmc.UnstructuredMesh.
@@ -539,6 +575,9 @@ class CadToDagmc:
539
575
  normally needed to ensure the geometry is meshed correctly. However if
540
576
  you know your geometry does not need imprinting you can set this to False
541
577
  and this can save time.
578
+ set_size: a dictionary of volume ids (int) and target mesh sizes
579
+ (floats) to set for each volume, passed to gmsh.model.mesh.setSize.
580
+
542
581
 
543
582
  Returns:
544
583
  --------
@@ -570,6 +609,7 @@ class CadToDagmc:
570
609
  max_mesh_size=max_mesh_size,
571
610
  mesh_algorithm=mesh_algorithm,
572
611
  dimensions=3,
612
+ set_size=set_size,
573
613
  )
574
614
 
575
615
  # makes the folder if it does not exist
@@ -589,13 +629,14 @@ class CadToDagmc:
589
629
  def export_gmsh_mesh_file(
590
630
  self,
591
631
  filename: str = "mesh.msh",
592
- min_mesh_size: float = 1,
593
- max_mesh_size: float = 5,
632
+ min_mesh_size: float | None = None,
633
+ max_mesh_size: float | None = None,
594
634
  mesh_algorithm: int = 1,
595
635
  dimensions: int = 2,
596
636
  method: str = "file",
597
637
  scale_factor: float = 1.0,
598
638
  imprint: bool = True,
639
+ set_size: dict[int, float] | None = None,
599
640
  ):
600
641
  """Saves a GMesh msh file of the geometry in either 2D surface mesh or
601
642
  3D volume mesh.
@@ -622,6 +663,8 @@ class CadToDagmc:
622
663
  normally needed to ensure the geometry is meshed correctly. However if
623
664
  you know your geometry does not need imprinting you can set this to False
624
665
  and this can save time.
666
+ set_size: a dictionary of volume ids (int) and target mesh sizes
667
+ (floats) to set for each volume, passed to gmsh.model.mesh.setSize.
625
668
  """
626
669
 
627
670
  assembly = cq.Assembly()
@@ -643,6 +686,7 @@ class CadToDagmc:
643
686
  max_mesh_size=max_mesh_size,
644
687
  mesh_algorithm=mesh_algorithm,
645
688
  dimensions=dimensions,
689
+ set_size=set_size,
646
690
  )
647
691
 
648
692
  # makes the folder if it does not exist
@@ -662,13 +706,14 @@ class CadToDagmc:
662
706
  def export_dagmc_h5m_file(
663
707
  self,
664
708
  filename: str = "dagmc.h5m",
665
- min_mesh_size: float = 1,
666
- max_mesh_size: float = 5,
709
+ min_mesh_size: float | None = None,
710
+ max_mesh_size: float | None = None,
667
711
  mesh_algorithm: int = 1,
668
712
  implicit_complement_material_tag: str | None = None,
669
713
  method: str = "file",
670
714
  scale_factor: float = 1.0,
671
715
  imprint: bool = True,
716
+ set_size: dict[int, float] | None = None,
672
717
  ) -> str:
673
718
  """Saves a DAGMC h5m file of the geometry
674
719
 
@@ -695,6 +740,8 @@ class CadToDagmc:
695
740
  normally needed to ensure the geometry is meshed correctly. However if
696
741
  you know your geometry does not need imprinting you can set this to False
697
742
  and this can save time.
743
+ set_size: a dictionary of volume ids (int) and target mesh sizes
744
+ (floats) to set for each volume, passed to gmsh.model.mesh.setSize.
698
745
 
699
746
  Returns:
700
747
  str: the DAGMC filename saved
@@ -739,6 +786,7 @@ class CadToDagmc:
739
786
  min_mesh_size=min_mesh_size,
740
787
  max_mesh_size=max_mesh_size,
741
788
  mesh_algorithm=mesh_algorithm,
789
+ set_size=set_size,
742
790
  )
743
791
 
744
792
  dims_and_vol_ids = volumes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: cad_to_dagmc
3
- Version: 0.7.7
3
+ Version: 0.8.0
4
4
  Summary: Converts CAD files to a DAGMC h5m file
5
5
  Author-email: Jonathan Shimwell <mail@jshimwell.com>
6
6
  Project-URL: Homepage, https://github.com/fusion-energy/cad_to_dagmc
@@ -35,7 +35,7 @@ Requires-Dist: vtk; extra == "tests"
35
35
  [![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/)
36
36
 
37
37
 
38
- A minimal package that converts CAD geometry to [DAGMC](https://github.com/svalinn/DAGMC/) compatible meshes
38
+ 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.
39
39
 
40
40
  cad-to-dagmc can create DAGMC compatible:
41
41
  - surface meshes / faceted geometry / triangular meshes
@@ -43,23 +43,23 @@ cad-to-dagmc can create DAGMC compatible:
43
43
 
44
44
  cad-to-dagmc can convert the following in to DAGMC compatible meshes:
45
45
  - STEP files
46
- - CadQuery objects
46
+ - CadQuery objects (in memory)
47
47
  - Gmsh meshes
48
48
 
49
- Options include
50
- - Ability to scale the output mesh (e.g from meters to cm)
51
- - Ability to skip imprinting stage
52
- - Specify meshing parameters for finer or coarser meshes or change the mesh algorithm
53
- - Ability to specify a material tag for the DAGMC implicit complement
54
- - Pass objects from CadQuery in memory (without writting to disk)
49
+ Cad-to-dagmc offers a wide range of features including.
50
+ - Geometry scaling with ```scale_factor``` argument
51
+ - Model wide mesh size parameters with ```min_mesh_size``` and ```max_mesh_size``` arguments
52
+ - Volume specific mesh sizing parameters with the ```set_size``` argument
53
+ - Parallel meshing to quickly mesh the geometry using multiple CPU cores
54
+ - Imprint and merging of CAD geometry, or disable with the ```imprint``` argument
55
+ - 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)
56
+ - Ability to tag the DAGMC implicit complement material using the ```implicit_complement_material_tag``` argument
57
+ - Selected different Gmesh mesh algorithms (defaults to 1) using the ```mesh_algorithm``` argument
58
+ - Pass CadQuery objects in memory for fast transfer of geometry using the ```method``` argument
59
+ - Easy to install with [pip](https://pypi.org/project/cad-to-dagmc/) and [Conda/Mamba](https://anaconda.org/conda-forge/cad_to_dagmc)
60
+ - 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).
61
+ - Compatible with [Paramak](https://github.com/fusion-energy/paramak) geometry for fusion simulations.
55
62
 
56
- cad-to-dagmc aims to produce DAGMC compatible h5m and vtk files from CAD geometry is intended to convert [STEP](http://www.steptools.com/stds/step/) files, [CadQuery](https://cadquery.readthedocs.io) or [Gmsh]([https://cadquery.readthedocs.io](https://gmsh.info/)) meshes objects to a [DAGMC](https://github.com/svalinn/DAGMC/) compatible h5m file or a DAGMC compatible Unstruuctre vtk file.
57
-
58
- 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/).
59
-
60
- 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.
61
-
62
- 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/)
63
63
 
64
64
  # Installation options
65
65
 
@@ -176,3 +176,7 @@ Installing one of the package dependancies (Gmsh) with pip appears to result in
176
176
  For examples showing creation of DAGMC h5m files, vtk files and usage within OpenMC transport code see the [examples folder](https://github.com/fusion-energy/cad_to_dagmc/tree/main/examples)
177
177
 
178
178
  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)
179
+
180
+ # Related software
181
+
182
+ 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/).
@@ -0,0 +1,8 @@
1
+ _version.py,sha256=vspFLRfYI6gAAN7kyihey2lhPos0jxqKaNDWFlKPlmU,411
2
+ cad_to_dagmc/__init__.py,sha256=fskHUTyCunSpnpJUvBfAYjx4uwDKXHTTiMP6GqnFRf0,494
3
+ cad_to_dagmc/core.py,sha256=w8Bu3MyjhQtW4KYRXktib7aPbjTy8jfSdpSgzw57gIc,31366
4
+ cad_to_dagmc-0.8.0.dist-info/LICENSE,sha256=B8kznH_777JVNZ3HOKDc4Tj24F7wJ68ledaNYeL9sCw,1070
5
+ cad_to_dagmc-0.8.0.dist-info/METADATA,sha256=GvclO4Hs5U2TwJLenoQZVAsQ0GSNOjOQ1IUhqS0rNWA,8700
6
+ cad_to_dagmc-0.8.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
7
+ cad_to_dagmc-0.8.0.dist-info/top_level.txt,sha256=zTi8C64SEBsE5WOtPovnxhOzt-E6Oc5nC3RW6M_5aEA,22
8
+ cad_to_dagmc-0.8.0.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- _version.py,sha256=OFzKtYPiFCCvMWwWVN3UDiEwBAcWMPY3Atug8b0zLFk,411
2
- cad_to_dagmc/__init__.py,sha256=fskHUTyCunSpnpJUvBfAYjx4uwDKXHTTiMP6GqnFRf0,494
3
- cad_to_dagmc/core.py,sha256=5xWb8oGRs6318CcUI_PADsF1vJjqzYPVNAQ8vKGjZE4,29063
4
- cad_to_dagmc-0.7.7.dist-info/LICENSE,sha256=B8kznH_777JVNZ3HOKDc4Tj24F7wJ68ledaNYeL9sCw,1070
5
- cad_to_dagmc-0.7.7.dist-info/METADATA,sha256=rGXnqaOFnpf4mXTn-BN9uXi8d3dwBt7SzcP5Ornd18o,8362
6
- cad_to_dagmc-0.7.7.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
7
- cad_to_dagmc-0.7.7.dist-info/top_level.txt,sha256=zTi8C64SEBsE5WOtPovnxhOzt-E6Oc5nC3RW6M_5aEA,22
8
- cad_to_dagmc-0.7.7.dist-info/RECORD,,