Skip to content

mfile_utils

get_mfile_initial_ixc_values(file_path)

Initialise the input file and obtain the initial values of the iteration variables

Parameters:

Name Type Description Default
file_path Path

The path to the MFile to get the initial iteration variable values from.

required
Notes

This method initialises a SingleRun. At present, this involves mutating the global data structure so it is not safe to run this method during a PROCESS run.

Source code in process/core/io/mfile_utils.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def get_mfile_initial_ixc_values(file_path: Path):
    """Initialise the input file and obtain the initial values of the iteration variables

    Parameters
    ----------
    file_path :
        The path to the MFile to get the initial iteration variable values from.

    Notes
    -----
    This method initialises a SingleRun. At present, this involves mutating the global
    data structure so it is not safe to run this method during a PROCESS run.
    """
    SingleRun(file_path.as_posix())
    iteration_variables.load_iteration_variables()

    iteration_variable_names = []
    iteration_variable_values = []

    for i in range(data_structure.numerics.nvar):
        ivar = data_structure.numerics.ixc[i].item()

        itv = iteration_variables.ITERATION_VARIABLES[ivar]

        iteration_variable_names.append(itv.name)
        if array := re.match(r"(\w+)\(([0-9]+)\)", itv.name):
            var_name = array.group(1)
            index = array.group(2)
            iteration_variable_values.append(
                getattr(itv.module, var_name)[int(index) - 1]
            )
        else:
            iteration_variable_values.append(getattr(itv.module, itv.name))

    return iteration_variable_names, iteration_variable_values