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

single function per reactor #335

Closed
wants to merge 3 commits into from
Closed
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
3 changes: 0 additions & 3 deletions docs/python_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ Assemblies
----------

.. autofunction:: tokamak

.. autofunction:: tokamak_from_plasma

.. autofunction:: spherical_tokamak

.. autofunction:: spherical_tokamak_from_plasma

Workplanes
----------
Expand Down
6 changes: 3 additions & 3 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ or the jupyter_cadquery package which allows for interactive 3D visualization in
view.export_html("3d.html")


Tokamak from plasma
-------------------
Tokamak
-------

- The tokamak_from_plasma function provides a parametric tokamak shaped reactor.
- The tokamak function provides a parametric tokamak shaped reactor.
- This is characterized by a continuous blanket that goes around the inboard and outboard sides of the plasma.
- This reactor requires few arguments to create as it keeps the vertical build of the blanket layers the same thickness as the radial build.

Expand Down
9 changes: 3 additions & 6 deletions examples/spherical_tokamak_from_plasma_minimal.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from pathlib import Path

from cad_to_dagmc import CadToDagmc
from example_util_functions import transport_particles_on_h5m_geometry

import paramak

my_reactor = paramak.spherical_tokamak_from_plasma(
my_reactor = paramak.spherical_tokamak(
radial_builds=[
[
(paramak.LayerType.GAP, 10),
Expand All @@ -26,7 +22,8 @@
my_reactor.save(f"spherical_tokamak_from_plasma_minimal.step")



# from cad_to_dagmc import CadToDagmc
# from example_util_functions import transport_particles_on_h5m_geometry
# my_model = CadToDagmc()
# material_tags = [
# "mat1"
Expand Down
9 changes: 3 additions & 6 deletions examples/spherical_tokamak_from_plasma_with_divertor.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
from pathlib import Path

from cad_to_dagmc import CadToDagmc
from example_util_functions import transport_particles_on_h5m_geometry

import paramak

my_reactor = paramak.spherical_tokamak_from_plasma(
my_reactor = paramak.spherical_tokamak(
radial_builds=[
[
(paramak.LayerType.GAP, 10),
Expand All @@ -29,6 +24,8 @@
print('written spherical_tokamak_from_plasma_with_divertor.step')


# from cad_to_dagmc import CadToDagmc
# from example_util_functions import transport_particles_on_h5m_geometry
# my_model = CadToDagmc()
# material_tags = ["mat1"] * 21 # the two divertors split the 3 blanket layers into 9 and the magnets also splt the blanket.
# my_model.add_cadquery_object(cadquery_object=my_reactor, material_tags=material_tags)
Expand Down
8 changes: 3 additions & 5 deletions examples/spherical_tokamak_from_plasma_with_pf_magnets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from cad_to_dagmc import CadToDagmc
from example_util_functions import transport_particles_on_h5m_geometry

import paramak

add_extra_cut_shapes = []
Expand All @@ -24,7 +21,7 @@
)


my_reactor = paramak.spherical_tokamak_from_plasma(
my_reactor = paramak.spherical_tokamak(
radial_builds=[
(paramak.LayerType.GAP, 10),
(paramak.LayerType.SOLID, 50),
Expand All @@ -43,7 +40,8 @@
)
my_reactor.save(f"spherical_tokamak_from_plasma_with_pf_magnets.step")


# from cad_to_dagmc import CadToDagmc
# from example_util_functions import transport_particles_on_h5m_geometry
# my_model = CadToDagmc()
# material_tags = ["mat1"] * 5
# my_model.add_cadquery_object(cadquery_object=my_reactor, material_tags=material_tags)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
from pathlib import Path

from cad_to_dagmc import CadToDagmc
from example_util_functions import transport_particles_on_h5m_geometry

import paramak

rotation_angle = 180
Expand All @@ -26,7 +21,7 @@
)


my_reactor = paramak.spherical_tokamak_from_plasma(
my_reactor = paramak.spherical_tokamak(
radial_builds=[
[
(paramak.LayerType.GAP, 10),
Expand All @@ -49,7 +44,8 @@
my_reactor.save(f"spherical_tokamak_from_plasma_with_pf_magnets_and_divertor.step")



# from cad_to_dagmc import CadToDagmc
# from example_util_functions import transport_particles_on_h5m_geometry
# my_model = CadToDagmc()
# material_tags = ["mat1"] * 5
# my_model.add_cadquery_object(cadquery_object=my_reactor, material_tags=material_tags)
Expand Down
4 changes: 1 addition & 3 deletions examples/spherical_tokamak_from_plasma_with_tf_magnets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from pathlib import Path

from cad_to_dagmc import CadToDagmc
from example_util_functions import transport_particles_on_h5m_geometry

Expand All @@ -14,7 +12,7 @@
azimuthal_placement_angles = [0, 30, 60, 90, 120, 150, 180],
)

result = paramak.spherical_tokamak_from_plasma(
result = paramak.spherical_tokamak(
radial_builds=[
(paramak.LayerType.GAP, 70),
(paramak.LayerType.SOLID, 10),
Expand Down
2 changes: 0 additions & 2 deletions examples/spherical_tokamak_minimal.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from pathlib import Path

from cad_to_dagmc import CadToDagmc
from example_util_functions import transport_particles_on_h5m_geometry

Expand Down
7 changes: 3 additions & 4 deletions examples/tokamak_from_plasma_minimal.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from cad_to_dagmc import CadToDagmc
from example_util_functions import transport_particles_on_h5m_geometry

import paramak

my_reactor = paramak.tokamak_from_plasma(
my_reactor = paramak.tokamak(
radial_builds=[
(paramak.LayerType.GAP, 10),
(paramak.LayerType.SOLID, 30),
Expand All @@ -25,6 +22,8 @@
my_reactor.save(f"tokamak_minimal.step")
print(f"Saved as tokamak_minimal.step")

# from cad_to_dagmc import CadToDagmc
# from example_util_functions import transport_particles_on_h5m_geometry
# my_model = CadToDagmc()
# material_tags = ["mat1"] * 6 # as inner and outer layers are one solid there are only 6 solids in model
# my_model.add_cadquery_object(cadquery_object=my_reactor, material_tags=material_tags)
Expand Down
6 changes: 2 additions & 4 deletions examples/tokamak_from_plasma_with_divertor.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@

from example_util_functions import transport_particles_on_h5m_geometry

import paramak

my_reactor = paramak.tokamak_from_plasma(
my_reactor = paramak.tokamak(
radial_builds=[
[
(paramak.LayerType.GAP, 10),
Expand All @@ -29,6 +26,7 @@
print(f"Saved as tokamak_with_divertor.step")

# from cad_to_dagmc import CadToDagmc
# from example_util_functions import transport_particles_on_h5m_geometry
# my_model = CadToDagmc()
# material_tags = ["mat1"] * 6 # as inner and outer layers are one solid there are only 6 solids in model
# my_model.add_cadquery_object(cadquery_object=my_reactor, material_tags=material_tags)
Expand Down
4 changes: 2 additions & 2 deletions src/paramak/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from importlib.metadata import version

from .assemblies.spherical_tokamak import spherical_tokamak, spherical_tokamak_from_plasma
from .assemblies.tokamak import tokamak, tokamak_from_plasma
from .assemblies.spherical_tokamak import spherical_tokamak
from .assemblies.tokamak import tokamak

from .workplanes.blanket_constant_thickness_arc_h import blanket_constant_thickness_arc_h
from .workplanes.blanket_from_plasma import blanket_from_plasma
Expand Down
50 changes: 48 additions & 2 deletions src/paramak/assemblies/spherical_tokamak.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def spherical_tokamak_from_plasma(
# slice opperation reverses the list and removes the last value to avoid two plasmas
vertical_build = upper_vertical_build[::-1][:-1] + [(LayerType.PLASMA, plasma_height)] + upper_vertical_build[1:]

return spherical_tokamak(
return spherical_tokamak_from_vertical_build(
radial_builds=radial_builds,
vertical_build=vertical_build,
triangularity=triangularity,
Expand All @@ -154,7 +154,7 @@ def spherical_tokamak_from_plasma(
)


def spherical_tokamak(
def spherical_tokamak_from_vertical_build(
radial_builds: Union[Sequence[Sequence[Tuple[str, float]]], Sequence[Tuple[str, float]]],
vertical_build: Sequence[Tuple[str, float]],
triangularity: float = 0.55,
Expand Down Expand Up @@ -260,3 +260,49 @@ def spherical_tokamak(
my_assembly.add(plasma, name="plasma")

return my_assembly



def spherical_tokamak(
radial_builds: Union[Sequence[Sequence[Tuple[str, float]]], Sequence[Tuple[str, float]]],
vertical_build: Sequence[Tuple[str, float]],
rotation_angle: float = 180.0,
triangularity: float = 0.55,
elongation: float = 2.0,
add_extra_cut_shapes: Sequence[cq.Workplane] = [],
):
"""
Creates a spherical tokamak fusion reactor from a radial build and plasma parameters.

Args:
radial_builds: A list of tuples containing the radial build of the reactor or a list of lists of tuples.
vertical_build: A list of tuples containing the vertical build of the reactor.
rotation_angle: The rotation angle of the plasma. Defaults to 180.0.
triangularity: The triangularity of the plasma. Defaults to 0.55.
elongation: The elongation of the plasma. Defaults to 2.0.
add_extra_cut_shapes: A list of extra shapes to cut the reactor with. Defaults to [].

Returns:
CadQuery.Assembly: A CadQuery Assembly object representing the tokamak fusion reactor.
"""

if elongation is None and vertical_build is not None:
assembly = spherical_tokamak_from_vertical_build(
radial_builds=radial_builds,
triangularity=triangularity,
rotation_angle=rotation_angle,
add_extra_cut_shapes=add_extra_cut_shapes,
vertical_build=vertical_build
)
elif elongation is not None and vertical_build is None:
assembly = spherical_tokamak_from_plasma(
radial_builds=radial_builds,
triangularity=triangularity,
rotation_angle=rotation_angle,
add_extra_cut_shapes=add_extra_cut_shapes,
elongation=elongation,
)
else:
raise ValueError("Either elongation or vertical_build must be provided but not both")

return assembly
44 changes: 42 additions & 2 deletions src/paramak/assemblies/tokamak.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def create_layers_from_plasma(

return layers


def tokamak_from_plasma(
radial_builds: Union[Sequence[Sequence[Tuple[str, float]]], Sequence[Tuple[str, float]]],
elongation: float = 2.0,
Expand Down Expand Up @@ -184,15 +185,15 @@ def tokamak_from_plasma(
# slice opperation reverses the list and removes the last value to avoid two plasmas
vertical_build = upper_vertical_build[::-1][:-1] + [(LayerType.PLASMA, plasma_height)] + upper_vertical_build[1:]

return tokamak(
return tokamak_from_vertical_build(
radial_builds=radial_builds,
vertical_build=vertical_build,
triangularity=triangularity,
rotation_angle=rotation_angle,
add_extra_cut_shapes=add_extra_cut_shapes,
)

def tokamak(
def tokamak_from_vertical_build(
radial_builds: Union[Sequence[Sequence[Tuple[str, float]]], Sequence[Tuple[str, float]]],
vertical_build: Sequence[Tuple[str, float]],
triangularity: float = 0.55,
Expand Down Expand Up @@ -286,3 +287,42 @@ def tokamak(
my_assembly.add(plasma, name="plasma")

return my_assembly


def tokamak(
radial_builds: Union[Sequence[Sequence[Tuple[LayerType, float]]], Sequence[Tuple[LayerType, float]]],
vertical_build_or_elongation: Union[float, Sequence[Tuple[LayerType, float]]] = 2.0,
rotation_angle: float = 180.0,
triangularity: float = 0.55,
add_extra_cut_shapes: Sequence[cq.Workplane] = [],
):
"""
Creates tokamak fusion reactor geometry from a radial build, plasma parameters and optional vertical builds and extra components.

Args:
radial_builds: A list of tuples each with a LayerType and a float describing the radial build of the reactor.
vertical_build_or_elongation: Either a float describing the elongation of the plasma or a list of tuples each with a LayerType and a float describing the vertical build of the reactor.
rotation_angle: The rotation angle of the plasma. Defaults to 180.0.
triangularity: The triangularity of the plasma. Defaults to 0.55.
add_extra_cut_shapes: A list of extra shapes to cut the reactor with. Defaults to [].

Returns:
CadQuery.Assembly: A CadQuery Assembly object representing the tokamak fusion reactor.
"""

if isinstance(vertical_build_or_elongation, float):
return tokamak_from_vertical_build(
radial_builds=radial_builds,
triangularity=triangularity,
rotation_angle=rotation_angle,
add_extra_cut_shapes=add_extra_cut_shapes,
vertical_build=vertical_build_or_elongation
)

return tokamak_from_plasma(
radial_builds=radial_builds,
triangularity=triangularity,
rotation_angle=rotation_angle,
add_extra_cut_shapes=add_extra_cut_shapes,
elongation=vertical_build_or_elongation,
)