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
4 changes: 2 additions & 2 deletions documentation/source/development/add-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Code example in the `input.py` file:
To add a `PROCESS` iteration variable please follow the steps below, in addition to the instructions for adding an input variable:


1. The parameter `ipnvars` in module `numerics` of `numerics.f90` will normally be greater than the actual number of iteration variables, and does not need to be changed.
1. The parameter `IPNVARS` in module `numerics` of `numerics.f90` will normally be greater than the actual number of iteration variables, and does not need to be changed.
2. Append a new iteration number key to the end of the `ITERATION_VARIABLES` dictionary in `iteration_variables.py`. The associated variable is the corresponding key value.
3. Set the variable origin file and then the associated lower and upper bounds
4. Update the `lablxc` description in `numerics.f90`.
Expand All @@ -80,7 +80,7 @@ ITERATION_VARIABLES = {

New figures of merit are added to `PROCESS` in the following way:

1. Increment the parameter `ipnfoms` in module `numerics` in source file `numerics.py` to accommodate the new figure of merit.
1. Increment the parameter `IPNFOMS` in module `numerics` in source file `numerics.py` to accommodate the new figure of merit.

2. Assign the new integer value and description string of the new figure of merit to the `FiguresOfMerit` enumerator in `numerics.py`.

Expand Down
23 changes: 11 additions & 12 deletions process/core/caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import numpy as np
from tabulate import tabulate

from process import data_structure
from process.core import constants
from process.core.final import finalise
from process.core.io.mfile import MFile
Expand Down Expand Up @@ -99,7 +98,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, self.data)
objf = objective_function(self.data.numerics.minmax, self.data)
conf, _, _, _, _ = constraints.constraint_eqns(m, -1, self.data)

if objf_prev is None and conf_prev is None:
Expand Down Expand Up @@ -161,15 +160,13 @@ def call_models_and_write_output(self, xc: np.ndarray, ifail: int):
for _ in range(10):
# Divert OUT.DAT and MFILE.DAT output to scratch files for
# idempotence checking
OutputFileManager.open_idempotence_files()
OutputFileManager.open_idempotence_files(self.data.globals.output_prefix)
self._call_models_once(xc)
# Write mfile
finalise(self.models, self.data, ifail)

# Extract data from intermediate idempotence-checking mfile
mfile_path = (
data_structure.global_variables.output_prefix
) + "IDEM_MFILE.DAT"
mfile_path = (self.data.globals.output_prefix) + "IDEM_MFILE.DAT"
mfile = MFile(mfile_path)
# Create mfile dict of float values: only compare floats
mfile_data = {
Expand Down Expand Up @@ -204,7 +201,9 @@ def call_models_and_write_output(self, xc: np.ndarray, ifail: int):
logger.debug("Mfiles idempotent, returning")
# Divert OUT.DAT and MFILE.DAT output back to original files
# now idempotence checking complete
OutputFileManager.close_idempotence_files()
OutputFileManager.close_idempotence_files(
self.data.globals.output_prefix
)
# Write final output file and mfile
finalise(self.models, self.data, ifail)
return
Expand All @@ -230,12 +229,12 @@ def call_models_and_write_output(self, xc: np.ndarray, ifail: int):
)

# Close idempotence files, write final output file and mfile
OutputFileManager.close_idempotence_files()
OutputFileManager.close_idempotence_files(self.data.globals.output_prefix)

except Exception:
# If exception in model evaluations delete intermediate idempotence
# files to clean up
OutputFileManager.close_idempotence_files()
OutputFileManager.close_idempotence_files(self.data.globals.output_prefix)
raise
else:
finalise(
Expand All @@ -261,7 +260,7 @@ def _call_models_once(self, xc: np.ndarray):
nvars = len(xc)

# Increment the call counter
data_structure.numerics.ncalls += 1
self.data.numerics.ncalls += 1

# Convert variables
set_scaled_iteration_variable(xc, nvars, self.data)
Expand Down Expand Up @@ -409,8 +408,8 @@ def write_output_files(
ifail : int
solver return code
"""
n = data_structure.numerics.nvar
x = data_structure.numerics.xcm[:n]
n = data.numerics.nvar
x = data.numerics.xcm[:n]
# Call models, ensuring output mfiles are fully idempotent
caller = Caller(models, data)
if runtime is not None:
Expand Down
26 changes: 14 additions & 12 deletions process/core/final.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from process.core import process_output as po
from process.core.solver import constraints
from process.core.solver.objectives import objective_function
from process.data_structure import numerics
from process.data_structure.numerics import PROCESSRunMode


Expand All @@ -33,7 +32,7 @@ def finalise(models, data, ifail: int, non_idempotent_msg: str | None = None):
po.oheadr(constants.NOUT, "Final UNFEASIBLE Point")

# Output relevant to no optimisation
if numerics.ioptimz == PROCESSRunMode.EVALUATION:
if data.numerics.ioptimz == PROCESSRunMode.EVALUATION:
output_evaluation(data)

# Print non-idempotence warning to OUT.DAT only
Expand All @@ -58,18 +57,21 @@ def output_evaluation(data):
po.oblnkl(constants.NOUT)

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

# Print the residuals of the constraint equations

residual_error, value, residual, symbols, units = constraints.constraint_eqns(
numerics.neqns + numerics.nineqns, -1, data
data.numerics.neqns + data.numerics.nineqns, -1, data
)

labels = [
numerics.lablcc[j]
for j in [i - 1 for i in numerics.icc[: numerics.neqns + numerics.nineqns]]
data.numerics.lablcc[j]
for j in [
i - 1
for i in data.numerics.icc[: data.numerics.neqns + data.numerics.nineqns]
]
]
physical_constraint = [f"{c} {u}" for c, u in zip(value, units, strict=False)]
physical_residual = [f"{c} {u}" for c, u in zip(residual, units, strict=False)]
Expand All @@ -84,20 +86,20 @@ def output_evaluation(data):

po.write(constants.NOUT, tabulate(table_data, headers="keys"))

for i in range(numerics.neqns):
constraint_id = numerics.icc[i]
for i in range(data.numerics.neqns):
constraint_id = data.numerics.icc[i]
po.ovarre(
constants.MFILE,
f"{labels[i]} normalised residue",
f"(eq_con{constraint_id:03d})",
residual_error[i],
)

for i in range(numerics.nineqns):
constraint_id = numerics.icc[numerics.neqns + i]
for i in range(data.numerics.nineqns):
constraint_id = data.numerics.icc[data.numerics.neqns + i]
po.ovarre(
constants.MFILE,
f"{labels[numerics.neqns + i]}",
f"{labels[data.numerics.neqns + i]}",
f"(ineq_con{constraint_id:03d})",
residual_error[numerics.neqns + i],
residual_error[data.numerics.neqns + i],
)
Loading
Loading