Skip to content

Commit

Permalink
Incorporate review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
connoramoreno committed Oct 3, 2024
1 parent 12a3fde commit b1713bf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 30 deletions.
23 changes: 12 additions & 11 deletions Examples/radial_distance_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
stellarator = ps.Stellarator(vmec_file)

# Define build parameters for in-vessel components
toroidal_angles = np.linspace(0, 90, num=97)
poloidal_angles = np.linspace(0, 360, num=97)
# Use 13 x 13 uniformly spaced grid for in-vessel build
toroidal_angles = np.linspace(0, 90, num=13)
poloidal_angles = np.linspace(0, 360, num=13)
wall_s = 1.08
# Define build parameters for magnet coils
coils_file = "coils.example"
Expand All @@ -39,7 +40,9 @@
# symmetric
available_space = enforce_helical_symmetry(available_space)
# Smooth matrix
available_space = smooth_matrix(available_space, 100, 1)
steps = 25 # Apply Gaussian filter 25 times
sigma = 0.5 # Smooth using half a standard deviation for the Gaussian kernel
available_space = smooth_matrix(available_space, steps, sigma)
# For matrices defined by angles that are regularly spaced, matrix smoothing
# can result in matrix elements that are close to, but not exactly, helcially
# symmetric
Expand All @@ -48,9 +51,7 @@
available_space = available_space - max(width, thickness)

# Define a matrix of uniform unit thickness
uniform_unit_thickness = np.ones(
(len(toroidal_angles[::8]), len(poloidal_angles[::8]))
)
uniform_unit_thickness = np.ones((len(toroidal_angles), len(poloidal_angles)))
# Define thickness matrices for each in-vessel component of uniform thickness
first_wall_thickness_matrix = uniform_unit_thickness * 5
back_wall_thickness_matrix = uniform_unit_thickness * 5
Expand All @@ -59,7 +60,7 @@

# Compute breeder thickness matrix
breeder_thickness_matrix = (
available_space[::8, ::8]
available_space
- first_wall_thickness_matrix
- back_wall_thickness_matrix
- shield_thickness_matrix
Expand All @@ -79,12 +80,12 @@

# Construct in-vessel components
stellarator.construct_invessel_build(
toroidal_angles[::8],
poloidal_angles[::8],
toroidal_angles,
poloidal_angles,
wall_s,
radial_build_dict,
# Set num_ribs and num_rib_pts to be less than length of corresponding
# array to ensure that only defined angular locations are used
# Set num_ribs and num_rib_pts such that four (60/12 - 1) additional
# locations are interpolated between each specified location
num_ribs=61,
num_rib_pts=61,
)
Expand Down
4 changes: 2 additions & 2 deletions parastell/magnet_coils.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def get_ob_mp_index(self):
radii = np.linalg.norm(self.coords[:, :2], axis=1)
# Determine whether adjacent points cross the midplane (if so, they will
# have opposite signs)
shifted_coords = np.append(self.coords[1:, :], self.coords[1, :])
shifted_coords = np.append(self.coords[1:], [self.coords[1]], axis=0)
midplane_flags = -np.sign(self.coords[:, 2] * shifted_coords[:, 2])
# Find index of outboard midplane point
outboard_index = np.argmax(midplane_flags * radii)
Expand All @@ -483,7 +483,7 @@ def orient_coords(self, positive=True):
(defaults to True). If negative, coordinates will progress in
negative direction.
"""
if (positive == (self.coords[0, 2] > self.coords[1, 2]) ):
if positive == (self.coords[0, 2] > self.coords[1, 2]):
self.coords = np.flip(self.coords, axis=0)


Expand Down
36 changes: 19 additions & 17 deletions parastell/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,28 @@ def enforce_helical_symmetry(matrix):
num_rows = matrix.shape[0]
num_columns = matrix.shape[1]

# Ensure poloidal symmetry at beginning and middle of period
# Ensure rows represent closed loops
for idx in range(num_rows):
matrix[idx, -1] = matrix[idx, 0]

# Ensure poloidal symmetry at beginning of period
matrix[0] = np.concatenate(
[
matrix[0, : int((num_columns - 1) / 2) + 1],
np.flip(matrix[0, : int(num_columns / 2)]),
]
)
matrix[int((num_rows - 1) / 2)] = np.concatenate(
[
matrix[int((num_rows - 1) / 2), : int((num_columns - 1) / 2) + 1],
np.flip(matrix[int((num_rows - 1) / 2), : int(num_columns / 2)]),
]
)

# Ensure helical symmetry toroidally and poloidally
for index in range(num_rows - 1, int((num_rows - 1) / 2), -1):
matrix[num_rows - 1 - index, -1] = matrix[num_rows - 1 - index, 0]
matrix[index] = np.flip(matrix[num_rows - 1 - index])
# Ensure helical symmetry toroidally and poloidally by mirroring the period
# about both matrix axes
flattened_matrix = matrix.flatten()

for idx, value in enumerate(
flattened_matrix[: int(len(flattened_matrix) / 2)], start=1
):
flattened_matrix[-idx] = value

matrix = flattened_matrix.reshape((num_rows, num_columns))

return matrix

Expand Down Expand Up @@ -79,8 +83,8 @@ def expand_list(list, num):
for entry, next_entry in zip(list[:-1], list[1:]):
num_new_entries = int(round((next_entry - entry) / avg_diff))

# don't append the last entry in the created linspace to avoid adding it twice when
# the next created linspace is appended
# Don't append the last entry in the created linspace to avoid adding
# it twice when the next created linspace is appended
list_exp = np.append(
list_exp,
np.linspace(entry, next_entry, num=num_new_entries + 1)[:-1],
Expand Down Expand Up @@ -161,11 +165,9 @@ def reorder_loop(list, index):
index (int): list index about which to reorder loop.
Returns:
reordered_loop (iterable): reordered closed loop.
(iterable): reordered closed loop.
"""
reordered_list = np.concatenate([list[index:], list[1:index+1]])

return reordered_list
return np.concatenate([list[index:], list[1 : index + 1]])


def smooth_matrix(matrix, steps, sigma):
Expand Down

0 comments on commit b1713bf

Please sign in to comment.