From 4a8c2b19f94bb63136be117d4797764c972159e6 Mon Sep 17 00:00:00 2001 From: shimwell Date: Tue, 1 Oct 2024 17:53:16 +0100 Subject: [PATCH] find replace radial_builds --- docs/usage.rst | 152 +++++++++--------- .../spherical_tokamak_from_plasma_minimal.py | 22 ++- ...rical_tokamak_from_plasma_with_divertor.py | 34 ++-- ...cal_tokamak_from_plasma_with_pf_magnets.py | 2 +- ...om_plasma_with_pf_magnets_and_divertors.py | 26 ++- ...cal_tokamak_from_plasma_with_tf_magnets.py | 2 +- examples/spherical_tokamak_minimal.py | 22 ++- examples/tokamak_from_plasma_minimal.py | 2 +- examples/tokamak_from_plasma_with_divertor.py | 21 +-- examples/tokamak_minimal.py | 2 +- examples/tokamak_with_pf_magnets.py | 2 +- src/paramak/assemblies/spherical_tokamak.py | 64 ++++---- src/paramak/assemblies/tokamak.py | 68 ++++---- src/paramak/utils.py | 46 ------ .../test_assemblies/test_spherical_tokamak.py | 4 +- 15 files changed, 207 insertions(+), 262 deletions(-) diff --git a/docs/usage.rst b/docs/usage.rst index 5575efcc..d71cf4f6 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -54,7 +54,7 @@ Tokamak from plasma import paramak result = paramak.tokamak_from_plasma( - radial_builds=[ + radial_build=[ (paramak.LayerType.GAP, 10), (paramak.LayerType.SOLID, 30), (paramak.LayerType.SOLID, 50), @@ -78,7 +78,7 @@ Tokamak from plasma import paramak result = paramak.tokamak_from_plasma( - radial_builds=[ + radial_build=[ (paramak.LayerType.GAP, 10), (paramak.LayerType.SOLID, 30), (paramak.LayerType.SOLID, 50), @@ -115,7 +115,7 @@ Spherical tokamak from plasma import paramak result = paramak.spherical_tokamak_from_plasma( - radial_builds=[ + radial_build=[ (paramak.LayerType.GAP, 10), (paramak.LayerType.SOLID, 60), (paramak.LayerType.SOLID, 20), @@ -136,7 +136,7 @@ Spherical tokamak from plasma import paramak result = paramak.spherical_tokamak_from_plasma( - radial_builds=[ + radial_build=[ (paramak.LayerType.GAP, 10), (paramak.LayerType.SOLID, 60), (paramak.LayerType.SOLID, 20), @@ -172,7 +172,7 @@ Tokamak import paramak result = paramak.tokamak( - radial_builds=[ + radial_build=[ (paramak.LayerType.GAP, 10), (paramak.LayerType.SOLID, 30), (paramak.LayerType.SOLID, 50), @@ -206,7 +206,7 @@ Tokamak import paramak result = paramak.tokamak( - radial_builds=[ + radial_build=[ (paramak.LayerType.GAP, 10), (paramak.LayerType.SOLID, 30), (paramak.LayerType.SOLID, 50), @@ -256,18 +256,16 @@ Spherical tokamak import paramak result = paramak.spherical_tokamak( - radial_builds=[ - [ - (paramak.LayerType.GAP, 10), - (paramak.LayerType.SOLID, 50), - (paramak.LayerType.SOLID, 10), - (paramak.LayerType.GAP, 50), - (paramak.LayerType.PLASMA, 300), - (paramak.LayerType.GAP, 60), - (paramak.LayerType.SOLID, 10), - (paramak.LayerType.SOLID, 60), - (paramak.LayerType.SOLID, 10), - ] + radial_build=[ + (paramak.LayerType.GAP, 10), + (paramak.LayerType.SOLID, 50), + (paramak.LayerType.SOLID, 10), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (paramak.LayerType.SOLID, 10), + (paramak.LayerType.SOLID, 60), + (paramak.LayerType.SOLID, 10), ], vertical_build=[ (paramak.LayerType.SOLID, 15), @@ -289,8 +287,7 @@ Spherical tokamak import paramak result = paramak.spherical_tokamak( - radial_builds=[ - [ + radial_build=[ (paramak.LayerType.GAP, 10), (paramak.LayerType.SOLID, 50), (paramak.LayerType.SOLID, 10), @@ -300,7 +297,6 @@ Spherical tokamak (paramak.LayerType.SOLID, 10), (paramak.LayerType.SOLID, 60), (paramak.LayerType.SOLID, 10), - ] ], vertical_build=[ (paramak.LayerType.SOLID, 15), @@ -332,49 +328,51 @@ Reactor with divertor(s) :width: 100% :height: 600px + # 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) result = paramak.spherical_tokamak_from_plasma( - radial_builds=[ - [ - (paramak.LayerType.GAP, 10), - (paramak.LayerType.SOLID, 50), - (paramak.LayerType.SOLID, 15), - (paramak.LayerType.GAP, 50), - (paramak.LayerType.PLASMA, 300), - (paramak.LayerType.GAP, 60), - (paramak.LayerType.SOLID, 15), - (paramak.LayerType.SOLID, 60), - (paramak.LayerType.SOLID, 10), - ], - [(paramak.LayerType.GAP, 75), ("lower_divertor", 100)], # this divertor connects to the center column - [(paramak.LayerType.GAP, 120), ("upper_divertor", 100)], # this divertor has some blanket between the center colum and itself + radial_build=[ + (paramak.LayerType.GAP, 10), + (paramak.LayerType.SOLID, 50), + (paramak.LayerType.SOLID, 15), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (paramak.LayerType.SOLID, 15), + (paramak.LayerType.SOLID, 60), + (paramak.LayerType.SOLID, 10), ], elongation=2, triangularity=0.55, rotation_angle=180, + extra_intersect_shapes=[divertor_lower] ).toCompound() .. code-block:: python + # 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) result = paramak.spherical_tokamak_from_plasma( - radial_builds=[ - [ - (paramak.LayerType.GAP, 10), - (paramak.LayerType.SOLID, 50), - (paramak.LayerType.SOLID, 15), - (paramak.LayerType.GAP, 50), - (paramak.LayerType.PLASMA, 300), - (paramak.LayerType.GAP, 60), - (paramak.LayerType.SOLID, 15), - (paramak.LayerType.SOLID, 60), - (paramak.LayerType.SOLID, 10), - ], - [(paramak.LayerType.GAP, 75), ("lower_divertor", 100)], # this divertor connects to the center column - [(paramak.LayerType.GAP, 120), ("upper_divertor", 140)], # this divertor has some blanket between the center colum and itself + radial_build=[ + (paramak.LayerType.GAP, 10), + (paramak.LayerType.SOLID, 50), + (paramak.LayerType.SOLID, 15), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (paramak.LayerType.SOLID, 15), + (paramak.LayerType.SOLID, 60), + (paramak.LayerType.SOLID, 10), ], elongation=2, triangularity=0.55, rotation_angle=180, + extra_intersect_shapes=[divertor_lower] ) result.save('reactor.step') @@ -415,7 +413,7 @@ Reactor with poloidal field coils ) result = paramak.spherical_tokamak_from_plasma( - radial_builds=[ + radial_build=[ (paramak.LayerType.GAP, 10), (paramak.LayerType.SOLID, 50), (paramak.LayerType.SOLID, 15), @@ -458,7 +456,7 @@ Reactor with poloidal field coils ) result = paramak.spherical_tokamak_from_plasma( - radial_builds=[ + radial_build=[ (paramak.LayerType.GAP, 10), (paramak.LayerType.SOLID, 50), (paramak.LayerType.SOLID, 15), @@ -506,7 +504,7 @@ Reactor with toroidal field coils ) result = paramak.spherical_tokamak_from_plasma( - radial_builds=[ + radial_build=[ (paramak.LayerType.GAP, 70), (paramak.LayerType.SOLID, 10), (paramak.LayerType.SOLID, 10), @@ -537,7 +535,7 @@ Reactor with toroidal field coils ) result = paramak.spherical_tokamak_from_plasma( - radial_builds=[ + radial_build=[ (paramak.LayerType.GAP, 70), (paramak.LayerType.SOLID, 10), (paramak.LayerType.SOLID, 10), @@ -573,7 +571,7 @@ Tokamak with negative triangularity import paramak result = paramak.tokamak( - radial_builds=[ + radial_build=[ (paramak.LayerType.GAP, 10), (paramak.LayerType.SOLID, 30), (paramak.LayerType.SOLID, 50), @@ -607,7 +605,7 @@ Tokamak with negative triangularity import paramak result = paramak.tokamak( - radial_builds=[ + radial_build=[ (paramak.LayerType.GAP, 10), (paramak.LayerType.SOLID, 30), (paramak.LayerType.SOLID, 50), @@ -656,18 +654,16 @@ Spherical tokamak with negative triangularity import paramak result = paramak.spherical_tokamak( - radial_builds=[ - [ - (paramak.LayerType.GAP, 10), - (paramak.LayerType.SOLID, 50), - (paramak.LayerType.SOLID, 15), - (paramak.LayerType.GAP, 50), - (paramak.LayerType.PLASMA, 300), - (paramak.LayerType.GAP, 60), - (paramak.LayerType.SOLID, 40), - (paramak.LayerType.SOLID, 60), - (paramak.LayerType.SOLID, 10), - ] + radial_build=[ + (paramak.LayerType.GAP, 10), + (paramak.LayerType.SOLID, 50), + (paramak.LayerType.SOLID, 15), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (paramak.LayerType.SOLID, 40), + (paramak.LayerType.SOLID, 60), + (paramak.LayerType.SOLID, 10), ], vertical_build=[ (paramak.LayerType.SOLID, 15), @@ -689,18 +685,16 @@ Spherical tokamak with negative triangularity import paramak result = paramak.spherical_tokamak( - radial_builds=[ - [ - (paramak.LayerType.GAP, 10), - (paramak.LayerType.SOLID, 50), - (paramak.LayerType.SOLID, 15), - (paramak.LayerType.GAP, 50), - (paramak.LayerType.PLASMA, 300), - (paramak.LayerType.GAP, 60), - (paramak.LayerType.SOLID, 10), - (paramak.LayerType.SOLID, 60), - (paramak.LayerType.SOLID, 10), - ] + radial_build=[ + (paramak.LayerType.GAP, 10), + (paramak.LayerType.SOLID, 50), + (paramak.LayerType.SOLID, 15), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (paramak.LayerType.SOLID, 10), + (paramak.LayerType.SOLID, 60), + (paramak.LayerType.SOLID, 10), ], vertical_build=[ (paramak.LayerType.SOLID, 15), diff --git a/examples/spherical_tokamak_from_plasma_minimal.py b/examples/spherical_tokamak_from_plasma_minimal.py index a821a25e..a3b23ac0 100644 --- a/examples/spherical_tokamak_from_plasma_minimal.py +++ b/examples/spherical_tokamak_from_plasma_minimal.py @@ -6,18 +6,16 @@ import paramak my_reactor = paramak.spherical_tokamak_from_plasma( - radial_builds=[ - [ - (paramak.LayerType.GAP, 10), - (paramak.LayerType.SOLID, 50), - (paramak.LayerType.SOLID, 15), - (paramak.LayerType.GAP, 50), - (paramak.LayerType.PLASMA, 300), - (paramak.LayerType.GAP, 60), - (paramak.LayerType.SOLID, 15), - (paramak.LayerType.SOLID, 60), - (paramak.LayerType.SOLID, 10), - ] + radial_build=[ + (paramak.LayerType.GAP, 10), + (paramak.LayerType.SOLID, 50), + (paramak.LayerType.SOLID, 15), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (paramak.LayerType.SOLID, 15), + (paramak.LayerType.SOLID, 60), + (paramak.LayerType.SOLID, 10), ], elongation=2, triangularity=0.55, diff --git a/examples/spherical_tokamak_from_plasma_with_divertor.py b/examples/spherical_tokamak_from_plasma_with_divertor.py index 94e7eb07..d0101ec7 100644 --- a/examples/spherical_tokamak_from_plasma_with_divertor.py +++ b/examples/spherical_tokamak_from_plasma_with_divertor.py @@ -4,31 +4,35 @@ from example_util_functions import transport_particles_on_h5m_geometry import paramak +from cadquery import Workplane, vis + + +# 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) my_reactor = paramak.spherical_tokamak_from_plasma( - radial_builds=[ - [ - (paramak.LayerType.GAP, 10), - (paramak.LayerType.SOLID, 50), - (paramak.LayerType.SOLID, 15), - (paramak.LayerType.GAP, 50), - (paramak.LayerType.PLASMA, 300), - (paramak.LayerType.GAP, 60), - (paramak.LayerType.SOLID, 15), - (paramak.LayerType.SOLID, 60), - (paramak.LayerType.SOLID, 10), - ], - [(paramak.LayerType.GAP, 75), ("lower_divertor", 100)], # this divertor connects to the center column - [(paramak.LayerType.GAP, 120), ("upper_divertor", 140)], # this divertor has some blanket between the center colum and itself + radial_build=[ + (paramak.LayerType.GAP, 10), + (paramak.LayerType.SOLID, 50), + (paramak.LayerType.SOLID, 15), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (paramak.LayerType.SOLID, 15), + (paramak.LayerType.SOLID, 60), + (paramak.LayerType.SOLID, 10), ], elongation=2, triangularity=0.55, rotation_angle=180, + extra_intersect_shapes=[divertor_lower] ) my_reactor.save("spherical_tokamak_from_plasma_with_divertor.step") print('written spherical_tokamak_from_plasma_with_divertor.step') - +vis.show(my_reactor) # 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) diff --git a/examples/spherical_tokamak_from_plasma_with_pf_magnets.py b/examples/spherical_tokamak_from_plasma_with_pf_magnets.py index f4db3c8f..807a4457 100644 --- a/examples/spherical_tokamak_from_plasma_with_pf_magnets.py +++ b/examples/spherical_tokamak_from_plasma_with_pf_magnets.py @@ -25,7 +25,7 @@ my_reactor = paramak.spherical_tokamak_from_plasma( - radial_builds=[ + radial_build=[ (paramak.LayerType.GAP, 10), (paramak.LayerType.SOLID, 50), (paramak.LayerType.SOLID, 15), diff --git a/examples/spherical_tokamak_from_plasma_with_pf_magnets_and_divertors.py b/examples/spherical_tokamak_from_plasma_with_pf_magnets_and_divertors.py index 4343321a..704484f4 100644 --- a/examples/spherical_tokamak_from_plasma_with_pf_magnets_and_divertors.py +++ b/examples/spherical_tokamak_from_plasma_with_pf_magnets_and_divertors.py @@ -25,21 +25,19 @@ ) ) - +#TODO +# [(paramak.LayerType.GAP, 75), ("lower_divertor", 100)], my_reactor = paramak.spherical_tokamak_from_plasma( - radial_builds=[ - [ - (paramak.LayerType.GAP, 10), - (paramak.LayerType.SOLID, 50), - (paramak.LayerType.SOLID, 15), - (paramak.LayerType.GAP, 50), - (paramak.LayerType.PLASMA, 300), - (paramak.LayerType.GAP, 60), - (paramak.LayerType.SOLID, 15), - (paramak.LayerType.SOLID, 60), - (paramak.LayerType.SOLID, 10), - ], - [(paramak.LayerType.GAP, 75), ("lower_divertor", 100)], + radial_build=[ + (paramak.LayerType.GAP, 10), + (paramak.LayerType.SOLID, 50), + (paramak.LayerType.SOLID, 15), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (paramak.LayerType.SOLID, 15), + (paramak.LayerType.SOLID, 60), + (paramak.LayerType.SOLID, 10), ], elongation=2, triangularity=0.55, diff --git a/examples/spherical_tokamak_from_plasma_with_tf_magnets.py b/examples/spherical_tokamak_from_plasma_with_tf_magnets.py index 4297e6c6..c510e569 100644 --- a/examples/spherical_tokamak_from_plasma_with_tf_magnets.py +++ b/examples/spherical_tokamak_from_plasma_with_tf_magnets.py @@ -15,7 +15,7 @@ ) result = paramak.spherical_tokamak_from_plasma( - radial_builds=[ + radial_build=[ (paramak.LayerType.GAP, 70), (paramak.LayerType.SOLID, 10), (paramak.LayerType.SOLID, 10), diff --git a/examples/spherical_tokamak_minimal.py b/examples/spherical_tokamak_minimal.py index 95ba4b71..a5aad263 100644 --- a/examples/spherical_tokamak_minimal.py +++ b/examples/spherical_tokamak_minimal.py @@ -6,18 +6,16 @@ import paramak my_reactor = paramak.spherical_tokamak( - radial_builds=[ - [ - (paramak.LayerType.GAP, 10), - (paramak.LayerType.SOLID, 50), - (paramak.LayerType.SOLID, 15), - (paramak.LayerType.GAP, 50), - (paramak.LayerType.PLASMA, 300), - (paramak.LayerType.GAP, 60), - (paramak.LayerType.SOLID, 40), - (paramak.LayerType.SOLID, 60), - (paramak.LayerType.SOLID, 10), - ] + radial_build=[ + (paramak.LayerType.GAP, 10), + (paramak.LayerType.SOLID, 50), + (paramak.LayerType.SOLID, 15), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (paramak.LayerType.SOLID, 40), + (paramak.LayerType.SOLID, 60), + (paramak.LayerType.SOLID, 10), ], vertical_build=[ (paramak.LayerType.SOLID, 15), diff --git a/examples/tokamak_from_plasma_minimal.py b/examples/tokamak_from_plasma_minimal.py index 4c81c745..f9e0cf52 100644 --- a/examples/tokamak_from_plasma_minimal.py +++ b/examples/tokamak_from_plasma_minimal.py @@ -4,7 +4,7 @@ import paramak my_reactor = paramak.tokamak_from_plasma( - radial_builds=[ + radial_build=[ (paramak.LayerType.GAP, 10), (paramak.LayerType.SOLID, 30), (paramak.LayerType.SOLID, 50), diff --git a/examples/tokamak_from_plasma_with_divertor.py b/examples/tokamak_from_plasma_with_divertor.py index 6554c25b..bf7e0065 100644 --- a/examples/tokamak_from_plasma_with_divertor.py +++ b/examples/tokamak_from_plasma_with_divertor.py @@ -4,21 +4,14 @@ import paramak from cadquery import vis, Workplane -radial_start = 300 -radial_thickness = 100 -height = 700 -points = [ - (radial_start, height), - (radial_start, 0), - (radial_start+radial_thickness, 0), - (radial_start+radial_thickness, height), -] -points.append(points[0]) -divertor_solid = Workplane('XZ', origin=(0,0,0)).polyline(points).close().revolve(180) +# 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) my_reactor = paramak.tokamak_from_plasma( - radial_builds=[ + radial_build=[ [ (paramak.LayerType.GAP, 10), (paramak.LayerType.SOLID, 30), @@ -38,11 +31,11 @@ elongation=2, triangularity=0.55, rotation_angle=180, - extra_intersect_shapes=[divertor_solid] + extra_intersect_shapes=[divertor_lower] ) my_reactor.save(f"tokamak_with_divertor.step") print(f"Saved as tokamak_with_divertor.step") -vis.show(my_reactor) +# vis.show(my_reactor) # from cad_to_dagmc import CadToDagmc # my_model = CadToDagmc() diff --git a/examples/tokamak_minimal.py b/examples/tokamak_minimal.py index c8c04eb6..b24ae32a 100644 --- a/examples/tokamak_minimal.py +++ b/examples/tokamak_minimal.py @@ -4,7 +4,7 @@ import paramak my_reactor = paramak.tokamak( - radial_builds=[ + radial_build=[ (paramak.LayerType.GAP, 10), (paramak.LayerType.SOLID, 30), (paramak.LayerType.SOLID, 50), diff --git a/examples/tokamak_with_pf_magnets.py b/examples/tokamak_with_pf_magnets.py index 0fcb4f69..956a1cdc 100644 --- a/examples/tokamak_with_pf_magnets.py +++ b/examples/tokamak_with_pf_magnets.py @@ -24,7 +24,7 @@ ) my_reactor = paramak.tokamak( - radial_builds=[ + radial_build=[ (paramak.LayerType.GAP, 10), (paramak.LayerType.SOLID, 30), (paramak.LayerType.SOLID, 50), diff --git a/src/paramak/assemblies/spherical_tokamak.py b/src/paramak/assemblies/spherical_tokamak.py index f3a5ed0a..ac8c5c06 100644 --- a/src/paramak/assemblies/spherical_tokamak.py +++ b/src/paramak/assemblies/spherical_tokamak.py @@ -1,11 +1,8 @@ from typing import Optional, Sequence, Tuple, Union import cadquery as cq -import numpy as np from ..utils import ( - build_divertor_modify_blanket, - extract_radial_builds, get_plasma_index, get_plasma_value, sum_up_to_gap_before_plasma, @@ -106,11 +103,12 @@ def create_center_column_shield_cylinders(radial_build, vertical_build, rotation def spherical_tokamak_from_plasma( - radial_builds: Union[Sequence[Sequence[Tuple[str, float]]], Sequence[Tuple[str, float]]], + radial_build: Sequence[Tuple[LayerType, float]], elongation: float = 2.0, triangularity: float = 0.55, rotation_angle: float = 180.0, add_extra_cut_shapes: Sequence[cq.Workplane] = [], + extra_intersect_shapes: Sequence[cq.Workplane] = [], ): """_summary_ @@ -125,10 +123,8 @@ def spherical_tokamak_from_plasma( _type_: _description_ """ - plasma_radial_build, _ = extract_radial_builds(radial_builds) - - inner_equatorial_point = sum_up_to_plasma(plasma_radial_build) - plasma_radial_thickness = get_plasma_value(plasma_radial_build) + inner_equatorial_point = sum_up_to_plasma(radial_build) + plasma_radial_thickness = get_plasma_value(radial_build) outer_equatorial_point = inner_equatorial_point + plasma_radial_thickness # sets major radius and minor radius from equatorial_points to allow a @@ -138,28 +134,30 @@ def spherical_tokamak_from_plasma( minor_radius = major_radius - inner_equatorial_point # make vertical build from outer radial build - pi = get_plasma_index(plasma_radial_build) - upper_vertical_build = plasma_radial_build[pi:] + pi = get_plasma_index(radial_build) + upper_vertical_build = radial_build[pi:] 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][:-1] + [(LayerType.PLASMA, plasma_height)] + upper_vertical_build[1:] return spherical_tokamak( - radial_builds=radial_builds, + radial_build=radial_build, vertical_build=vertical_build, triangularity=triangularity, rotation_angle=rotation_angle, add_extra_cut_shapes=add_extra_cut_shapes, + extra_intersect_shapes=extra_intersect_shapes ) def spherical_tokamak( - radial_builds: Union[Sequence[Sequence[Tuple[str, float]]], Sequence[Tuple[str, float]]], + radial_build: Union[Sequence[Sequence[Tuple[str, float]]], Sequence[Tuple[str, float]]], vertical_build: Sequence[Tuple[str, float]], triangularity: float = 0.55, rotation_angle: Optional[str] = 180.0, add_extra_cut_shapes: Sequence[cq.Workplane] = [], + extra_intersect_shapes: Sequence[cq.Workplane] = [], ): """_summary_ @@ -175,10 +173,8 @@ def spherical_tokamak( _type_: _description_ """ - plasma_radial_build, divertor_radial_builds = extract_radial_builds(radial_builds) - - inner_equatorial_point = sum_up_to_plasma(plasma_radial_build) - plasma_radial_thickness = get_plasma_value(plasma_radial_build) + inner_equatorial_point = sum_up_to_plasma(radial_build) + plasma_radial_thickness = get_plasma_value(radial_build) plasma_vertical_thickness = get_plasma_value(vertical_build) outer_equatorial_point = inner_equatorial_point + plasma_radial_thickness @@ -201,20 +197,20 @@ def spherical_tokamak( ) inner_radial_build = create_center_column_shield_cylinders( - radial_build=plasma_radial_build, + radial_build=radial_build, vertical_build=vertical_build, rotation_angle=rotation_angle, ) blanket_cutting_cylinder = center_column_shield_cylinder( inner_radius=0, - thickness=sum_up_to_gap_before_plasma(plasma_radial_build), + thickness=sum_up_to_gap_before_plasma(radial_build), rotation_angle=360, height=2 * blanket_rear_wall_end_height, ) blanket_layers = create_blanket_layers_after_plasma( - radial_build=plasma_radial_build, + radial_build=radial_build, vertical_build=vertical_build, minor_radius=minor_radius, major_radius=major_radius, @@ -224,9 +220,6 @@ def spherical_tokamak( center_column=blanket_cutting_cylinder, ) - divertor_layers, blanket_layers = build_divertor_modify_blanket( - blanket_layers, divertor_radial_builds, blanket_rear_wall_end_height, rotation_angle - ) my_assembly = cq.Assembly() @@ -237,17 +230,34 @@ def spherical_tokamak( else: raise ValueError(f"add_extra_cut_shapes should only contain cadquery Workplanes, not {type(entry)}") - if len(add_extra_cut_shapes) == 0: + # builds up the intersect shapes + intersect_shapes_to_cut = [] + if len(extra_intersect_shapes)>0: + all_shapes = [] + for shape in inner_radial_build + blanket_layers: + all_shapes.extend(shape) + + # makes a union of the the radial build to use as a base for the intersect shapes + reactor_compound=inner_radial_build[0] + for i, entry in enumerate(inner_radial_build[1:] + blanket_layers): + reactor_compound = reactor_compound.union(entry) + + # adds the extra intersect shapes to the assembly + for i, entry in enumerate(extra_intersect_shapes): + reactor_entry_intersection = entry.intersect(reactor_compound) + intersect_shapes_to_cut.append(reactor_entry_intersection) + my_assembly.add(reactor_entry_intersection, name=f"extra_intersect_shapes_{i+1}") + + # builds just the core if there are no extra parts + if len(add_extra_cut_shapes) == 0 and len(intersect_shapes_to_cut) == 0: for i, entry in enumerate(inner_radial_build): my_assembly.add(entry, name=f"inboard_layer_{i+1})") for i, entry in enumerate(blanket_layers): my_assembly.add(entry, name=f"outboard_layer_{i+1})") - for i, entry in enumerate(divertor_layers): - my_assembly.add(entry, name=f"{entry.name})") # gets upper or lower name else: shapes_and_components = [] - for i, entry in enumerate(inner_radial_build + blanket_layers + divertor_layers): - for cutter in add_extra_cut_shapes: + for i, entry in enumerate(inner_radial_build + blanket_layers): + for cutter in add_extra_cut_shapes + extra_intersect_shapes: entry = entry.cut(cutter) # TODO use something like this to return a list of material tags for the solids in order, as some solids get split into multiple # for subentry in entry.objects: diff --git a/src/paramak/assemblies/tokamak.py b/src/paramak/assemblies/tokamak.py index 9f04f46c..7d827141 100644 --- a/src/paramak/assemblies/tokamak.py +++ b/src/paramak/assemblies/tokamak.py @@ -2,7 +2,7 @@ import cadquery as cq -from ..utils import build_divertor_modify_blanket, extract_radial_builds, get_plasma_index, sum_after_plasma, LayerType +from ..utils import get_plasma_index, LayerType from ..workplanes.blanket_from_plasma import blanket_from_plasma from ..workplanes.center_column_shield_cylinder import center_column_shield_cylinder from ..workplanes.plasma_simplified import plasma_simplified @@ -157,18 +157,16 @@ def create_layers_from_plasma( return layers def tokamak_from_plasma( - radial_builds: Sequence[Tuple[str, float]], + radial_build: Sequence[Tuple[LayerType, float]], elongation: float = 2.0, triangularity: float = 0.55, rotation_angle: float = 180.0, add_extra_cut_shapes: Sequence[cq.Workplane] = [], extra_intersect_shapes: Sequence[cq.Workplane] = [], ): - - plasma_radial_build, _ = extract_radial_builds(radial_builds) - inner_equatorial_point = sum_up_to_plasma(plasma_radial_build) - plasma_radial_thickness = get_plasma_value(plasma_radial_build) + inner_equatorial_point = sum_up_to_plasma(radial_build) + plasma_radial_thickness = get_plasma_value(radial_build) outer_equatorial_point = inner_equatorial_point + plasma_radial_thickness # sets major radius and minor radius from equatorial_points to allow a @@ -178,15 +176,15 @@ def tokamak_from_plasma( minor_radius = major_radius - inner_equatorial_point # make vertical build from outer radial build - pi = get_plasma_index(plasma_radial_build) - upper_vertical_build = plasma_radial_build[pi:] + pi = get_plasma_index(radial_build) + upper_vertical_build = radial_build[pi:] 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][:-1] + [(LayerType.PLASMA, plasma_height)] + upper_vertical_build[1:] return tokamak( - radial_builds=radial_builds, + radial_build=radial_build, vertical_build=vertical_build, triangularity=triangularity, rotation_angle=rotation_angle, @@ -195,7 +193,7 @@ def tokamak_from_plasma( ) def tokamak( - radial_builds: Union[Sequence[Sequence[Tuple[str, float]]], Sequence[Tuple[str, float]]], + 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, @@ -206,20 +204,19 @@ def tokamak( Creates a tokamak fusion reactor from a radial build and plasma parameters. Args: - radial_builds (Sequence[tuple[str, float]]): A list of tuples containing the radial build of the reactor. - elongation (float, optional): The elongation of the plasma. Defaults to 2.0. - triangularity (float, optional): The triangularity of the plasma. Defaults to 0.55. - rotation_angle (float, optional): The rotation angle of the plasma. Defaults to 180.0. - add_extra_cut_shapes (Sequence, optional): A list of extra shapes to cut the reactor with. Defaults to []. + radial_build: A list of tuples containing the radial build of the reactor. + elongation: The elongation of the plasma. Defaults to 2.0. + triangularity: The triangularity of the plasma. Defaults to 0.55. + rotation_angle: The rotation angle of the plasma. Defaults to 180.0. + add_extra_cut_shapes: A list of extra shapes to cut the reactor with. Defaults to []. + extra_intersect_shapes: A list of extra shapes to intersect the reactor with. Defaults to []. Returns: CadQuery.Assembly: A CadQuery Assembly object representing the tokamak fusion reactor. """ - plasma_radial_build, divertor_radial_builds = extract_radial_builds(radial_builds) - - inner_equatorial_point = sum_up_to_plasma(plasma_radial_build) - plasma_radial_thickness = get_plasma_value(plasma_radial_build) + inner_equatorial_point = sum_up_to_plasma(radial_build) + plasma_radial_thickness = get_plasma_value(radial_build) plasma_vertical_thickness = get_plasma_value(vertical_build) outer_equatorial_point = inner_equatorial_point + plasma_radial_thickness @@ -238,11 +235,11 @@ def tokamak( ) inner_radial_build = create_center_column_shield_cylinders( - plasma_radial_build, rotation_angle, blanket_rear_wall_end_height + radial_build, rotation_angle, blanket_rear_wall_end_height ) blanket_layers = create_layers_from_plasma( - radial_build=plasma_radial_build, + radial_build=radial_build, vertical_build=vertical_build, minor_radius=minor_radius, major_radius=major_radius, @@ -252,43 +249,42 @@ def tokamak( center_column=inner_radial_build[0], # blanket_cutting_cylinder, ) - divertor_layers, blanket_layers = build_divertor_modify_blanket( - blanket_layers, divertor_radial_builds, blanket_rear_wall_end_height, rotation_angle - ) - my_assembly = cq.Assembly() for i, entry in enumerate(add_extra_cut_shapes): - if isinstance(entry, cq.Workplane): my_assembly.add(entry, name=f"add_extra_cut_shape_{i+1}") else: raise ValueError(f"add_extra_cut_shapes should only contain cadquery Workplanes, not {type(entry)}") - + + # builds up the intersect shapes intersect_shapes_to_cut = [] if len(extra_intersect_shapes)>0: - # make a large comp all_shapes = [] for shape in inner_radial_build + blanket_layers: - all_shapes.extend(shape[0]) - reactor_compound = cq.Compound.makeCompound(all_shapes) + all_shapes.extend(shape) + + # makes a union of the the radial build to use as a base for the intersect shapes + reactor_compound=inner_radial_build[0] + for i, entry in enumerate(inner_radial_build[1:] + blanket_layers): + reactor_compound = reactor_compound.union(entry) + # adds the extra intersect shapes to the assembly for i, entry in enumerate(extra_intersect_shapes): - reactor_entry_intersection = entry.intersect(reactor_compound) - if reactor_entry_intersection.val().Volume() > 0: - intersect_shapes_to_cut.append(reactor_entry_intersection) + reactor_entry_intersection = entry.intersect(reactor_compound) + intersect_shapes_to_cut.append(reactor_entry_intersection) + my_assembly.add(reactor_entry_intersection, name=f"extra_intersect_shapes_{i+1}") + # builds just the core if there are no extra parts if len(add_extra_cut_shapes) == 0 and len(intersect_shapes_to_cut) == 0: for i, entry in enumerate(inner_radial_build): my_assembly.add(entry, name=f"inboard_layer_{i+1})") for i, entry in enumerate(blanket_layers): my_assembly.add(entry, name=f"outboard_layer_{i+1})") - for i, entry in enumerate(divertor_layers): - my_assembly.add(entry, name=f"{entry.name})") # gets upper or lower name else: shapes_and_components = [] for i, entry in enumerate(inner_radial_build + blanket_layers + divertor_layers): - for cutter in add_extra_cut_shapes + intersect_shapes_to_cut: + for cutter in add_extra_cut_shapes + extra_intersect_shapes: entry = entry.cut(cutter) # TODO use something like this to return a list of material tags for the solids in order, as some solids get split into multiple # for subentry in entry.objects: diff --git a/src/paramak/utils.py b/src/paramak/utils.py index 19fc15e9..a06974ac 100644 --- a/src/paramak/utils.py +++ b/src/paramak/utils.py @@ -178,30 +178,6 @@ def create_divertor_envelope(divertor_radial_build, blanket_height, rotation_ang return divertor_solid -def build_divertor_modify_blanket(outer_layers, divertor_radial_builds, blanket_rear_wall_end_height, rotation_angle): - - divertor_layers = [] - for divertor_radial_build in divertor_radial_builds: - - divertor_solid = create_divertor_envelope(divertor_radial_build, blanket_rear_wall_end_height, rotation_angle) - - # finds the intersection of the blanket and divertor rectangle envelope. - outer_layer_envelope = outer_layers[0] - for outer_layer in outer_layers[1:]: - outer_layer_envelope = outer_layer_envelope.union(outer_layer) - - divertor_solid = divertor_solid.intersect(outer_layer_envelope) - # we reapply this name as it appears to get lost and we might need it when adding to assembly - divertor_solid.name = is_lower_or_upper_divertor(divertor_radial_build) - - # cuts the diverter out of the outer layers of the blanket - for i, layer in enumerate(outer_layers): - layer = layer.cut(divertor_solid) - outer_layers[i] = layer - divertor_layers.append(divertor_solid) - return divertor_layers, outer_layers - - def is_plasma_radial_build(radial_build): for entry in radial_build: # if entry == LayerType.PLASMA: @@ -211,28 +187,6 @@ def is_plasma_radial_build(radial_build): return False -def extract_radial_builds(radial_build): - # TODO more rubust method of finding if it is a single list of tupes or multiple lists - # only one radial build so it should be a plasma based radial build - divertor_radial_builds = [] - if isinstance(radial_build[0][0], LayerType) and ( - isinstance(radial_build[0][1], float) or isinstance(radial_build[0][1], int) - ): - plasma_radial_build = radial_build - else: - for entry in radial_build: - if is_plasma_radial_build(entry): - # TODO this assumes there is only one radial build, which needs to e checked - plasma_radial_build = entry - else: - divertor_radial_builds.append(entry) - - validate_plasma_radial_build(plasma_radial_build) - for divertor_radial_build in divertor_radial_builds: - validate_divertor_radial_build(divertor_radial_build) - return plasma_radial_build, divertor_radial_builds - - def validate_divertor_radial_build(radial_build): if len(radial_build) != 2: raise ValidationError( diff --git a/tests/test_assemblies/test_spherical_tokamak.py b/tests/test_assemblies/test_spherical_tokamak.py index 53c692c5..c65fcdea 100644 --- a/tests/test_assemblies/test_spherical_tokamak.py +++ b/tests/test_assemblies/test_spherical_tokamak.py @@ -33,7 +33,7 @@ def test_transport_with_magnets(rotation_angle): ) my_reactor = paramak.spherical_tokamak_from_plasma( - radial_builds=[ + radial_build=[ (paramak.LayerType.GAP, 10), (paramak.LayerType.SOLID, 50), (paramak.LayerType.SOLID, 15), @@ -70,7 +70,7 @@ def test_transport_with_magnets(rotation_angle): def test_transport_without_magnets(): reactor = paramak.spherical_tokamak_from_plasma( - radial_builds=[ + radial_build=[ (paramak.LayerType.GAP, 10), (paramak.LayerType.SOLID, 50), (paramak.LayerType.SOLID, 15),