Skip to content

Commit

Permalink
added magnets
Browse files Browse the repository at this point in the history
  • Loading branch information
shimwell committed Dec 1, 2024
1 parent ef7f739 commit 529fda7
Showing 1 changed file with 78 additions and 5 deletions.
83 changes: 78 additions & 5 deletions examples/spherical_tokamak_from_plasma_with_color_animation.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import paramak
import imageio
import cadquery_png_plugin.plugin
import numpy as np
import cadquery as cq

# Original radial build values
original_radial_build = [
(paramak.LayerType.GAP, 10),
(paramak.LayerType.GAP, 55),
(paramak.LayerType.SOLID, 50),
(paramak.LayerType.SOLID, 15),
(paramak.LayerType.GAP, 50),
Expand All @@ -16,9 +18,53 @@
]
original_elongation = 2
original_triangularity = 0.55
original_n_tf_coils = 8
original_coil_height_factor = 1

# Function to create a reactor with modified radial build
def create_reactor(radial_build, elongation, triangularity):
def create_reactor(radial_build, elongation, triangularity, n_tf_coils, coil_height_factor):
reactor_diameter = sum([layer[1] for layer in radial_build])
reactor_height = elongation * radial_build[4][1] * 0.5 + sum([layer[1] for layer in radial_build[5:]])
tf_coils = paramak.toroidal_field_coil_rectangle(
horizontal_start_point=(10, reactor_height+5),
vertical_mid_point=(reactor_diameter+5,0),
thickness = 40,
distance = 50 ,
rotation_angle = 180.0,
name = "toroidal_field_coil",
with_inner_leg = True,
azimuthal_placement_angles=np.linspace(0, 180, n_tf_coils)
)

coils = [tf_coils]
for case_thickness, height, width, center_point in zip(
[10, 15, 15, 10],
[20, 50, 50, 20],
[20, 50, 50, 20],
[
(reactor_diameter+5+50+10+20/2, 300*coil_height_factor),
(reactor_diameter+5+50+15+50/2, 100*coil_height_factor),
(reactor_diameter+5+50+15+50/2, -100*coil_height_factor),
(reactor_diameter+5+50+10+20/2, -300*coil_height_factor)
]
):
coils.append(
paramak.poloidal_field_coil(
height=height, width=width,
center_point=center_point,
rotation_angle=180
)
)
coils.append(
paramak.poloidal_field_coil_case(
coil_height=height,
coil_width=width,
casing_thickness=case_thickness,
rotation_angle=180,
center_point=center_point
)
)

return paramak.spherical_tokamak_from_plasma(
radial_build=radial_build,
elongation=elongation,
Expand All @@ -31,11 +77,25 @@ def create_reactor(radial_build, elongation, triangularity):
"layer_3": (0.1, 0.1, 0.9),
"layer_4": (0.4, 0.4, 0.8),
"layer_5": (0.5, 0.5, 0.8),
"add_extra_cut_shape_1": (0.6, 0.3, 0.4), # tf coils
"add_extra_cut_shape_2": (0.4, 0.9, 0.4), # pf coil
"add_extra_cut_shape_3": (0.9, 0.4, 0.4), # pf coil case
"add_extra_cut_shape_4": (0.4, 0.9, 0.4), # pf coil
"add_extra_cut_shape_5": (0.9, 0.4, 0.4), # pf coil case
"add_extra_cut_shape_6": (0.4, 0.9, 0.4), # pf coil
"add_extra_cut_shape_7": (0.9, 0.4, 0.4), # pf coil case
"add_extra_cut_shape_8": (0.4, 0.9, 0.4), # pf coil
"add_extra_cut_shape_9": (0.9, 0.4, 0.4), # pf coil case

},
extra_cut_shapes=coils
)

# Function to export reactor to PNG
def export_reactor_to_png(reactor, file_path):
reactor.add(
cq.Workplane('XZ').text("Paramak", fontsize=200, distance=10
).translate((0, 0, -615)))
reactor.exportPNG(
options={
"width": 1280,
Expand All @@ -44,6 +104,7 @@ def export_reactor_to_png(reactor, file_path):
},
file_path=file_path
)
print(f'written {file_path}')

# Generate reactors with varying radial build values
frame = 0
Expand All @@ -53,21 +114,33 @@ def export_reactor_to_png(reactor, file_path):
for factor in factors:
modified_radial_build = original_radial_build.copy()
modified_radial_build[i] = (layer_type, original_value * factor)
reactor = create_reactor(modified_radial_build, original_elongation, original_triangularity)
reactor = create_reactor(modified_radial_build, original_elongation, original_triangularity, original_n_tf_coils, original_coil_height_factor)
export_reactor_to_png(reactor, f'spherical_tokamak_frame_{frame:03d}.png')
frame += 1

for factor in factors:
modified_elongation = original_elongation * factor
reactor = create_reactor(original_radial_build, modified_elongation, original_triangularity)
reactor = create_reactor(original_radial_build, modified_elongation, original_triangularity, original_n_tf_coils,original_coil_height_factor)
export_reactor_to_png(reactor, f'spherical_tokamak_frame_{frame:03d}.png')
frame += 1

for modified_triangularity in [0.55, 0.3667, 0.1833, 0.0, -0.1833, -0.3667, -0.55, -0.3667, -0.1833, 0.0, 0.1833, 0.3667, 0.55]:
reactor = create_reactor(original_radial_build, original_elongation, modified_triangularity)
reactor = create_reactor(original_radial_build, original_elongation, modified_triangularity, original_n_tf_coils)
export_reactor_to_png(reactor, f'spherical_tokamak_frame_{frame:03d}.png')
frame += 1

for modified_n_tf_coils in [original_n_tf_coils, original_n_tf_coils -1 , original_n_tf_coils -2, original_n_tf_coils-3, original_n_tf_coils-2, original_n_tf_coils-1,original_n_tf_coils]:
reactor = create_reactor(original_radial_build, original_elongation, original_triangularity, modified_n_tf_coils, original_coil_height_factor)
export_reactor_to_png(reactor, f'spherical_tokamak_frame_{frame:03d}.png')
frame += 1

for modified_coil_height_factor in [1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.4, 1.3, 1.2, 1.1, 1]:
reactor = create_reactor(original_radial_build, original_elongation, original_triangularity, modified_n_tf_coils, modified_coil_height_factor)
export_reactor_to_png(reactor, f'spherical_tokamak_frame_{frame:03d}.png')
frame += 1



# Convert all the frames PNG files into a GIF
def create_gif_from_frames(frame_count, output_file):
with imageio.get_writer(output_file, mode='I', duration=0.1) as writer:
Expand Down

0 comments on commit 529fda7

Please sign in to comment.