Skip to content

Commit

Permalink
clean up example
Browse files Browse the repository at this point in the history
  • Loading branch information
Edgar-21 committed Jan 27, 2025
1 parent e543f5d commit 20f5a1a
Showing 1 changed file with 56 additions and 43 deletions.
99 changes: 56 additions & 43 deletions Examples/pydagmc_example.py
Original file line number Diff line number Diff line change
@@ -1,74 +1,87 @@
# Parastell can also generate invessel components with PyMOAB and PyDAGMC.
# For complex geometry this may be more reliable than the CAD workflow, but
# results in faceted solids, rather than the smooth spline surfaces in the
# CAD workflow.
import numpy as np
import parastell.parastell as ps
from parastell.utils import merge_dagmc_files, enforce_helical_symmetry

ribs = 61
rib_pts = 63

toroidal_angles = np.linspace(0, 90, ribs)
poloidal_angles = np.linspace(0, 360, rib_pts)

challenge_thickness_matrix = enforce_helical_symmetry(
np.random.rand(ribs, rib_pts) * 100
)
wall_s = 1.08
from parastell.utils import merge_dagmc_files

# 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)

ones = np.ones((ribs, rib_pts))
# 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
# Use more points in the point cloud to smooth the ivb components
num_ribs = 150
num_rib_pts = 160

# 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": ones * 0.2,
"mat_tag": "iron",
},
"first_wall": {"thickness_matrix": uniform_unit_thickness * 5},
"breeder": {
"thickness_matrix": challenge_thickness_matrix,
"mat_tag": "iron",
},
"back_wall": {
"thickness_matrix": ones * 0.01,
"mat_tag": "iron",
},
"shield": {
"thickness_matrix": ones * 50,
"mat_tag": "iron",
"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 * 40},
"vacuum_vessel": {
"thickness_matrix": ones * 10,
"mat_tag": "tungsten",
},
"test_1": {
"thickness_matrix": ones * 0.1,
"mat_tag": "tungsten",
},
"test_": {
"thickness_matrix": ones * 5,
"mat_tag": "tungsten",
"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,
use_pydagmc=True,
num_ribs=ribs * 3,
num_rib_pts=rib_pts * 3,
num_ribs=num_ribs,
num_rib_pts=num_rib_pts,
)

# this file contains only the in vessel components
stellarator.invessel_build.dag_model.write_file("dagmc.h5m")

# Define build parameters for magnet coils
coils_file = "coils.example"
width = 40.0
thickness = 50.0
toroidal_extent = 90.0

# Now, generate the magnet CAD files, and create a separate DAGMC model
stellarator.construct_magnets(
"../tests/files_for_tests/coils.example", 10, 10, 90
coils_file, width, thickness, toroidal_extent, sample_mod=6
)
stellarator.export_magnets(
step_filename="magnets",
export_mesh=False,
export_dir=export_dir,
)
stellarator.export_magnets()

stellarator.build_cubit_model(skip_imprint=False, legacy_faceting=False)
stellarator.export_dagmc("magnets.h5m")
merge_dagmc_files(["dagmc.h5m", "magnets.h5m"], "merged_dagmc.h5m")

# it is recommended to use the DAGMC command line tool overlap_check
# to verify that the geometry is valid, and that the magnets and ivb
# components do not intersect.

0 comments on commit 20f5a1a

Please sign in to comment.