Skip to content
Open
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
5 changes: 2 additions & 3 deletions examples/introduction.ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,10 @@
# we have set some values on the `CostModel` instance and can print them.

# %%
import process.data_structure

# Print some values on the CostModel instance
print(f"Heat transport system: {process.data_structure.cost_variables.c226:.3e} M$")
print(f"Electrical plant equipment: {process.data_structure.cost_variables.c24:.3e} M$")
print(f"Heat transport system: {single_run.data.costs.c226:.3e} M$")
print(f"Electrical plant equipment: {single_run.data.costs.c24:.3e} M$")

# %%
# Clean up
Expand Down
2 changes: 1 addition & 1 deletion process/core/caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def call_models(self, xc: np.ndarray, m: int) -> tuple[float, np.ndarray]:
for _ in range(10):
self._call_models_once(xc)
# Evaluate objective function and constraints
objf = objective_function(data_structure.numerics.minmax)
objf = objective_function(data_structure.numerics.minmax, self.data)
conf, _, _, _, _ = constraints.constraint_eqns(m, -1, self.data)

if objf_prev is None and conf_prev is None:
Expand Down
2 changes: 1 addition & 1 deletion process/core/final.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def output_evaluation(data):
po.oblnkl(constants.NOUT)

# Evaluate objective function
norm_objf = objective_function(numerics.minmax)
norm_objf = objective_function(numerics.minmax, data)
po.ovarre(constants.MFILE, "Normalised objective function", "(norm_objf)", norm_objf)

# Print the residuals of the constraint equations
Expand Down
2 changes: 0 additions & 2 deletions process/core/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from process.data_structure.buildings_variables import init_buildings_variables
from process.data_structure.ccfe_hcpb_module import init_ccfe_hcpb_module
from process.data_structure.constraint_variables import init_constraint_variables
from process.data_structure.cost_variables import init_cost_variables
from process.data_structure.current_drive_variables import init_current_drive_variables
from process.data_structure.dcll_variables import init_dcll_module
from process.data_structure.divertor_variables import init_divertor_variables
Expand Down Expand Up @@ -270,7 +269,6 @@ def init_all_module_vars():
logging_model_handler.clear_logs()
data_structure.numerics.init_numerics()
init_buildings_variables()
init_cost_variables()
init_divertor_variables()
init_fwbs_variables()
data_structure.global_variables.init_global_variables()
Expand Down
328 changes: 118 additions & 210 deletions process/core/input.py

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions process/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from dataclasses import dataclass, fields

from process.data_structure.cost_2015_variables import Cost2015Data
from process.data_structure.cost_variables import CostData
from process.data_structure.cs_fatigue_variables import CSFatigueData
from process.data_structure.vacuum_variables import VacuumData
from process.data_structure.water_usage_variables import WaterUseData
Expand All @@ -15,6 +16,7 @@ class DataStructure:
costs_2015: Cost2015Data = initialise_later
cs_fatigue: CSFatigueData = initialise_later
vacuum: VacuumData = initialise_later
costs: CostData = initialise_later

def __post_init__(self):
for f in fields(self):
Expand Down
9 changes: 4 additions & 5 deletions process/core/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from process.data_structure import (
build_variables,
constraint_variables,
cost_variables,
current_drive_variables,
divertor_variables,
fwbs_variables,
Expand Down Expand Up @@ -1103,11 +1102,11 @@ def scan_select(self, nwp, swp, iscn):
case 20:
constraint_variables.t_burn_min = swp[iscn - 1]
case 22:
if cost_variables.i_plant_availability == 1:
if self.data.costs.i_plant_availability == 1:
raise ProcessValueError(
"Do not scan f_t_plant_available if i_plant_availability=1"
)
cost_variables.f_t_plant_available = swp[iscn - 1]
self.data.costs.f_t_plant_available = swp[iscn - 1]
case 24:
constraint_variables.p_fusion_total_max_mw = swp[iscn - 1]
case 25:
Expand Down Expand Up @@ -1205,9 +1204,9 @@ def scan_select(self, nwp, swp, iscn):
case 76:
heat_transport_variables.eta_turbine = swp[iscn - 1]
case 77:
cost_variables.startupratio = swp[iscn - 1]
self.data.costs.startupratio = swp[iscn - 1]
case 78:
cost_variables.fkind = swp[iscn - 1]
self.data.costs.fkind = swp[iscn - 1]
case 79:
current_drive_variables.eta_ecrh_injector_wall_plug = swp[iscn - 1]
case 80:
Expand Down
31 changes: 14 additions & 17 deletions process/core/solver/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,15 +1315,15 @@ def constraint_equation_60(constraint_registration, _data):


@ConstraintManager.register_constraint(61, "", ">=")
def constraint_equation_61(constraint_registration, _data):
def constraint_equation_61(constraint_registration, data):
"""Equation for availability lower limit

f_t_plant_available: Total plant availability fraction
avail_min: Minimum availability
"""
return geq(
data_structure.cost_variables.f_t_plant_available,
data_structure.cost_variables.avail_min,
data.costs.f_t_plant_available,
data.costs.avail_min,
constraint_registration,
)

Expand Down Expand Up @@ -1715,7 +1715,7 @@ def constraint_equation_84(constraint_registration, _data):


@ConstraintManager.register_constraint(85, "years", "=")
def constraint_equation_85(constraint_registration, _data):
def constraint_equation_85(constraint_registration, data):
"""Equality constraint for the centerpost (CP) lifetime

Depending on the chosen option i_cp_lifetime:
Expand All @@ -1731,20 +1731,20 @@ def constraint_equation_85(constraint_registration, _data):
the CP lifetime must equate
"""
# The CP lifetime is equal to the the divertor one
if data_structure.cost_variables.i_cp_lifetime == 0:
bound = data_structure.cost_variables.cplife_input
if data.costs.i_cp_lifetime == 0:
bound = data.costs.cplife_input

elif data_structure.cost_variables.i_cp_lifetime == 1:
bound = data_structure.cost_variables.life_div_fpy
elif data.costs.i_cp_lifetime == 1:
bound = data.costs.life_div_fpy

# The CP lifetime is equal to the tritium breeding blankets / FW one
elif data_structure.cost_variables.i_cp_lifetime == 2:
elif data.costs.i_cp_lifetime == 2:
bound = data_structure.fwbs_variables.life_blkt_fpy

elif data_structure.cost_variables.i_cp_lifetime == 3:
bound = data_structure.cost_variables.life_plant
elif data.costs.i_cp_lifetime == 3:
bound = data.costs.life_plant

return eq(data_structure.cost_variables.cplife, bound, constraint_registration)
return eq(data.costs.cplife, bound, constraint_registration)


@ConstraintManager.register_constraint(86, "m", "<=")
Expand Down Expand Up @@ -1810,11 +1810,8 @@ def constraint_equation_90(constraint_registration, data):
n_cycle: Allowable number of cycles for CS
n_cycle_min: Minimum required cycles for CS
"""
if (
data_structure.cost_variables.ibkt_life == 1
and data.cs_fatigue.bkt_life_csf == 1
):
data.cs_fatigue.n_cycle_min = data_structure.cost_variables.bktcycles
if data.costs.ibkt_life == 1 and data.cs_fatigue.bkt_life_csf == 1:
data.cs_fatigue.n_cycle_min = data.costs.bktcycles

return geq(
data.cs_fatigue.n_cycle,
Expand Down
4 changes: 2 additions & 2 deletions process/core/solver/evaluators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import numpy as np

from process.core.caller import Caller
from process.data_structure import cost_variables as cv
from process.data_structure import global_variables as gv
from process.data_structure import numerics
from process.data_structure import physics_variables as pv
Expand All @@ -28,6 +27,7 @@ def __init__(self, models, data, _x):
:type x: np.ndarray
"""
self.caller = Caller(models, data)
self.data = data

def fcnvmc1(self, _n, m, xv, ifail):
"""Function evaluator for VMCON.
Expand Down Expand Up @@ -75,7 +75,7 @@ def fcnvmc1(self, _n, m, xv, ifail):
logger.debug(f"{(1 - (ifail % 7)) - 1 = }")
logger.debug(f"{(numerics.nviter % 2) - 1 = }")
logger.debug(f"{pv.temp_plasma_electron_vol_avg_kev = }")
logger.debug(f"{cv.coe = }")
logger.debug(f"{self.data.costs.coe = }")
logger.debug(f"{pv.rmajor = }")
logger.debug(f"{pv.p_fusion_total_mw = }")
logger.debug(f"{pv.b_plasma_toroidal_on_axis = }")
Expand Down
19 changes: 11 additions & 8 deletions process/core/solver/objectives.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np

from process.core.exceptions import ProcessValueError
from process.core.model import DataStructure
from process.data_structure import (
cost_variables,
current_drive_variables,
divertor_variables,
heat_transport_variables,
Expand Down Expand Up @@ -32,7 +32,7 @@
}


def objective_function(minmax: int) -> float:
def objective_function(minmax: int, data: DataStructure) -> float:
"""Calculate the specified objective function

Parameters
Expand All @@ -57,6 +57,9 @@ def objective_function(minmax: int) -> float:
* 17: Net electrical output
* 18: NULL, f(x) = 1
* 19: Major radius/burn time
data: DataStructure
data structure object for providing data to the
objective function
"""
figure_of_merit = abs(minmax)

Expand All @@ -80,12 +83,12 @@ def objective_function(minmax: int) -> float:
+ physics_variables.p_plasma_ohmic_mw
)
case 6:
objective_metric = cost_variables.coe / 100.0
objective_metric = data.costs.coe / 100.0
case 7:
objective_metric = (
cost_variables.cdirt / 1.0e3
if cost_variables.ireactor == 0
else cost_variables.concost / 1.0e4
data.costs.cdirt / 1.0e3
if data.costs.ireactor == 0
else data.costs.concost / 1.0e4
)
case 8:
objective_metric = physics_variables.aspect
Expand All @@ -98,9 +101,9 @@ def objective_function(minmax: int) -> float:
case 14:
objective_metric = times_variables.t_plant_pulse_burn / 2.0e4
case 15:
if cost_variables.i_plant_availability != 1:
if data.costs.i_plant_availability != 1:
raise ProcessValueError("minmax=15 requires i_plant_availability=1")
objective_metric = cost_variables.f_t_plant_available
objective_metric = data.costs.f_t_plant_available
case 16:
objective_metric = 0.95 * (physics_variables.rmajor / 9.0) - 0.05 * (
times_variables.t_plant_pulse_burn / 7200.0
Expand Down
Loading
Loading