Skip to content

Commit 19a9aac

Browse files
authored
Merge pull request #268 from svalinn/fix-examples
2 parents 60e4fd5 + 4f50655 commit 19a9aac

11 files changed

+63
-62
lines changed

examples/config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ source_mesh:
8282
filename: source_mesh
8383

8484
dagmc_export:
85-
skip_imprint: False
8685
filename: dagmc
8786

8887
cub5_export: False

examples/custom_first_wall_profile_example.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
# Define desired toroidal and poloidal angles for building the stellarator
4343
toroidal_angles = [0.0, 11.25, 22.5, 33.75, 45.0, 56.25, 67.5, 78.75, 90.0]
4444
poloidal_angles = [0.0, 45.0, 90.0, 135.0, 180.0, 225.0, 270.0, 315.0, 360.0]
45-
wall_s = 1.08
45+
wall_s = 1.0
4646

4747
# Define a matrix of uniform unit thickness
4848
uniform_unit_thickness = np.ones((len(toroidal_angles), len(poloidal_angles)))
@@ -73,7 +73,7 @@
7373
}
7474
# Construct in-vessel components
7575
stellarator.construct_invessel_build(
76-
toroidal_angles, poloidal_angles, wall_s, radial_build_dict, scale=1
76+
toroidal_angles, poloidal_angles, wall_s, radial_build_dict
7777
)
7878
# Export in-vessel component files
7979
stellarator.export_invessel_build_step(export_dir=export_dir)
@@ -89,9 +89,6 @@
8989
)
9090
# Export magnet files
9191
stellarator.export_magnets_step(filename="magnets", export_dir=export_dir)
92-
stellarator.export_magnet_mesh_cubit(
93-
filename="magnet_mesh", export_dir=export_dir
94-
)
9592

9693
# Define source mesh parameters
9794
cfs_values = np.linspace(0.0, 1.0, num=11)
@@ -102,8 +99,7 @@
10299
# Export source file
103100
stellarator.export_source_mesh(filename="source_mesh", export_dir=export_dir)
104101

105-
# Build Cubit model of Parastell Components
106-
stellarator.build_cubit_model(skip_imprint=True)
107-
108-
# Export DAGMC neutronics H5M file
109-
stellarator.export_cubit_dagmc(filename="dagmc", export_dir=export_dir)
102+
# Build DAGMC neutronics model
103+
stellarator.build_cad_to_dagmc_model()
104+
# Export DAGMC H5M file
105+
stellarator.export_cad_to_dagmc(filename="dagmc", export_dir=export_dir)

examples/custom_source_example.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import parastell.source_mesh as sm
22
from parastell.pystell import read_vmec
3-
import subprocess
43
import numpy as np
54

65

@@ -40,6 +39,4 @@ def my_custom_reaction_rate(n_i, T_i):
4039
source_mesh_obj.create_vertices()
4140
source_mesh_obj.create_mesh()
4241

43-
# export and convert to vtk for visualization
4442
source_mesh_obj.export_mesh("source_mesh.h5m")
45-
subprocess.run("mbconvert source_mesh.h5m source_mesh.vtk", shell=True)

examples/nwl_cubit_example.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
# Construct and export DAGMC neutronics model
4646
dagmc_filename = Path("nwl_geom").with_suffix(".h5m")
47-
stellarator.build_cubit_model(skip_imprint=True)
47+
stellarator.build_cubit_model()
4848
tag_surface(1, "vacuum")
4949
stellarator.export_cubit_dagmc(filename=dagmc_filename)
5050

@@ -67,5 +67,7 @@
6767
num_threads=6,
6868
)
6969
)
70-
nwl_utils.plot_nwl(nwl_mean, toroidal_bins, poloidal_bins)
71-
nwl_utils.plot_nwl(nwl_std_dev, toroidal_bins, poloidal_bins)
70+
nwl_utils.plot_nwl(nwl_mean, toroidal_bins, poloidal_bins, filename="nwl_mean")
71+
nwl_utils.plot_nwl(
72+
nwl_std_dev, toroidal_bins, poloidal_bins, filename="nwl_std_dev"
73+
)

examples/nwl_pydagmc_example.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from pathlib import Path
22

33
import parastell.parastell as ps
4-
from parastell.cubit_utils import tag_surface
54
from parastell import nwl_utils
65
import numpy as np
76

@@ -81,5 +80,7 @@
8180
num_threads=6,
8281
)
8382
)
84-
nwl_utils.plot_nwl(nwl_mean, toroidal_bins, poloidal_bins)
85-
nwl_utils.plot_nwl(nwl_std_dev, toroidal_bins, poloidal_bins)
83+
nwl_utils.plot_nwl(nwl_mean, toroidal_bins, poloidal_bins, filename="nwl_mean")
84+
nwl_utils.plot_nwl(
85+
nwl_std_dev, toroidal_bins, poloidal_bins, filename="nwl_std_dev"
86+
)

examples/parastell_cad_to_dagmc_example.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
)
5050
# Export in-vessel component files
5151
stellarator.export_invessel_build_step(export_dir=export_dir)
52+
# Export weight window mesh
5253
stellarator.export_invessel_build_mesh_gmsh(
5354
[
5455
"chamber",
@@ -88,8 +89,7 @@
8889
# Export source file
8990
stellarator.export_source_mesh(filename="source_mesh", export_dir=export_dir)
9091

91-
# Build Cubit model of Parastell Components
92+
# Build DAGMC neutronics model
9293
stellarator.build_cad_to_dagmc_model()
93-
94-
# Export DAGMC neutronics H5M file
94+
# Export DAGMC H5M file
9595
stellarator.export_cad_to_dagmc(filename="dagmc", export_dir=export_dir)

examples/parastell_cubit_example.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
)
5050
# Export in-vessel component files
5151
stellarator.export_invessel_build_step(export_dir=export_dir)
52+
# Export weight window mesh
5253
stellarator.export_invessel_build_mesh_cubit(
5354
[
5455
"chamber",
@@ -85,8 +86,7 @@
8586
# Export source file
8687
stellarator.export_source_mesh(filename="source_mesh", export_dir=export_dir)
8788

88-
# Build Cubit model of Parastell Components
89-
stellarator.build_cubit_model(skip_imprint=False)
90-
91-
# Export DAGMC neutronics H5M file
89+
# Build DAGMC neutronics model
90+
stellarator.build_cubit_model()
91+
# Export DAGMC H5M file
9292
stellarator.export_cubit_dagmc(filename="dagmc", export_dir=export_dir)

examples/parastell_pydagmc_example.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@
5858
num_ribs=num_ribs,
5959
num_rib_pts=num_rib_pts,
6060
)
61-
# Export in-vessel component files
62-
stellarator.export_invessel_build_mesh_moab(
63-
"vacuum_vessel", "vacuum_vessel_tally_mesh"
64-
)
6561

6662
# Define build parameters for magnet coils
6763
coils_file = "coils.example"
@@ -73,7 +69,25 @@
7369
coils_file, width, thickness, toroidal_extent, sample_mod=6
7470
)
7571

72+
# PyDAGMC model must be built before any meshing in Gmsh
7673
stellarator.build_pydagmc_model(
7774
magnet_exporter="cad_to_dagmc", max_mesh_size=60
7875
)
7976
stellarator.export_pydagmc_model(filename="dagmc")
77+
78+
# Export weight window mesh
79+
# Note that PyDAGMC workflow does not model the vacuum chamber - cannot be meshed
80+
stellarator.export_invessel_build_mesh_gmsh(
81+
[
82+
"first_wall",
83+
"breeder",
84+
"back_wall",
85+
"shield",
86+
"vacuum_vessel",
87+
],
88+
"weight_window_mesh",
89+
)
90+
# Export in-vessel component files
91+
stellarator.export_invessel_build_mesh_moab(
92+
["vacuum_vessel"], "vacuum_vessel_tally_mesh"
93+
)

examples/radial_distance_example.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@
4848
# symmetric
4949
available_space = enforce_helical_symmetry(available_space)
5050
# Modify available space to account for thickness of magnets
51-
available_space = available_space - max(width, thickness)
51+
tolerance = 5
52+
available_space = available_space - (
53+
np.sqrt(width * width + thickness * thickness) + tolerance
54+
)
5255

5356
# Define a matrix of uniform unit thickness
5457
uniform_unit_thickness = np.ones((len(toroidal_angles), len(poloidal_angles)))
@@ -111,8 +114,7 @@
111114
# Export source file
112115
stellarator.export_source_mesh(filename="source_mesh", export_dir=export_dir)
113116

114-
# Build Cubit model of Parastell Components
115-
stellarator.build_cubit_model(skip_imprint=False)
116-
117-
# Export DAGMC neutronics H5M file
118-
stellarator.export_cubit_dagmc(filename="dagmc", export_dir=export_dir)
117+
# Build DAGMC neutronics model
118+
stellarator.build_cad_to_dagmc_model()
119+
# Export DAGMC H5M file
120+
stellarator.export_cad_to_dagmc(filename="dagmc", export_dir=export_dir)

parastell/nwl_utils.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,6 @@ def compute_nwl(
330330
poloidal_extent + poloidal_extent / num_poloidal_bins / 2
331331
)
332332

333-
toroidal_angles = []
334-
poloidal_angles = []
335333
nwl_all_batches = []
336334

337335
batch_size = math.ceil(num_particles / num_batches)
@@ -343,20 +341,20 @@ def compute_nwl(
343341

344342
crossings = coords[batch_start : batch_start + batch_size]
345343

346-
toroidal_angle_batch, poloidal_angle_batch = compute_flux_coordinates(
347-
ref_surf,
348-
wall_s,
349-
crossings,
350-
num_threads,
351-
conv_tol,
344+
toroidal_angles_batch, poloidal_angles_batch = (
345+
compute_flux_coordinates(
346+
ref_surf,
347+
wall_s,
348+
crossings,
349+
num_threads,
350+
conv_tol,
351+
)
352352
)
353-
toroidal_angles += toroidal_angle_batch
354-
poloidal_angles += poloidal_angle_batch
355353

356354
# Bin particle crossings
357355
counts, toroidal_bin_edges, poloidal_bin_edges = np.histogram2d(
358-
toroidal_angles,
359-
poloidal_angles,
356+
toroidal_angles_batch,
357+
poloidal_angles_batch,
360358
bins=[num_toroidal_bins, num_poloidal_bins],
361359
range=[
362360
[toroidal_bin_min, toroidal_bin_max],

0 commit comments

Comments
 (0)