cad-to-dagmc 0.7.7__py3-none-any.whl → 0.8.1__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.1'
16
+ __version_tuple__ = version_tuple = (0, 8, 1)
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
@@ -468,6 +503,7 @@ class CadToDagmc:
468
503
  cq.assembly.Assembly | cq.occ_impl.shapes.Compound | cq.occ_impl.shapes.Solid
469
504
  ),
470
505
  material_tags: list[str] | None,
506
+ scale_factor: float = 1.0,
471
507
  ) -> int:
472
508
  """Loads the parts from CadQuery object into the model.
473
509
 
@@ -479,6 +515,10 @@ class CadToDagmc:
479
515
  same order as the volumes in the geometry added (STP file and
480
516
  CadQuery objects) and match the material tags used in the
481
517
  neutronics code (e.g. OpenMC).
518
+ scale_factor: a scaling factor to apply to the geometry that can be
519
+ used to increase the size or decrease the size of the geometry.
520
+ Useful when converting the geometry to cm for use in neutronics
521
+ simulations.
482
522
 
483
523
  Returns:
484
524
  int: number of volumes in the stp file.
@@ -492,12 +532,17 @@ class CadToDagmc:
492
532
  else:
493
533
  iterable_solids = cadquery_object.val().Solids()
494
534
 
495
- _check_material_tags(material_tags, iterable_solids)
535
+ if scale_factor == 1.0:
536
+ scaled_iterable_solids = iterable_solids
537
+ else:
538
+ scaled_iterable_solids = [part.scale(scale_factor) for part in iterable_solids]
539
+
540
+ _check_material_tags(material_tags, scaled_iterable_solids)
496
541
  if material_tags:
497
542
  self.material_tags = self.material_tags + material_tags
498
- self.parts = self.parts + iterable_solids
543
+ self.parts = self.parts + scaled_iterable_solids
499
544
 
500
- return len(iterable_solids)
545
+ return len(scaled_iterable_solids)
501
546
 
502
547
  def export_unstructured_mesh_file(
503
548
  self,
@@ -508,6 +553,7 @@ class CadToDagmc:
508
553
  method: str = "file",
509
554
  scale_factor: float = 1.0,
510
555
  imprint: bool = True,
556
+ set_size: dict[int, float] | None = None,
511
557
  ):
512
558
  """
513
559
  Exports an unstructured mesh file in VTK format for use with openmc.UnstructuredMesh.
@@ -539,6 +585,9 @@ class CadToDagmc:
539
585
  normally needed to ensure the geometry is meshed correctly. However if
540
586
  you know your geometry does not need imprinting you can set this to False
541
587
  and this can save time.
588
+ set_size: a dictionary of volume ids (int) and target mesh sizes
589
+ (floats) to set for each volume, passed to gmsh.model.mesh.setSize.
590
+
542
591
 
543
592
  Returns:
544
593
  --------
@@ -570,6 +619,7 @@ class CadToDagmc:
570
619
  max_mesh_size=max_mesh_size,
571
620
  mesh_algorithm=mesh_algorithm,
572
621
  dimensions=3,
622
+ set_size=set_size,
573
623
  )
574
624
 
575
625
  # makes the folder if it does not exist
@@ -589,13 +639,14 @@ class CadToDagmc:
589
639
  def export_gmsh_mesh_file(
590
640
  self,
591
641
  filename: str = "mesh.msh",
592
- min_mesh_size: float = 1,
593
- max_mesh_size: float = 5,
642
+ min_mesh_size: float | None = None,
643
+ max_mesh_size: float | None = None,
594
644
  mesh_algorithm: int = 1,
595
645
  dimensions: int = 2,
596
646
  method: str = "file",
597
647
  scale_factor: float = 1.0,
598
648
  imprint: bool = True,
649
+ set_size: dict[int, float] | None = None,
599
650
  ):
600
651
  """Saves a GMesh msh file of the geometry in either 2D surface mesh or
601
652
  3D volume mesh.
@@ -622,6 +673,8 @@ class CadToDagmc:
622
673
  normally needed to ensure the geometry is meshed correctly. However if
623
674
  you know your geometry does not need imprinting you can set this to False
624
675
  and this can save time.
676
+ set_size: a dictionary of volume ids (int) and target mesh sizes
677
+ (floats) to set for each volume, passed to gmsh.model.mesh.setSize.
625
678
  """
626
679
 
627
680
  assembly = cq.Assembly()
@@ -643,6 +696,7 @@ class CadToDagmc:
643
696
  max_mesh_size=max_mesh_size,
644
697
  mesh_algorithm=mesh_algorithm,
645
698
  dimensions=dimensions,
699
+ set_size=set_size,
646
700
  )
647
701
 
648
702
  # makes the folder if it does not exist
@@ -662,13 +716,14 @@ class CadToDagmc:
662
716
  def export_dagmc_h5m_file(
663
717
  self,
664
718
  filename: str = "dagmc.h5m",
665
- min_mesh_size: float = 1,
666
- max_mesh_size: float = 5,
719
+ min_mesh_size: float | None = None,
720
+ max_mesh_size: float | None = None,
667
721
  mesh_algorithm: int = 1,
668
722
  implicit_complement_material_tag: str | None = None,
669
723
  method: str = "file",
670
724
  scale_factor: float = 1.0,
671
725
  imprint: bool = True,
726
+ set_size: dict[int, float] | None = None,
672
727
  ) -> str:
673
728
  """Saves a DAGMC h5m file of the geometry
674
729
 
@@ -695,6 +750,8 @@ class CadToDagmc:
695
750
  normally needed to ensure the geometry is meshed correctly. However if
696
751
  you know your geometry does not need imprinting you can set this to False
697
752
  and this can save time.
753
+ set_size: a dictionary of volume ids (int) and target mesh sizes
754
+ (floats) to set for each volume, passed to gmsh.model.mesh.setSize.
698
755
 
699
756
  Returns:
700
757
  str: the DAGMC filename saved
@@ -739,6 +796,7 @@ class CadToDagmc:
739
796
  min_mesh_size=min_mesh_size,
740
797
  max_mesh_size=max_mesh_size,
741
798
  mesh_algorithm=mesh_algorithm,
799
+ set_size=set_size,
742
800
  )
743
801
 
744
802
  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.1
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=Z8fNqmfsoA07nbVEewR90wZCgaN6eyDwPwgtgc2KIak,411
2
+ cad_to_dagmc/__init__.py,sha256=fskHUTyCunSpnpJUvBfAYjx4uwDKXHTTiMP6GqnFRf0,494
3
+ cad_to_dagmc/core.py,sha256=DbxXCaVEIiJxulRJlatoQg-yce37SS9Dx914Gt91qKY,31883
4
+ cad_to_dagmc-0.8.1.dist-info/LICENSE,sha256=B8kznH_777JVNZ3HOKDc4Tj24F7wJ68ledaNYeL9sCw,1070
5
+ cad_to_dagmc-0.8.1.dist-info/METADATA,sha256=AQ41vcWt_gHdZFL_rh7n28O5CheNftqa-FWdaVWvhjI,8700
6
+ cad_to_dagmc-0.8.1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
7
+ cad_to_dagmc-0.8.1.dist-info/top_level.txt,sha256=zTi8C64SEBsE5WOtPovnxhOzt-E6Oc5nC3RW6M_5aEA,22
8
+ cad_to_dagmc-0.8.1.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,,