diff --git a/docs/usage.rst b/docs/usage.rst index ad085696..d0b7cd91 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -55,18 +55,18 @@ Tokamak from plasma import paramak result = paramak.tokamak_from_plasma( radial_builds=[ - ("gap", 10), - ("layer", 30), - ("layer", 50), - ("layer", 10), - ("layer", 120), - ("layer", 20), - ("gap", 60), - ("plasma", 300), - ("gap", 60), - ("layer", 20), - ("layer", 120), - ("layer", 10), + (paramak.LayerType.GAP, 10), + (LayerType.SOLID, 30), + (LayerType.SOLID, 50), + (LayerType.SOLID, 10), + (LayerType.SOLID, 120), + (LayerType.SOLID, 20), + (paramak.LayerType.GAP, 60), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 20), + (LayerType.SOLID, 120), + (LayerType.SOLID, 10), ], elongation=2, triangularity=0.55, @@ -79,18 +79,18 @@ Tokamak from plasma import paramak result = paramak.tokamak_from_plasma( radial_builds=[ - ("gap", 10), - ("layer", 30), - ("layer", 50), - ("layer", 10), - ("layer", 120), - ("layer", 20), - ("gap", 60), - ("plasma", 300), - ("gap", 60), - ("layer", 20), - ("layer", 120), - ("layer", 10), + (paramak.LayerType.GAP, 10), + (LayerType.SOLID, 30), + (LayerType.SOLID, 50), + (LayerType.SOLID, 10), + (LayerType.SOLID, 120), + (LayerType.SOLID, 20), + (paramak.LayerType.GAP, 60), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 20), + (LayerType.SOLID, 120), + (LayerType.SOLID, 10), ], elongation=2, triangularity=0.55, @@ -116,15 +116,15 @@ Spherical tokamak from plasma import paramak result = paramak.spherical_tokamak_from_plasma( radial_builds=[ - ("gap", 10), - ("layer", 60), - ("layer", 20), - ("gap", 60), - ("plasma", 300), - ("gap", 60), - ("layer", 20), - ("layer", 120), - ("layer", 10), + (paramak.LayerType.GAP, 10), + (LayerType.SOLID, 60), + (LayerType.SOLID, 20), + (paramak.LayerType.GAP, 60), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 20), + (LayerType.SOLID, 120), + (LayerType.SOLID, 10), ], elongation=2, triangularity=0.55, @@ -137,15 +137,15 @@ Spherical tokamak from plasma import paramak result = paramak.spherical_tokamak_from_plasma( radial_builds=[ - ("gap", 10), - ("layer", 60), - ("layer", 20), - ("gap", 60), - ("plasma", 300), - ("gap", 60), - ("layer", 20), - ("layer", 120), - ("layer", 10), + (paramak.LayerType.GAP, 10), + (LayerType.SOLID, 60), + (LayerType.SOLID, 20), + (paramak.LayerType.GAP, 60), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 20), + (LayerType.SOLID, 120), + (LayerType.SOLID, 10), ], elongation=2, triangularity=0.55, @@ -173,29 +173,29 @@ Tokamak result = paramak.tokamak( radial_builds=[ - ("gap", 10), - ("layer", 30), - ("layer", 50), - ("layer", 10), - ("layer", 120), - ("layer", 20), - ("gap", 60), - ("plasma", 300), - ("gap", 60), - ("layer", 20), - ("layer", 120), - ("layer", 10), + (paramak.LayerType.GAP, 10), + (LayerType.SOLID, 30), + (LayerType.SOLID, 50), + (LayerType.SOLID, 10), + (LayerType.SOLID, 120), + (LayerType.SOLID, 20), + (paramak.LayerType.GAP, 60), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 20), + (LayerType.SOLID, 120), + (LayerType.SOLID, 10), ], vertical_build=[ - ("layer", 15), - ("layer", 80), - ("layer", 10), - ("gap", 50), - ("plasma", 700), - ("gap", 60), - ("layer", 10), - ("layer", 40), - ("layer", 15), + (LayerType.SOLID, 15), + (LayerType.SOLID, 80), + (LayerType.SOLID, 10), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 700), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 10), + (LayerType.SOLID, 40), + (LayerType.SOLID, 15), ], triangularity=0.55, rotation_angle=180, @@ -207,29 +207,29 @@ Tokamak result = paramak.tokamak( radial_builds=[ - ("gap", 10), - ("layer", 30), - ("layer", 50), - ("layer", 10), - ("layer", 120), - ("layer", 20), - ("gap", 60), - ("plasma", 300), - ("gap", 60), - ("layer", 20), - ("layer", 120), - ("layer", 10), + (paramak.LayerType.GAP, 10), + (LayerType.SOLID, 30), + (LayerType.SOLID, 50), + (LayerType.SOLID, 10), + (LayerType.SOLID, 120), + (LayerType.SOLID, 20), + (paramak.LayerType.GAP, 60), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 20), + (LayerType.SOLID, 120), + (LayerType.SOLID, 10), ], vertical_build=[ - ("layer", 15), - ("layer", 80), - ("layer", 10), - ("gap", 50), - ("plasma", 700), - ("gap", 60), - ("layer", 10), - ("layer", 40), - ("layer", 15), + (LayerType.SOLID, 15), + (LayerType.SOLID, 80), + (LayerType.SOLID, 10), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 700), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 10), + (LayerType.SOLID, 40), + (LayerType.SOLID, 15), ], triangularity=0.55, rotation_angle=180, @@ -258,27 +258,27 @@ Spherical tokamak result = paramak.spherical_tokamak( radial_builds=[ [ - ("gap", 10), - ("layer", 50), - ("layer", 10), - ("gap", 50), - ("plasma", 300), - ("gap", 60), - ("layer", 10), - ("layer", 60), - ("layer", 10), + (paramak.LayerType.GAP, 10), + (LayerType.SOLID, 50), + (LayerType.SOLID, 10), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 10), + (LayerType.SOLID, 60), + (LayerType.SOLID, 10), ] ], vertical_build=[ - ("layer", 15), - ("layer", 120), - ("layer", 10), - ("gap", 50), - ("plasma", 700), - ("gap", 60), - ("layer", 10), - ("layer", 30), - ("layer", 15), + (LayerType.SOLID, 15), + (LayerType.SOLID, 120), + (LayerType.SOLID, 10), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 700), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 10), + (LayerType.SOLID, 30), + (LayerType.SOLID, 15), ], rotation_angle=180, triangularity=0.55, @@ -291,27 +291,27 @@ Spherical tokamak result = paramak.spherical_tokamak( radial_builds=[ [ - ("gap", 10), - ("layer", 50), - ("layer", 10), - ("gap", 50), - ("plasma", 300), - ("gap", 60), - ("layer", 10), - ("layer", 60), - ("layer", 10), + (paramak.LayerType.GAP, 10), + (LayerType.SOLID, 50), + (LayerType.SOLID, 10), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 10), + (LayerType.SOLID, 60), + (LayerType.SOLID, 10), ] ], vertical_build=[ - ("layer", 15), - ("layer", 120), - ("layer", 10), - ("gap", 50), - ("plasma", 700), - ("gap", 60), - ("layer", 10), - ("layer", 30), - ("layer", 15), + (LayerType.SOLID, 15), + (LayerType.SOLID, 120), + (LayerType.SOLID, 10), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 700), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 10), + (LayerType.SOLID, 30), + (LayerType.SOLID, 15), ], rotation_angle=180, triangularity=0.55, @@ -335,18 +335,18 @@ Reactor with divertor(s) result = paramak.spherical_tokamak_from_plasma( radial_builds=[ [ - ("gap", 10), - ("layer", 50), - ("layer", 15), - ("gap", 50), - ("plasma", 300), - ("gap", 60), - ("layer", 15), - ("layer", 60), - ("layer", 10), + (paramak.LayerType.GAP, 10), + (LayerType.SOLID, 50), + (LayerType.SOLID, 15), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 15), + (LayerType.SOLID, 60), + (LayerType.SOLID, 10), ], - [("gap", 75), ("lower_divertor", 100)], # this divertor connects to the center column - [("gap", 120), ("upper_divertor", 100)], # this divertor has some blanket between the center colum and itself + [(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 ], elongation=2, triangularity=0.55, @@ -359,18 +359,18 @@ Reactor with divertor(s) result = paramak.spherical_tokamak_from_plasma( radial_builds=[ [ - ("gap", 10), - ("layer", 50), - ("layer", 15), - ("gap", 50), - ("plasma", 300), - ("gap", 60), - ("layer", 15), - ("layer", 60), - ("layer", 10), + (paramak.LayerType.GAP, 10), + (LayerType.SOLID, 50), + (LayerType.SOLID, 15), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 15), + (LayerType.SOLID, 60), + (LayerType.SOLID, 10), ], - [("gap", 75), ("lower_divertor", 100)], # this divertor connects to the center column - [("gap", 120), ("upper_divertor", 140)], # this divertor has some blanket between the center colum and itself + [(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 ], elongation=2, triangularity=0.55, @@ -416,15 +416,15 @@ Reactor with poloidal field coils result = paramak.spherical_tokamak_from_plasma( radial_builds=[ - ("gap", 10), - ("layer", 50), - ("layer", 15), - ("gap", 50), - ("plasma", 300), - ("gap", 60), - ("layer", 15), - ("layer", 60), - ("layer", 10), + (paramak.LayerType.GAP, 10), + (LayerType.SOLID, 50), + (LayerType.SOLID, 15), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 15), + (LayerType.SOLID, 60), + (LayerType.SOLID, 10), ], elongation=2, triangularity=0.55, @@ -459,15 +459,15 @@ Reactor with poloidal field coils result = paramak.spherical_tokamak_from_plasma( radial_builds=[ - ("gap", 10), - ("layer", 50), - ("layer", 15), - ("gap", 50), - ("plasma", 300), - ("gap", 60), - ("layer", 15), - ("layer", 60), - ("layer", 10), + (paramak.LayerType.GAP, 10), + (LayerType.SOLID, 50), + (LayerType.SOLID, 15), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 15), + (LayerType.SOLID, 60), + (LayerType.SOLID, 10), ], elongation=2, triangularity=0.55, @@ -507,15 +507,15 @@ Reactor with toroidal field coils result = paramak.spherical_tokamak_from_plasma( radial_builds=[ - ("gap", 70), - ("layer", 10), - ("layer", 10), - ("gap", 50), - ("plasma", 300), - ("gap", 60), - ("layer", 10), - ("layer", 60), - ("layer", 10), + (paramak.LayerType.GAP, 70), + (LayerType.SOLID, 10), + (LayerType.SOLID, 10), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 10), + (LayerType.SOLID, 60), + (LayerType.SOLID, 10), ], elongation=2.5, rotation_angle=180, @@ -538,15 +538,15 @@ Reactor with toroidal field coils result = paramak.spherical_tokamak_from_plasma( radial_builds=[ - ("gap", 70), - ("layer", 10), - ("layer", 10), - ("gap", 50), - ("plasma", 300), - ("gap", 60), - ("layer", 10), - ("layer", 60), - ("layer", 10), + (paramak.LayerType.GAP, 70), + (LayerType.SOLID, 10), + (LayerType.SOLID, 10), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 10), + (LayerType.SOLID, 60), + (LayerType.SOLID, 10), ], elongation=2.5, rotation_angle=180, @@ -574,29 +574,29 @@ Tokamak with negative triangularity result = paramak.tokamak( radial_builds=[ - ("gap", 10), - ("layer", 30), - ("layer", 50), - ("layer", 10), - ("layer", 120), - ("layer", 20), - ("gap", 60), - ("plasma", 300), - ("gap", 60), - ("layer", 20), - ("layer", 120), - ("layer", 10), + (paramak.LayerType.GAP, 10), + (LayerType.SOLID, 30), + (LayerType.SOLID, 50), + (LayerType.SOLID, 10), + (LayerType.SOLID, 120), + (LayerType.SOLID, 20), + (paramak.LayerType.GAP, 60), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 20), + (LayerType.SOLID, 120), + (LayerType.SOLID, 10), ], vertical_build=[ - ("layer", 15), - ("layer", 80), - ("layer", 10), - ("gap", 50), - ("plasma", 700), - ("gap", 60), - ("layer", 10), - ("layer", 40), - ("layer", 15), + (LayerType.SOLID, 15), + (LayerType.SOLID, 80), + (LayerType.SOLID, 10), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 700), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 10), + (LayerType.SOLID, 40), + (LayerType.SOLID, 15), ], triangularity=-0.55, rotation_angle=180, @@ -608,29 +608,29 @@ Tokamak with negative triangularity result = paramak.tokamak( radial_builds=[ - ("gap", 10), - ("layer", 30), - ("layer", 50), - ("layer", 10), - ("layer", 120), - ("layer", 20), - ("gap", 60), - ("plasma", 300), - ("gap", 60), - ("layer", 20), - ("layer", 120), - ("layer", 10), + (paramak.LayerType.GAP, 10), + (LayerType.SOLID, 30), + (LayerType.SOLID, 50), + (LayerType.SOLID, 10), + (LayerType.SOLID, 120), + (LayerType.SOLID, 20), + (paramak.LayerType.GAP, 60), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 20), + (LayerType.SOLID, 120), + (LayerType.SOLID, 10), ], vertical_build=[ - ("layer", 15), - ("layer", 80), - ("layer", 10), - ("gap", 50), - ("plasma", 700), - ("gap", 60), - ("layer", 10), - ("layer", 40), - ("layer", 15), + (LayerType.SOLID, 15), + (LayerType.SOLID, 80), + (LayerType.SOLID, 10), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 700), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 10), + (LayerType.SOLID, 40), + (LayerType.SOLID, 15), ], triangularity=-0.55, rotation_angle=180, @@ -658,27 +658,27 @@ Spherical tokamak with negative triangularity result = paramak.spherical_tokamak( radial_builds=[ [ - ("gap", 10), - ("layer", 50), - ("layer", 15), - ("gap", 50), - ("plasma", 300), - ("gap", 60), - ("layer", 40), - ("layer", 60), - ("layer", 10), + (paramak.LayerType.GAP, 10), + (LayerType.SOLID, 50), + (LayerType.SOLID, 15), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 40), + (LayerType.SOLID, 60), + (LayerType.SOLID, 10), ] ], vertical_build=[ - ("layer", 15), - ("layer", 80), - ("layer", 10), - ("gap", 50), - ("plasma", 700), - ("gap", 60), - ("layer", 10), - ("layer", 40), - ("layer", 15), + (LayerType.SOLID, 15), + (LayerType.SOLID, 80), + (LayerType.SOLID, 10), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 700), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 10), + (LayerType.SOLID, 40), + (LayerType.SOLID, 15), ], rotation_angle=180, triangularity=-0.55, @@ -691,27 +691,27 @@ Spherical tokamak with negative triangularity result = paramak.spherical_tokamak( radial_builds=[ [ - ("gap", 10), - ("layer", 50), - ("layer", 15), - ("gap", 50), - ("plasma", 300), - ("gap", 60), - ("layer", 10), - ("layer", 60), - ("layer", 10), + (paramak.LayerType.GAP, 10), + (LayerType.SOLID, 50), + (LayerType.SOLID, 15), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 10), + (LayerType.SOLID, 60), + (LayerType.SOLID, 10), ] ], vertical_build=[ - ("layer", 15), - ("layer", 80), - ("layer", 10), - ("gap", 50), - ("plasma", 700), - ("gap", 60), - ("layer", 10), - ("layer", 40), - ("layer", 15), + (LayerType.SOLID, 15), + (LayerType.SOLID, 80), + (LayerType.SOLID, 10), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 700), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 10), + (LayerType.SOLID, 40), + (LayerType.SOLID, 15), ], rotation_angle=180, triangularity=-0.55, diff --git a/examples/spherical_tokamak_from_plasma_minimal.py b/examples/spherical_tokamak_from_plasma_minimal.py index 37592d59..f5b281b7 100644 --- a/examples/spherical_tokamak_from_plasma_minimal.py +++ b/examples/spherical_tokamak_from_plasma_minimal.py @@ -8,15 +8,15 @@ my_reactor = paramak.spherical_tokamak_from_plasma( radial_builds=[ [ - ("gap", 10), - ("layer", 50), - ("layer", 15), - ("gap", 50), - ("plasma", 300), - ("gap", 60), - ("layer", 15), - ("layer", 60), - ("layer", 10), + (paramak.LayerType.GAP, 10), + (LayerType.SOLID, 50), + (LayerType.SOLID, 15), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 15), + (LayerType.SOLID, 60), + (LayerType.SOLID, 10), ] ], elongation=2, diff --git a/examples/spherical_tokamak_from_plasma_with_divertor.py b/examples/spherical_tokamak_from_plasma_with_divertor.py index 62858134..ce402568 100644 --- a/examples/spherical_tokamak_from_plasma_with_divertor.py +++ b/examples/spherical_tokamak_from_plasma_with_divertor.py @@ -8,18 +8,18 @@ my_reactor = paramak.spherical_tokamak_from_plasma( radial_builds=[ [ - ("gap", 10), - ("layer", 50), - ("layer", 15), - ("gap", 50), - ("plasma", 300), - ("gap", 60), - ("layer", 15), - ("layer", 60), - ("layer", 10), + (paramak.LayerType.GAP, 10), + (LayerType.SOLID, 50), + (LayerType.SOLID, 15), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 15), + (LayerType.SOLID, 60), + (LayerType.SOLID, 10), ], - [("gap", 75), ("lower_divertor", 100)], # this divertor connects to the center column - [("gap", 120), ("upper_divertor", 140)], # this divertor has some blanket between the center colum and itself + [(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 ], elongation=2, triangularity=0.55, diff --git a/examples/spherical_tokamak_from_plasma_with_pf_magnets.py b/examples/spherical_tokamak_from_plasma_with_pf_magnets.py index df88df43..ce137a0a 100644 --- a/examples/spherical_tokamak_from_plasma_with_pf_magnets.py +++ b/examples/spherical_tokamak_from_plasma_with_pf_magnets.py @@ -26,15 +26,15 @@ my_reactor = paramak.spherical_tokamak_from_plasma( radial_builds=[ - ("gap", 10), - ("layer", 50), - ("layer", 15), - ("gap", 50), - ("plasma", 300), - ("gap", 60), - ("layer", 15), - ("layer", 60), - ("layer", 10), + (paramak.LayerType.GAP, 10), + (LayerType.SOLID, 50), + (LayerType.SOLID, 15), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 15), + (LayerType.SOLID, 60), + (LayerType.SOLID, 10), ], elongation=2, triangularity=0.55, 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 77c91b31..5ae3fc76 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 @@ -29,17 +29,17 @@ my_reactor = paramak.spherical_tokamak_from_plasma( radial_builds=[ [ - ("gap", 10), - ("layer", 50), - ("layer", 15), - ("gap", 50), - ("plasma", 300), - ("gap", 60), - ("layer", 15), - ("layer", 60), - ("layer", 10), + (paramak.LayerType.GAP, 10), + (LayerType.SOLID, 50), + (LayerType.SOLID, 15), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 15), + (LayerType.SOLID, 60), + (LayerType.SOLID, 10), ], - [("gap", 75), ("lower_divertor", 100)], + [(paramak.LayerType.GAP, 75), ("lower_divertor", 100)], ], 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 851d640a..c716a06d 100644 --- a/examples/spherical_tokamak_from_plasma_with_tf_magnets.py +++ b/examples/spherical_tokamak_from_plasma_with_tf_magnets.py @@ -16,15 +16,15 @@ result = paramak.spherical_tokamak_from_plasma( radial_builds=[ - ("gap", 70), - ("layer", 10), - ("layer", 10), - ("gap", 50), - ("plasma", 300), - ("gap", 60), - ("layer", 10), - ("layer", 60), - ("layer", 10), + (paramak.LayerType.GAP, 70), + (LayerType.SOLID, 10), + (LayerType.SOLID, 10), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 10), + (LayerType.SOLID, 60), + (LayerType.SOLID, 10), ], elongation=2.5, rotation_angle=180, diff --git a/examples/spherical_tokamak_minimal.py b/examples/spherical_tokamak_minimal.py index 393628b8..6f8136f8 100644 --- a/examples/spherical_tokamak_minimal.py +++ b/examples/spherical_tokamak_minimal.py @@ -8,27 +8,27 @@ my_reactor = paramak.spherical_tokamak( radial_builds=[ [ - ("gap", 10), - ("layer", 50), - ("layer", 15), - ("gap", 50), - ("plasma", 300), - ("gap", 60), - ("layer", 40), - ("layer", 60), - ("layer", 10), + (paramak.LayerType.GAP, 10), + (LayerType.SOLID, 50), + (LayerType.SOLID, 15), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 40), + (LayerType.SOLID, 60), + (LayerType.SOLID, 10), ] ], vertical_build=[ - ("layer", 15), - ("layer", 80), - ("layer", 10), - ("gap", 50), - ("plasma", 700), - ("gap", 60), - ("layer", 10), - ("layer", 40), - ("layer", 15), + (LayerType.SOLID, 15), + (LayerType.SOLID, 80), + (LayerType.SOLID, 10), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 700), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 10), + (LayerType.SOLID, 40), + (LayerType.SOLID, 15), ], rotation_angle=180, triangularity=-0.55, diff --git a/examples/tokamak_from_plasma_minimal.py b/examples/tokamak_from_plasma_minimal.py index 1ecb19e4..c1b0f03b 100644 --- a/examples/tokamak_from_plasma_minimal.py +++ b/examples/tokamak_from_plasma_minimal.py @@ -5,18 +5,18 @@ my_reactor = paramak.tokamak_from_plasma( radial_builds=[ - ("gap", 10), - ("layer", 30), - ("layer", 50), - ("layer", 10), - ("layer", 120), - ("layer", 20), - ("gap", 60), - ("plasma", 300), - ("gap", 60), - ("layer", 20), - ("layer", 120), - ("layer", 10), + (paramak.LayerType.GAP, 10), + (LayerType.SOLID, 30), + (LayerType.SOLID, 50), + (LayerType.SOLID, 10), + (LayerType.SOLID, 120), + (LayerType.SOLID, 20), + (paramak.LayerType.GAP, 60), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 20), + (LayerType.SOLID, 120), + (LayerType.SOLID, 10), ], elongation=2, triangularity=0.55, diff --git a/examples/tokamak_from_plasma_with_divertor.py b/examples/tokamak_from_plasma_with_divertor.py index 6ec86e8c..1c902047 100644 --- a/examples/tokamak_from_plasma_with_divertor.py +++ b/examples/tokamak_from_plasma_with_divertor.py @@ -6,20 +6,20 @@ my_reactor = paramak.tokamak( radial_builds=[ [ - ("gap", 10), - ("layer", 30), - ("layer", 50), - ("layer", 10), - ("layer", 120), - ("layer", 20), - ("gap", 60), - ("plasma", 300), - ("gap", 60), - ("layer", 20), - ("layer", 120), - ("layer", 10), + (paramak.LayerType.GAP, 10), + (LayerType.SOLID, 30), + (LayerType.SOLID, 50), + (LayerType.SOLID, 10), + (LayerType.SOLID, 120), + (LayerType.SOLID, 20), + (paramak.LayerType.GAP, 60), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 20), + (LayerType.SOLID, 120), + (LayerType.SOLID, 10), ], - [("gap", 300), ("lower_divertor", 150)], + [(paramak.LayerType.GAP, 300), ("lower_divertor", 150)], ], elongation=2, triangularity=0.55, diff --git a/examples/tokamak_minimal.py b/examples/tokamak_minimal.py index 93758e61..2b216a25 100644 --- a/examples/tokamak_minimal.py +++ b/examples/tokamak_minimal.py @@ -5,29 +5,29 @@ my_reactor = paramak.tokamak( radial_builds=[ - ("gap", 10), - ("layer", 30), - ("layer", 50), - ("layer", 10), - ("layer", 120), - ("layer", 20), - ("gap", 60), - ("plasma", 300), - ("gap", 60), - ("layer", 20), - ("layer", 120), - ("layer", 10), + (paramak.LayerType.GAP, 10), + (LayerType.SOLID, 30), + (LayerType.SOLID, 50), + (LayerType.SOLID, 10), + (LayerType.SOLID, 120), + (LayerType.SOLID, 20), + (paramak.LayerType.GAP, 60), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 20), + (LayerType.SOLID, 120), + (LayerType.SOLID, 10), ], vertical_build=[ - ("layer", 15), - ("layer", 80), - ("layer", 10), - ("gap", 50), - ("plasma", 700), - ("gap", 60), - ("layer", 10), - ("layer", 40), - ("layer", 15), + (LayerType.SOLID, 15), + (LayerType.SOLID, 80), + (LayerType.SOLID, 10), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 700), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 10), + (LayerType.SOLID, 40), + (LayerType.SOLID, 15), ], triangularity=0.55, rotation_angle=180, diff --git a/examples/tokamak_with_pf_magnets.py b/examples/tokamak_with_pf_magnets.py index 5dbb199a..da8dbb74 100644 --- a/examples/tokamak_with_pf_magnets.py +++ b/examples/tokamak_with_pf_magnets.py @@ -25,29 +25,29 @@ my_reactor = paramak.tokamak( radial_builds=[ - ("gap", 10), - ("layer", 30), - ("layer", 50), - ("layer", 10), - ("layer", 120), - ("layer", 20), - ("gap", 60), - ("plasma", 300), - ("gap", 60), - ("layer", 20), - ("layer", 120), - ("layer", 10), + (paramak.LayerType.GAP, 10), + (LayerType.SOLID, 30), + (LayerType.SOLID, 50), + (LayerType.SOLID, 10), + (LayerType.SOLID, 120), + (LayerType.SOLID, 20), + (paramak.LayerType.GAP, 60), + (paramak.LayerType.PLASMA, 300), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 20), + (LayerType.SOLID, 120), + (LayerType.SOLID, 10), ], vertical_build=[ - ("layer", 15), - ("layer", 80), - ("layer", 10), - ("gap", 50), - ("plasma", 700), - ("gap", 60), - ("layer", 10), - ("layer", 40), - ("layer", 15), + (LayerType.SOLID, 15), + (LayerType.SOLID, 80), + (LayerType.SOLID, 10), + (paramak.LayerType.GAP, 50), + (paramak.LayerType.PLASMA, 700), + (paramak.LayerType.GAP, 60), + (LayerType.SOLID, 10), + (LayerType.SOLID, 40), + (LayerType.SOLID, 15), ], triangularity=0.55, rotation_angle=180, diff --git a/src/paramak/__init__.py b/src/paramak/__init__.py index 59a2cf4e..f793fab8 100644 --- a/src/paramak/__init__.py +++ b/src/paramak/__init__.py @@ -15,7 +15,7 @@ from .workplanes.toroidal_field_coil_rectangle import toroidal_field_coil_rectangle from .workplanes.u_shaped_dome import u_shaped_dome -# from .utils import * +from .utils import LayerType __version__ = version("paramak") diff --git a/src/paramak/assemblies/spherical_tokamak.py b/src/paramak/assemblies/spherical_tokamak.py index d30f871a..f3a5ed0a 100644 --- a/src/paramak/assemblies/spherical_tokamak.py +++ b/src/paramak/assemblies/spherical_tokamak.py @@ -11,6 +11,7 @@ sum_up_to_gap_before_plasma, sum_up_to_plasma, sum_before_after_plasma, + LayerType ) from ..workplanes.blanket_from_plasma import blanket_from_plasma from ..workplanes.center_column_shield_cylinder import center_column_shield_cylinder @@ -33,7 +34,7 @@ def create_blanket_layers_after_plasma( lower_thicknees = vertical_build[plasma_index_vertical - 1 - i][1] radial_thickness = item[1] - if item[0] == "gap": + if item[0] == LayerType.GAP: cumulative_thickness_rb += radial_thickness cumulative_thickness_uvb += upper_thicknees cumulative_thickness_lvb += lower_thicknees @@ -80,11 +81,11 @@ def create_center_column_shield_cylinders(radial_build, vertical_build, rotation center_column_shield_height = sum([item[1] for item in vertical_build]) for index, item in enumerate(radial_build): - if item[0] == "plasma": + if item[0] == LayerType.PLASMA: break - if item[0] == "gap" and radial_build[index + 1][0] == "plasma": + if item[0] == LayerType.GAP and radial_build[index + 1][0] == LayerType.PLASMA: break - if item[0] == "gap": + if item[0] == LayerType.GAP: total_sum += item[1] continue @@ -142,7 +143,7 @@ def spherical_tokamak_from_plasma( 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] + [("plasma", plasma_height)] + upper_vertical_build[1:] + vertical_build = upper_vertical_build[::-1][:-1] + [(LayerType.PLASMA, plasma_height)] + upper_vertical_build[1:] return spherical_tokamak( radial_builds=radial_builds, diff --git a/src/paramak/assemblies/tokamak.py b/src/paramak/assemblies/tokamak.py index 37115eeb..6fd46391 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 +from ..utils import build_divertor_modify_blanket, extract_radial_builds, get_plasma_index, sum_after_plasma, 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 @@ -15,9 +15,9 @@ def count_cylinder_layers(radial_build): found_plasma = False for item in radial_build: - if item[0] == "plasma": + if item[0] == LayerType.PLASMA: found_plasma = True - elif item[0] == "layer": + elif item[0] == LayerType.SOLID: if not found_plasma: before_plasma += 1 else: @@ -34,10 +34,10 @@ def create_center_column_shield_cylinders(radial_build, rotation_angle, center_c number_of_cylinder_layers = count_cylinder_layers(radial_build) for index, item in enumerate(radial_build): - if item[0] == "plasma": + if item[0] == LayerType.PLASMA: break - if item[0] == "gap": + if item[0] == LayerType.GAP: total_sum += item[1] continue @@ -62,7 +62,7 @@ def create_center_column_shield_cylinders(radial_build, rotation_angle, center_c def distance_to_plasma(radial_build, index): distance = 0 for item in radial_build[index + 1 :]: - if item[0] == "plasma": + if item[0] == LayerType.PLASMA: break distance += item[1] return distance @@ -83,14 +83,14 @@ def create_layers_from_plasma( cumulative_thickness_lvb = 0 for index_delta in range(indexes_from_plamsa_to_end): - if radial_build[plasma_index_rb + index_delta][0] == "plasma": + if radial_build[plasma_index_rb + index_delta][0] == LayerType.PLASMA: continue outer_layer_thickness = radial_build[plasma_index_rb + index_delta][1] inner_layer_thickness = radial_build[plasma_index_rb - index_delta][1] upper_layer_thickness = vertical_build[plasma_index_vb - index_delta][1] lower_layer_thickness = vertical_build[plasma_index_vb + index_delta][1] - if radial_build[plasma_index_rb + index_delta][0] == "gap": + if radial_build[plasma_index_rb + index_delta][0] == LayerType.GAP: cumulative_thickness_orb += outer_layer_thickness cumulative_thickness_irb += inner_layer_thickness cumulative_thickness_uvb += upper_layer_thickness @@ -98,7 +98,7 @@ def create_layers_from_plasma( continue # build outer layer - if radial_build[plasma_index_rb + index_delta][0] == "layer": + if radial_build[plasma_index_rb + index_delta][0] == LayerType.SOLID: outer_layer = blanket_from_plasma( minor_radius=minor_radius, major_radius=major_radius, @@ -182,7 +182,7 @@ def tokamak_from_plasma( 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] + [("plasma", plasma_height)] + upper_vertical_build[1:] + vertical_build = upper_vertical_build[::-1][:-1] + [(LayerType.PLASMA, plasma_height)] + upper_vertical_build[1:] return tokamak( radial_builds=radial_builds, diff --git a/src/paramak/utils.py b/src/paramak/utils.py index 7704e9fc..19fc15e9 100644 --- a/src/paramak/utils.py +++ b/src/paramak/utils.py @@ -1,8 +1,14 @@ import typing +from enum import Enum from cadquery import Workplane +class LayerType(Enum): + GAP = 'gap' + SOLID = 'solid' + PLASMA = 'plasma' + def instructions_from_points(points): # obtains the first two values of the points list XZ_points = [(p[0], p[1]) for p in points] @@ -96,9 +102,9 @@ def rotate_solid(angles: typing.Sequence[float], solid: Workplane) -> Workplane: def sum_up_to_gap_before_plasma(radial_build): total_sum = 0 for i, item in enumerate(radial_build): - if item[0] == "plasma": + if item[0] == LayerType.PLASMA: return total_sum - if item[0] == "gap" and i + 1 < len(radial_build) and radial_build[i + 1][0] == "plasma": + if item[0] == LayerType.GAP and i + 1 < len(radial_build) and radial_build[i + 1][0] == LayerType.PLASMA: return total_sum total_sum += item[1] return total_sum @@ -107,7 +113,7 @@ def sum_up_to_gap_before_plasma(radial_build): def sum_up_to_plasma(radial_build): total_sum = 0 for item in radial_build: - if item[0] == "plasma": + if item[0] == LayerType.PLASMA: break total_sum += item[1] return total_sum @@ -119,7 +125,7 @@ def sum_after_plasma(radial_build): for item in radial_build: if plasma_found: total_sum += item[1] - if item[0] == "plasma": + if item[0] == LayerType.PLASMA: plasma_found = True return total_sum @@ -135,7 +141,7 @@ def sum_before_after_plasma(vertical_build): plasma_found = False for item in vertical_build: - if item[0] == "plasma": + if item[0] == LayerType.PLASMA: plasma_value = item[1] / 2 plasma_found = True continue @@ -198,7 +204,9 @@ def build_divertor_modify_blanket(outer_layers, divertor_radial_builds, blanket_ def is_plasma_radial_build(radial_build): for entry in radial_build: - if entry[0] == "plasma": + # if entry == LayerType.PLASMA: + # return True + if entry[0] == LayerType.PLASMA: return True return False @@ -207,14 +215,14 @@ 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], str) and ( + 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 htere is only one radial build, which needs to e checked + # TODO this assumes there is only one radial build, which needs to e checked plasma_radial_build = entry else: divertor_radial_builds.append(entry) @@ -228,12 +236,12 @@ def extract_radial_builds(radial_build): def validate_divertor_radial_build(radial_build): if len(radial_build) != 2: raise ValidationError( - f'The radial build for the divertor should only contain two entries, for example (("gap",10), ("lower_divertor", 10)) not {radial_build}' + f'The radial build for the divertor should only contain two entries, for example ((LayerType.GAP,10), ("lower_divertor", 10)) not {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 ("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"}: @@ -241,9 +249,9 @@ def validate_divertor_radial_build(radial_build): f'The second entry in the radial build for the divertor should be either "lower_divertor" or "upper_divertor" not {radial_build[1][0]}' ) - if radial_build[0][0] != "gap": + if radial_build[0][0] != LayerType.GAP: raise ValidationError( - f'The first entry in the radial build for the divertor should be a "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)): @@ -259,27 +267,29 @@ def validate_divertor_radial_build(radial_build): def validate_plasma_radial_build(radial_build): # TODO should end with layer, not gap - valid_strings = {"gap", "layer", "plasma"} + valid_strings = {LayerType.GAP, LayerType.SOLID, LayerType.PLASMA} plasma_count = 0 plasma_index = -1 for index, item in enumerate(radial_build): - if not (isinstance(item[0], str) and isinstance(item[1], (int, float))): - raise ValidationError(f"Invalid tuple structure at index {index}: {item}") + if not isinstance(item[0], LayerType): + raise ValidationError(f"First entry in each radial build Tuple should be a paramak.LayerType") + if not isinstance(item[1], (int, float)): + raise ValidationError(f"Second entry in each radial build Tuple should be a Float") if item[0] not in valid_strings: - raise ValidationError(f"Invalid string '{item[0]}' at index {index}") + raise ValidationError(f"Invalid entry '{item[0]}' at index {index}") if item[1] <= 0: raise ValidationError(f"Non-positive value '{item[1]}' at index {index}") - if item[0] == "plasma": + if item[0] == LayerType.PLASMA: plasma_count += 1 plasma_index = index if plasma_count > 1: - raise ValidationError("Multiple 'plasma' entries found") + raise ValidationError("Multiple LayerType.PLASMA entries found") if plasma_count != 1: - raise ValidationError("'plasma' entry not found or found multiple times") + raise ValidationError("LayerType.PLASMA entry not found or found multiple times") if plasma_index == 0 or plasma_index == len(radial_build) - 1: - raise ValidationError("'plasma' entry must have at least one entry before and after it") - if radial_build[plasma_index - 1][0] != "gap" or radial_build[plasma_index + 1][0] != "gap": - raise ValidationError("'plasma' entry must be preceded and followed by a 'gap'") + raise ValidationError("LayerType.PLASMA entry must have at least one entry before and after it") + if radial_build[plasma_index - 1][0] != LayerType.GAP or radial_build[plasma_index + 1][0] != LayerType.GAP: + raise ValidationError("LayerType.PLASMA entry must be preceded and followed by a LayerType.GAP") def is_lower_or_upper_divertor(radial_build): @@ -293,26 +303,26 @@ def is_lower_or_upper_divertor(radial_build): def get_plasma_value(radial_build): for item in radial_build: - if item[0] == "plasma": + if item[0] == LayerType.PLASMA: return item[1] - raise ValueError("'plasma' entry not found") + raise ValueError("LayerType.PLASMA entry not found") def get_plasma_index(radial_build): for i, item in enumerate(radial_build): - if item[0] == "plasma": + if item[0] == LayerType.PLASMA: return i - raise ValueError("'plasma' entry not found") + raise ValueError("LayerType.PLASMA entry not found") def get_gap_after_plasma(radial_build): for index, item in enumerate(radial_build): - if item[0] == "plasma": - if index + 1 < len(radial_build) and radial_build[index + 1][0] == "gap": + if item[0] == LayerType.PLASMA: + if index + 1 < len(radial_build) and radial_build[index + 1][0] == LayerType.GAP: return radial_build[index + 1][1] else: - raise ValueError("'plasma' entry is not followed by a 'gap'") - raise ValueError("'plasma' entry not found") + raise ValueError("LayerType.PLASMA entry is not followed by a 'gap'") + raise ValueError("LayerType.PLASMA entry not found") def sum_after_gap_following_plasma(radial_build): @@ -323,14 +333,14 @@ def sum_after_gap_following_plasma(radial_build): for item in radial_build: if found_gap_after_plasma: total_sum += item[1] - elif found_plasma and item[0] == "gap": + elif found_plasma and item[0] == LayerType.GAP: found_gap_after_plasma = True - elif item[0] == "plasma": + elif item[0] == LayerType.PLASMA: found_plasma = True if not found_plasma: - raise ValueError("'plasma' entry not found") + raise ValueError("LayerType.PLASMA entry not found") if not found_gap_after_plasma: - raise ValueError("'plasma' entry is not followed by a 'gap'") + raise ValueError("LayerType.PLASMA entry is not followed by a 'gap'") return total_sum diff --git a/tests/test_assemblies/test_spherical_tokamak.py b/tests/test_assemblies/test_spherical_tokamak.py index bf926ff1..53c692c5 100644 --- a/tests/test_assemblies/test_spherical_tokamak.py +++ b/tests/test_assemblies/test_spherical_tokamak.py @@ -34,16 +34,16 @@ def test_transport_with_magnets(rotation_angle): my_reactor = paramak.spherical_tokamak_from_plasma( radial_builds=[ - ("gap", 10), - ("layer", 50), - ("layer", 15), - ("gap", 50), - ("plasma", 300), - ("gap", 60), - ("layer", 15), - ("layer", 60), - ("layer", 10), - ("gap", 10), + (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, 10), ], elongation=2, triangularity=0.55, @@ -71,16 +71,16 @@ def test_transport_with_magnets(rotation_angle): def test_transport_without_magnets(): reactor = paramak.spherical_tokamak_from_plasma( radial_builds=[ - ("gap", 10), - ("layer", 50), - ("layer", 15), - ("gap", 50), - ("plasma", 300), - ("gap", 60), - ("layer", 15), - ("layer", 60), - ("layer", 10), - ("gap", 10), + (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, 10), ], elongation=2, triangularity=0.55, diff --git a/tests/test_utils.py b/tests/test_utils.py index 29ecfa20..9a74cf37 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -8,46 +8,47 @@ sum_up_to_plasma, validate_divertor_radial_build, validate_plasma_radial_build, + LayerType ) def test_validate_divertor_radial_build_valid(): - radial_build = [("gap", 10), ("lower_divertor", 20)] + radial_build = [(LayerType.GAP, 10), ("lower_divertor", 20)] assert validate_divertor_radial_build(radial_build) is None def test_validate_divertor_radial_build_invalid_length(): - radial_build = [("gap", 10)] + radial_build = [(LayerType.GAP, 10)] with pytest.raises(ValidationError, match="should only contain two entries"): validate_divertor_radial_build(radial_build) def test_validate_divertor_radial_build_invalid_tuple_length(): - radial_build = [("gap", 10, 5), ("lower_divertor", 20)] + radial_build = [(LayerType.GAP, 10, 5), ("lower_divertor", 20)] with pytest.raises(ValidationError, match="should only contain tuples of length 2"): validate_divertor_radial_build(radial_build) def test_validate_divertor_radial_build_invalid_second_entry(): - radial_build = [("gap", 10), ("divertor", 20)] + radial_build = [(LayerType.GAP, 10), ("divertor", 20)] with pytest.raises(ValidationError, match='should be either "lower_divertor" or "upper_divertor"'): validate_divertor_radial_build(radial_build) def test_validate_divertor_radial_build_invalid_first_entry(): - radial_build = [("layer", 10), ("lower_divertor", 20)] - with pytest.raises(ValidationError, match='should be a "gap"'): + radial_build = [(LayerType.SOLID, 10), ("lower_divertor", 20)] + with pytest.raises(ValidationError, match='should be a LayerType.GAP'): validate_divertor_radial_build(radial_build) def test_validate_divertor_radial_build_non_positive_thickness(): - radial_build = [("gap", -10), ("lower_divertor", 20)] + radial_build = [(LayerType.GAP, -10), ("lower_divertor", 20)] with pytest.raises(ValidationError, match="should both be positive values"): validate_divertor_radial_build(radial_build) def test_validate_divertor_radial_build_invalid_thickness_type(): - radial_build = [("gap", "10"), ("lower_divertor", 20)] + radial_build = [(LayerType.GAP, "10"), ("lower_divertor", 20)] with pytest.raises(ValidationError, match="should both be integers or floats"): validate_divertor_radial_build(radial_build) @@ -55,43 +56,43 @@ def test_validate_divertor_radial_build_invalid_thickness_type(): def test_get_plasma_value(): radial_build = [ ( - "gap", + LayerType.GAP, 10, ), ( - "layer", + LayerType.SOLID, 50, ), ( - "layer", + LayerType.SOLID, 5, ), ( - "gap", + LayerType.GAP, 50, ), ( - "plasma", + LayerType.PLASMA, 50, ), ( - "gap", + LayerType.GAP, 60, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "gap", + LayerType.GAP, 10, ), ] @@ -101,86 +102,86 @@ def test_get_plasma_value(): def test_get_plasma_value_not_found(): radial_build = [ ( - "gap", + LayerType.GAP, 10, ), ( - "layer", + LayerType.SOLID, 50, ), ( - "layer", + LayerType.SOLID, 5, ), ( - "gap", + LayerType.GAP, 50, ), ( - "gap", + LayerType.GAP, 60, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "gap", + LayerType.GAP, 10, ), ] - with pytest.raises(ValueError, match="'plasma' entry not found"): + with pytest.raises(ValueError, match="LayerType.PLASMA entry not found"): get_plasma_value(radial_build) def test_valid_case(): radial_build = [ ( - "gap", + LayerType.GAP, 10, ), ( - "layer", + LayerType.SOLID, 50, ), ( - "layer", + LayerType.SOLID, 5, ), ( - "gap", + LayerType.GAP, 50, ), ( - "plasma", + LayerType.PLASMA, 50, ), ( - "gap", + LayerType.GAP, 60, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "gap", + LayerType.GAP, 10, ), ] @@ -190,176 +191,176 @@ def test_valid_case(): def test_plasma_not_preceded_by_gap(): radial_build = [ ( - "gap", + LayerType.GAP, 10, ), ( - "layer", + LayerType.SOLID, 50, ), ( - "layer", + LayerType.SOLID, 5, ), ( - "plasma", + LayerType.PLASMA, 50, ), ( - "gap", + LayerType.GAP, 60, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "gap", + LayerType.GAP, 10, ), ] - with pytest.raises(ValidationError, match="'plasma' entry must be preceded and followed by a 'gap'"): + with pytest.raises(ValidationError, match="LayerType.PLASMA entry must be preceded and followed by a LayerType.GAP"): validate_plasma_radial_build(radial_build) def test_plasma_not_followed_by_gap(): radial_build = [ ( - "gap", + LayerType.GAP, 10, ), ( - "layer", + LayerType.SOLID, 50, ), ( - "gap", + LayerType.GAP, 5, ), ( - "plasma", + LayerType.PLASMA, 50, ), ( - "layer", + LayerType.SOLID, 60, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "gap", + LayerType.GAP, 10, ), ] - with pytest.raises(ValidationError, match="'plasma' entry must be preceded and followed by a 'gap'"): + with pytest.raises(ValidationError, match="LayerType.PLASMA entry must be preceded and followed by a LayerType.GAP"): validate_plasma_radial_build(radial_build) def test_missing_plasma(): radial_build = [ ( - "gap", + LayerType.GAP, 10, ), ( - "layer", + LayerType.SOLID, 50, ), ( - "layer", + LayerType.SOLID, 5, ), ( - "gap", + LayerType.GAP, 50, ), ( - "gap", + LayerType.GAP, 60, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "gap", + LayerType.GAP, 10, ), ] - with pytest.raises(ValidationError, match="'plasma' entry not found or found multiple times"): + with pytest.raises(ValidationError, match="LayerType.PLASMA entry not found or found multiple times"): validate_plasma_radial_build(radial_build) def test_multiple_plasma(): radial_build = [ ( - "gap", + LayerType.GAP, 10, ), ( - "layer", + LayerType.SOLID, 50, ), ( - "plasma", + LayerType.PLASMA, 50, ), ( - "gap", + LayerType.GAP, 50, ), ( - "plasma", + LayerType.PLASMA, 50, ), ( - "gap", + LayerType.GAP, 60, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "gap", + LayerType.GAP, 10, ), ] - with pytest.raises(ValidationError, match="Multiple 'plasma' entries found"): + with pytest.raises(ValidationError, match="Multiple LayerType.PLASMA entries found"): validate_plasma_radial_build(radial_build) @@ -370,101 +371,101 @@ def test_first_entry_not_string(): 10, ), ( - "layer", + LayerType.SOLID, 50, ), ( - "layer", + LayerType.SOLID, 5, ), ( - "gap", + LayerType.GAP, 50, ), ( - "plasma", + LayerType.PLASMA, 50, ), ( - "gap", + LayerType.GAP, 60, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "gap", + LayerType.GAP, 10, ), ] - with pytest.raises(ValidationError, match="Invalid tuple structure at index 0"): + with pytest.raises(ValidationError, match="First entry in each radial build Tuple should be a paramak.LayerType"): validate_plasma_radial_build(radial_build) def test_second_entry_not_number(): radial_build = [ ( - "gap", + LayerType.GAP, 10, ), ( - "layer", + LayerType.SOLID, "50", ), ( - "layer", + LayerType.SOLID, 5, ), ( - "gap", + LayerType.GAP, 50, ), ( - "plasma", + LayerType.PLASMA, 50, ), ( - "gap", + LayerType.GAP, 60, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "gap", + LayerType.GAP, 10, ), ] - with pytest.raises(ValidationError, match="Invalid tuple structure at index 1"): + with pytest.raises(ValidationError, match="Second entry in each radial build Tuple should be a Float"): validate_plasma_radial_build(radial_build) def test_invalid_string(): radial_build = [ ( - "gap", + LayerType.GAP, 10, ), ( - "layer", + LayerType.SOLID, 50, ), ( @@ -472,172 +473,172 @@ def test_invalid_string(): 5, ), # Invalid string ( - "gap", + LayerType.GAP, 50, ), ( - "plasma", + LayerType.PLASMA, 50, ), ( - "gap", + LayerType.GAP, 60, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "gap", + LayerType.GAP, 10, ), ] - with pytest.raises(ValidationError, match="Invalid string 'invalid' at index 2"): + with pytest.raises(ValidationError, match="First entry in each radial build Tuple should be a paramak.LayerType"): validate_plasma_radial_build(radial_build) def test_plasma_first_entry(): radial_build = [ ( - "plasma", + LayerType.PLASMA, 50, ), ( - "gap", + LayerType.GAP, 10, ), ( - "layer", + LayerType.SOLID, 50, ), ( - "layer", + LayerType.SOLID, 5, ), ( - "gap", + LayerType.GAP, 50, ), ( - "gap", + LayerType.GAP, 60, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "gap", + LayerType.GAP, 10, ), ] - with pytest.raises(ValidationError, match="'plasma' entry must have at least one entry before and after it"): + with pytest.raises(ValidationError, match="LayerType.PLASMA entry must have at least one entry before and after it"): validate_plasma_radial_build(radial_build) def test_plasma_last_entry(): radial_build = [ ( - "gap", + LayerType.GAP, 10, ), ( - "layer", + LayerType.SOLID, 50, ), ( - "layer", + LayerType.SOLID, 5, ), ( - "gap", + LayerType.GAP, 50, ), ( - "gap", + LayerType.GAP, 60, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "gap", + LayerType.GAP, 10, ), ( - "plasma", + LayerType.PLASMA, 50, ), ] - with pytest.raises(ValidationError, match="'plasma' entry must have at least one entry before and after it"): + with pytest.raises(ValidationError, match="LayerType.PLASMA entry must have at least one entry before and after it"): validate_plasma_radial_build(radial_build) def test_non_positive_values(): radial_build = [ ( - "gap", + LayerType.GAP, 10, ), ( - "layer", + LayerType.SOLID, 50, ), ( - "layer", + LayerType.SOLID, 0, ), # Non-positive value ( - "gap", + LayerType.GAP, 50, ), ( - "plasma", + LayerType.PLASMA, 50, ), ( - "gap", + LayerType.GAP, 60, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "gap", + LayerType.GAP, 10, ), ] @@ -648,43 +649,43 @@ def test_non_positive_values(): def test_sum_up_to_plasma_middle(): radial_build = [ ( - "gap", + LayerType.GAP, 10, ), ( - "layer", + LayerType.SOLID, 50, ), ( - "layer", + LayerType.SOLID, 5, ), ( - "gap", + LayerType.GAP, 50, ), ( - "plasma", + LayerType.PLASMA, 50, ), ( - "gap", + LayerType.GAP, 60, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "gap", + LayerType.GAP, 10, ), ] @@ -694,43 +695,43 @@ def test_sum_up_to_plasma_middle(): def test_sum_up_to_plasma_first(): radial_build = [ ( - "plasma", + LayerType.PLASMA, 50, ), ( - "gap", + LayerType.GAP, 10, ), ( - "layer", + LayerType.SOLID, 50, ), ( - "layer", + LayerType.SOLID, 5, ), ( - "gap", + LayerType.GAP, 50, ), ( - "gap", + LayerType.GAP, 60, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "gap", + LayerType.GAP, 10, ), ] @@ -740,43 +741,43 @@ def test_sum_up_to_plasma_first(): def test_sum_up_to_plasma_last(): radial_build = [ ( - "gap", + LayerType.GAP, 10, ), ( - "layer", + LayerType.SOLID, 50, ), ( - "layer", + LayerType.SOLID, 5, ), ( - "gap", + LayerType.GAP, 50, ), ( - "gap", + LayerType.GAP, 60, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "gap", + LayerType.GAP, 10, ), ( - "plasma", + LayerType.PLASMA, 50, ), ] @@ -786,39 +787,39 @@ def test_sum_up_to_plasma_last(): def test_sum_up_to_plasma_not_present(): radial_build = [ ( - "gap", + LayerType.GAP, 10, ), ( - "layer", + LayerType.SOLID, 50, ), ( - "layer", + LayerType.SOLID, 5, ), ( - "gap", + LayerType.GAP, 50, ), ( - "gap", + LayerType.GAP, 60, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "gap", + LayerType.GAP, 10, ), ] @@ -833,43 +834,43 @@ def test_sum_up_to_plasma_empty(): def test_sum_up_to_plasma_multiple_entries(): radial_build = [ ( - "gap", + LayerType.GAP, 10, ), ( - "layer", + LayerType.SOLID, 20, ), ( - "layer", + LayerType.SOLID, 30, ), ( - "gap", + LayerType.GAP, 40, ), ( - "plasma", + LayerType.PLASMA, 50, ), ( - "gap", + LayerType.GAP, 60, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "gap", + LayerType.GAP, 10, ), ] @@ -879,125 +880,125 @@ def test_sum_up_to_plasma_multiple_entries(): def test_get_gap_after_plasma_not_followed_by_gap(): radial_build = [ ( - "gap", + LayerType.GAP, 10, ), ( - "layer", + LayerType.SOLID, 50, ), ( - "gap", + LayerType.GAP, 5, ), ( - "plasma", + LayerType.PLASMA, 50, ), ( - "layer", + LayerType.SOLID, 60, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "gap", + LayerType.GAP, 10, ), ] - with pytest.raises(ValueError, match="'plasma' entry is not followed by a 'gap'"): + with pytest.raises(ValueError, match="LayerType.PLASMA entry is not followed by a 'gap'"): get_gap_after_plasma(radial_build) def test_get_gap_after_plasma_not_found(): radial_build = [ ( - "gap", + LayerType.GAP, 10, ), ( - "layer", + LayerType.SOLID, 50, ), ( - "gap", + LayerType.GAP, 5, ), ( - "layer", + LayerType.SOLID, 50, ), ( - "gap", + LayerType.GAP, 60, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "gap", + LayerType.GAP, 10, ), ] - with pytest.raises(ValueError, match="'plasma' entry not found"): + with pytest.raises(ValueError, match="LayerType.PLASMA entry not found"): get_gap_after_plasma(radial_build) def test_sum_after_gap_following_plasma(): radial_build = [ ( - "gap", + LayerType.GAP, 10, ), ( - "layer", + LayerType.SOLID, 50, ), ( - "gap", + LayerType.GAP, 5, ), ( - "plasma", + LayerType.PLASMA, 50, ), ( - "gap", + LayerType.GAP, 60, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "gap", + LayerType.GAP, 10, ), ] @@ -1007,41 +1008,41 @@ def test_sum_after_gap_following_plasma(): def test_sum_after_gap_following_plasma_not_found(): radial_build = [ ( - "gap", + LayerType.GAP, 10, ), ( - "layer", + LayerType.SOLID, 50, ), ( - "gap", + LayerType.GAP, 5, ), ( - "layer", + LayerType.SOLID, 50, ), ( - "gap", + LayerType.GAP, 60, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "layer", + LayerType.SOLID, 2, ), ( - "gap", + LayerType.GAP, 10, ), ] - with pytest.raises(ValueError, match="'plasma' entry not found"): + with pytest.raises(ValueError, match="LayerType.PLASMA entry not found"): sum_after_gap_following_plasma(radial_build)