cad-to-dagmc 0.7.4__py3-none-any.whl → 0.7.6__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 +2 -2
- cad_to_dagmc/core.py +75 -17
- {cad_to_dagmc-0.7.4.dist-info → cad_to_dagmc-0.7.6.dist-info}/METADATA +1 -1
- cad_to_dagmc-0.7.6.dist-info/RECORD +8 -0
- cad_to_dagmc-0.7.4.dist-info/RECORD +0 -8
- {cad_to_dagmc-0.7.4.dist-info → cad_to_dagmc-0.7.6.dist-info}/LICENSE +0 -0
- {cad_to_dagmc-0.7.4.dist-info → cad_to_dagmc-0.7.6.dist-info}/WHEEL +0 -0
- {cad_to_dagmc-0.7.4.dist-info → cad_to_dagmc-0.7.6.dist-info}/top_level.txt +0 -0
_version.py
CHANGED
cad_to_dagmc/core.py
CHANGED
|
@@ -5,6 +5,7 @@ import numpy as np
|
|
|
5
5
|
from cadquery import importers
|
|
6
6
|
from pymoab import core, types
|
|
7
7
|
import tempfile
|
|
8
|
+
import warnings
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
def _define_moab_core_and_tags() -> tuple[core.Core, dict]:
|
|
@@ -76,6 +77,7 @@ def _vertices_to_h5m(
|
|
|
76
77
|
triangles:
|
|
77
78
|
material_tags:
|
|
78
79
|
h5m_filename:
|
|
80
|
+
implicit_complement_material_tag:
|
|
79
81
|
"""
|
|
80
82
|
|
|
81
83
|
if len(material_tags) != len(triangles_by_solid_by_face):
|
|
@@ -184,7 +186,15 @@ def _vertices_to_h5m(
|
|
|
184
186
|
|
|
185
187
|
moab_core.add_entities(file_set, all_sets)
|
|
186
188
|
|
|
187
|
-
|
|
189
|
+
# makes the folder if it does not exist
|
|
190
|
+
if Path(h5m_filename).parent:
|
|
191
|
+
Path(h5m_filename).parent.mkdir(parents=True, exist_ok=True)
|
|
192
|
+
|
|
193
|
+
# moab_core.write_file only accepts strings
|
|
194
|
+
if isinstance(h5m_filename, Path):
|
|
195
|
+
moab_core.write_file(str(h5m_filename))
|
|
196
|
+
else:
|
|
197
|
+
moab_core.write_file(h5m_filename)
|
|
188
198
|
|
|
189
199
|
print(f"written DAGMC file {h5m_filename}")
|
|
190
200
|
|
|
@@ -230,8 +240,7 @@ def _mesh_brep(
|
|
|
230
240
|
mesh_algorithm: int = 1,
|
|
231
241
|
dimensions: int = 2,
|
|
232
242
|
):
|
|
233
|
-
"""Creates a conformal surface meshes of the volumes in a Brep file using
|
|
234
|
-
Gmsh.
|
|
243
|
+
"""Creates a conformal surface meshes of the volumes in a Brep file using Gmsh.
|
|
235
244
|
|
|
236
245
|
Args:
|
|
237
246
|
occ_shape: the occ_shape of the Brep file to convert
|
|
@@ -339,6 +348,12 @@ def _check_material_tags(material_tags, iterable_solids):
|
|
|
339
348
|
if not isinstance(material_tag, str):
|
|
340
349
|
msg = f"material_tags should be an iterable of strings."
|
|
341
350
|
raise ValueError(msg)
|
|
351
|
+
if len(material_tag) > 28:
|
|
352
|
+
msg = (
|
|
353
|
+
f"Material tag {material_tag} is too long. DAGMC will truncate this material tag "
|
|
354
|
+
f"to 28 characters. The resulting tag in the h5m file will be {material_tag[:28]}"
|
|
355
|
+
)
|
|
356
|
+
warnings.warn(msg)
|
|
342
357
|
|
|
343
358
|
|
|
344
359
|
def order_material_ids_by_brep_order(original_ids, scrambled_id, material_tags):
|
|
@@ -357,6 +372,7 @@ class MeshToDagmc:
|
|
|
357
372
|
|
|
358
373
|
# TODO add export_unstructured_mesh_file
|
|
359
374
|
# TODO add add_gmsh_msh_file
|
|
375
|
+
# TODO test for exports result in files
|
|
360
376
|
|
|
361
377
|
def export_dagmc_h5m_file(
|
|
362
378
|
self,
|
|
@@ -491,6 +507,7 @@ class CadToDagmc:
|
|
|
491
507
|
mesh_algorithm: int = 1,
|
|
492
508
|
method: str = "file",
|
|
493
509
|
scale_factor: float = 1.0,
|
|
510
|
+
imprint: bool = True,
|
|
494
511
|
):
|
|
495
512
|
"""
|
|
496
513
|
Exports an unstructured mesh file in VTK format for use with openmc.UnstructuredMesh.
|
|
@@ -518,6 +535,10 @@ class CadToDagmc:
|
|
|
518
535
|
scale_factor: a scaling factor to apply to the geometry that can be
|
|
519
536
|
used to enlarge or shrink the geometry. Useful when converting
|
|
520
537
|
Useful when converting the geometry to cm for use in neutronics
|
|
538
|
+
imprint: whether to imprint the geometry or not. Defaults to True as this is
|
|
539
|
+
normally needed to ensure the geometry is meshed correctly. However if
|
|
540
|
+
you know your geometry does not need imprinting you can set this to False
|
|
541
|
+
and this can save time.
|
|
521
542
|
|
|
522
543
|
Returns:
|
|
523
544
|
--------
|
|
@@ -525,6 +546,8 @@ class CadToDagmc:
|
|
|
525
546
|
The gmsh object after finalizing the mesh.
|
|
526
547
|
"""
|
|
527
548
|
|
|
549
|
+
# gmesh writes out a vtk file that is accepted by openmc.UnstructuredMesh
|
|
550
|
+
# The library argument must be set to "moab"
|
|
528
551
|
if Path(filename).suffix != ".vtk":
|
|
529
552
|
raise ValueError("Unstructured mesh filename must have a .vtk extension")
|
|
530
553
|
|
|
@@ -532,7 +555,10 @@ class CadToDagmc:
|
|
|
532
555
|
for part in self.parts:
|
|
533
556
|
assembly.add(part)
|
|
534
557
|
|
|
535
|
-
|
|
558
|
+
if imprint:
|
|
559
|
+
imprinted_assembly, _ = cq.occ_impl.assembly.imprint(assembly)
|
|
560
|
+
else:
|
|
561
|
+
imprinted_assembly = assembly
|
|
536
562
|
|
|
537
563
|
gmsh = init_gmsh()
|
|
538
564
|
|
|
@@ -546,9 +572,15 @@ class CadToDagmc:
|
|
|
546
572
|
dimensions=3,
|
|
547
573
|
)
|
|
548
574
|
|
|
549
|
-
#
|
|
550
|
-
|
|
551
|
-
|
|
575
|
+
# makes the folder if it does not exist
|
|
576
|
+
if Path(filename).parent:
|
|
577
|
+
Path(filename).parent.mkdir(parents=True, exist_ok=True)
|
|
578
|
+
|
|
579
|
+
# gmsh.write only accepts strings
|
|
580
|
+
if isinstance(filename, Path):
|
|
581
|
+
gmsh.write(str(filename))
|
|
582
|
+
else:
|
|
583
|
+
gmsh.write(filename)
|
|
552
584
|
|
|
553
585
|
gmsh.finalize()
|
|
554
586
|
|
|
@@ -563,6 +595,7 @@ class CadToDagmc:
|
|
|
563
595
|
dimensions: int = 2,
|
|
564
596
|
method: str = "file",
|
|
565
597
|
scale_factor: float = 1.0,
|
|
598
|
+
imprint: bool = True,
|
|
566
599
|
):
|
|
567
600
|
"""Saves a GMesh msh file of the geometry in either 2D surface mesh or
|
|
568
601
|
3D volume mesh.
|
|
@@ -585,13 +618,20 @@ class CadToDagmc:
|
|
|
585
618
|
scale_factor: a scaling factor to apply to the geometry that can be
|
|
586
619
|
used to enlarge or shrink the geometry. Useful when converting
|
|
587
620
|
Useful when converting the geometry to cm for use in neutronics
|
|
621
|
+
imprint: whether to imprint the geometry or not. Defaults to True as this is
|
|
622
|
+
normally needed to ensure the geometry is meshed correctly. However if
|
|
623
|
+
you know your geometry does not need imprinting you can set this to False
|
|
624
|
+
and this can save time.
|
|
588
625
|
"""
|
|
589
626
|
|
|
590
627
|
assembly = cq.Assembly()
|
|
591
628
|
for part in self.parts:
|
|
592
629
|
assembly.add(part)
|
|
593
630
|
|
|
594
|
-
|
|
631
|
+
if imprint:
|
|
632
|
+
imprinted_assembly, _ = cq.occ_impl.assembly.imprint(assembly)
|
|
633
|
+
else:
|
|
634
|
+
imprinted_assembly = assembly
|
|
595
635
|
|
|
596
636
|
gmsh = init_gmsh()
|
|
597
637
|
|
|
@@ -605,7 +645,15 @@ class CadToDagmc:
|
|
|
605
645
|
dimensions=dimensions,
|
|
606
646
|
)
|
|
607
647
|
|
|
608
|
-
|
|
648
|
+
# makes the folder if it does not exist
|
|
649
|
+
if Path(filename).parent:
|
|
650
|
+
Path(filename).parent.mkdir(parents=True, exist_ok=True)
|
|
651
|
+
|
|
652
|
+
# gmsh.write only accepts strings
|
|
653
|
+
if isinstance(filename, Path):
|
|
654
|
+
gmsh.write(str(filename))
|
|
655
|
+
else:
|
|
656
|
+
gmsh.write(filename)
|
|
609
657
|
|
|
610
658
|
print(f"written GMSH mesh file {filename}")
|
|
611
659
|
|
|
@@ -620,11 +668,11 @@ class CadToDagmc:
|
|
|
620
668
|
implicit_complement_material_tag: str | None = None,
|
|
621
669
|
method: str = "file",
|
|
622
670
|
scale_factor: float = 1.0,
|
|
671
|
+
imprint: bool = True,
|
|
623
672
|
) -> str:
|
|
624
673
|
"""Saves a DAGMC h5m file of the geometry
|
|
625
674
|
|
|
626
675
|
Args:
|
|
627
|
-
|
|
628
676
|
filename (str, optional): the filename to use for the saved DAGMC file. Defaults to "dagmc.h5m".
|
|
629
677
|
min_mesh_size (float, optional): the minimum size of mesh elements to use. Defaults to 1.
|
|
630
678
|
max_mesh_size (float, optional): the maximum size of mesh elements to use. Defaults to 5.
|
|
@@ -643,6 +691,10 @@ class CadToDagmc:
|
|
|
643
691
|
scale_factor: a scaling factor to apply to the geometry that can be
|
|
644
692
|
used to enlarge or shrink the geometry. Useful when converting
|
|
645
693
|
Useful when converting the geometry to cm for use in neutronics
|
|
694
|
+
imprint: whether to imprint the geometry or not. Defaults to True as this is
|
|
695
|
+
normally needed to ensure the geometry is meshed correctly. However if
|
|
696
|
+
you know your geometry does not need imprinting you can set this to False
|
|
697
|
+
and this can save time.
|
|
646
698
|
|
|
647
699
|
Returns:
|
|
648
700
|
str: the DAGMC filename saved
|
|
@@ -652,21 +704,27 @@ class CadToDagmc:
|
|
|
652
704
|
for part in self.parts:
|
|
653
705
|
assembly.add(part)
|
|
654
706
|
|
|
655
|
-
imprinted_assembly, imprinted_solids_with_org_id = cq.occ_impl.assembly.imprint(assembly)
|
|
656
|
-
|
|
657
707
|
original_ids = _get_ids_from_assembly(assembly)
|
|
658
|
-
scrambled_ids = _get_ids_from_imprinted_assembly(imprinted_solids_with_org_id)
|
|
659
708
|
|
|
660
709
|
# both id lists should be the same length as each other and the same
|
|
661
710
|
# length as the self.material_tags
|
|
662
|
-
|
|
663
711
|
if len(original_ids) != len(self.material_tags):
|
|
664
712
|
msg = f"Number of volumes {len(original_ids)} is not equal to number of material tags {len(self.material_tags)}"
|
|
665
713
|
raise ValueError(msg)
|
|
666
714
|
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
715
|
+
if imprint:
|
|
716
|
+
imprinted_assembly, imprinted_solids_with_org_id = cq.occ_impl.assembly.imprint(
|
|
717
|
+
assembly
|
|
718
|
+
)
|
|
719
|
+
|
|
720
|
+
scrambled_ids = _get_ids_from_imprinted_assembly(imprinted_solids_with_org_id)
|
|
721
|
+
|
|
722
|
+
material_tags_in_brep_order = order_material_ids_by_brep_order(
|
|
723
|
+
original_ids, scrambled_ids, self.material_tags
|
|
724
|
+
)
|
|
725
|
+
else:
|
|
726
|
+
material_tags_in_brep_order = self.material_tags
|
|
727
|
+
imprinted_assembly = assembly
|
|
670
728
|
|
|
671
729
|
_check_material_tags(material_tags_in_brep_order, self.parts)
|
|
672
730
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
_version.py,sha256=YfWC5HL1qwRHd8dXdkHZTT_yZBvn1CZl5nECK7W3nWQ,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.6.dist-info/LICENSE,sha256=B8kznH_777JVNZ3HOKDc4Tj24F7wJ68ledaNYeL9sCw,1070
|
|
5
|
+
cad_to_dagmc-0.7.6.dist-info/METADATA,sha256=2NAu-K_ok2f5xUdatiXXXTi7hLhTtzO3pkFhvVDq6mo,7937
|
|
6
|
+
cad_to_dagmc-0.7.6.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
7
|
+
cad_to_dagmc-0.7.6.dist-info/top_level.txt,sha256=zTi8C64SEBsE5WOtPovnxhOzt-E6Oc5nC3RW6M_5aEA,22
|
|
8
|
+
cad_to_dagmc-0.7.6.dist-info/RECORD,,
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
_version.py,sha256=23GyHFOGbZ47N1N7nnKbPQ9DYbuR8l4JJZLlq4C_xKg,411
|
|
2
|
-
cad_to_dagmc/__init__.py,sha256=fskHUTyCunSpnpJUvBfAYjx4uwDKXHTTiMP6GqnFRf0,494
|
|
3
|
-
cad_to_dagmc/core.py,sha256=7L4HtFUc6C2_C5JG29FLiGXB6gaS7eQfgtNtTgp38bY,26414
|
|
4
|
-
cad_to_dagmc-0.7.4.dist-info/LICENSE,sha256=B8kznH_777JVNZ3HOKDc4Tj24F7wJ68ledaNYeL9sCw,1070
|
|
5
|
-
cad_to_dagmc-0.7.4.dist-info/METADATA,sha256=143eCryJu05KVSyW4xbIwnWkXJHiWf-GrlF5JnJ2tL4,7937
|
|
6
|
-
cad_to_dagmc-0.7.4.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
7
|
-
cad_to_dagmc-0.7.4.dist-info/top_level.txt,sha256=zTi8C64SEBsE5WOtPovnxhOzt-E6Oc5nC3RW6M_5aEA,22
|
|
8
|
-
cad_to_dagmc-0.7.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|