diff --git a/process/core/io/plot/cli.py b/process/core/io/plot/cli.py index 8ac687659a..622aa80a68 100644 --- a/process/core/io/plot/cli.py +++ b/process/core/io/plot/cli.py @@ -207,7 +207,7 @@ def sankey(mfile, format_): "Variables will be plotted in order of input" ), ) -def plot_scans_cli( +def plot_scans_cli( # noqa: PLR0917 mfiles, output_names, output_names2, @@ -235,22 +235,22 @@ def plot_scans_cli( list(filter(None, output_names)), list(filter(None, output_names2)), outputdir, - term_output, save_format, axis_font_size, axis_tick_size, - x_axis_percent, list(map(float, filter(None, x_axis_max))), list(map(float, filter(None, x_axis_range))), - y_axis_percent, list(map(float, filter(None, y_axis_max))), list(map(float, filter(None, y_axis_range))), - y_axis_percent2, list(map(float, filter(None, y_axis2_max))), list(map(float, filter(None, y_axis_range2))), label_name, - twod_contour, - stack_plots, + x_axis_percent=x_axis_percent, + y_axis_percent=y_axis_percent, + y_axis_percent2=y_axis_percent2, + term_output=term_output, + twod_contour=twod_contour, + stack_plots=stack_plots, ) diff --git a/process/core/io/plot/scans.py b/process/core/io/plot/scans.py index d1325f59f4..cb5f9e3b7a 100644 --- a/process/core/io/plot/scans.py +++ b/process/core/io/plot/scans.py @@ -174,20 +174,21 @@ def plot_scan( output_names: Sequence[str] = (), output_names2: Sequence[str] = (), outputdir: Path | None = None, - term_output: bool = False, save_format: str = "pdf", axis_font_size: float = 18, axis_tick_size: float = 16, - x_axis_percent: bool = False, x_axis_max: Sequence[float] = (), - x_axis_range: Sequence[float] = (), - y_axis_percent: bool = False, y_axis_max: Sequence[float] = (), - y_axis_range: Sequence[float] = (), - y_axis_percent2: bool = False, y_axis2_max: Sequence[float] = (), + x_axis_range: Sequence[float] = (), + y_axis_range: Sequence[float] = (), y_axis_range2: Sequence[float] = (), label_name: Sequence[str] = (), + *, + x_axis_percent: bool = False, + y_axis_percent: bool = False, + y_axis_percent2: bool = False, + term_output: bool = False, twod_contour: bool = False, stack_plots: bool = False, ): diff --git a/process/models/build.py b/process/models/build.py index eef57180e6..237d92ae90 100644 --- a/process/models/build.py +++ b/process/models/build.py @@ -1,6 +1,7 @@ """Module containing routines for build calculations""" import logging +from dataclasses import dataclass from enum import IntEnum, unique import numpy as np @@ -24,6 +25,14 @@ logger = logging.getLogger(__name__) +@dataclass +class RZPoint: + """A generic container for data that has r and z components""" + + r: float + z: float + + @unique class FwBlktVVShape(IntEnum): """Enum for first wall, blanket, and vacuum vessel shape options.""" @@ -593,21 +602,15 @@ def plate_sin(l_div_plate, theta, beta): thetao=thetao, rco=rco, rci=rci, - rxpt=rxpt, - zxpt=zxpt, - rspi=rspi, - zspi=zspi, + xpt=RZPoint(r=rxpt, z=zxpt), + spi=RZPoint(r=rspi, z=zspi), zspo=zspo, # Position of inner strike points - rplti=rspi + inner_plte_cos, - rplbi=rspi - inner_plte_cos, - zplti=zplti, - zplbi=zplbi, + plti=RZPoint(r=rspi + inner_plte_cos, z=zplti), + plbi=RZPoint(r=rspi - inner_plte_cos, z=zplbi), # Position of outer plate ends - rplto=self.data.build.rspo - outer_plte_cos, - rplbo=self.data.build.rspo + outer_plte_cos, - zplto=zplto, - zplbo=zplbo, + plto=RZPoint(r=self.data.build.rspo - outer_plte_cos, z=zplto), + plbo=RZPoint(r=self.data.build.rspo + outer_plte_cos, z=zplbo), ) return divht @@ -621,19 +624,13 @@ def divertor_geom_output( thetao, rco, rci, - rxpt, - zxpt, - rspi, - zspi, + xpt, + spi, zspo, - rplti, - rplbi, - zplti, - zplbi, - rplto, - rplbo, - zplto, - zplbo, + plti, + plbi, + plto, + plbo, ): """Divertor geometry output""" po.oheadr(self.outfile, "Divertor build and plasma position") @@ -668,8 +665,8 @@ def divertor_geom_output( ), ("Plasma outer arc radius of curvature (m)", "(rco)", rco), ("Plasma inner arc radius of curvature (m)", "(rci)", rci), - ("Plasma lower X-pt, radial (m)", "(rxpt)", rxpt), - ("Plasma lower X-pt, vertical (m)", "(zxpt)", zxpt), + ("Plasma lower X-pt, radial (m)", "(rxpt)", xpt.r), + ("Plasma lower X-pt, vertical (m)", "(zxpt)", xpt.z), ( "Poloidal plane angle between vertical and inner leg (rad)", "(thetai)", @@ -702,18 +699,18 @@ def divertor_geom_output( ), ("Inner divertor plate length (m)", "(plleni)", self.data.build.plleni), ("Outer divertor plate length (m)", "(plleno)", self.data.build.plleno), - ("Inner strike point, radial (m)", "(rspi)", rspi), - ("Inner strike point, vertical (m)", "(zspi)", zspi), - ("Inner plate top, radial (m)", "(rplti)", rplti), - ("Inner plate top, vertical (m)", "(zplti)", zplti), - ("Inner plate bottom, radial (m)", "(rplbi)", rplbi), - ("Inner plate bottom, vertical (m)", "(zplbi)", zplbi), + ("Inner strike point, radial (m)", "(rspi)", spi.r), + ("Inner strike point, vertical (m)", "(zspi)", spi.z), + ("Inner plate top, radial (m)", "(rplti)", plti.r), + ("Inner plate top, vertical (m)", "(zplti)", plti.z), + ("Inner plate bottom, radial (m)", "(rplbi)", plbi.r), + ("Inner plate bottom, vertical (m)", "(zplbi)", plbi.z), ("Outer strike point, radial (m)", "(rspo)", self.data.build.rspo), ("Outer strike point, vertical (m)", "(zspo)", zspo), - ("Outer plate top, radial (m)", "(rplto)", rplto), - ("Outer plate top, vertical (m)", "(zplto)", zplto), - ("Outer plate bottom, radial (m)", "(rplbo)", rplbo), - ("Outer plate bottom, vertical (m)", "(zplbo)", zplbo), + ("Outer plate top, radial (m)", "(rplto)", plto.r), + ("Outer plate top, vertical (m)", "(zplto)", plto.z), + ("Outer plate bottom, radial (m)", "(rplbo)", plbo.r), + ("Outer plate bottom, vertical (m)", "(zplbo)", plbo.z), ("Calculated maximum divertor height (m)", "(divht)", divht), ]: po.ovarre(self.outfile, desc, name, var, "OP ") @@ -746,12 +743,12 @@ def divertor_geom_output( "(dz_tf_plasma_centre_offset)", self.data.build.dz_tf_plasma_centre_offset, ), - ("Plasma upper X-pt, radial (m)", "(rxpt)", rxpt), - ("Plasma upper X-pt, vertical (m)", "(-zxpt)", -zxpt), + ("Plasma upper X-pt, radial (m)", "(rxpt)", xpt.r), + ("Plasma upper X-pt, vertical (m)", "(-zxpt)", -xpt.z), ("Plasma outer arc radius of curvature (m)", "(rco)", rco), ("Plasma inner arc radius of curvature (m)", "(rci)", rci), - ("Plasma lower X-pt, radial (m)", "(rxpt)", rxpt), - ("Plasma lower X-pt, vertical (m)", "(zxpt)", zxpt), + ("Plasma lower X-pt, radial (m)", "(rxpt)", xpt.r), + ("Plasma lower X-pt, vertical (m)", "(zxpt)", xpt.z), ( "Poloidal plane angle between vertical and inner leg (rad)", "(thetai)", @@ -784,38 +781,38 @@ def divertor_geom_output( ), ("Inner divertor plate length (m)", "(plleni)", self.data.build.plleni), ("Outer divertor plate length (m)", "(plleno)", self.data.build.plleno), - ("Upper inner strike point, radial (m)", "(rspi)", rspi), - ("Upper inner strike point, vertical (m)", "(-zspi)", -zspi), - ("Upper inner plate top, radial (m)", "(rplti)", rplti), - ("Upper inner plate top, vertical (m)", "(-zplti)", -zplti), - ("Upper inner plate bottom, radial (m)", "(rplbi)", rplbi), - ("Upper inner plate bottom, vertical (m)", "(-zplbi)", -zplbi), + ("Upper inner strike point, radial (m)", "(rspi)", spi.r), + ("Upper inner strike point, vertical (m)", "(-zspi)", -spi.z), + ("Upper inner plate top, radial (m)", "(rplti)", plti.r), + ("Upper inner plate top, vertical (m)", "(-zplti)", -plti.z), + ("Upper inner plate bottom, radial (m)", "(rplbi)", plbi.r), + ("Upper inner plate bottom, vertical (m)", "(-zplbi)", -plbi.z), ( "Upper outer strike point, radial (m)", "(rspo)", self.data.build.rspo, ), ("Upper outer strike point, vertical (m)", "(-zspo)", -zspo), - ("Upper outer plate top, radial (m)", "(rplto)", rplto), - ("Upper outer plate top, vertical (m)", "(-zplto)", -zplto), - ("Upper outer plate bottom, radial (m)", "(rplbo)", rplbo), - ("Upper outer plate bottom, vertical (m)", "(-zplbo)", -zplbo), - ("Lower inner strike point, radial (m)", "(rspi)", rspi), - ("Lower inner strike point, vertical (m)", "(zspi)", zspi), - ("Lower inner plate top, radial (m)", "(rplti)", rplti), - ("Lower inner plate top, vertical (m)", "(zplti)", zplti), - ("Lower inner plate bottom, radial (m)", "(rplbi)", rplbi), - ("Lower inner plate bottom, vertical (m)", "(zplbi)", zplbi), + ("Upper outer plate top, radial (m)", "(rplto)", plto.r), + ("Upper outer plate top, vertical (m)", "(-zplto)", -plto.z), + ("Upper outer plate bottom, radial (m)", "(rplbo)", plbo.r), + ("Upper outer plate bottom, vertical (m)", "(-zplbo)", -plbo.z), + ("Lower inner strike point, radial (m)", "(rspi)", spi.r), + ("Lower inner strike point, vertical (m)", "(zspi)", spi.z), + ("Lower inner plate top, radial (m)", "(rplti)", plti.r), + ("Lower inner plate top, vertical (m)", "(zplti)", plti.z), + ("Lower inner plate bottom, radial (m)", "(rplbi)", plbi.r), + ("Lower inner plate bottom, vertical (m)", "(zplbi)", plbi.z), ( "Lower outer strike point, radial (m)", "(rspo)", self.data.build.rspo, ), ("Lower outer strike point, vertical (m)", "(zspo)", zspo), - ("Lower outer plate top, radial (m)", "(rplto)", rplto), - ("Lower outer plate top, vertical (m)", "(zplto)", zplto), - ("Lower outer plate bottom, radial (m)", "(rplbo)", rplbo), - ("Lower outer plate bottom, vertical (m)", "(zplbo)", zplbo), + ("Lower outer plate top, radial (m)", "(rplto)", plto.r), + ("Lower outer plate top, vertical (m)", "(zplto)", plto.z), + ("Lower outer plate bottom, radial (m)", "(rplbo)", plbo.r), + ("Lower outer plate bottom, vertical (m)", "(zplbo)", plbo.z), ("Calculated maximum divertor height (m)", "(divht)", divht), ]: po.ovarre(self.outfile, desc, name, var, "OP ") diff --git a/process/models/physics/confinement_time.py b/process/models/physics/confinement_time.py index b0de2ba695..8840ed8cce 100644 --- a/process/models/physics/confinement_time.py +++ b/process/models/physics/confinement_time.py @@ -56,7 +56,7 @@ def output(self): def run(self): """PlasmaConfinementTime model doesn't need to be run""" - def calculate_confinement_time( + def calculate_confinement_time( # noqa: PLR0917 self, m_fuel_amu: float, p_alpha_total_mw: float, diff --git a/process/models/stellarator/coils/output.py b/process/models/stellarator/coils/output.py index 4b0280625c..2ceb8a55f0 100644 --- a/process/models/stellarator/coils/output.py +++ b/process/models/stellarator/coils/output.py @@ -1,9 +1,16 @@ """Module to output stellarator modular coil results.""" +from __future__ import annotations + +from typing import TYPE_CHECKING + from process.core import process_output as po +if TYPE_CHECKING: + from process.core.data_structure.base import DataStructure + -def write( +def write( # noqa: PLR0917 stellarator, a_tf_wp_no_insulation, centering_force_avg_mn, @@ -29,7 +36,7 @@ def write( toroidalgap, allowed_quench_voltage, quench_voltage, - data, + data: DataStructure, ): """Writes stellarator modular coil output to file @@ -88,7 +95,7 @@ def write( quench_voltage : - data: DataStructure + data: data structure object """ diff --git a/process/models/stellarator/neoclassics.py b/process/models/stellarator/neoclassics.py index 3b9d761c95..03b5c40260 100644 --- a/process/models/stellarator/neoclassics.py +++ b/process/models/stellarator/neoclassics.py @@ -1,6 +1,7 @@ """Module containing neoclassics routines""" import logging +from dataclasses import dataclass import numpy as np @@ -11,6 +12,20 @@ logger = logging.getLogger(__name__) +@dataclass +class NormalisedCollisionality: + """Storage for normalised collisionality""" + + e: float + """electron""" + D: float + """Deutrerium""" + T: float + """Tritium""" + He: float + """Helium""" + + class Neoclassics(Model): """Module containing neoclassics routines""" @@ -395,10 +410,12 @@ def calc_neoclassics(self): chi_PROCESS_e = self.st_calc_eff_chi() - nu_star_e = self.data.neoclassics.nu_star_averaged[0] - nu_star_d = self.data.neoclassics.nu_star_averaged[1] - nu_star_T = self.data.neoclassics.nu_star_averaged[2] - nu_star_He = self.data.neoclassics.nu_star_averaged[3] + nu_star = NormalisedCollisionality( + e=self.data.neoclassics.nu_star_averaged[0], + D=self.data.neoclassics.nu_star_averaged[1], + T=self.data.neoclassics.nu_star_averaged[2], + He=self.data.neoclassics.nu_star_averaged[3], + ) return ( q_PROCESS, @@ -424,10 +441,7 @@ def calc_neoclassics(self): dmdt_neo_fuel_from_e, chi_neo_e, chi_PROCESS_e, - nu_star_e, - nu_star_d, - nu_star_T, - nu_star_He, + nu_star, ) def neoclassics_calc_KT(self): diff --git a/process/models/stellarator/stellarator.py b/process/models/stellarator/stellarator.py index e75fc106c8..72440cef34 100644 --- a/process/models/stellarator/stellarator.py +++ b/process/models/stellarator/stellarator.py @@ -2424,10 +2424,7 @@ def st_phys(self, output): dmdt_neo_fuel_from_e, chi_neo_e, chi_PROCESS_e, - nu_star_e, - nu_star_d, - nu_star_T, - nu_star_He, + nu_star, ) = self.neoclassics.calc_neoclassics() if output: @@ -2446,10 +2443,7 @@ def st_phys(self, output): self.data.physics.gradient_length_ne, self.data.physics.gradient_length_te, self.data.physics.rho_star, - nu_star_e, - nu_star_d, - nu_star_T, - nu_star_He, + nu_star, self.data.physics.nd_plasma_electron_line, self.data.physics.nd_plasma_electrons_max, ) @@ -2470,10 +2464,7 @@ def st_phys_output( gradient_length_ne, gradient_length_te, rho_star, - nu_star_e, - nu_star_D, - nu_star_T, - nu_star_He, + nu_star, nd_plasma_electron_line, nd_plasma_electrons_max, ): @@ -2568,16 +2559,16 @@ def st_phys_output( self.outfile, "Normalized collisionality (electrons)", "(nu_star_e)", - nu_star_e, + nu_star.e, ) po.ovarre( - self.outfile, "Normalized collisionality (D)", "(nu_star_D)", nu_star_D + self.outfile, "Normalized collisionality (D)", "(nu_star_D)", nu_star.D ) po.ovarre( - self.outfile, "Normalized collisionality (T)", "(nu_star_T)", nu_star_T + self.outfile, "Normalized collisionality (T)", "(nu_star_T)", nu_star.T ) po.ovarre( - self.outfile, "Normalized collisionality (He)", "(nu_star_He)", nu_star_He + self.outfile, "Normalized collisionality (He)", "(nu_star_He)", nu_star.He ) po.ovarre( diff --git a/process/models/structure.py b/process/models/structure.py index 1489b3db6d..710eced0d9 100644 --- a/process/models/structure.py +++ b/process/models/structure.py @@ -92,7 +92,8 @@ def structure( blmass, m_fw_blkt_div_coolant_total, dewmass, - output, + *, + output: bool, ): """Method to calculate mass of support structure diff --git a/process/models/tfcoil/base.py b/process/models/tfcoil/base.py index 871cad4bba..be1540d62e 100644 --- a/process/models/tfcoil/base.py +++ b/process/models/tfcoil/base.py @@ -8,7 +8,7 @@ from dataclasses import dataclass from enum import IntEnum, unique from types import DynamicClassAttribute -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, NamedTuple import numba import numpy as np @@ -115,6 +115,21 @@ class TFGlobalGeometry: """Minimum thickness of the sidewall case [m].""" +class RTZPoint(NamedTuple): + """A generic container for data that has radial, toroidal and z components""" + + r: numba.float64[:] + t: numba.float64[:] + z: numba.float64[:] + + +class YoungsModulusComponents(NamedTuple): + """Components of youngs modulus""" + + axial: float + trans: float + + class TFCoil(Model): """Calculates the parameters of a resistive TF coil system for a fusion power plant @@ -130,7 +145,7 @@ def run(self): def run_base_tf(self): """Run main tfcoil subroutine without outputting.""" - global_tf_geometry: TFGlobalGeometry = self.tf_global_geometry( + global_tf_geometry = self.tf_global_geometry( i_tf_case_geom=self.data.tfcoil.i_tf_case_geom, i_f_dr_tf_plasma_case=self.data.tfcoil.i_f_dr_tf_plasma_case, f_dr_tf_plasma_case=self.data.tfcoil.f_dr_tf_plasma_case, @@ -2226,7 +2241,7 @@ def generic_tf_coil_area_and_masses(self): @staticmethod @numba.njit(cache=True) - def stresscl( + def stresscl( # noqa: PLR0917 n_tf_layer, n_radial_array, n_tf_wp_stress_layers, @@ -3243,31 +3258,21 @@ def stresscl( # ---------------- return ( - sig_tf_r_max, - sig_tf_t_max, - sig_tf_z_max, + RTZPoint(r=sig_tf_r_max, t=sig_tf_t_max, z=sig_tf_z_max), sig_tf_vmises_max, s_shear_tf_peak, deflect, - eyoung_axial, - eyoung_trans, - eyoung_wp_axial, - eyoung_wp_trans, + YoungsModulusComponents(axial=eyoung_axial, trans=eyoung_trans), + YoungsModulusComponents(axial=eyoung_wp_axial, trans=eyoung_wp_trans), poisson_wp_trans, radial_array, s_shear_cea_tf_cond, poisson_wp_axial, - sig_tf_r, - sig_tf_smeared_r, - sig_tf_smeared_t, - sig_tf_smeared_z, - sig_tf_t, + RTZPoint(r=sig_tf_r, t=sig_tf_t, z=sig_tf_z), + RTZPoint(r=sig_tf_smeared_r, t=sig_tf_smeared_t, z=sig_tf_smeared_z), s_shear_tf, sig_tf_vmises, - sig_tf_z, - str_tf_r, - str_tf_t, - str_tf_z, + RTZPoint(r=str_tf_r, t=str_tf_t, z=str_tf_z), n_radial_array, n_tf_bucking, sig_tf_wp, @@ -3279,33 +3284,23 @@ def stresscl( sig_tf_wp_av_z, ) - def out_stress( + def out_stress( # noqa: PLR0917 self, - sig_tf_r_max, - sig_tf_t_max, - sig_tf_z_max, + sig_tf_max, sig_tf_vmises_max, s_shear_tf_peak, deflect, - eyoung_axial, - eyoung_trans, - eyoung_wp_axial, - eyoung_wp_trans, + eyoung, + eyoung_wp, poisson_wp_trans, radial_array, s_shear_cea_tf_cond, poisson_wp_axial, - sig_tf_r, - sig_tf_smeared_r, - sig_tf_smeared_t, - sig_tf_smeared_z, - sig_tf_t, + sig_tf, + sig_tf_smeared, s_shear_tf, sig_tf_vmises, - sig_tf_z, - str_tf_r, - str_tf_t, - str_tf_z, + str_tf, n_radial_array, n_tf_bucking, sig_tf_wp_av_z, @@ -3316,11 +3311,7 @@ def out_stress( Parameters ---------- - sig_tf_r_max : - - sig_tf_t_max : - - sig_tf_z_max : + sig_tf_max : sig_tf_vmises_max : @@ -3328,13 +3319,9 @@ def out_stress( deflect : - eyoung_axial : + eyoung : - eyoung_trans : - - eyoung_wp_axial : - - eyoung_wp_trans : + eyoung_wp : poisson_wp_trans : @@ -3344,27 +3331,15 @@ def out_stress( poisson_wp_axial : - sig_tf_r : - - sig_tf_smeared_r : - - sig_tf_smeared_t : + sig_tf : - sig_tf_smeared_z : - - sig_tf_t : + sig_tf_smeared: s_shear_tf : sig_tf_vmises : - sig_tf_z : - - str_tf_r : - - str_tf_t : - - str_tf_z : + str_tf: n_radial_array : @@ -3474,17 +3449,17 @@ def table_format_arrays(a, mult=1, delim="\t\t"): po.write( self.outfile, f" Radial stress \t\t\t (MPa) \t\t" - f"{table_format_arrays(sig_tf_r_max, 1e-6)}", + f"{table_format_arrays(sig_tf_max.r, 1e-6)}", ) po.write( self.outfile, f" Toroidal stress \t\t\t (MPa) \t\t" - f"{table_format_arrays(sig_tf_t_max, 1e-6)}", + f"{table_format_arrays(sig_tf_max.t, 1e-6)}", ) po.write( self.outfile, f" Vertical stress \t\t\t (MPa) \t\t" - f"{table_format_arrays(sig_tf_z_max, 1e-6)}", + f"{table_format_arrays(sig_tf_max.z, 1e-6)}", ) po.write( self.outfile, @@ -3512,26 +3487,26 @@ def table_format_arrays(a, mult=1, delim="\t\t"): po.write( self.outfile, f" Toroidal modulus \t\t\t (GPa) \t\t" - f"{table_format_arrays(eyoung_trans, 1e-9)}", + f"{table_format_arrays(eyoung.trans, 1e-9)}", ) po.write( self.outfile, f" Vertical modulus \t\t\t (GPa) \t\t" - f"{table_format_arrays(eyoung_axial, 1e-9)}", + f"{table_format_arrays(eyoung.axial, 1e-9)}", ) po.write(self.outfile, "") po.ovarre( self.outfile, "WP transverse modulus (GPa)", "(eyoung_wp_trans*1.0d-9)", - eyoung_wp_trans * 1.0e-9, + eyoung_wp.trans * 1.0e-9, "OP ", ) po.ovarre( self.outfile, "WP vertical modulus (GPa)", "(eyoung_wp_axial*1.0d-9)", - eyoung_wp_axial * 1.0e-9, + eyoung_wp.axial * 1.0e-9, "OP ", ) po.ovarre( @@ -3555,19 +3530,19 @@ def table_format_arrays(a, mult=1, delim="\t\t"): constants.MFILE, f"Radial stress at maximum shear of layer {ii + 1} (Pa)", f"(sig_tf_r_max({ii + 1}))", - sig_tf_r_max[ii], + sig_tf_max.r[ii], ) po.ovarre( constants.MFILE, f"toroidal stress at maximum shear of layer {ii + 1} (Pa)", f"(sig_tf_t_max({ii + 1}))", - sig_tf_t_max[ii], + sig_tf_max.t[ii], ) po.ovarre( constants.MFILE, f"Vertical stress at maximum shear of layer {ii + 1} (Pa)", f"(sig_tf_z_max({ii + 1}))", - sig_tf_z_max[ii], + sig_tf_max.z[ii], ) po.ovarre( constants.MFILE, @@ -3597,12 +3572,12 @@ def table_format_arrays(a, mult=1, delim="\t\t"): sig_file_data = { "Points per layers": n_radial_array, "Radius (m)": radial_array, - "Radial stress (MPa)": sig_tf_r * 1e-6, - "Toroidal stress (MPa)": sig_tf_t * 1e-6, - "Vertical stress (MPa)": sig_tf_z * 1e-6, - "Radial smear stress (MPa)": sig_tf_smeared_r * 1e-6, - "Toroidal smear stress (MPa)": sig_tf_smeared_t * 1e-6, - "Vertical smear stress (MPa)": sig_tf_smeared_z * 1e-6, + "Radial stress (MPa)": sig_tf.r * 1e-6, + "Toroidal stress (MPa)": sig_tf.t * 1e-6, + "Vertical stress (MPa)": sig_tf.z * 1e-6, + "Radial smear stress (MPa)": sig_tf_smeared.r * 1e-6, + "Toroidal smear stress (MPa)": sig_tf_smeared.t * 1e-6, + "Vertical smear stress (MPa)": sig_tf_smeared.z * 1e-6, "Von-Mises stress (MPa)": sig_tf_vmises * 1e-6, "CEA Tresca stress (MPa)": ( s_shear_cea_tf_cond * 1e-6 @@ -3614,9 +3589,9 @@ def table_format_arrays(a, mult=1, delim="\t\t"): if self.data.tfcoil.i_tf_stress_model != 1: sig_file_data = { **sig_file_data, - "Radial strain": str_tf_r, - "Toroidal strain": str_tf_t, - "Vertical strain": str_tf_z, + "Radial strain": str_tf.r, + "Toroidal strain": str_tf.t, + "Vertical strain": str_tf.z, } if self.data.tfcoil.i_tf_sup == TFConductorModel.SUPERCONDUCTING: diff --git a/process/models/tfcoil/resistive.py b/process/models/tfcoil/resistive.py index f001be489a..7d29d18bda 100644 --- a/process/models/tfcoil/resistive.py +++ b/process/models/tfcoil/resistive.py @@ -105,31 +105,21 @@ def run(self, output: bool = False): try: # noqa: PLW0717 ( - sig_tf_r_max, - sig_tf_t_max, - sig_tf_z_max, + sig_tf_max, sig_tf_vmises_max, s_shear_tf_peak, deflect, - eyoung_axial, - eyoung_trans, - eyoung_wp_axial, - eyoung_wp_trans, + eyoung, + eyoung_wp, poisson_wp_trans, radial_array, s_shear_cea_tf_cond, poisson_wp_axial, - sig_tf_r, - sig_tf_smeared_r, - sig_tf_smeared_t, - sig_tf_smeared_z, - sig_tf_t, + sig_tf, + sig_tf_smeared, s_shear_tf, sig_tf_vmises, - sig_tf_z, - str_tf_r, - str_tf_t, - str_tf_z, + str_tf, n_radial_array, n_tf_bucking, self.data.tfcoil.sig_tf_wp, @@ -236,31 +226,21 @@ def run(self, output: bool = False): if output: self.out_stress( - sig_tf_r_max, - sig_tf_t_max, - sig_tf_z_max, + sig_tf_max, sig_tf_vmises_max, s_shear_tf_peak, deflect, - eyoung_axial, - eyoung_trans, - eyoung_wp_axial, - eyoung_wp_trans, + eyoung, + eyoung_wp, poisson_wp_trans, radial_array, s_shear_cea_tf_cond, poisson_wp_axial, - sig_tf_r, - sig_tf_smeared_r, - sig_tf_smeared_t, - sig_tf_smeared_z, - sig_tf_t, + sig_tf, + sig_tf_smeared, s_shear_tf, sig_tf_vmises, - sig_tf_z, - str_tf_r, - str_tf_t, - str_tf_z, + str_tf, n_radial_array, n_tf_bucking, sig_tf_wp_av_z, diff --git a/process/models/tfcoil/superconducting.py b/process/models/tfcoil/superconducting.py index 836d28c674..09b00dbe1d 100644 --- a/process/models/tfcoil/superconducting.py +++ b/process/models/tfcoil/superconducting.py @@ -1435,19 +1435,17 @@ def vv_stress_on_quench(self): d_sc_tf = self.data.superconducting_tfcoil d_sc_tf.vv_stress_quench = vv_stress_on_quench( - # TF shape - H_coil=H_coil, - ri_coil=ri_coil, - ro_coil=ro_coil, - rm_coil=rm_coil, - ccl_length_coil=self.data.tfcoil.len_tf_coil, - theta1_coil=self.data.tfcoil.theta1_coil, - # VV shape - H_vv=H_vv, - ri_vv=ri_vv, - ro_vv=ro_vv, - rm_vv=rm_vv, - theta1_vv=self.data.tfcoil.theta1_vv, + coil=TFComponentShape( + H=H_coil, + ri=ri_coil, + ro=ro_coil, + rm=rm_coil, + ccl_length=self.data.tfcoil.len_tf_coil, + theta1=self.data.tfcoil.theta1_coil, + ), + vv=VVComponentShape( + H=H_vv, ri=ri_vv, ro=ro_vv, rm=rm_vv, theta1=self.data.tfcoil.theta1_vv + ), # TF properties n_tf_coils=self.data.tfcoil.n_tf_coils, n_tf_coil_turns=self.data.tfcoil.n_tf_coil_turns, @@ -2115,31 +2113,21 @@ def run_and_output_stress(self) -> None: try: # noqa: PLW0717 ( - sig_tf_r_max, - sig_tf_t_max, - sig_tf_z_max, + sig_tf_max, sig_tf_vmises_max, s_shear_tf_peak, deflect, - eyoung_axial, - eyoung_trans, - eyoung_wp_axial, - eyoung_wp_trans, + eyoung, + eyoung_wp, poisson_wp_trans, radial_array, s_shear_cea_tf_cond, poisson_wp_axial, - sig_tf_r, - sig_tf_smeared_r, - sig_tf_smeared_t, - sig_tf_smeared_z, - sig_tf_t, + sig_tf, + sig_tf_smeared, s_shear_tf, sig_tf_vmises, - sig_tf_z, - str_tf_r, - str_tf_t, - str_tf_z, + str_tf, n_radial_array, n_tf_bucking, self.data.tfcoil.sig_tf_wp, @@ -2245,31 +2233,21 @@ def run_and_output_stress(self) -> None: ) self.out_stress( - sig_tf_r_max, - sig_tf_t_max, - sig_tf_z_max, + sig_tf_max, sig_tf_vmises_max, s_shear_tf_peak, deflect, - eyoung_axial, - eyoung_trans, - eyoung_wp_axial, - eyoung_wp_trans, + eyoung, + eyoung_wp, poisson_wp_trans, radial_array, s_shear_cea_tf_cond, poisson_wp_axial, - sig_tf_r, - sig_tf_smeared_r, - sig_tf_smeared_t, - sig_tf_smeared_z, - sig_tf_t, + sig_tf, + sig_tf_smeared, s_shear_tf, sig_tf_vmises, - sig_tf_z, - str_tf_r, - str_tf_t, - str_tf_z, + str_tf, n_radial_array, n_tf_bucking, sig_tf_wp_av_z, @@ -2538,31 +2516,21 @@ def run(self, output: bool = False): try: # noqa: PLW0717 ( - sig_tf_r_max, - sig_tf_t_max, - sig_tf_z_max, + sig_tf_max, sig_tf_vmises_max, s_shear_tf_peak, deflect, - eyoung_axial, - eyoung_trans, - eyoung_wp_axial, - eyoung_wp_trans, + eyoung, + eyoung_wp, poisson_wp_trans, radial_array, s_shear_cea_tf_cond, poisson_wp_axial, - sig_tf_r, - sig_tf_smeared_r, - sig_tf_smeared_t, - sig_tf_smeared_z, - sig_tf_t, + sig_tf, + sig_tf_smeared, s_shear_tf, sig_tf_vmises, - sig_tf_z, - str_tf_r, - str_tf_t, - str_tf_z, + str_tf, n_radial_array, n_tf_bucking, self.data.tfcoil.sig_tf_wp, @@ -2669,31 +2637,21 @@ def run(self, output: bool = False): if output: self.out_stress( - sig_tf_r_max, - sig_tf_t_max, - sig_tf_z_max, + sig_tf_max, sig_tf_vmises_max, s_shear_tf_peak, deflect, - eyoung_axial, - eyoung_trans, - eyoung_wp_axial, - eyoung_wp_trans, + eyoung, + eyoung_wp, poisson_wp_trans, radial_array, s_shear_cea_tf_cond, poisson_wp_axial, - sig_tf_r, - sig_tf_smeared_r, - sig_tf_smeared_t, - sig_tf_smeared_z, - sig_tf_t, + sig_tf, + sig_tf_smeared, s_shear_tf, sig_tf_vmises, - sig_tf_z, - str_tf_r, - str_tf_t, - str_tf_z, + str_tf, n_radial_array, n_tf_bucking, sig_tf_wp_av_z, @@ -4068,31 +4026,21 @@ def run(self, output: bool = False): try: # noqa: PLW0717 ( - sig_tf_r_max, - sig_tf_t_max, - sig_tf_z_max, + sig_tf_max, sig_tf_vmises_max, s_shear_tf_peak, deflect, - eyoung_axial, - eyoung_trans, - eyoung_wp_axial, - eyoung_wp_trans, + eyoung, + eyoung_wp, poisson_wp_trans, radial_array, s_shear_cea_tf_cond, poisson_wp_axial, - sig_tf_r, - sig_tf_smeared_r, - sig_tf_smeared_t, - sig_tf_smeared_z, - sig_tf_t, + sig_tf, + sig_tf_smeared, s_shear_tf, sig_tf_vmises, - sig_tf_z, - str_tf_r, - str_tf_t, - str_tf_z, + str_tf, n_radial_array, n_tf_bucking, self.data.tfcoil.sig_tf_wp, @@ -4198,31 +4146,21 @@ def run(self, output: bool = False): ) if output: self.out_stress( - sig_tf_r_max, - sig_tf_t_max, - sig_tf_z_max, + sig_tf_max, sig_tf_vmises_max, s_shear_tf_peak, deflect, - eyoung_axial, - eyoung_trans, - eyoung_wp_axial, - eyoung_wp_trans, + eyoung, + eyoung_wp, poisson_wp_trans, radial_array, s_shear_cea_tf_cond, poisson_wp_axial, - sig_tf_r, - sig_tf_smeared_r, - sig_tf_smeared_t, - sig_tf_smeared_z, - sig_tf_t, + sig_tf, + sig_tf_smeared, s_shear_tf, sig_tf_vmises, - sig_tf_z, - str_tf_r, - str_tf_t, - str_tf_z, + str_tf, n_radial_array, n_tf_bucking, sig_tf_wp_av_z, @@ -4982,20 +4920,40 @@ def _theta_factor_integral( return (chi1 + 2.0 * chi2) / (2.0 * np.pi) +@dataclass +class ComponentShape: + """Shape properties for a component all on the current centre line""" + + H: float + """The maximum height of the shape""" + ri: float + """The radius of the inboard edge""" + ro: float + """The radius of the outboard edge""" + rm: float + """The radius where the maximum height occurs""" + theta1: float + """The polar angle of the point at which one circular arc is + joined to another circular arc in the approximation to the CCL, + using an arbitrary origin of coordinates (Rc2, Zc2).""" + + +@dataclass +class TFComponentShape(ComponentShape): + """Shape properties for a TF coil""" + + ccl_length: float + """The length of the TF coil CCL""" + + +@dataclass +class VVComponentShape(ComponentShape): + """Shape properties for a vacuum vessel""" + + def vv_stress_on_quench( - # TF shape - H_coil: float, - ri_coil: float, - ro_coil: float, - rm_coil: float, - ccl_length_coil: float, - theta1_coil: float, - # VV shape - H_vv: float, - ri_vv: float, - ro_vv: float, - rm_vv: float, - theta1_vv: float, + coil: TFComponentShape, + vv: VVComponentShape, # TF properties n_tf_coils: float, n_tf_coil_turns: float, @@ -5021,32 +4979,10 @@ def vv_stress_on_quench( Parameters ---------- - H_coil : - the maximum height of the TF coil CCL - ri_coil : - the radius of the inboard edge of the TF coil CCL - ro_coil : - the radius of the outboard edge of the TF coil CCL - rm_coil : - the radius where the maximum height of the TF coil CCL occurs - ccl_length_coil : - the length of the TF coil CCL - theta1_coil : - the polar angle of the point at which one circular arc is - joined to another circular arc in the approximation to the coil CCL, - using an arbitrary origin of coordinates (Rc2, Zc2). - H_vv : - the maximum height of the VV CCL - ri_vv : - the radius of the inboard edge of the VV CCL - ro_vv : - the radius of the outboard edge of the VV CCL - rm_vv : - the radius where the maximum height of the VV CCL occurs - theta1_vv : - the polar angle of the point at which one circular arc is - joined to another circular arc in the approximation to the VV CCL, - using an arbitrary origin of coordinates (Rc2, Zc2). + coil : + Tf coil properties on the CCL + vv : + VV properties on the CCL n_tf_coils : the number of TF coils n_tf_coil_turns : @@ -5084,23 +5020,23 @@ def vv_stress_on_quench( ‌ """ # Convert angles into radians - theta1_vv_rad = np.pi * (theta1_vv / 180.0) + theta1_vv_rad = np.pi * (vv.theta1 / 180.0) # Poloidal loop resistance (PLR) in ohms - theta_vv = _theta_factor_integral(ro_vv, ri_vv, rm_vv, H_vv, theta1_vv_rad) - plr_coil = ((0.5 * ccl_length_coil) / (n_tf_coils * (s_cc + s_rp))) * 1e-6 + theta_vv = _theta_factor_integral(vv.ro, vv.ri, vv.rm, vv.H, theta1_vv_rad) + plr_coil = ((0.5 * coil.ccl_length) / (n_tf_coils * (s_cc + s_rp))) * 1e-6 plr_vv = ((0.84 / d_vv) * theta_vv) * 1e-6 # relevant self-inductances in henry (H) coil_structure_self_inductance = ( (constants.RMU0 / np.pi) - * H_coil - * _inductance_factor(H_coil, ri_coil, ro_coil, rm_coil, theta1_coil) + * coil.H + * _inductance_factor(coil.H, coil.ri, coil.ro, coil.rm, coil.theta1) ) vv_self_inductance = ( (constants.RMU0 / np.pi) - * H_vv - * _inductance_factor(H_vv, ri_vv, ro_vv, rm_vv, theta1_vv) + * vv.H + * _inductance_factor(vv.H, vv.ri, vv.ro, vv.rm, vv.theta1) ) # s^-1 @@ -5124,15 +5060,15 @@ def vv_stress_on_quench( ) i2 = (lambda1 / lambda2) * i1 - a_vv = (ro_vv + ri_vv) / (ro_vv - ri_vv) + a_vv = (vv.ro + vv.ri) / (vv.ro - vv.ri) b_vvi = (constants.RMU0 * (n_tf_coils * n_tf_coil_turns * i0 + i1 + (i2 / 2))) / ( - 2 * np.pi * ri_vv + 2 * np.pi * vv.ri ) - j_vvi = i2 / (2 * np.pi * d_vv * ri_vv) + j_vvi = i2 / (2 * np.pi * d_vv * vv.ri) zeta = 1 + ((a_vv - 1) * np.log((a_vv + 1) / (a_vv - 1)) / (2 * a_vv)) - return zeta * b_vvi * j_vvi * ri_vv + return zeta * b_vvi * j_vvi * vv.ri def _inductance_factor( diff --git a/process/models/vacuum.py b/process/models/vacuum.py index b305bd93ea..e64ddfbec7 100644 --- a/process/models/vacuum.py +++ b/process/models/vacuum.py @@ -525,7 +525,7 @@ def _newton_function(d_i, l1, l2, l3, xmult_i, ceff_i): ) return d_i - y / dy, a1 - def _write_to_outfile( + def _write_to_outfile( # noqa: PLR0917 self, ogas, s, diff --git a/pyproject.toml b/pyproject.toml index ad4be3616d..603509b7b1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -115,7 +115,7 @@ dependencies = ["pre-commit", "ruff==0.16.5", "ty"] [tool.hatch.envs.lint.scripts] fmt = ["pre-commit run --all-files --hook-stage manual {args:}"] -fmt_extra = ["ruff check --select=C901,PLR0904,PLR0912,PLR0913,PLR0914,PLR0915,PLR0916,PLR0917,PLR1702,S307 {args:.}"] +fmt_extra = ["ruff check --select=C901,PLR0904,PLR0912,PLR0913,PLR0914,PLR0915,PLR0916,PLR1702,S307 {args:.}"] [tool.coverage.report] exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"] @@ -244,7 +244,6 @@ ignore = [ "PLR0914", "PLR0915", "PLR0916", - "PLR0917", "PLR1702", "S307", diff --git a/tests/unit/models/tfcoil/test_sctfcoil.py b/tests/unit/models/tfcoil/test_sctfcoil.py index 5dd134b05f..0a3414558c 100644 --- a/tests/unit/models/tfcoil/test_sctfcoil.py +++ b/tests/unit/models/tfcoil/test_sctfcoil.py @@ -5,6 +5,7 @@ from process.models.superconductors import SuperconductorModel from process.models.tfcoil import superconducting as sctf +from process.models.tfcoil.superconducting import TFComponentShape, VVComponentShape @pytest.fixture @@ -1500,18 +1501,11 @@ def test_vv_stress_on_quench(): pytest.approx( sctf.vv_stress_on_quench( # TF shape - H_coil=9.5, - ri_coil=3.55, - ro_coil=15.62, - rm_coil=7.66, - ccl_length_coil=51.1, - theta1_coil=48, + coil=TFComponentShape( + H=9.5, ri=3.55, ro=15.62, rm=7.66, ccl_length=51.1, theta1=48 + ), # VV shape - H_vv=7.9, - ri_vv=4.45, - ro_vv=13.09, - rm_vv=7.88, - theta1_vv=1, + vv=VVComponentShape(H=7.9, ri=4.45, ro=13.09, rm=7.88, theta1=1), # TF properties n_tf_coils=18, n_tf_coil_turns=192, diff --git a/tests/unit/models/tfcoil/test_tfcoil.py b/tests/unit/models/tfcoil/test_tfcoil.py index 1804bc9a3c..4a54d5494e 100644 --- a/tests/unit/models/tfcoil/test_tfcoil.py +++ b/tests/unit/models/tfcoil/test_tfcoil.py @@ -1238,16 +1238,6 @@ def test_stresscl(stressclparam, monkeypatch, tfcoil): _, _, _, - _, - _, - _, - _, - _, - _, - _, - _, - _, - _, sig_tf_wp, sig_tf_case, _,