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
2 changes: 1 addition & 1 deletion examples/data/large_tokamak_varyrun_IN.DAT
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ sig_tf_wp_max = 7.5E8 * Allowable maximum shear stress in TF coil conduit (Tr
*---------------------*
icc = 5
ixc = 6 * nd_plasma_electrons_vol_avg [m-3]
nd_plasma_electrons_vol_avg = 8E20
nd_plasma_electrons_vol_avg = 6E19

* Neutron wall load upper limit *
*-------------------------------*
Expand Down
22 changes: 20 additions & 2 deletions examples/vary_run_example.ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
# %autoreload 2

import os
import re
import shutil
import tempfile
from pathlib import Path
Expand All @@ -108,6 +109,7 @@
from process.core.repository import get_process_root
from process.main import VaryRun

# %%
# Path to files
data_dir = get_process_root() / "../examples/data/"
conf_file = data_dir / "run_process.conf"
Expand All @@ -132,6 +134,21 @@
vary_run.run()
os.chdir(cwd)

# %%
# Find the final file created, as this file converges
# VaryRun will raise an error if it does not find a converging input file
# within the maximum number of iterations
path_to_varyrun_files = Path(temp_dir.name)

in_dats_created = [
file.name
for file in path_to_varyrun_files.iterdir()
if re.match(r"([0-9]+)_IN.DAT", file.name) is not None
]

final_file_prefix = max(int(name.strip("_IN.DAT")) for name in in_dats_created)
converging_in_dat = str(final_file_prefix) + "_IN.DAT"

# %%
# Get the initial values from the original input file
iteration_variable_names, original_iteration_variable_values = (
Expand All @@ -142,13 +159,14 @@
# VaryRun always produces a file called IN.DAT in the same directory
# as the conf file
_, updated_iteration_variable_values = get_mfile_initial_ixc_values(
Path(temp_dir.name) / "2_IN.DAT", vary_run.data
path_to_varyrun_files / converging_in_dat, vary_run.data
)

# %% [markdown]
# ## Compare iteration variable values
#
# `VaryRun` has changed the values of some iteration variables.
# `VaryRun` has found a converging input file and has changed the initial values of the
# iteration variables:

# %%
import pandas as pd
Expand Down
12 changes: 11 additions & 1 deletion process/core/io/vary_run/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from numpy.random import default_rng

from process.core.data_structure.base import DataStructure
from process.core.exceptions import ProcessError
from process.core.io.in_dat import InDat
from process.core.io.mfile import MFile
from process.core.io.vary_run.tools import (
Expand Down Expand Up @@ -262,7 +263,14 @@ def create_readme(self):
Path(self.wdir, "README.txt").write_text(self.comment)

def error_status2readme(self, mfile):
"""Appends PROCESS outcome to README.txt if reached maximum iterations"""
"""Appends PROCESS outcome to README.txt if reached maximum iterations

Raises
------
ProcessError
If VaryRun does not find a converging IN.DAT within the maximum
number of iterations
"""
m_file = MFile(filename=self.wdir / mfile)

try:
Expand Down Expand Up @@ -298,6 +306,8 @@ def error_status2readme(self, mfile):
with open(Path(self.wdir, "README.txt"), "a") as readme:
readme.write(error_status)
print(ifail_msg)
if ifail != SolverOutputCondition.CONVERGED:
raise ProcessError(ifail_msg)

def modify_in_dat(self):
"""Modifies the original IN.DAT file"""
Expand Down
15 changes: 0 additions & 15 deletions tests/integration/data/run_process.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,3 @@ FACTOR = 1.5

* Number of allowed unfeasible points that do not trigger rerunning.
NO_ALLOWED_UNFEASIBLE = 0

* include a summary file with the iteration variables at each stage.
INCLUDE_ITERVAR_DIFF = True

* add iteration variables - comma separated
ADD_IXC =

* remove iteration variables - comma separated
DEL_IXC =

* add constraint equations - comma separated
ADD_ICC =

* remove constraint equations - comma separated
DEL_ICC =
Loading