cad-to-dagmc 0.7.3__py3-none-any.whl → 0.7.5__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.3'
16
- __version_tuple__ = version_tuple = (0, 7, 3)
15
+ __version__ = version = '0.7.5'
16
+ __version_tuple__ = version_tuple = (0, 7, 5)
cad_to_dagmc/core.py CHANGED
@@ -1,7 +1,8 @@
1
+ from pathlib import Path
1
2
  import cadquery as cq
2
3
  import gmsh
3
4
  import numpy as np
4
- from cadquery import importers, exporters
5
+ from cadquery import importers
5
6
  from pymoab import core, types
6
7
  import tempfile
7
8
 
@@ -484,19 +485,62 @@ class CadToDagmc:
484
485
 
485
486
  def export_unstructured_mesh_file(
486
487
  self,
487
- filename: str = "umesh.h5m",
488
+ filename: str = "umesh.vtk",
488
489
  min_mesh_size: float = 1,
489
490
  max_mesh_size: float = 5,
490
491
  mesh_algorithm: int = 1,
491
492
  method: str = "file",
492
493
  scale_factor: float = 1.0,
494
+ imprint: bool = True,
493
495
  ):
496
+ """
497
+ Exports an unstructured mesh file in VTK format for use with openmc.UnstructuredMesh.
498
+ Compatible with the MOAB unstructured mesh library. Example useage
499
+ openmc.UnstructuredMesh(filename="umesh.vtk", library="moab")
500
+
501
+ Parameters:
502
+ -----------
503
+ filename : str, optional
504
+ The name of the output file. Default is "umesh.vtk".
505
+ min_mesh_size: the minimum mesh element size to use in Gmsh. Passed
506
+ into gmsh.option.setNumber("Mesh.MeshSizeMin", min_mesh_size)
507
+ max_mesh_size: the maximum mesh element size to use in Gmsh. Passed
508
+ into gmsh.option.setNumber("Mesh.MeshSizeMax", max_mesh_size)
509
+ mesh_algorithm: The Gmsh mesh algorithm number to use. Passed into
510
+ gmsh.option.setNumber("Mesh.Algorithm", mesh_algorithm)
511
+ method: the method to use to import the geometry into gmsh. Options
512
+ are 'file' or 'in memory'. 'file' is the default and will write
513
+ the geometry to a temporary file before importing it into gmsh.
514
+ 'in memory' will import the geometry directly into gmsh but
515
+ requires the version of OpenCASCADE used to build gmsh to be
516
+ the same as the version used by CadQuery. This is possible to
517
+ ensure when installing the package with Conda but harder when
518
+ installing from PyPI.
519
+ scale_factor: a scaling factor to apply to the geometry that can be
520
+ used to enlarge or shrink the geometry. Useful when converting
521
+ Useful when converting the geometry to cm for use in neutronics
522
+ imprint: whether to imprint the geometry or not. Defaults to True as this is
523
+ normally needed to ensure the geometry is meshed correctly. However if
524
+ you know your geometry does not need imprinting you can set this to False
525
+ and this can save time.
526
+
527
+ Returns:
528
+ --------
529
+ gmsh : gmsh
530
+ The gmsh object after finalizing the mesh.
531
+ """
532
+
533
+ if Path(filename).suffix != ".vtk":
534
+ raise ValueError("Unstructured mesh filename must have a .vtk extension")
494
535
 
495
536
  assembly = cq.Assembly()
496
537
  for part in self.parts:
497
538
  assembly.add(part)
498
539
 
499
- imprinted_assembly, _ = cq.occ_impl.assembly.imprint(assembly)
540
+ if imprint:
541
+ imprinted_assembly, _ = cq.occ_impl.assembly.imprint(assembly)
542
+ else:
543
+ imprinted_assembly = assembly
500
544
 
501
545
  gmsh = init_gmsh()
502
546
 
@@ -510,12 +554,9 @@ class CadToDagmc:
510
554
  dimensions=3,
511
555
  )
512
556
 
513
- # gmesh writes out a vtk file that is converted by pymoab into a h5 file
514
- gmsh.write(filename + ".vtk")
515
-
516
- moab_core = core.Core()
517
- moab_core.load_file(filename + ".vtk")
518
- moab_core.write_file(filename)
557
+ # gmesh writes out a vtk file that is accepted by openmc.UnstructuredMesh
558
+ # The library argument must be set to "moab"
559
+ gmsh.write(filename)
519
560
 
520
561
  gmsh.finalize()
521
562
 
@@ -530,6 +571,7 @@ class CadToDagmc:
530
571
  dimensions: int = 2,
531
572
  method: str = "file",
532
573
  scale_factor: float = 1.0,
574
+ imprint: bool = True,
533
575
  ):
534
576
  """Saves a GMesh msh file of the geometry in either 2D surface mesh or
535
577
  3D volume mesh.
@@ -552,13 +594,20 @@ class CadToDagmc:
552
594
  scale_factor: a scaling factor to apply to the geometry that can be
553
595
  used to enlarge or shrink the geometry. Useful when converting
554
596
  Useful when converting the geometry to cm for use in neutronics
597
+ imprint: whether to imprint the geometry or not. Defaults to True as this is
598
+ normally needed to ensure the geometry is meshed correctly. However if
599
+ you know your geometry does not need imprinting you can set this to False
600
+ and this can save time.
555
601
  """
556
602
 
557
603
  assembly = cq.Assembly()
558
604
  for part in self.parts:
559
605
  assembly.add(part)
560
606
 
561
- imprinted_assembly, _ = cq.occ_impl.assembly.imprint(assembly)
607
+ if imprint:
608
+ imprinted_assembly, _ = cq.occ_impl.assembly.imprint(assembly)
609
+ else:
610
+ imprinted_assembly = assembly
562
611
 
563
612
  gmsh = init_gmsh()
564
613
 
@@ -587,11 +636,11 @@ class CadToDagmc:
587
636
  implicit_complement_material_tag: str | None = None,
588
637
  method: str = "file",
589
638
  scale_factor: float = 1.0,
639
+ imprint: bool = True,
590
640
  ) -> str:
591
641
  """Saves a DAGMC h5m file of the geometry
592
642
 
593
643
  Args:
594
-
595
644
  filename (str, optional): the filename to use for the saved DAGMC file. Defaults to "dagmc.h5m".
596
645
  min_mesh_size (float, optional): the minimum size of mesh elements to use. Defaults to 1.
597
646
  max_mesh_size (float, optional): the maximum size of mesh elements to use. Defaults to 5.
@@ -610,6 +659,10 @@ class CadToDagmc:
610
659
  scale_factor: a scaling factor to apply to the geometry that can be
611
660
  used to enlarge or shrink the geometry. Useful when converting
612
661
  Useful when converting the geometry to cm for use in neutronics
662
+ imprint: whether to imprint the geometry or not. Defaults to True as this is
663
+ normally needed to ensure the geometry is meshed correctly. However if
664
+ you know your geometry does not need imprinting you can set this to False
665
+ and this can save time.
613
666
 
614
667
  Returns:
615
668
  str: the DAGMC filename saved
@@ -619,21 +672,27 @@ class CadToDagmc:
619
672
  for part in self.parts:
620
673
  assembly.add(part)
621
674
 
622
- imprinted_assembly, imprinted_solids_with_org_id = cq.occ_impl.assembly.imprint(assembly)
623
-
624
675
  original_ids = _get_ids_from_assembly(assembly)
625
- scrambled_ids = _get_ids_from_imprinted_assembly(imprinted_solids_with_org_id)
626
676
 
627
677
  # both id lists should be the same length as each other and the same
628
678
  # length as the self.material_tags
629
-
630
679
  if len(original_ids) != len(self.material_tags):
631
680
  msg = f"Number of volumes {len(original_ids)} is not equal to number of material tags {len(self.material_tags)}"
632
681
  raise ValueError(msg)
633
682
 
634
- material_tags_in_brep_order = order_material_ids_by_brep_order(
635
- original_ids, scrambled_ids, self.material_tags
636
- )
683
+ if imprint:
684
+ imprinted_assembly, imprinted_solids_with_org_id = cq.occ_impl.assembly.imprint(
685
+ assembly
686
+ )
687
+
688
+ scrambled_ids = _get_ids_from_imprinted_assembly(imprinted_solids_with_org_id)
689
+
690
+ material_tags_in_brep_order = order_material_ids_by_brep_order(
691
+ original_ids, scrambled_ids, self.material_tags
692
+ )
693
+ else:
694
+ material_tags_in_brep_order = self.material_tags
695
+ imprinted_assembly = assembly
637
696
 
638
697
  _check_material_tags(material_tags_in_brep_order, self.parts)
639
698
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cad_to_dagmc
3
- Version: 0.7.3
3
+ Version: 0.7.5
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
@@ -14,12 +14,12 @@ Description-Content-Type: text/markdown
14
14
  License-File: LICENSE
15
15
  Requires-Dist: trimesh
16
16
  Requires-Dist: networkx
17
- Requires-Dist: cadquery >=2.4.0
18
- Requires-Dist: numpy <=1.26.4
17
+ Requires-Dist: cadquery>=2.4.0
18
+ Requires-Dist: numpy<=1.26.4
19
19
  Requires-Dist: gmsh
20
20
  Provides-Extra: tests
21
- Requires-Dist: pytest ; extra == 'tests'
22
- Requires-Dist: vtk ; extra == 'tests'
21
+ Requires-Dist: pytest; extra == "tests"
22
+ Requires-Dist: vtk; extra == "tests"
23
23
 
24
24
 
25
25
  [![N|Python](https://www.python.org/static/community_logos/python-powered-w-100x40.png)](https://www.python.org)
@@ -0,0 +1,8 @@
1
+ _version.py,sha256=AfxYsOLHf-d9Yv9B0Y-QKGSJPkQBqceXnCr_lUKXMKM,411
2
+ cad_to_dagmc/__init__.py,sha256=fskHUTyCunSpnpJUvBfAYjx4uwDKXHTTiMP6GqnFRf0,494
3
+ cad_to_dagmc/core.py,sha256=AfYKmrGCFcXZnsxCW72rdSAJY4kvffk1MTG4uURH-cw,27768
4
+ cad_to_dagmc-0.7.5.dist-info/LICENSE,sha256=B8kznH_777JVNZ3HOKDc4Tj24F7wJ68ledaNYeL9sCw,1070
5
+ cad_to_dagmc-0.7.5.dist-info/METADATA,sha256=okv56zxnjveO_HMC58bd8gO27vLZ_TXKsY5r1N0hVpw,7937
6
+ cad_to_dagmc-0.7.5.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
7
+ cad_to_dagmc-0.7.5.dist-info/top_level.txt,sha256=zTi8C64SEBsE5WOtPovnxhOzt-E6Oc5nC3RW6M_5aEA,22
8
+ cad_to_dagmc-0.7.5.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.5.0)
2
+ Generator: setuptools (75.6.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,8 +0,0 @@
1
- _version.py,sha256=9Y_dpdWykJt40jFoLa3Q4GkYvOMvJ1Y09SkdBJZvTM4,411
2
- cad_to_dagmc/__init__.py,sha256=fskHUTyCunSpnpJUvBfAYjx4uwDKXHTTiMP6GqnFRf0,494
3
- cad_to_dagmc/core.py,sha256=_5q_nL_I95JlR1EOAGrG38jMN5SPPZYR86Icg-5At2s,24522
4
- cad_to_dagmc-0.7.3.dist-info/LICENSE,sha256=B8kznH_777JVNZ3HOKDc4Tj24F7wJ68ledaNYeL9sCw,1070
5
- cad_to_dagmc-0.7.3.dist-info/METADATA,sha256=L5xUGum0Sz5YlvxleYPlOpbLIRrMtuX5Gnas6diRRTM,7941
6
- cad_to_dagmc-0.7.3.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
7
- cad_to_dagmc-0.7.3.dist-info/top_level.txt,sha256=zTi8C64SEBsE5WOtPovnxhOzt-E6Oc5nC3RW6M_5aEA,22
8
- cad_to_dagmc-0.7.3.dist-info/RECORD,,