Skip to content
Draft
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
12 changes: 7 additions & 5 deletions process/core/caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def call_models(self, xc: np.ndarray, m: int) -> tuple[float, np.ndarray]:

# Evaluate models up to 10 times; any more implies non-converging values
for _ in range(10):
self._call_models_once(xc)
self._call_models_once(xc, self.data)
# Evaluate objective function and constraints
objf = objective_function(data_structure.numerics.minmax, self.data)
conf, _, _, _, _ = constraints.constraint_eqns(m, -1, self.data)
Expand Down Expand Up @@ -161,7 +161,7 @@ def call_models_and_write_output(self, xc: np.ndarray, ifail: int):
# Divert OUT.DAT and MFILE.DAT output to scratch files for
# idempotence checking
OutputFileManager.open_idempotence_files()
self._call_models_once(xc)
self._call_models_once(xc, self.data)
# Write mfile
finalise(self.models, self.data, ifail)

Expand Down Expand Up @@ -244,7 +244,7 @@ def call_models_and_write_output(self, xc: np.ndarray, ifail: int):
non_idempotent_msg=non_idempotent_warning + "\n" + non_idempotent_table,
)

def _call_models_once(self, xc: np.ndarray):
def _call_models_once(self, xc: np.ndarray, data: DataStructure):
"""Call the physics and engineering models.

This method is the principal caller of all the physics and
Expand All @@ -255,6 +255,8 @@ def _call_models_once(self, xc: np.ndarray):
----------
xc : np.array
Array of optimisation parameters
data: DataStructure
data structure object
"""
# Number of active iteration variables
nvars = len(xc)
Expand All @@ -267,13 +269,13 @@ def _call_models_once(self, xc: np.ndarray):

# Perform the various function calls
# Stellarator caller
if data_structure.stellarator_variables.istell != 0:
if data.stellarator.istell != 0:
self.models.stellarator.run()
# TODO Is this return safe?
return

# Inertial Fusion Energy calls
if data_structure.ife_variables.ife != 0:
if data.ife.ife != 0:
self.models.ife.run()
return

Expand Down
51 changes: 17 additions & 34 deletions process/core/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,17 @@
from process.core.solver import iteration_variables
from process.core.solver.constraints import ConstraintManager
from process.data_structure.divertor_variables import init_divertor_variables
from process.data_structure.ife_variables import init_ife_variables
from process.data_structure.impurity_radiation_module import (
init_impurity_radiation_module,
)
from process.data_structure.neoclassics_variables import init_neoclassics_variables
from process.data_structure.pf_power_variables import init_pf_power_variables
from process.data_structure.pfcoil_variables import (
init_pfcoil_module,
init_pfcoil_variables,
)
from process.data_structure.physics_variables import (
init_physics_module,
init_physics_variables,
)
from process.data_structure.power_variables import init_power_variables
from process.data_structure.rebco_variables import init_rebco_variables
from process.data_structure.scan_variables import init_scan_variables
from process.data_structure.stellarator_variables import init_stellarator_variables
from process.data_structure.superconducting_tf_coil_variables import (
init_superconducting_tf_coil_variables,
)
Expand Down Expand Up @@ -72,7 +65,7 @@ def init_process(data: DataStructure):
set_active_constraints()

# set the device type (icase)
set_device_type()
set_device_type(data)

# Initialise the Stellarator
st_init(data)
Expand Down Expand Up @@ -252,20 +245,15 @@ def init_all_module_vars():
data_structure.numerics.init_numerics()
init_divertor_variables()
data_structure.global_variables.init_global_variables()
init_ife_variables()
init_impurity_radiation_module()
init_pfcoil_module()
init_physics_module()
init_physics_variables()
init_scan_variables()
init_superconducting_tf_coil_variables()
init_stellarator_variables()
init_tfcoil_variables()
constants.init_constants()
init_pfcoil_variables()
init_pf_power_variables()
init_rebco_variables()
init_power_variables()
init_neoclassics_variables()


Expand Down Expand Up @@ -394,10 +382,7 @@ def check_process(inputs, data): # noqa: ARG001
)

# Plasma profile consistency checks
if (
data_structure.ife_variables.ife != 1
and data_structure.physics_variables.i_plasma_pedestal == 1
):
if data.ife.ife != 1 and data_structure.physics_variables.i_plasma_pedestal == 1:
# Temperature checks
if (
data_structure.physics_variables.temp_plasma_pedestal_kev
Expand Down Expand Up @@ -615,9 +600,9 @@ def check_process(inputs, data): # noqa: ARG001
# 2 : PF coil on top of TF coil
# 3 : PF coil outside of TF coil
if data_structure.physics_variables.itartpf == 0:
data_structure.pfcoil_variables.i_pf_location[0] = 2
data_structure.pfcoil_variables.i_pf_location[1] = 3
data_structure.pfcoil_variables.i_pf_location[2] = 3
data.pf_coil.i_pf_location[0] = 2
data.pf_coil.i_pf_location[1] = 3
data.pf_coil.i_pf_location[2] = 3

# Water cooled copper magnets initalisation / checks
if (
Expand Down Expand Up @@ -757,18 +742,18 @@ def check_process(inputs, data): # noqa: ARG001
# Check PF coil configurations
j = 0
k = 0
for i in range(data_structure.pfcoil_variables.n_pf_coil_groups):
for i in range(data.pf_coil.n_pf_coil_groups):
if (
data_structure.pfcoil_variables.i_pf_location[i] != 2
and data_structure.pfcoil_variables.n_pf_coils_in_group[i] != 2
data.pf_coil.i_pf_location[i] != 2
and data.pf_coil.n_pf_coils_in_group[i] != 2
):
raise ProcessValidationError(
"n_pf_coils_in_group(i) .ne. 2 is not a valid option except for (i_pf_location = 2)"
)

if data_structure.pfcoil_variables.i_pf_location[i] == 2:
if data.pf_coil.i_pf_location[i] == 2:
j += 1
k += data_structure.pfcoil_variables.n_pf_coils_in_group[i]
k += data.pf_coil.n_pf_coils_in_group[i]

if k == 1:
raise ProcessValidationError(
Expand Down Expand Up @@ -1119,8 +1104,8 @@ def check_process(inputs, data): # noqa: ARG001
)

# PF coil resistivity is zero if superconducting
if data_structure.pfcoil_variables.i_pf_conductor == 0:
data_structure.pfcoil_variables.rho_pf_coil = 0.0
if data.pf_coil.i_pf_conductor == 0:
data.pf_coil.rho_pf_coil = 0.0

# If there is no NBI, then hot beam density should be zero
if data.current_drive.i_hcd_calculations == 1:
Expand All @@ -1137,9 +1122,7 @@ def check_process(inputs, data): # noqa: ARG001
# Ensure that blanket material fractions allow non-zero space for steel
# CCFE HCPB Model

if data_structure.stellarator_variables.istell == 0 and (
data.fwbs.i_blanket_type == 1
):
if data.stellarator.istell == 0 and (data.fwbs.i_blanket_type == 1):
fsum = data.fwbs.breeder_multiplier + data.fwbs.vfcblkt + data.fwbs.vfpblkt
if fsum >= 1.0:
raise ProcessValidationError(
Expand Down Expand Up @@ -1217,7 +1200,7 @@ def check_process(inputs, data): # noqa: ARG001
: data_structure.numerics.neqns + data_structure.numerics.nineqns
]
== 60
).any() and data_structure.pfcoil_variables.i_cs_superconductor == 8:
).any() and data.pf_coil.i_cs_superconductor == 8:
raise ProcessValidationError(
"turn off CS temperature margin constraint icc = 60 when using REBCO"
)
Expand Down Expand Up @@ -1256,8 +1239,8 @@ def set_active_constraints():
data_structure.numerics.nineqns = num_constraints - data_structure.numerics.neqns


def set_device_type():
if data_structure.ife_variables.ife == 1:
def set_device_type(data):
if data.ife.ife == 1:
data_structure.global_variables.icase = "Inertial Fusion model"
elif data_structure.stellarator_variables.istell != 0:
elif data.stellarator.istell != 0:
data_structure.global_variables.icase = "Stellarator model"
Loading