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

formatting changes #354

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@
"collapse_navigation": True,
"show_version_warning_banner": True,
}
html_sidebars = {
"**": ["sidebar-nav-bs"]
}
html_sidebars = {"**": ["sidebar-nav-bs"]}

html_favicon = '_static/favicon.ico'
html_favicon = "_static/favicon.ico"
master_doc = "index"
1 change: 0 additions & 1 deletion examples/spherical_tokamak_from_plasma_minimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
my_reactor.save(f"spherical_tokamak_from_plasma_minimal.step")



# from cad_to_dagmc import CadToDagmc
# my_model = CadToDagmc()
# material_tags = [
Expand Down
6 changes: 3 additions & 3 deletions examples/spherical_tokamak_from_plasma_with_divertor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# makes a rectangle that overlaps the lower blanket under the plasma
# the intersection of this and the layers will form the lower divertor
points = [(150, -700), (150, 0), (270, 0), (270, -700)]
divertor_lower = Workplane('XZ', origin=(0,0,0)).polyline(points).close().revolve(180)
divertor_lower = Workplane("XZ", origin=(0, 0, 0)).polyline(points).close().revolve(180)

my_reactor = paramak.spherical_tokamak_from_plasma(
radial_build=[
Expand All @@ -26,10 +26,10 @@
elongation=2,
triangularity=0.55,
rotation_angle=180,
extra_intersect_shapes=[divertor_lower]
extra_intersect_shapes=[divertor_lower],
)
my_reactor.save("spherical_tokamak_from_plasma_with_divertor.step")
print('written spherical_tokamak_from_plasma_with_divertor.step')
print("written spherical_tokamak_from_plasma_with_divertor.step")

# from cad_to_dagmc import CadToDagmc
# vis.show(my_reactor)
Expand Down
7 changes: 2 additions & 5 deletions examples/spherical_tokamak_from_plasma_with_pf_magnets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@

extra_cut_shapes = []
for case_thickness, height, width, center_point in zip(
[10, 15, 15, 10], [20, 50, 50, 20], [20, 50, 50, 20],
[(500, 300), (560, 100), (560, -100), (500, -300)]
[10, 15, 15, 10], [20, 50, 50, 20], [20, 50, 50, 20], [(500, 300), (560, 100), (560, -100), (500, -300)]
):
extra_cut_shapes.append(
paramak.poloidal_field_coil(
height=height, width=width, center_point=center_point, rotation_angle=270
)
paramak.poloidal_field_coil(height=height, width=width, center_point=center_point, rotation_angle=270)
)
extra_cut_shapes.append(
paramak.poloidal_field_coil_case(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
)
)

#TODO
# TODO
# [(paramak.LayerType.GAP, 75), ("lower_divertor", 100)],
my_reactor = paramak.spherical_tokamak_from_plasma(
radial_build=[
Expand Down
29 changes: 14 additions & 15 deletions examples/spherical_tokamak_from_plasma_with_tf_magnets.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@

import paramak


rotation_angle=90
rotation_angle = 90
tf_style_1 = paramak.toroidal_field_coil_rectangle(
horizontal_start_point = (10, 520),
vertical_mid_point = (600, 0),
thickness = 50,
distance = 40,
with_inner_leg = True,
azimuthal_placement_angles = [0, 30, 60, 90, 120, 150, 180],
rotation_angle=rotation_angle
horizontal_start_point=(10, 520),
vertical_mid_point=(600, 0),
thickness=50,
distance=40,
with_inner_leg=True,
azimuthal_placement_angles=[0, 30, 60, 90, 120, 150, 180],
rotation_angle=rotation_angle,
)

result1 = paramak.spherical_tokamak_from_plasma(
Expand All @@ -28,7 +27,7 @@
elongation=2.5,
rotation_angle=rotation_angle,
triangularity=0.55,
extra_cut_shapes=[tf_style_1]
extra_cut_shapes=[tf_style_1],
)

result1.save("spherical_tokamak_from_plasma_with_rect_tf_coils.step")
Expand All @@ -37,10 +36,10 @@
tf_style_2 = paramak.toroidal_field_coil_princeton_d(
r1=5,
r2=610,
thickness = 50,
distance = 40,
azimuthal_placement_angles = [0, 30, 60, 90, 120, 150, 180],
rotation_angle=rotation_angle
thickness=50,
distance=40,
azimuthal_placement_angles=[0, 30, 60, 90, 120, 150, 180],
rotation_angle=rotation_angle,
)

result2 = paramak.spherical_tokamak_from_plasma(
Expand All @@ -58,7 +57,7 @@
elongation=2.5,
rotation_angle=rotation_angle,
triangularity=0.55,
extra_cut_shapes=[tf_style_2]
extra_cut_shapes=[tf_style_2],
)

result2.save("spherical_tokamak_from_plasma_with_prin_tf_coils.step")
Expand Down
5 changes: 2 additions & 3 deletions examples/tokamak_from_plasma_with_divertor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from example_util_functions import transport_particles_on_h5m_geometry
from paramak.utils import create_wire_workplane_from_points
import paramak
Expand All @@ -7,7 +6,7 @@
# makes a rectangle that overlaps the lower blanket under the plasma
# the intersection of this and the layers will form the lower divertor
points = [(300, -700), (300, 0), (400, 0), (400, -700)]
divertor_lower = Workplane('XZ', origin=(0,0,0)).polyline(points).close().revolve(180)
divertor_lower = Workplane("XZ", origin=(0, 0, 0)).polyline(points).close().revolve(180)


my_reactor = paramak.tokamak_from_plasma(
Expand All @@ -28,7 +27,7 @@
elongation=2,
triangularity=0.55,
rotation_angle=180,
extra_intersect_shapes=[divertor_lower]
extra_intersect_shapes=[divertor_lower],
)
my_reactor.save(f"tokamak_with_divertor.step")
print(f"Saved as tokamak_with_divertor.step")
Expand Down
7 changes: 2 additions & 5 deletions examples/tokamak_with_pf_magnets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@

extra_cut_shapes = []
for case_thickness, height, width, center_point in zip(
[10, 15, 15, 10], [20, 50, 50, 20], [20, 50, 50, 20],
[(700, 300), (800, 100), (800, -100), (700, -300)]
[10, 15, 15, 10], [20, 50, 50, 20], [20, 50, 50, 20], [(700, 300), (800, 100), (800, -100), (700, -300)]
):
extra_cut_shapes.append(
paramak.poloidal_field_coil(
height=height, width=width, center_point=center_point, rotation_angle=180
)
paramak.poloidal_field_coil(height=height, width=width, center_point=center_point, rotation_angle=180)
)
extra_cut_shapes.append(
paramak.poloidal_field_coil_case(
Expand Down
26 changes: 11 additions & 15 deletions examples/tokamak_with_pf_tf_magnets_divertor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from example_util_functions import transport_particles_on_h5m_geometry

import paramak
Expand All @@ -7,30 +6,27 @@
# makes a rectangle that overlaps the lower blanket under the plasma
# the intersection of this and the layers will form the lower divertor
points = [(300, -700), (300, 0), (400, 0), (400, -700)]
divertor_lower = cq.Workplane('XZ', origin=(0,0,0)).polyline(points).close().revolve(180)
divertor_lower = cq.Workplane("XZ", origin=(0, 0, 0)).polyline(points).close().revolve(180)

# creates a toroidal
# creates a toroidal
tf = paramak.toroidal_field_coil_rectangle(
horizontal_start_point = (10, 520),
vertical_mid_point = (860, 0),
thickness = 50,
distance = 40,
horizontal_start_point=(10, 520),
vertical_mid_point=(860, 0),
thickness=50,
distance=40,
rotation_angle=180,
with_inner_leg = True,
azimuthal_placement_angles = [0, 30, 60, 90, 120, 150, 180],
with_inner_leg=True,
azimuthal_placement_angles=[0, 30, 60, 90, 120, 150, 180],
)

extra_cut_shapes = [tf]

# creates pf coil
for case_thickness, height, width, center_point in zip(
[10, 15, 15, 10], [20, 50, 50, 20], [20, 50, 50, 20],
[(730, 370), (810, 235), (810, -235), (730, -370)]
[10, 15, 15, 10], [20, 50, 50, 20], [20, 50, 50, 20], [(730, 370), (810, 235), (810, -235), (730, -370)]
):
extra_cut_shapes.append(
paramak.poloidal_field_coil(
height=height, width=width, center_point=center_point, rotation_angle=180
)
paramak.poloidal_field_coil(height=height, width=width, center_point=center_point, rotation_angle=180)
)
extra_cut_shapes.append(
paramak.poloidal_field_coil_case(
Expand Down Expand Up @@ -75,7 +71,7 @@
triangularity=0.55,
rotation_angle=180,
extra_cut_shapes=extra_cut_shapes,
extra_intersect_shapes=[divertor_lower]
extra_intersect_shapes=[divertor_lower],
)
my_reactor.save(f"tokamak_with_divertor.step")
print(f"Saved as tokamak_with_divertor.step")
Expand Down
13 changes: 7 additions & 6 deletions src/paramak/assemblies/spherical_tokamak.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sum_up_to_gap_before_plasma,
sum_up_to_plasma,
sum_before_after_plasma,
LayerType
LayerType,
)
from ..workplanes.blanket_from_plasma import blanket_from_plasma
from ..workplanes.center_column_shield_cylinder import center_column_shield_cylinder
Expand Down Expand Up @@ -147,7 +147,7 @@ def spherical_tokamak_from_plasma(
triangularity=triangularity,
rotation_angle=rotation_angle,
extra_cut_shapes=extra_cut_shapes,
extra_intersect_shapes=extra_intersect_shapes
extra_intersect_shapes=extra_intersect_shapes,
)


Expand Down Expand Up @@ -220,7 +220,6 @@ def spherical_tokamak(
center_column=blanket_cutting_cylinder,
)


my_assembly = cq.Assembly()

for i, entry in enumerate(extra_cut_shapes):
Expand All @@ -232,13 +231,13 @@ def spherical_tokamak(

# builds up the intersect shapes
intersect_shapes_to_cut = []
if len(extra_intersect_shapes)>0:
if len(extra_intersect_shapes) > 0:
all_shapes = []
for shape in inner_radial_build + blanket_layers:
all_shapes.append(shape)

# makes a union of the the radial build to use as a base for the intersect shapes
reactor_compound=inner_radial_build[0]
reactor_compound = inner_radial_build[0]
for i, entry in enumerate(inner_radial_build[1:] + blanket_layers):
reactor_compound = reactor_compound.union(entry)

Expand All @@ -265,7 +264,9 @@ def spherical_tokamak(
shapes_and_components.append(entry)

for i, entry in enumerate(shapes_and_components):
my_assembly.add(entry, name=f"layer_{i+1})") #TODO track the names of shapes, even when extra shapes are made due to splitting
my_assembly.add(
entry, name=f"layer_{i+1})"
) # TODO track the names of shapes, even when extra shapes are made due to splitting

my_assembly.add(plasma, name="plasma")

Expand Down
33 changes: 14 additions & 19 deletions src/paramak/assemblies/tokamak.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,8 @@ def create_layers_from_plasma(
major_radius=major_radius,
triangularity=triangularity,
elongation=elongation,
thickness=[
upper_layer_thickness,
outer_layer_thickness,
lower_layer_thickness
],
offset_from_plasma=[
cumulative_thickness_uvb,
cumulative_thickness_orb,
cumulative_thickness_lvb
],
thickness=[upper_layer_thickness, outer_layer_thickness, lower_layer_thickness],
offset_from_plasma=[cumulative_thickness_uvb, cumulative_thickness_orb, cumulative_thickness_lvb],
start_angle=90,
stop_angle=-90,
rotation_angle=rotation_angle,
Expand Down Expand Up @@ -156,6 +148,7 @@ def create_layers_from_plasma(

return layers


def tokamak_from_plasma(
radial_build: Sequence[Tuple[LayerType, float]],
elongation: float = 2.0,
Expand All @@ -177,9 +170,9 @@ def tokamak_from_plasma(

# make vertical build from inner radial build
pi = get_plasma_index(radial_build)
rbi = len(radial_build)-1 - pi # number of unique entries in outer or inner radial build
upper_vertical_build = radial_build[pi-rbi:pi][::-1] #get the inner radial build
rbi = len(radial_build) - 1 - pi # number of unique entries in outer or inner radial build
upper_vertical_build = radial_build[pi - rbi : pi][::-1] # get the inner radial build

plasma_height = 2 * minor_radius * elongation
# slice opperation reverses the list and removes the last value to avoid two plasmas
vertical_build = upper_vertical_build[::-1] + [(LayerType.PLASMA, plasma_height)] + upper_vertical_build
Expand All @@ -193,13 +186,14 @@ def tokamak_from_plasma(
extra_intersect_shapes=extra_intersect_shapes,
)


def tokamak(
radial_build: Union[Sequence[Sequence[Tuple[str, float]]], Sequence[Tuple[str, float]]],
vertical_build: Sequence[Tuple[str, float]],
triangularity: float = 0.55,
rotation_angle: float = 180.0,
extra_cut_shapes: Sequence[cq.Workplane] = [],
extra_intersect_shapes: Sequence[cq.Workplane] = [],
extra_cut_shapes: Sequence[cq.Workplane] = [],
extra_intersect_shapes: Sequence[cq.Workplane] = [],
):
"""
Creates a tokamak fusion reactor from a radial build and plasma parameters.
Expand Down Expand Up @@ -260,13 +254,13 @@ def tokamak(

# builds up the intersect shapes
intersect_shapes_to_cut = []
if len(extra_intersect_shapes)>0:
if len(extra_intersect_shapes) > 0:
all_shapes = []
for shape in inner_radial_build + blanket_layers:
all_shapes.append(shape)

# makes a union of the the radial build to use as a base for the intersect shapes
reactor_compound=inner_radial_build[0]
reactor_compound = inner_radial_build[0]
for i, entry in enumerate(inner_radial_build[1:] + blanket_layers):
reactor_compound = reactor_compound.union(entry)

Expand All @@ -293,8 +287,9 @@ def tokamak(
shapes_and_components.append(entry)

for i, entry in enumerate(shapes_and_components):
my_assembly.add(entry, name=f"layer_{i+1})") #TODO track the names of shapes, even when extra shapes are made due to splitting

my_assembly.add(
entry, name=f"layer_{i+1})"
) # TODO track the names of shapes, even when extra shapes are made due to splitting

my_assembly.add(plasma, name="plasma")

Expand Down
13 changes: 7 additions & 6 deletions src/paramak/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@


class LayerType(Enum):
GAP = 'gap'
SOLID = 'solid'
PLASMA = 'plasma'
GAP = "gap"
SOLID = "solid"
PLASMA = "plasma"


def instructions_from_points(points):
# obtains the first two values of the points list
Expand Down Expand Up @@ -61,7 +62,7 @@ def create_wire_workplane_from_points(points, plane, origin=(0, 0, 0), obj=None)

all_spline = all(entry[-1] == "spline" for entry in points)

#TODO add check for all straights and do polyline
# TODO add check for all straights and do polyline

if all_spline:
entry_values = [entry[:2] for entry in points[:-1]]
Expand Down Expand Up @@ -197,7 +198,7 @@ def validate_divertor_radial_build(radial_build):

if len(radial_build[0]) != 2 or len(radial_build[1]) != 2:
raise ValidationError(
'The radial build for the divertor should only contain tuples of length 2,, for example (LayerType.GAP,10)'
"The radial build for the divertor should only contain tuples of length 2,, for example (LayerType.GAP,10)"
)

if radial_build[1][0] not in {"lower_divertor", "upper_divertor"}:
Expand All @@ -207,7 +208,7 @@ def validate_divertor_radial_build(radial_build):

if radial_build[0][0] != LayerType.GAP:
raise ValidationError(
f'The first entry in the radial build for the divertor should be a LayerType.GAP not {radial_build[0][0]}'
f"The first entry in the radial build for the divertor should be a LayerType.GAP not {radial_build[0][0]}"
)

if not isinstance(radial_build[0][1], (int, float)) or not isinstance(radial_build[1][1], (int, float)):
Expand Down
Loading