diff --git a/process/io/data_structure_dicts.py b/process/io/data_structure_dicts.py
index 0ec1b82248..72fd4f1765 100644
--- a/process/io/data_structure_dicts.py
+++ b/process/io/data_structure_dicts.py
@@ -248,22 +248,6 @@ def dict_var_type():
return di
-def dict_icc_full():
- """Function to return a dictionary matching str(icc_no) to a dictionary
- containing the name of that constraint equation. Looks in
- numerics.f90 at !+ad_varc lines in lablcc to get icc_no and
- variable names.
-
- Example of a lablxc line we are looking for:
- !+ad_varc
( 5) * beta
-
- Example dictionary entry:
- DICT_IXC_FULL['5'] = {'name' : 'beta'}
- """
-
- return {str(k): {"name": v.name} for k, v in ITERATION_VARIABLES.items()}
-
-
def dict_input_bounds():
"""Returns a dictionary matching variable names to dictionary containing
upper and lower bounds that PROCESS checks variable lies between when
@@ -363,7 +347,6 @@ def get_dicts():
SourceDictionary("DICT_INPUT_BOUNDS", dict_input_bounds),
SourceDictionary("DICT_NSWEEP2VARNAME", dict_nsweep2varname),
SourceDictionary("DICT_VAR_TYPE", dict_var_type),
- SourceDictionary("DICT_ICC_FULL", dict_icc_full),
SourceDictionary("DICT_IXC2NSWEEP", dict_ixc2nsweep),
SourceDictionary("DICT_NSWEEP2IXC", dict_nsweep2ixc),
SourceDictionary("DICT_IXC_FULL", dict_ixc_full),
diff --git a/process/io/in_dat.py b/process/io/in_dat.py
index f56552ae73..e1c1daa8cf 100644
--- a/process/io/in_dat.py
+++ b/process/io/in_dat.py
@@ -16,6 +16,8 @@
from re import sub
from sys import stderr
+from process.constraints import ConstraintManager
+from process.exceptions import ProcessValidationError
from process.io.data_structure_dicts import get_dicts
# ioptimz values
@@ -188,20 +190,23 @@ def get_constraint_equations(data):
:return: dict of the constraint numbers and their comments
:rtype: dict
"""
- # Load dicts from dicts JSON file
- dicts = get_dicts()
-
constraints = {}
# List of constraint equation numbers in IN.DAT
- constraint_numbers = data["icc"].value
+ constraint_numbers = [int(i) for i in data["icc"].value]
# Find associated comments and create constraint dict
for constraint_number in constraint_numbers:
- if str(constraint_number) not in dicts["DICT_ICC_FULL"]:
- continue
- comment = dicts["DICT_ICC_FULL"][str(constraint_number)]["name"]
- constraints[constraint_number] = comment
+ constraint = ConstraintManager.get_constraint(constraint_number)
+
+ if constraint is None:
+ raise ProcessValidationError(
+ f"Constraint equation {constraint_number} requested but has not been registered"
+ )
+
+ # TODO: we should store a short description of each constraint that we can use here.
+ # Currently, no such information exists.
+ constraints[constraint_number] = ""
return constraints
@@ -867,6 +872,21 @@ def __init__(self, name, value, v_type, parameter_group, comment):
self.parameter_group = parameter_group
self.comment = comment
+ def __eq__(self, value):
+ # intentionally missing .comment, this is not necessary for the variables to be equal
+ return (
+ self.name == value.name
+ and self.value == value.value
+ and self.v_type == value.v_type
+ and self.parameter_group == value.parameter_group
+ )
+
+ def __repr__(self):
+ return (
+ f"{type(self).__name__}(name={self.name!r}, value={self.value!r}, v_type={self.v_type!r}, "
+ f"parameter_group={self.parameter_group!r}, comment={self.comment!r})"
+ )
+
@property
def get_value(self):
"""Return value in correct format"""
diff --git a/tests/integration/test_indat.py b/tests/integration/test_indat.py
new file mode 100644
index 0000000000..7f5303d9eb
--- /dev/null
+++ b/tests/integration/test_indat.py
@@ -0,0 +1,27 @@
+"""Tests for InDat and INVariable classes"""
+
+import pytest
+
+from process.io.in_dat import InDat, INVariable
+
+
+@pytest.mark.parametrize("value", ["1", "1.0", "1,2,3", "1.0, 2.0", "string"])
+def test_invariable_equality(value):
+ """A test to check equality between INVariable's"""
+ name = "test"
+ v_type = "Parameter"
+ parameter_group = "test_group"
+
+ v1 = INVariable(name, value, v_type, parameter_group, "")
+ v2 = INVariable(name, value, v_type, parameter_group, "different comment")
+
+ assert v1 == v2
+
+
+def test_rewritten_indat_identical(temp_data_cwd):
+ indat = InDat(filename=str(temp_data_cwd / "large_tokamak_IN.DAT"))
+ indat.write_in_dat("new.IN.DAT")
+
+ new_indat = InDat(filename=str(temp_data_cwd / "new.IN.DAT"))
+
+ assert indat.data == new_indat.data