8000 Convert warnings to Python by timothy-nunn · Pull Request #3680 · ukaea/PROCESS · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Convert warnings to Python #3680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ LIST(APPEND PROCESS_SRCS
structure_variables.f90
output.f90
init_module.f90
error_handling.f90
global_variables.f90
constraint_variables.f90
vacuum_variables.f90
Expand Down
24 changes: 3 additions & 21 deletions documentation/proc-pages/usage/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,9 @@ it often requires a great deal of painstaking adjustment of the input file to ov
## Error handling

In general, errors detected during a run are handled in a consistent manner, with the code
producing useful diagnostic messages to help the user understand what has happened.

There are three levels of errors and warnings that may occur:

* **Level 1** -- An *informational* message is produced under certain conditions, for example if
the code modified the user's input choice for some reason.
* **Level 2** -- A *warning* message is produced if a non-fatal situation has occurred that may
result in an output case that is inaccurate or unreliable in some way.
* **Level 3** -- An *error* message will occur is a severe of fatal error has occurred and the program cannot continue.

These messages are printed on the screen during the course of a run, and those still active at the
final (feasible or unfeasible) solution point are also written to the end of the output file
(messages encountered during the iteration process are not copied to the output file, as the
convergence to a valid solution might resolve some of the warnings produced earlier in the
solution process).

The `error_status` variable returns the highest security level that has been encountered (or zero
if no abnormal conditions have been found); of a severe error (level 3) is flagged at any point the
program is terminated immediately. The final message number encountered during a run is returned via
output variable `error_id` . In addition, with certain messages, a number of diagnostic values may
also be given; these can be used to provide extra diagnostic information if the source code is available
producing useful diagnostic messages to help the user understand what has happened. In the case of an
unrecoverable error, PROCESS will fail with a Python exception. If the error is recoverable, a warning
will be logged that is written to the terminal and output file at the end of the run.

### General problems

Expand Down
17 changes: 10 additions & 7 deletions process/blanket_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@
build_variables,
constants,
divertor_variables,
error_handling,
fwbs_variables,
heat_transport_variables,
physics_variables,
primary_pumping_variables,
)
from process.fortran import (
error_handling as eh,
)
from process.utilities.f2py_string_patch import f2py_compatible_to_string
from process.warning_handler import WarningManager

# Acronyms for this module:
# BB Breeding Blanket
Expand Down Expand Up @@ -647,7 +644,9 @@ def thermo_hydraulic_model_pressure_drop_calculations(self, output: bool):
if (blanket_library.bllengi < (fwbs_variables.b_bz_liq * 3)) or (
blanket_library.bllengo < (fwbs_variables.b_bz_liq * 3)
):
eh.report_error(278)
WarningManager.create_warning(
"Your blanket modules are too small for the Liquid Metal pipes"
)

# Unless there is no IB blanket...
else:
Expand All @@ -661,7 +660,9 @@ def thermo_hydraulic_model_pressure_drop_calculations(self, output: bool):
) / fwbs_variables.nopipes
# Poloidal
if blanket_library.bllengo < (fwbs_variables.b_bz_liq * 3):
eh.report_error(278)
WarningManager.create_warning(
"Your blanket modules are too small for the Liquid Metal pipes"
)

# Calculate total flow lengths, used for pressure drop calculation
# Blanket primary coolant flow
Expand Down Expand Up @@ -1345,7 +1346,9 @@ def liquid_breeder_properties(self, output: bool = False):
(t_ranges[:, 0] > mid_temp_liq).any()
or (t_ranges[:, 1] < mid_temp_liq).any()
):
error_handling.report_error(280)
WarningManager.create_warning(
"Outside temperature limit for one or more liquid metal breeder properties"
)

if output:
po.ocmmnt(
Expand Down
64 changes: 40 additions & 24 deletions process/build.py
10000
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @ F438 @
constants,
current_drive_variables,
divertor_variables,
error_handling,
fwbs_variables,
numerics,
pfcoil_variables,
physics_variables,
tfcoil_variables,
)
from process.warning_handler import WarningManager

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -100,9 +100,9 @@ def portsz(self):
current_drive_variables.rtanmax = f * np.cos(eps) - 0.5e0 * c

else: # coil separation is too narrow for beam...
error_handling.fdiags[0] = g
error_handling.fdiags[1] = c
error_handling.report_error(63)
WarningManager.create_warning(
"Max beam tangency radius set =0 temporarily; change beamwd", g=g, c=c
)

current_drive_variables.rtanmax = 0.0e0

Expand Down Expand Up @@ -1757,9 +1757,11 @@ def calculate_radial_build(self, output: bool) -> None:

# Notify user that build_variables.r_cp_top has been set to 1.01*build_variables.r_tf_inboard_out (lvl 2 error)
if build_variables.r_cp_top < 1.01e0 * build_variables.r_tf_inboard_out:
error_handling.fdiags[0] = build_variables.r_cp_top
error_handling.fdiags[1] = build_variables.r_tf_inboard_out
error_handling.report_error(268)
WarningManager.create_warning(
"TF CP top radius (r_cp_top) replaced by 1.01*r_tf_inboard_out -> potential top rbuild issue",
r_cp_top=build_variables.r_cp_top,
r_tf_inboard_out=build_variables.r_tf_inboard_out,
)

# build_variables.r_cp_top correction
build_variables.r_cp_top = build_variables.r_tf_inboard_out * 1.01e0
Expand All @@ -1773,9 +1775,11 @@ def calculate_radial_build(self, output: bool) -> None:
elif build_variables.i_r_cp_top == 1:
# Notify user that build_variables.r_cp_top has been set to 1.01*build_variables.r_tf_inboard_out (lvl 2 error)
if build_variables.r_cp_top < 1.01e0 * build_variables.r_tf_inboard_out:
error_handling.fdiags[0] = build_variables.r_cp_top
error_handling.fdiags[1] = build_variables.r_tf_inboard_out
error_handling.report_error(268)
WarningManager.create_warning(
"TF CP top radius (r_cp_top) replaced by 1.01*r_tf_inboard_out -> potential top rbuild issue",
r_cp_top=build_variables.r_cp_top,
r_tf_inboard_out=build_variables.r_tf_inboard_out,
)

# build_variables.r_cp_top correction
build_variables.r_cp_top = build_variables.r_tf_inboard_out * 1.01e0
Expand Down Expand Up @@ -1809,8 +1813,10 @@ def calculate_radial_build(self, output: bool) -> None:
)
+ tfcoil_variables.drtop
):
error_handling.fdiags[0] = build_variables.r_cp_top
error_handling.report_error(256)
WarningManager.create_warning(
"Top CP radius larger that its value determined with plasma shape",
r_cp_top=build_variables.r_cp_top,
)
if build_variables.i_tf_inside_cs == 1:
# Radial position of vacuum vessel [m]
build_variables.r_vv_inboard_out = (
Expand Down Expand Up @@ -2064,24 +2070,34 @@ def calculate_radial_build(self, output: bool) -> None:
)
po.ocmmnt(self.outfile, " its range of applicability.)")
po.oblnkl(self.outfile)
error_handling.report_error(62)
WarningManager.create_warning(
"Ripple result may be inaccurate, as the fit has been extrapolated"
)

if build_python_variables.ripflag == 1:
error_handling.fdiags[0] = (
tfcoil_variables.wwp1
* tfcoil_variables.n_tf_coils
/ physics_variables.rmajor
WarningManager.create_warning(
"(TF coil ripple calculation) Dimensionless coil width X out of fitted range",
diagnostic=(
tfcoil_variables.wwp1
* tfcoil_variables.n_tf_coils
/ physics_variables.rmajor
),
)
error_handling.report_error(141)

elif build_python_variables.ripflag == 2:
# Convert to integer as idiags is integer array
error_handling.idiags[0] = int(tfcoil_variables.n_tf_coils)
error_handling.report_error(142)
WarningManager.create_warning(
"(TF coil ripple calculation) No of TF coils not between 16 and 20 inclusive",
n_tf_coils=tfcoil_variables.n_tf_coils,
)
else:
error_handling.fdiags[0] = (
physics_variables.rmajor + physics_variables.rminor
) / build_variables.r_tf_outboard_mid
error_handling.report_error(143)
WarningManager.create_warning(
"(TF coil ripple calculation) (R+a)/rtot out of fitted range",
diagnostic=(
(physics_variables.rmajor + physics_variables.rminor)
/ build_variables.r_tf_outboard_mid
),
)

po.ovarin(
self.outfile,
Expand Down
5 changes: 4 additions & 1 deletion process/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import process.fortran as fortran
from process.exceptions import ProcessError, ProcessValueError
from process.warning_handler import WarningManager

ConstraintSymbolType = Literal["=", ">=", "<="]

Expand Down Expand Up @@ -1026,7 +1027,9 @@ def constraint_equation_33():
j_tf_wp: winding pack current density (A/m2)
"""
if fortran.constraint_variables.fiooic > 0.7:
fortran.error_handling.report_error(285)
WarningManager.create_warning(
"fiooic shouldn't be above 0.7 for engineering reliability"
)

cc = (
fortran.tfcoil_variables.j_tf_wp / fortran.tfcoil_variables.jwdgcrt
Expand Down
9 changes: 4 additions & 5 deletions process/current_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
heat_transport_variables,
physics_variables,
)
from process.fortran import (
error_handling as eh,
)
from process.plasma_profiles import PlasmaProfile
from process.warning_handler import WarningManager


class NeutralBeam:
Expand Down Expand Up @@ -793,7 +791,6 @@ def legend(self, zlocal, arg):
Abramowitz and Stegun, equation 8.12.1
"""
if abs(arg) > (1.0e0 + 1.0e-10):
eh.fdiags[0] = arg
raise ProcessValueError("Invalid argument", arg=arg)

arg2 = min(arg, (1.0e0 - 1.0e-10))
Expand Down Expand Up @@ -1073,7 +1070,9 @@ def lhrad(self):
rat0 = rat1

else:
eh.report_error(16)
WarningManager.create_warning(
"LH penetration radius not found after lapno iterations, using 0.8*rminor"
)
rat0 = 0.8e0

return rat0
Expand Down
25 changes: 13 additions & 12 deletions process/fw.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@
blanket_library,
build_variables,
constants,
error_handling,
fwbs_variables,
)
from process.fortran import (
error_handling as eh,
)
from process.utilities.f2py_string_patch import f2py_compatible_to_string
from process.warning_handler import WarningManager


class Fw:
Expand Down Expand Up @@ -151,10 +148,12 @@ def fw_temp(

# Print debug info if temperature too low/high or NaN/Inf
if np.isnan(temp_k):
eh.report_error(223)
WarningManager.create_warning("NaN first wall temperature")
elif (temp_k <= 100) or (temp_k > 1500):
eh.fdiags[0] = temp_k
eh.report_error(224)
WarningManager.create_warning(
"First wall temperature (temp_k) out of range : [100-1500] K",
temp_k=temp_k,
)

# Thermal conductivity of first wall material (W/m.K)
tkfw = self.fw_thermal_conductivity(temp_k)
Expand Down Expand Up @@ -445,17 +444,19 @@ def heat_transfer(

# Check that Reynolds number is in valid range for the Gnielinski correlation
if (reynolds <= 3000.0) or (reynolds > 5.0e6):
error_handling.fdiags[0] = reynolds
error_handling.report_error(225)
WarningManager.create_warning(
"Reynolds number out of range : [3e3-5000e3]", reynolds=reynolds
)

# Check that Prandtl number is in valid range for the Gnielinski correlation
if (pr < 0.5) or (pr > 2000.0):
error_handling.fdiags[0] = pr
error_handling.report_error(226)
WarningManager.create_warning(
"Prandtl number out of range : [0.5-2000]", pr=pr
)

# Check that the Darcy friction factor is in valid range for the Gnielinski correlation
if f <= 0.0:
error_handling.report_error(227)
WarningManager.create_warning("Negative Darcy friction factor (f)")

return heat_transfer_coefficient

Expand Down
16 changes: 8 additions & 8 deletions process/hcpb.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
primary_pumping_variables,
tfcoil_variables,
)
from process.fortran import (
error_handling as eh,
)
from process.warning_handler import WarningManager


class CCFE_HCPB:
Expand Down Expand Up @@ -574,11 +572,13 @@ def nuclear_heating_blanket(self):
)

if fwbs_variables.p_blkt_nuclear_heat_total_mw < 1:
eh.fdiags[0] = fwbs_variables.p_blkt_nuclear_heat_total_mw
eh.fdiags[1] = ccfe_hcpb_module.exp_blanket
eh.fdiags[2] = physics_variables.p_fusion_total_mw
eh.fdiags[3] = mass
eh.report_error(274)
WarningManager.create_warning(
"Blanket heating is <1 MW or NaN. Is something wrong?",
p_blkt_nuclear_heat_total_mw=fwbs_variables.p_blkt_nuclear_heat_total_mw,
exp_blanket=ccfe_hcpb_module.exp_blanket,
fusion_power=physics_variables.p_fusion_total_mw,
mass=mass,
)

def nuclear_heating_shield(self):
"""Nuclear heating in the shield for CCFE HCPB model
Expand Down
8 changes: 2 additions & 6 deletions process/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
from process.tf_coil import init_tfcoil_variables
from process.utilities.f2py_string_patch import f2py_compatible_to_string
from process.vacuum import init_vacuum_variables
from process.warning_handler import WarningManager
from process.water_use import init_watuse_variables


Expand All @@ -63,9 +64,6 @@ def init_process():
the default values for the global variables, reads in data from
the input file, and checks the run parameters for consistency.
"""
# Initialise error handling
fortran.error_handling.initialise_error_list()

# Initialise the program variables
iteration_variables.initialise_iteration_variables()

Expand Down Expand Up @@ -252,11 +250,11 @@ def init_all_module_vars():
run. This matters ever since Process is used as a shared library, rather
than a 'run-once' executable.
"""
WarningManager.reinitialise()
fortran.numerics.init_numerics()
init_buildings_variables()
init_cost_variables()
init_divertor_variables()
fortran.error_handling.init_error_handling()
init_fwbs_variables()
fortran.global_variables.init_global_variables()
init_ccfe_hcpb_module()
Expand Down Expand Up @@ -293,8 +291,6 @@ def init_all_module_vars():
init_cost_variables_new()
init_python_build_variables()

fortran.init_module.init_fortran_modules()


def check_process(inputs): # noqa: ARG001
"""Routine to reset specific variables if certain options are
Expand Down
5 changes: 1 addition & 4 deletions process/io/process_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,7 @@ def error_status2readme(self, directory="."):
if os.path.isfile("MFILE.DAT"):
m_file = MFile(filename=directory + "/MFILE.DAT")

error_status = (
f"Error status: {m_file.data['error_status'].get_scan(-1)} "
6144 f"Error ID: {m_file.data['error_id'].get_scan(-1)}\n"
)
error_status = f"Error status: {m_file.data['error_status'].get_scan(-1)} "

if self.comment != "":
with open(directory + "/README.txt", "a") as readme:
Expand Down
Loading
Loading
0