Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full model DAGMC faceting via CAD-to-DAGMC #180

Merged
merged 25 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a626684
Update conda environment file and documentation to reflect changes in…
connoramoreno Dec 2, 2024
5262b74
Store magnet CAD solids in MagnetSet class object
connoramoreno Dec 2, 2024
2bdb60a
Modify storage of magnet coil CAD solids
connoramoreno Dec 2, 2024
b620060
Rename method that exports DAGMC models via Cubit
connoramoreno Dec 2, 2024
b2684bf
Add Stellarmesh model creation and export methods
connoramoreno Dec 2, 2024
c27d6a9
Separate concerns for Stellarmesh model creation
connoramoreno Dec 2, 2024
2ca79b9
Update tests
connoramoreno Dec 2, 2024
ebf95f9
Improve API
connoramoreno Dec 2, 2024
4b28416
Convert new workflow to one using CAD-to-DAGMC
connoramoreno Dec 12, 2024
ad3c7da
Update examples
connoramoreno Dec 12, 2024
78d6b4f
Revert installation instructions
connoramoreno Dec 12, 2024
f543715
Update syntax
connoramoreno Dec 12, 2024
bdc6a62
Skip imprinting in CAD-to-DAGMC routine
connoramoreno Jan 3, 2025
6caf33a
Update parastell/magnet_coils.py
connoramoreno Jan 16, 2025
7347d90
Change optional attributes to optional arguments in Cubit DAGMC export
connoramoreno Jan 16, 2025
7a58433
Change references of cf to cubit
connoramoreno Jan 16, 2025
c55b11b
Update examples and tests
connoramoreno Jan 16, 2025
770c67a
Restructure workflow for extraction of CAD solids and material tags
connoramoreno Jan 23, 2025
b3f693d
Add CAD-to-DAGMC example and rename Cubit example
connoramoreno Jan 23, 2025
68ee8f3
Remove extraneous argument from InVesselBuild.extract_solids_and_mat_…
connoramoreno Jan 23, 2025
ec7e121
Fix list storage
connoramoreno Jan 23, 2025
c43a63e
Update parastell/parastell.py
connoramoreno Jan 27, 2025
6c8ec28
Update parastell/parastell.py
connoramoreno Jan 27, 2025
951f086
Fix black formatting
connoramoreno Jan 27, 2025
f6fa1b1
Add IVB or MS solids/material tags to storage lists conditionally
connoramoreno Jan 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Examples/nwl_geom_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
split_chamber=False,
)
# Export in-vessel component files
stellarator.export_invessel_build(
export_cad_to_dagmc=False, export_dir=export_dir
)
stellarator.export_invessel_build(export_dir=export_dir)

# Define source mesh parameters
mesh_size = (11, 81, 61)
Expand All @@ -48,4 +46,4 @@
# Export DAGMC neutronics H5M file
stellarator.build_cubit_model(skip_imprint=True)
tag_surface(1, "vacuum")
stellarator.export_dagmc(filename="nwl_geom", export_dir=export_dir)
stellarator.export_cubit_dagmc(filename="nwl_geom", export_dir=export_dir)
82 changes: 82 additions & 0 deletions Examples/parastell_cad_to_dagmc_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import numpy as np

import parastell.parastell as ps


# Define directory to export all output files to
export_dir = ""
# Define plasma equilibrium VMEC file
vmec_file = "wout_vmec.nc"

# Instantiate ParaStell build
stellarator = ps.Stellarator(vmec_file)

# Define build parameters for in-vessel components
toroidal_angles = [0.0, 11.25, 22.5, 33.75, 45.0, 56.25, 67.5, 78.75, 90.0]
poloidal_angles = [0.0, 45.0, 90.0, 135.0, 180.0, 225.0, 270.0, 315.0, 360.0]
wall_s = 1.08

# Define a matrix of uniform unit thickness
uniform_unit_thickness = np.ones((len(toroidal_angles), len(poloidal_angles)))

radial_build_dict = {
"first_wall": {"thickness_matrix": uniform_unit_thickness * 5},
"breeder": {
"thickness_matrix": (
[
[75.0, 75.0, 75.0, 25.0, 25.0, 25.0, 75.0, 75.0, 75.0],
[75.0, 75.0, 75.0, 25.0, 25.0, 75.0, 75.0, 75.0, 75.0],
[75.0, 75.0, 25.0, 25.0, 75.0, 75.0, 75.0, 75.0, 75.0],
[65.0, 25.0, 25.0, 65.0, 75.0, 75.0, 75.0, 75.0, 65.0],
[45.0, 45.0, 75.0, 75.0, 75.0, 75.0, 75.0, 45.0, 45.0],
[65.0, 75.0, 75.0, 75.0, 75.0, 65.0, 25.0, 25.0, 65.0],
[75.0, 75.0, 75.0, 75.0, 75.0, 25.0, 25.0, 75.0, 75.0],
[75.0, 75.0, 75.0, 75.0, 25.0, 25.0, 75.0, 75.0, 75.0],
[75.0, 75.0, 75.0, 25.0, 25.0, 25.0, 75.0, 75.0, 75.0],
]
)
},
"back_wall": {"thickness_matrix": uniform_unit_thickness * 5},
"shield": {"thickness_matrix": uniform_unit_thickness * 50},
"vacuum_vessel": {
"thickness_matrix": uniform_unit_thickness * 10,
"mat_tag": "vac_vessel",
},
}
# Construct in-vessel components
stellarator.construct_invessel_build(
toroidal_angles, poloidal_angles, wall_s, radial_build_dict
)
# Export in-vessel component files
stellarator.export_invessel_build(export_dir=export_dir)

# Define build parameters for magnet coils
coils_file = "coils.example"
width = 40.0
thickness = 50.0
toroidal_extent = 90.0
# Construct magnets
stellarator.construct_magnets(
coils_file, width, thickness, toroidal_extent, sample_mod=6
)
# Export magnet files
stellarator.export_magnets(
step_filename="magnets",
export_mesh=True,
mesh_filename="magnet_mesh",
export_dir=export_dir,
)

# Define source mesh parameters
mesh_size = (11, 81, 61)
toroidal_extent = 90.0
# Construct source
stellarator.construct_source_mesh(mesh_size, toroidal_extent)
# Export source file
stellarator.export_source_mesh(filename="source_mesh", export_dir=export_dir)

# Build Cubit model of Parastell Components
stellarator.build_cad_to_dagmc_model()

# Export DAGMC neutronics H5M file
stellarator.export_cad_to_dagmc(filename="dagmc", export_dir=export_dir)
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@
toroidal_angles, poloidal_angles, wall_s, radial_build_dict
)
# Export in-vessel component files
stellarator.export_invessel_build(
export_cad_to_dagmc=False, export_dir=export_dir
)
stellarator.export_invessel_build(export_dir=export_dir)

# Define build parameters for magnet coils
coils_file = "coils.example"
Expand Down Expand Up @@ -81,4 +79,4 @@
stellarator.build_cubit_model(skip_imprint=False)

# Export DAGMC neutronics H5M file
stellarator.export_dagmc(filename="dagmc", export_dir=export_dir)
stellarator.export_cubit_dagmc(filename="dagmc", export_dir=export_dir)
2 changes: 1 addition & 1 deletion Examples/radial_distance_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@
stellarator.build_cubit_model(skip_imprint=False)

# Export DAGMC neutronics H5M file
stellarator.export_dagmc(filename="dagmc", export_dir=export_dir)
stellarator.export_cubit_dagmc(filename="dagmc", export_dir=export_dir)
10 changes: 4 additions & 6 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ conda install -c conda-forge mamba

The subsequent mamba and pip install commands should be run with this environment activated.

Mamba install ParaStell and PyStell-UW Python dependencies available on `conda-forge`:
Mamba install ParaStell Python dependencies available on `conda-forge`:

```
mamba install -c conda-forge numpy scipy scikit-learn cadquery cad_to_dagmc matplotlib
mamba install -c conda-forge moab=5.5.0=nompi_tempest_*
mamba install -c conda-forge pip numpy=1.26.4 scipy scikit-learn cadquery moab=5.5.1=nompi_tempest_* cad_to_dagmc ca-certificates certifi openssl openmc=0.15.0=dagmc_nompi_* matplotlib
```

Pip install the remaining ParaStell and PyStell-UW Python dependencies:
Pip install the remaining ParaStell Python dependencies:

```
pip install netCDF4
pip install pyyaml
pip install netCDF4 pyyaml pytest git+https://github.com/aaroncbader/pystell_uw.git
```
4 changes: 2 additions & 2 deletions parastell/cubit_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ def tag_surface(surface_id, tag):


def export_dagmc_cubit(
anisotropic_ratio=100.0,
deviation_angle=5.0,
filename="dagmc",
export_dir="",
anisotropic_ratio=100.0,
deviation_angle=5.0,
delete_upon_export=True,
):
"""Exports DAGMC neutronics H5M file of ParaStell components via Coreform
Expand Down
48 changes: 12 additions & 36 deletions parastell/invessel_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import cubit
import cadquery as cq
import cad_to_dagmc
import pystell.read_vmec as read_vmec

from . import log
Expand All @@ -15,12 +14,9 @@
normalize,
expand_list,
read_yaml_config,
filter_kwargs,
m2cm,
)

export_allowed_kwargs = ["export_cad_to_dagmc", "dagmc_filename"]


def orient_spline_surfaces(volume_id):
"""Extracts the inner and outer surface IDs for a given ParaStell in-vessel
Expand Down Expand Up @@ -316,35 +312,22 @@ def export_step(self, export_dir=""):
)
cq.exporters.export(component, str(export_path))

def export_cad_to_dagmc(self, dagmc_filename="dagmc", export_dir=""):
"""Exports DAGMC neutronics H5M file of ParaStell in-vessel components
via CAD-to-DAGMC.
def extract_solids_and_mat_tags(self):
"""Appends in-vessel component CadQuery solid objects and material
tags to corresponding input lists.

Arguments:
dagmc_filename (str): name of DAGMC output file, excluding '.h5m'
extension (optional, defaults to 'dagmc').
export_dir (str): directory to which to export the DAGMC output file
(optional, defaults to empty string).
Returns:
solids (list): list of in-vessel component CadQuery solid objects.
mat_tags (list): list of in-vessel component material tags.
"""
self._logger.info(
"Exporting DAGMC neutronics model of in-vessel components..."
)

model = cad_to_dagmc.CadToDagmc()
solids = []
mat_tags = []

for name, component in self.Components.items():
model.add_cadquery_object(
component,
material_tags=[
self.radial_build.radial_build[name]["mat_tag"]
],
)

export_path = Path(export_dir) / Path(dagmc_filename).with_suffix(
".h5m"
)
for name, solid in self.Components.items():
solids.append(solid)
mat_tags.append(self.radial_build.radial_build[name]["mat_tag"])

model.export_dagmc_h5m_file(filename=str(export_path))
return solids, mat_tags

def export_component_mesh(
self, components, mesh_size=5, import_dir="", export_dir=""
Expand Down Expand Up @@ -875,13 +858,6 @@ def generate_invessel_build():

invessel_build.export_step(export_dir=args.export_dir)

if invessel_build_dict["export_cad_to_dagmc"]:

invessel_build.export_cad_to_dagmc(
export_dir=args.export_dir,
**(filter_kwargs(invessel_build_dict, ["dagmc_filename"])),
)


if __name__ == "__main__":
generate_invessel_build()
19 changes: 16 additions & 3 deletions parastell/magnet_coils.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ def build_magnet_coils(self):

self._cut_magnets()

self.coil_solids = [coil.solid for coil in self.magnet_coils]

def import_step_cubit(self):
"""Import STEP file for magnet set into Coreform Cubit."""
first_vol_id = 1
Expand Down Expand Up @@ -268,11 +270,22 @@ def export_step(self, step_filename="magnet_set", export_dir=""):
self.step_filename
).with_suffix(".step")

coil_set = cq.Compound.makeCompound(
[coil.solid for coil in self.magnet_coils]
)
coil_set = cq.Compound.makeCompound(self.coil_solids)
cq.exporters.export(coil_set, str(export_path))

def extract_solids_and_mat_tag(self):
"""Appends magnet set CadQuery solid objects and material tag to
corresponding input lists.

Returns:
solids (list): list of magnet set CadQuery solid objects.
mat_tags (list): list of magnet set material tags.
"""
solids = self.coil_solids
mat_tags = [self.mat_tag] * len(self.coil_solids)

return solids, mat_tags

def mesh_magnets(self, min_size=20.0, max_size=50.0, max_gradient=1.5):
"""Creates tetrahedral mesh of magnet volumes via Coreform Cubit.

Expand Down
Loading
Loading