diff --git a/.github/workflows/ci_with_benchmarks.yml b/.github/workflows/ci_with_benchmarks.yml index dc7f904..c5cc50f 100644 --- a/.github/workflows/ci_with_benchmarks.yml +++ b/.github/workflows/ci_with_benchmarks.yml @@ -37,7 +37,7 @@ jobs: sudo apt-get upgrade -y sudo apt-get install -y libgl1-mesa-glx libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev libosmesa6 libosmesa6-dev libgles2-mesa-dev libarchive-dev libpangocairo-1.0-0 mamba activate - mamba install -y -c cadquery -c conda-forge moab gmsh python-gmsh cadquery=master "openmc=0.13.3=dagmc*nompi*" + mamba install -y -c conda-forge moab gmsh python-gmsh cadquery=2.4.0 "openmc=0.14.0=dagmc*nompi*" python -m pip install --upgrade pip python -m pip install cad_to_dagmc openmc_data_downloader openmc_data_downloader -l ENDFB-7.1-NNDC -i Fe56 Be9 diff --git a/.github/workflows/ci_with_install.yml b/.github/workflows/ci_with_install.yml index 8064ecb..8939686 100644 --- a/.github/workflows/ci_with_install.yml +++ b/.github/workflows/ci_with_install.yml @@ -1,9 +1,4 @@ -# This CI will launch a Docker image that contains all the dependencies required -# within that image the pytest test suite is run -# container: -# image: continuumio/miniconda3:23.3.1-0 - name: CI with install on: @@ -40,11 +35,13 @@ jobs: sudo apt-get upgrade -y sudo apt-get install -y libgl1-mesa-glx libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev libosmesa6 libosmesa6-dev libgles2-mesa-dev libarchive-dev libpangocairo-1.0-0 mamba activate - mamba install -y -c cadquery -c conda-forge moab gmsh python-gmsh cadquery=master + mamba create --name cad_to_dagmc python=3.12 + mamba activate cad_to_dagmc + mamba install -y -c conda-forge moab gmsh python-gmsh ocp=7.7.2.0 cadquery=2.4.0 python -m pip install --upgrade pip python -m pip install . python -c "import cad_to_dagmc" - mamba install -y -c conda-forge "openmc=0.13.3=dagmc*nompi*" + mamba install -y -c conda-forge "openmc=0.14.0=dagmc*nompi*" python -m pip install .[tests] pytest tests -v cd examples @@ -53,7 +50,8 @@ jobs: python cadquery_compound.py python cadquery_object_and_stp_file.py python cadquery_text.py - python curved_cadquery_object.py + python curved_cadquery_object_to_dagmc_surface_mesh.py + python curved_cadquery_object_to_dagmc_volume_mesh.py python multiple_cadquery_objects.py python multiple_stp_files.py python single_stp_file_multiple_volumes.py diff --git a/.github/workflows/ci_with_pip_install.yml b/.github/workflows/ci_with_pip_install.yml new file mode 100644 index 0000000..932617a --- /dev/null +++ b/.github/workflows/ci_with_pip_install.yml @@ -0,0 +1,57 @@ + +name: CI with pip install + +on: + pull_request: + branches: + - main + paths-ignore: + - 'docs/**' + - '.gitignore' + - '*.md' + - 'CITATION.cff' + - 'LICENSE.txt' + - 'readthedocs.yml' + push: + branches: + - main + +jobs: + testing: + runs-on: ubuntu-latest + container: + image: openmc/openmc:develop-dagmc + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: install non pypi dependencies + shell: bash + run: | + apt-get --allow-releaseinfo-change update + apt-get update -y + apt-get upgrade -y + apt-get install -y libgl1-mesa-glx libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev libosmesa6 libosmesa6-dev libgles2-mesa-dev libarchive-dev libpangocairo-1.0-0 libxcursor-dev libxft2 libxinerama-dev + apt install python3 + apt install python3-pip + python -m pip install --upgrade pip + python -m pip install gmsh + python -m pip install cadquery-ocp==7.7.2 + python -m pip install cadquery==2.4.0 + python -m pip install . + python -c "import cad_to_dagmc" + python -m pip install .[tests] + pytest tests -v + cd examples + python create_stp_files_for_examples.py + python cadquery_assembly.py + python cadquery_compound.py + python cadquery_object_and_stp_file.py + python cadquery_text.py + python curved_cadquery_object_to_dagmc_surface_mesh.py + python curved_cadquery_object_to_dagmc_volume_mesh.py + python multiple_cadquery_objects.py + python multiple_stp_files.py + python single_stp_file_multiple_volumes.py + python single_cadquery_object.py + python single_stp_file.py diff --git a/examples/cadquery_assembly.py b/examples/cadquery_assembly.py index 6de7acf..0dace22 100644 --- a/examples/cadquery_assembly.py +++ b/examples/cadquery_assembly.py @@ -10,5 +10,5 @@ assembly.add(result2) my_model = CadToDagmc() -my_model.add_cadquery_object(assembly, material_tags=["mat1", "mat2"]) -my_model.export_dagmc_h5m_file(min_mesh_size=0.5, max_mesh_size=1.0) +my_model.add_cadquery_object(assembly) +my_model.export_dagmc_h5m_file(min_mesh_size=0.5, max_mesh_size=1.0, material_tags=["mat1", "mat2"]) diff --git a/examples/cadquery_compound.py b/examples/cadquery_compound.py index aaa9573..bb58eb7 100644 --- a/examples/cadquery_compound.py +++ b/examples/cadquery_compound.py @@ -24,5 +24,5 @@ compound_of_shapes = cq.Compound.makeCompound([cq_shape_1.val(), cq_shape_2.val()]) my_model = CadToDagmc() -my_model.add_cadquery_object(object=compound_of_shapes, material_tags=["mat1", "mat2"]) -my_model.export_dagmc_h5m_file(max_mesh_size=0.2, min_mesh_size=0.1) +my_model.add_cadquery_object(object=compound_of_shapes) +my_model.export_dagmc_h5m_file(max_mesh_size=0.2, min_mesh_size=0.1, material_tags=["mat1", "mat2"]) diff --git a/examples/cadquery_object_and_stp_file.py b/examples/cadquery_object_and_stp_file.py index 1a96c17..e4d23e5 100644 --- a/examples/cadquery_object_and_stp_file.py +++ b/examples/cadquery_object_and_stp_file.py @@ -4,6 +4,13 @@ result = cq.Workplane("XY").moveTo(10, 0).box(3, 3, 0.5).edges("|Z").fillet(0.125) my_model = CadToDagmc() -my_model.add_cadquery_object(object=result, material_tags=["mat1"]) -my_model.add_stp_file(filename="single_cube.stp", material_tags=["mat2"], scale_factor=0.1) -my_model.export_dagmc_h5m_file(max_mesh_size=0.2, min_mesh_size=0.1) + +my_model.add_cadquery_object(result) + +my_model.add_stp_file(filename="single_cube.stp", scale_factor=0.1) + +my_model.export_dagmc_h5m_file( + max_mesh_size=0.2, + min_mesh_size=0.1, + material_tags=["mat1", "mat2"], +) diff --git a/examples/cadquery_text.py b/examples/cadquery_text.py index d69e710..8be66b2 100644 --- a/examples/cadquery_text.py +++ b/examples/cadquery_text.py @@ -5,8 +5,12 @@ my_model = CadToDagmc() -my_model.add_cadquery_object( - object=text, +my_model.add_cadquery_object(object=text) + +my_model.export_dagmc_h5m_file( + filename="cadquery_text.h5m", + max_mesh_size=0.2, + min_mesh_size=0.1, material_tags=[ "mat1", "mat2", @@ -15,5 +19,3 @@ "mat5", ], # 5 volumes one for each letter ) - -my_model.export_dagmc_h5m_file(filename="cadquery_text.h5m", max_mesh_size=0.2, min_mesh_size=0.1) diff --git a/examples/curved_cadquery_object.py b/examples/curved_cadquery_object_to_dagmc_surface_mesh.py similarity index 87% rename from examples/curved_cadquery_object.py rename to examples/curved_cadquery_object_to_dagmc_surface_mesh.py index 107b2e7..37dd70a 100644 --- a/examples/curved_cadquery_object.py +++ b/examples/curved_cadquery_object_to_dagmc_surface_mesh.py @@ -39,11 +39,11 @@ def gear(t, r1=4, r2=1): my_model = CadToDagmc() -my_model.add_cadquery_object( - result, - material_tags=["mat1"], -) +my_model.add_cadquery_object(result) my_model.export_dagmc_h5m_file( - filename="cadquery_objects_and_stp_files.h5m", max_mesh_size=1, min_mesh_size=0.1 + filename="cadquery_objects_and_stp_files.h5m", + max_mesh_size=1, + min_mesh_size=0.1, + material_tags=["mat1"], ) diff --git a/examples/multiple_cadquery_objects.py b/examples/multiple_cadquery_objects.py index a25e04a..6d8d4da 100644 --- a/examples/multiple_cadquery_objects.py +++ b/examples/multiple_cadquery_objects.py @@ -7,6 +7,6 @@ box_with_round_corners = cq.Workplane("XY").box(2, 1, 1) my_model = CadToDagmc() -my_model.add_cadquery_object(box, material_tags=["mat1"]) -my_model.add_cadquery_object(box_with_round_corners, material_tags=["mat2"]) -my_model.export_dagmc_h5m_file() +my_model.add_cadquery_object(box) +my_model.add_cadquery_object(box_with_round_corners) +my_model.export_dagmc_h5m_file(material_tags=["mat1", "mat2"]) diff --git a/examples/multiple_stp_files.py b/examples/multiple_stp_files.py index 8099094..9279f60 100644 --- a/examples/multiple_stp_files.py +++ b/examples/multiple_stp_files.py @@ -1,9 +1,12 @@ from cad_to_dagmc import CadToDagmc my_model = CadToDagmc() -my_model.add_stp_file("two_connected_cubes.stp", material_tags=["mat1", "mat2"]) -my_model.add_stp_file("single_sphere.stp", material_tags=["mat3"]) +my_model.add_stp_file("two_connected_cubes.stp") +my_model.add_stp_file("single_sphere.stp") my_model.export_dagmc_h5m_file( - max_mesh_size=1, min_mesh_size=0.5, implicit_complement_material_tag="air" + max_mesh_size=1, + min_mesh_size=0.5, + implicit_complement_material_tag="air", + material_tags=["mat1", "mat2", "mat3"], ) diff --git a/examples/single_cadquery_object.py b/examples/single_cadquery_object.py index b70923f..ba52ebd 100644 --- a/examples/single_cadquery_object.py +++ b/examples/single_cadquery_object.py @@ -4,5 +4,5 @@ result = sphere = cq.Workplane().moveTo(100, 0).sphere(5) my_model = CadToDagmc() -my_model.add_cadquery_object(result, material_tags=["mat1"]) -my_model.export_dagmc_h5m_file() +my_model.add_cadquery_object(result) +my_model.export_dagmc_h5m_file(material_tags=["mat1"]) diff --git a/examples/single_stp_file.py b/examples/single_stp_file.py index 93413eb..adbdc05 100644 --- a/examples/single_stp_file.py +++ b/examples/single_stp_file.py @@ -1,5 +1,5 @@ from cad_to_dagmc import CadToDagmc my_model = CadToDagmc() -my_model.add_stp_file("spline_extrude.stp", material_tags=["mat1"]) -my_model.export_dagmc_h5m_file() +my_model.add_stp_file("spline_extrude.stp") +my_model.export_dagmc_h5m_file(material_tags=["mat1"]) diff --git a/examples/single_stp_file_multiple_volumes.py b/examples/single_stp_file_multiple_volumes.py index 960adac..9fd9f0d 100644 --- a/examples/single_stp_file_multiple_volumes.py +++ b/examples/single_stp_file_multiple_volumes.py @@ -2,5 +2,5 @@ my_model = CadToDagmc() # the d and c from the word dagmc would be tagged with one material and the agm are tagged with another material -my_model.add_stp_file("text_dagmc.stp", material_tags=["mat1", "mat2", "mat2", "mat2", "mat1"]) -my_model.export_dagmc_h5m_file() +my_model.add_stp_file("text_dagmc.stp") +my_model.export_dagmc_h5m_file(material_tags=["mat1", "mat2", "mat2", "mat2", "mat1"]) diff --git a/examples/unsructured_volume_mesh/curved_cadquery_object_to_dagmc_volume_mesh.py b/examples/unsructured_volume_mesh/curved_cadquery_object_to_dagmc_volume_mesh.py new file mode 100644 index 0000000..a6b7d6b --- /dev/null +++ b/examples/unsructured_volume_mesh/curved_cadquery_object_to_dagmc_volume_mesh.py @@ -0,0 +1,62 @@ +from cad_to_dagmc import CadToDagmc +import cadquery as cq +from math import sin, cos, pi, floor + + +# define the generating function +def hypocycloid(t, r1, r2): + return ( + (r1 - r2) * cos(t) + r2 * cos(r1 / r2 * t - t), + (r1 - r2) * sin(t) + r2 * sin(-(r1 / r2 * t - t)), + ) + + +def epicycloid(t, r1, r2): + return ( + (r1 + r2) * cos(t) - r2 * cos(r1 / r2 * t + t), + (r1 + r2) * sin(t) - r2 * sin(r1 / r2 * t + t), + ) + + +def gear(t, r1=4, r2=1): + if (-1) ** (1 + floor(t / 2 / pi * (r1 / r2))) < 0: + return epicycloid(t, r1, r2) + else: + return hypocycloid(t, r1, r2) + + +# create the gear profile and extrude it +result = ( + cq.Workplane("XY") + .parametricCurve(lambda t: gear(t * 2 * pi, 6, 1)) + .twistExtrude(15, 90) + .faces(">Z") + .workplane() + .circle(2) + .cutThruAll() +) +assembly = cq.Assembly() +assembly.add(result) +assembly.save("twist.step") + +s = cq.Workplane("XY") +sPnts = [ + (2.75, 1.5), + (2.5, 1.75), + (2.0, 1.5), + (1.5, 1.0), + (1.0, 1.25), + (0.5, 1.0), + (0, 1.0), +] +r = s.lineTo(3.0, 0).lineTo(3.0, 1.0).spline(sPnts, includeCurrent=True).close() +result2 = r.extrude(-20) +assembly.add(result2) +assembly.save("twist_and_extrude.step") + +my_model = CadToDagmc() + +my_model.add_cadquery_object(result) +my_model.add_cadquery_object(result2) + +my_model.export_unstructured_mesh_file(filename="umesh.h5m", max_mesh_size=1, min_mesh_size=0.1) diff --git a/examples/unsructured_volume_mesh/simulate_unstrucutred_volume_mesh_with_openmc.py b/examples/unsructured_volume_mesh/simulate_unstrucutred_volume_mesh_with_openmc.py new file mode 100644 index 0000000..cc28b65 --- /dev/null +++ b/examples/unsructured_volume_mesh/simulate_unstrucutred_volume_mesh_with_openmc.py @@ -0,0 +1,66 @@ +# script assumes that "umesh.h5m" has been created by +# curved_cadquery_object_to_dagmc_volume_mesh.py has been + +import openmc + +umesh = openmc.UnstructuredMesh("umesh.h5m", library="moab") +mesh_filter = openmc.MeshFilter(umesh) +tally = openmc.Tally(name="t1") +tally.filters = [mesh_filter] +tally.scores = ["flux"] +tally.estimator = "tracklength" +my_tallies = openmc.Tallies([tally]) + + +mat1 = openmc.Material() +mat1.add_element("Pb", 84.2, percent_type="ao") +mat1.add_element( + "Li", + 15.8, + percent_type="ao", + enrichment=50.0, + enrichment_target="Li6", + enrichment_type="ao", +) +mat1.set_density("g/cm3", 11) +my_materials = openmc.Materials([mat1]) + +surf1 = openmc.Sphere(r=500, boundary_type="vacuum") +region1 = -surf1 + +cell1 = openmc.Cell(region=region1) +cell1.fill = mat1 + +my_geometry = openmc.Geometry([cell1]) + + +my_settings = openmc.Settings() +my_settings.batches = 10 +my_settings.inactive = 0 +my_settings.particles = 5000 +my_settings.run_mode = "fixed source" + +# Create a DT point source +my_source = openmc.Source() +# my_source = openmc.IndependentSource() +my_source.space = openmc.stats.Point((0, 0, 0)) +my_source.angle = openmc.stats.Isotropic() +my_source.energy = openmc.stats.Discrete([14e6], [1]) +my_settings.source = my_source + +model = openmc.model.Model(my_geometry, my_materials, my_settings, my_tallies) +sp_filename = model.run() + +sp = openmc.StatePoint(sp_filename) + +tally_result = sp.get_tally(name="t1") + + +# umesh = tally_result.find_filter(openmc.MeshFilter) +umesh_from_sp = sp.meshes[1] + +centroids = umesh_from_sp.centroids +mesh_vols = umesh_from_sp.volumes + +flux_mean = tally_result.get_values(scores=["flux"], value="mean").reshape(umesh_from_sp.dimension) +umesh_from_sp.write_data_to_vtk(filename="tally.vtk", datasets={"mean": flux_mean}) diff --git a/src/cad_to_dagmc/core.py b/src/cad_to_dagmc/core.py index 5924c16..31c2ac6 100644 --- a/src/cad_to_dagmc/core.py +++ b/src/cad_to_dagmc/core.py @@ -197,6 +197,7 @@ def _mesh_brep( min_mesh_size: float = 1, max_mesh_size: float = 10, mesh_algorithm: int = 1, + dimensions: int = 2, ): """Creates a conformal surface meshes of the volumes in a Brep file using Gmsh. @@ -209,6 +210,8 @@ def _mesh_brep( into gmsh.option.setNumber("Mesh.MeshSizeMax", max_mesh_size) mesh_algorithm: The Gmsh mesh algorithm number to use. Passed into 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() Returns: The resulting gmsh object and volumes @@ -223,7 +226,7 @@ def _mesh_brep( gmsh.option.setNumber("Mesh.Algorithm", mesh_algorithm) gmsh.option.setNumber("Mesh.MeshSizeMin", min_mesh_size) gmsh.option.setNumber("Mesh.MeshSizeMax", max_mesh_size) - gmsh.model.mesh.generate(2) + gmsh.model.mesh.generate(dimensions) return gmsh, volumes @@ -310,12 +313,10 @@ def _order_material_ids_by_brep_order(original_ids, scrambled_id, material_tags) class CadToDagmc: def __init__(self): self.parts = [] - self.material_tags = [] def add_stp_file( self, filename: str, - material_tags: typing.Iterable[str], scale_factor: float = 1.0, ): """Loads the parts from stp file into the model. @@ -337,23 +338,18 @@ def add_stp_file( scaled_part = part else: scaled_part = part.scale(scale_factor) - self.add_cadquery_object(object=scaled_part, material_tags=material_tags) + self.add_cadquery_object(object=scaled_part) def add_cadquery_object( self, object: typing.Union[ cq.assembly.Assembly, cq.occ_impl.shapes.Compound, cq.occ_impl.shapes.Solid ], - material_tags: typing.Iterable[str], ): """Loads the parts from CadQuery object into the model. Args: object: the cadquery object to convert - material_tags: the names of the DAGMC material tags to assign. - These will need to be in the same order as the volumes in the - STP file and match the material tags used in the neutronics - code (e.g. OpenMC). """ if isinstance(object, cq.assembly.Assembly): @@ -365,12 +361,36 @@ def add_cadquery_object( iterable_solids = object.val().Solids() self.parts = self.parts + iterable_solids - if len(iterable_solids) != len(material_tags): - msg = f"Number of volumes {len(iterable_solids)} is not equal to number of material tags {len(material_tags)}" - raise ValueError(msg) + def export_unstructured_mesh_file( + self, + filename: str = "umesh.h5m", + min_mesh_size: float = 1, + max_mesh_size: float = 5, + mesh_algorithm: int = 1, + ): - for material_tag in material_tags: - self.material_tags.append(material_tag) + assembly = cq.Assembly() + for part in self.parts: + assembly.add(part) + + imprinted_assembly, _ = cq.occ_impl.assembly.imprint(assembly) + + gmsh, volumes = _mesh_brep( + brep_object=imprinted_assembly.wrapped._address(), + min_mesh_size=min_mesh_size, + max_mesh_size=max_mesh_size, + mesh_algorithm=mesh_algorithm, + dimensions=3, + ) + + # gmesh writes out a vtk file that is converted by pymoab into a h5 file + gmsh.write(filename + ".vtk") + + moab_core = core.Core() + moab_core.load_file(filename + ".vtk") + moab_core.write_file(filename) + + gmsh.finalize() def export_gmsh_mesh_file( self, @@ -378,14 +398,18 @@ def export_gmsh_mesh_file( min_mesh_size: float = 1, max_mesh_size: float = 5, mesh_algorithm: int = 1, + dimensions: int = 2, ): - """Saves a GMesh msh file of the geometry + """Saves a GMesh msh file of the geometry in either 2D surface mesh or + 3D volume mesh. Args: filename min_mesh_size: the minimum size of mesh elements to use. max_mesh_size: the maximum size of mesh elements to use. mesh_algorithm: the gmsh mesh algorithm to use. + dimensions: The number of dimensions, 2 for a surface mesh 3 for a + volume mesh. Passed to gmsh.model.mesh.generate() """ assembly = cq.Assembly() @@ -399,16 +423,16 @@ def export_gmsh_mesh_file( min_mesh_size=min_mesh_size, max_mesh_size=max_mesh_size, mesh_algorithm=mesh_algorithm, + dimensions=dimensions, ) - _mesh_to_h5m_in_memory_method(volumes=volumes) - gmsh.write(filename) gmsh.finalize() def export_dagmc_h5m_file( self, + material_tags: typing.Iterable[str], filename: str = "dagmc.h5m", min_mesh_size: float = 1, max_mesh_size: float = 5, @@ -422,6 +446,10 @@ def export_dagmc_h5m_file( min_mesh_size: the minimum size of mesh elements to use. max_mesh_size: the maximum size of mesh elements to use. mesh_algorithm: the gmsh mesh algorithm to use. + material_tags: the names of the DAGMC material tags to assign. + These will need to be in the same order as the volumes in the + geometry geometry added (STP file and CadQuery objects) and + match the material tags used in the neutronics code (e.g. OpenMC). implicit_complement_material_tag: the name of the material tag to use for the implicit complement (void space). Defaults to None which is a vacuum. @@ -438,12 +466,16 @@ def export_dagmc_h5m_file( # both id lists should be the same length as each other and the same # length as the self.material_tags + if len(original_ids) != len(material_tags): + msg = f"Number of volumes {len(original_ids)} is not equal to number of material tags {len(material_tags)}" + raise ValueError(msg) + material_tags_in_brep_order = _order_material_ids_by_brep_order( - original_ids, scrambled_ids, self.material_tags + original_ids, scrambled_ids, material_tags ) gmsh, volumes = _mesh_brep( - brep_object=imprinted_assembly.wrapped._address(), + brep_object=imprinted_assembly.wrapped._address(), # in memory address min_mesh_size=min_mesh_size, max_mesh_size=max_mesh_size, mesh_algorithm=mesh_algorithm, diff --git a/tests/test_file_creation.py b/tests/test_file_creation.py index e76f61b..38e079d 100644 --- a/tests/test_file_creation.py +++ b/tests/test_file_creation.py @@ -50,10 +50,12 @@ def test_h5m_with_single_volume_list(): h5m_file = "tests/single_cube.h5m" my_model = CadToDagmc() - my_model.add_stp_file(filename="tests/single_cube.stp", material_tags=["mat1"]) - my_model.export_dagmc_h5m_file(filename=h5m_file) + my_model.add_stp_file(filename="tests/single_cube.stp") + my_model.export_dagmc_h5m_file(filename=h5m_file, material_tags=["mat1"]) my_model.export_gmsh_mesh_file(filename="test.msh") assert Path("test.msh").is_file() + my_model.export_gmsh_mesh_file(filename="test3d.msh", dimensions=3) + assert Path("test3d.msh").is_file() assert get_volumes_and_materials_from_h5m(h5m_file) == {1: "mat:mat1"} @@ -63,8 +65,8 @@ def test_h5m_with_single_volume_2(): h5m_file = "tests/curved_extrude.h5m" my_model = CadToDagmc() - my_model.add_stp_file(filename="tests/curved_extrude.stp", material_tags=["mat1"]) - my_model.export_dagmc_h5m_file(filename=h5m_file) + my_model.add_stp_file(filename="tests/curved_extrude.stp") + my_model.export_dagmc_h5m_file(filename=h5m_file, material_tags=["mat1"]) assert get_volumes_and_materials_from_h5m(h5m_file) == {1: "mat:mat1"} @@ -108,11 +110,11 @@ def test_h5m_with_multi_volume_touching(): ] for stp_file, mat_tags, h5m_file in zip(stp_files, material_tags, h5m_files): my_model = CadToDagmc() - my_model.add_stp_file(stp_file, material_tags=mat_tags) + my_model.add_stp_file(stp_file) assert my_model.material_tags == mat_tags - my_model.export_dagmc_h5m_file(filename=h5m_file) + my_model.export_dagmc_h5m_file(filename=h5m_file, material_tags=mat_tags) tags_dict = {} for counter, loop_mat_tag in enumerate(mat_tags, 1): @@ -143,9 +145,12 @@ def test_cq_compound(): compound_of_workplanes = cq.Compound.makeCompound([cq_shape_1.val(), cq_shape_2.val()]) my_model = CadToDagmc() - my_model.add_cadquery_object(object=compound_of_workplanes, material_tags=["mat1", "mat2"]) + my_model.add_cadquery_object(object=compound_of_workplanes) my_model.export_dagmc_h5m_file( - filename="compound_dagmc.h5m", max_mesh_size=0.2, min_mesh_size=0.1 + filename="compound_dagmc.h5m", + max_mesh_size=0.2, + min_mesh_size=0.1, + material_tags=["mat1", "mat2"], ) assert Path("compound_dagmc.h5m").is_file() @@ -161,10 +166,13 @@ def test_gmsh_mesh_with_single_volume_list(): gmsh_mesh_file = "tests/single_cube.msh" my_model = CadToDagmc() - my_model.add_stp_file(filename="tests/single_cube.stp", material_tags=["mat1"]) + my_model.add_stp_file(filename="tests/single_cube.stp") my_model.export_gmsh_mesh_file(filename=gmsh_mesh_file) my_model.export_gmsh_mesh_file(filename="test2.msh") assert Path("test2.msh").is_file() + assert Path("tests/single_cube.msh").is_file() + my_model.export_gmsh_mesh_file(filename="test2_3d.msh", dimensions=3) + assert Path("test2_3d.msh").is_file() def test_gmsh_mesh_with_single_volume_2(): @@ -173,7 +181,7 @@ def test_gmsh_mesh_with_single_volume_2(): gmsh_mesh_file = "tests/curved_extrude.msh" my_model = CadToDagmc() - my_model.add_stp_file(filename="tests/curved_extrude.stp", material_tags=["mat1"]) + my_model.add_stp_file(filename="tests/curved_extrude.stp") my_model.export_gmsh_mesh_file(filename=gmsh_mesh_file) @@ -189,16 +197,10 @@ def test_gmsh_mesh_with_multi_volume_not_touching(): ] for stp_file, mat_tags, gmsh_mesh_file in zip(stp_files, material_tags, gmsh_mesh_files): my_model = CadToDagmc() - my_model.add_stp_file(filename=stp_file, material_tags=mat_tags) - - assert my_model.material_tags == mat_tags + my_model.add_stp_file(filename=stp_file) my_model.export_gmsh_mesh_file(filename=gmsh_mesh_file) - tags_dict = {} - for counter, loop_mat_tag in enumerate(mat_tags, 1): - tags_dict[counter] = f"mat:{loop_mat_tag}" - def test_gmsh_mesh_with_multi_volume_touching(): stp_files = [ @@ -215,9 +217,7 @@ def test_gmsh_mesh_with_multi_volume_touching(): ] for stp_file, mat_tags, gmsh_mesh_file in zip(stp_files, material_tags, gmsh_mesh_files): my_model = CadToDagmc() - my_model.add_stp_file(stp_file, material_tags=mat_tags) - - assert my_model.material_tags == mat_tags + my_model.add_stp_file(stp_file) my_model.export_gmsh_mesh_file(filename=gmsh_mesh_file) diff --git a/tests/test_h5m_in_transport.py b/tests/test_h5m_in_transport.py index 9db7e09..ae82a29 100644 --- a/tests/test_h5m_in_transport.py +++ b/tests/test_h5m_in_transport.py @@ -127,9 +127,11 @@ def test_transport_result_h5m_with_2_sep_volumes(): # cq.Assembly().add(workplane1).add(workplane2) my_model = CadToDagmc() - my_model.add_cadquery_object(workplane1, material_tags=[material_tags[0]]) - my_model.add_cadquery_object(workplane2, material_tags=[material_tags[1]]) - my_model.export_dagmc_h5m_file(filename=h5m_filename) + my_model.add_cadquery_object(workplane1) + my_model.add_cadquery_object(workplane2) + my_model.export_dagmc_h5m_file( + filename=h5m_filename, material_tags=[material_tags[0], material_tags[1]] + ) transport_particles_on_h5m_geometry( h5m_filename=h5m_filename, @@ -146,8 +148,8 @@ def test_transport_result_h5m_with_1_volumes(): workplane1 = cq.Workplane("XY").cylinder(height=10, radius=4) my_model = CadToDagmc() - my_model.add_cadquery_object(workplane1, material_tags=[material_tags[0]]) - my_model.export_dagmc_h5m_file(filename=h5m_filename) + my_model.add_cadquery_object(workplane1) + my_model.export_dagmc_h5m_file(filename=h5m_filename, material_tags=[material_tags[0]]) transport_particles_on_h5m_geometry( h5m_filename=h5m_filename, @@ -165,9 +167,11 @@ def test_transport_result_h5m_with_2_joined_volumes(): workplane2 = cq.Workplane("XY").cylinder(height=10, radius=5).cut(workplane1) my_model = CadToDagmc() - my_model.add_cadquery_object(workplane1, material_tags=[material_tags[0]]) - my_model.add_cadquery_object(workplane2, material_tags=[material_tags[1]]) - my_model.export_dagmc_h5m_file(filename=h5m_filename) + my_model.add_cadquery_object(workplane1) + my_model.add_cadquery_object(workplane2) + my_model.export_dagmc_h5m_file( + filename=h5m_filename, material_tags=[material_tags[0], material_tags[1]] + ) transport_particles_on_h5m_geometry( h5m_filename="h5m_from_in_memory_method.h5m", diff --git a/tests/test_python_api.py b/tests/test_python_api.py index 6b7c40d..aa14765 100644 --- a/tests/test_python_api.py +++ b/tests/test_python_api.py @@ -48,25 +48,28 @@ def test_max_mesh_size_impacts_file_size(): sphere = cq.Workplane().sphere(100) c2d = CadToDagmc() - c2d.add_cadquery_object(sphere, ["m1"]) + c2d.add_cadquery_object(sphere) os.system("rm *.h5m") c2d.export_dagmc_h5m_file( min_mesh_size=10, max_mesh_size=20, mesh_algorithm=1, filename="test_10_30.h5m", + material_tags=["m1"], ) c2d.export_dagmc_h5m_file( min_mesh_size=20, max_mesh_size=30, mesh_algorithm=1, filename="test_20_30.h5m", + material_tags=["m1"], ) c2d.export_dagmc_h5m_file( min_mesh_size=20, max_mesh_size=25, mesh_algorithm=1, filename="test_20_25.h5m", + material_tags=["m1"], ) assert Path("test_10_30.h5m").is_file() @@ -88,14 +91,16 @@ def test_h5m_file_tags(): sphere3 = cq.Workplane().moveTo(-100, -100).sphere(20) c2d = CadToDagmc() - c2d.add_cadquery_object(sphere1, ["mat1"]) - c2d.add_cadquery_object(sphere2, ["mat2"]) - c2d.add_cadquery_object(sphere3, ["mat3"]) + c2d.add_cadquery_object(sphere1) + c2d.add_cadquery_object(sphere2) + c2d.add_cadquery_object(sphere3) test_h5m_filename = "test_dagmc.h5m" os.system(f"rm {test_h5m_filename}") - returned_filename = c2d.export_dagmc_h5m_file(test_h5m_filename) + returned_filename = c2d.export_dagmc_h5m_file( + filename=test_h5m_filename, material_tags=["mat1", "mat2", "mat3"] + ) assert Path(test_h5m_filename).is_file() assert Path(returned_filename).is_file()