Skip to content
Closed
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
10 changes: 6 additions & 4 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 @@ -273,7 +275,7 @@ def _call_models_once(self, xc: np.ndarray):
return

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

Expand Down
41 changes: 15 additions & 26 deletions process/core/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,11 @@
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,
Expand Down Expand Up @@ -72,7 +67,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,17 +247,14 @@ 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()
Expand Down Expand Up @@ -394,10 +386,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 +604,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 +746,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 +1108,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 Down Expand Up @@ -1217,7 +1206,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 +1245,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:
data_structure.global_variables.icase = "Stellarator model"
Loading
Loading