Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions process/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,11 @@
CPH2O = 4180.0
"""specific heat capacity of water (J/kg/K)"""

den_copper: float = None
"""density of copper (kg/m3)"""
DEN_COPPER = 8900.0
"""Density of copper [kg/m³]"""

den_aluminium: float = None
"""density of aluminium (kg/m3)"""
DEN_ALUMINIUM = 2700.0
"""Density of aluminium [kg/m³]"""

DENH2O = 985.0
"""density of water (kg/m3)"""
Expand All @@ -307,10 +307,3 @@

ACCELERATION_GRAVITY = 9.81
"""Acceleration due to gravity [m/s2]"""


def init_constants():
global den_copper, den_aluminium

den_copper = 8900.0
den_aluminium = 2700.0
12 changes: 0 additions & 12 deletions process/core/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from process.core import constants, process_output
from process.core.exceptions import ProcessValidationError
from process.core.input import parse_input_file
from process.core.log import logging_model_handler
from process.core.solver import iteration_variables
from process.core.solver.constraints import ConstraintManager
from process.data_structure.blanket_variables import BlktModelTypes
Expand Down Expand Up @@ -222,17 +221,6 @@ def run_summary(data: DataStructure):
)


def init_all_module_vars():
"""Initialise all module variables
This is vital to ensure a 'clean' state of Process before a new run starts,
otherwise components of the previous run's state can persist into the new
run. This matters ever since Process is used as a shared library, rather
than a 'run-once' executable.
"""
logging_model_handler.clear_logs()
constants.init_constants()


def check_process(inputs, data): # noqa: ARG001
"""Routine to reset specific variables if certain options are
being used
Expand Down
5 changes: 0 additions & 5 deletions process/core/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from typing import TYPE_CHECKING, Any
from warnings import warn

import process
from process.core.exceptions import (
ProcessValidationError,
ProcessValueError,
Expand Down Expand Up @@ -281,15 +280,11 @@ def __post_init__(self):
"cturbb": InputVariable("costs", float, range=(100.0, 1000.0)),
"dz_vv_lower": InputVariable("build", float, range=(0.0, 10.0)),
"dz_vv_upper": InputVariable("build", float, range=(0.0, 10.0)),
"den_aluminium": InputVariable(
process.core.constants, float, range=(2500.0, 30000.0)
),
"den_tf_coil_case": InputVariable("tfcoil", float, range=(1000.0, 100000.0)),
"dcdrv0": InputVariable("ife", float, range=(0.0, 200.0)),
"dcdrv1": InputVariable("ife", float, range=(0.0, 200.0)),
"dcdrv2": InputVariable("ife", float, range=(0.0, 200.0)),
"den_tf_wp_turn_insulation": InputVariable("tfcoil", float, range=(500.0, 10000.0)),
"den_copper": InputVariable(process.core.constants, float, range=(8000.0, 10000.0)),
"declblkt": InputVariable("fwbs", float, range=(0.01, 0.2)),
"declfw": InputVariable("fwbs", float, range=(0.01, 0.2)),
"declshld": InputVariable("fwbs", float, range=(0.01, 0.2)),
Expand Down
4 changes: 2 additions & 2 deletions process/core/io/data_structure_dicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import numpy as np

from process.core.init import init_all_module_vars
from process.core.input import INPUT_VARIABLES
from process.core.log import logging_model_handler
from process.core.solver.iteration_variables import ITERATION_VARIABLES

INPUT_TYPE_MAP = {int: "int", float: "real", str: "string"}
Expand Down Expand Up @@ -182,7 +182,7 @@ def get_dicts():
dict_objects = []
# Different dict objects, e.g. variable descriptions

init_all_module_vars()
logging_model_handler.clear_logs()
# Make dict objects
# Some dicts depend on other dicts already existing in output_dicts, so
# be careful if changing the order!
Expand Down
6 changes: 4 additions & 2 deletions process/core/io/obsolete_vars.py

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please mark den_copper and den_aluminium as obsolete too (e.g. "den_aluminium": None)

Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,12 @@
"ims": "i_blkt_module_segmentation",
"i_coolant_pumping": "i_p_coolant_pumping",
"vfblkt": "f_a_blkt_cooling_channels",
"dalu": "den_aluminium",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be kept in "dalu": None,

"dalu": None,
"den_aluminium": None,
"dcase": "den_tf_coil_case",
"dcondins": "den_tf_wp_turn_insulation",
"dcopper": "den_copper",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be kept in "dcopper": None,

"dcopper": None,
"den_copper": None,
"denstl": "den_steel",
"ripmax": "ripple_b_tf_plasma_edge_max",
"n_layer": "n_tf_wp_layers",
Expand Down
4 changes: 2 additions & 2 deletions process/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def run(self):
FileNotFoundError
if input file doesn't exist
"""
init.init_all_module_vars()
logging_model_handler.clear_logs()
self.config.setup(self.data)

setup_loggers(Path(self.config.wdir) / "process.log")
Expand Down Expand Up @@ -358,7 +358,7 @@ def init_module_vars():
This "resets" all module variables to their initialised values, so each
new run doesn't have any side-effects from previous runs.
"""
init.init_all_module_vars()
logging_model_handler.clear_logs()

def set_filenames(self, filepath_out):
"""Validate the input filename and create other filenames from it."""
Expand Down
8 changes: 4 additions & 4 deletions process/models/costs/costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,7 @@ def acc2222(self):
)
* 1.0e6
/ self.data.pf_coil.j_pf_coil_wp_peak[i]
* constants.den_copper
* constants.DEN_COPPER
)
else:
costpfcu = (
Expand All @@ -1684,7 +1684,7 @@ def acc2222(self):
)
* 1.0e6
/ self.data.pf_coil.j_pf_coil_wp_peak[i]
* constants.den_copper
* constants.DEN_COPPER
)

# Total cost/metre of superconductor and copper wire
Expand Down Expand Up @@ -1751,7 +1751,7 @@ def acc2222(self):
/ self.data.pf_coil.n_pf_coil_turns[
self.data.pf_coil.n_cs_pf_coils - 1
]
* constants.den_copper
* constants.DEN_COPPER
)
else:
# MDK I don't know if this is ccorrect as we never use the resistive model
Expand All @@ -1762,7 +1762,7 @@ def acc2222(self):
/ self.data.pf_coil.n_pf_coil_turns[
self.data.pf_coil.n_cs_pf_coils - 1
]
* constants.den_copper
* constants.DEN_COPPER
)

# Total cost/metre of superconductor and copper wire (Central Solenoid)
Expand Down
4 changes: 2 additions & 2 deletions process/models/pfcoil.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ def pfcoil(self):
else:
self.data.pf_coil.m_pf_coil_conductor[i] = (
volpf
* constants.den_copper
* constants.DEN_COPPER
* (1.0e0 - self.data.pf_coil.f_a_pf_coil_void[i])
)

Expand Down Expand Up @@ -3498,7 +3498,7 @@ def ohcalc(self):
* 2.0e0
* np.pi
* self.data.pf_coil.r_pf_coil_middle[self.data.pf_coil.n_cs_pf_coils - 1]
* constants.den_copper
* constants.DEN_COPPER
)

if self.data.pf_coil.i_pf_conductor == PFConductorModel.SUPERCONDUCTING:
Expand Down
2 changes: 1 addition & 1 deletion process/models/power.py
Original file line number Diff line number Diff line change
Expand Up @@ -2118,7 +2118,7 @@ def tfpwr(self, output: bool):

# Bus mass (kg)
self.data.tfcoil.m_tf_bus = (
self.data.tfcoil.len_tf_bus * a_tf_bus * constants.den_copper
self.data.tfcoil.len_tf_bus * a_tf_bus * constants.DEN_COPPER
)

# Total maximum impedance MDK actually just fixed resistance
Expand Down
2 changes: 1 addition & 1 deletion process/models/stellarator/coils/mass.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def copper(data: DataStructure):
* (1.0e0 - data.tfcoil.f_a_tf_turn_cable_space_extra_void)
* data.tfcoil.f_a_tf_turn_cable_copper
- data.tfcoil.len_tf_coil * data.tfcoil.a_tf_wp_coolant_channels
) * constants.den_copper
) * constants.DEN_COPPER


def conduit_steel(data):
Expand Down
14 changes: 7 additions & 7 deletions process/models/tfcoil/resistive.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,22 +763,22 @@ def resistive_tf_coil_areas_and_masses(self):
self.data.fwbs.den_steel * vol_case / self.data.tfcoil.n_tf_coils
) # Per TF leg, no casing for outer leg
self.data.tfcoil.m_tf_coil_copper = (
constants.den_copper * vol_cond / self.data.tfcoil.n_tf_coils
constants.DEN_COPPER * vol_cond / self.data.tfcoil.n_tf_coils
)
self.data.tfcoil.whtconal = 0.0e0

# Outer legs/CP weights
if self.data.physics.itart == 1:
# Weight of all the TF legs
self.data.tfcoil.whttflgs = self.data.tfcoil.n_tf_coils * (
constants.den_copper * vol_cond_leg
constants.DEN_COPPER * vol_cond_leg
+ self.data.tfcoil.den_tf_wp_turn_insulation
* (vol_ins_leg + vol_gr_ins_leg)
)

# CP weight
self.data.tfcoil.whtcp = (
constants.den_copper * self.data.tfcoil.vol_cond_cp
constants.DEN_COPPER * self.data.tfcoil.vol_cond_cp
+ self.data.tfcoil.den_tf_wp_turn_insulation
* (
self.data.superconducting_tfcoil.vol_ins_cp
Expand All @@ -793,25 +793,25 @@ def resistive_tf_coil_areas_and_masses(self):
elif self.data.tfcoil.i_tf_sup == TFConductorModel.HELIUM_COOLED_ALUMINIUM:
# Casing weight (CP only if self.data.physics.itart = 1)bper leg/coil
self.data.tfcoil.m_tf_coil_case = (
constants.den_aluminium * vol_case / self.data.tfcoil.n_tf_coils
constants.DEN_ALUMINIUM * vol_case / self.data.tfcoil.n_tf_coils
)
self.data.tfcoil.m_tf_coil_copper = 0.0e0
self.data.tfcoil.whtconal = (
constants.den_aluminium * vol_cond / self.data.tfcoil.n_tf_coils
constants.DEN_ALUMINIUM * vol_cond / self.data.tfcoil.n_tf_coils
)

# Outer legs/CP weights
if self.data.physics.itart == 1:
# Weight of all the TF legs
self.data.tfcoil.whttflgs = self.data.tfcoil.n_tf_coils * (
constants.den_aluminium * vol_cond_leg
constants.DEN_ALUMINIUM * vol_cond_leg
+ self.data.tfcoil.den_tf_wp_turn_insulation
* (vol_ins_leg + vol_gr_ins_leg)
)

# CP weight
self.data.tfcoil.whtcp = (
constants.den_aluminium * self.data.tfcoil.vol_cond_cp
constants.DEN_ALUMINIUM * self.data.tfcoil.vol_cond_cp
+ self.data.tfcoil.den_tf_wp_turn_insulation
* (
self.data.superconducting_tfcoil.vol_ins_cp
Expand Down
2 changes: 1 addition & 1 deletion process/models/tfcoil/superconducting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1973,7 +1973,7 @@ def superconducting_tf_coil_areas_and_masses(self):
* (1.0e0 - self.data.tfcoil.f_a_tf_turn_cable_space_extra_void)
* self.data.tfcoil.f_a_tf_turn_cable_copper
- self.data.tfcoil.len_tf_coil * self.data.tfcoil.a_tf_wp_coolant_channels
) * constants.den_copper
) * constants.DEN_COPPER
self.data.tfcoil.m_tf_coil_copper = max(0.0e0, self.data.tfcoil.m_tf_coil_copper)

# Steel conduit (sheath) mass [kg]
Expand Down
7 changes: 0 additions & 7 deletions tests/integration/test_vmcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import numpy as np
import pytest

from process.core.init import init_all_module_vars
from process.core.model import DataStructure
from process.core.solver.evaluators import Evaluators
from process.core.solver.solver import get_solver
Expand All @@ -21,12 +20,6 @@
logger = logging.getLogger(__name__)


@pytest.fixture(autouse=True) # noqa: RUF076
def reinit():
"""Re-initialise Fortran module variables before each test is run."""
init_all_module_vars()


@pytest.fixture
def data_structure_obj():
return DataStructure()
Expand Down
14 changes: 0 additions & 14 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,6 @@

import pytest

from process.core.init import init_all_module_vars


@pytest.fixture(autouse=True) # noqa: RUF076
def reinit_fix():
"""Re-initialise the data structure before each test is run.

This is run once before each unit test (function scope),
ensuring that all of the module variables are set to their initial values.
'autouse' ensures that this fixture is used automatically by any test
function in the unit directory.
"""
init_all_module_vars()


@pytest.fixture
def input_file():
Expand Down
3 changes: 0 additions & 3 deletions tests/unit/core/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pytest

from process.core.exceptions import ProcessValueError
from process.core.init import init_all_module_vars
from process.core.model import DataStructure
from process.core.solver.constraints import ConstraintManager

Expand All @@ -17,8 +16,6 @@ def test_constraint_functions(constraint_registration):
"""A simple test that runs a constraint with PROCESS' default initialisation to check
that no attribute or type errors (etc) occur.
"""
init_all_module_vars()

# Allow zero division errors because this means all of the attributes exist
# and are initialised with a number.
# Allow ProcessValueError because that happens when a constraint is incompatible with
Expand Down
10 changes: 1 addition & 9 deletions tests/unit/models/test_availability.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import pytest

from process.core.init import init_all_module_vars


@pytest.fixture
def availability(process_models):
Expand Down Expand Up @@ -71,8 +69,6 @@ def test_avail_1(monkeypatch, availability):
:param availability: fixture containing an initialised `Availability` object
:type availability: tests.unit.test_availability.availability (functional fixture)
"""
# Initialise fortran variables to keep test isolated from others
init_all_module_vars()

# Mock module vars
monkeypatch.setattr(availability.data.costs, "i_plant_availability", 1)
Expand All @@ -95,9 +91,6 @@ def test_avail_1(monkeypatch, availability):
cfactr_exp = 0.0006344554455445239
assert pytest.approx(cfactr_exp) == cfactr_obs

# Initialise fortran variables again to reset for other tests
init_all_module_vars()


def test_calc_u_unplanned_hcd(availability):
"""Test calc_u_unplanned_hcd.
Expand Down Expand Up @@ -589,8 +582,7 @@ def test_avail_st(monkeypatch, availability):
:param availability: fixture containing an initialised `Availability` object
:type availability: tests.unit.test_availability.availability (functional fixture)
"""
# Initialise fortran variables to keep test isolated from others
init_all_module_vars()

monkeypatch.setattr(availability.data.costs, "tmain", 1.0)
monkeypatch.setattr(availability.data.costs, "life_plant", 30.0)
monkeypatch.setattr(availability.data.costs, "u_unplanned_cp", 0.05)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/models/test_pfcoil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2548,7 +2548,7 @@ def test_pfcoil(monkeypatch, pfcoil):
pfcoil.data.times, "t_plant_pulse_plasma_current_ramp_down", 1.82538e2
)
monkeypatch.setattr(pfcoil.data.times, "t_plant_pulse_fusion_ramp", 1.0e1)
monkeypatch.setattr(constants, "den_copper", 8.9e3)
monkeypatch.setattr(constants, "DEN_COPPER", 8.9e3)
monkeypatch.setattr(pfcoil.data.pf_coil, "first_call", True)

pfcoil.pfcoil()
Expand Down Expand Up @@ -2635,7 +2635,7 @@ def test_ohcalc(monkeypatch, reinitialise_error_module, cs_coil):
monkeypatch.setattr(cs_coil.data.tfcoil, "bcritsc", 2.4e1)
monkeypatch.setattr(cs_coil.data.tfcoil, "b_crit_upper_nbti", 1.486e1)
monkeypatch.setattr(cs_coil.data.tfcoil, "t_crit_nbti", 9.04)
monkeypatch.setattr(constants, "den_copper", 8.9e3)
monkeypatch.setattr(constants, "DEN_COPPER", 8.9e3)

# Mocks for peak_b_field_at_pf_coil()
monkeypatch.setattr(cs_coil.data.build, "iohcl", 1)
Expand Down
Loading