Skip to content
Draft
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
103 changes: 0 additions & 103 deletions process/core/io/in_dat/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1646,106 +1646,3 @@ def number_of_itvars(self):
The number of itvars
"""
return len(self.data["ixc"].value)


class StructuredInputData:
"""Combines structured input file data and methods for accessing it.

This class uses the InDat class to read in an IN.DAT input file and create
a structured dict from it, combined with methods for accessing the data in
that dict. This is useful for exporting the IN.DAT data to other modules,
for example the input_validator module.

The data dict stored within this class differs from the INDat.data dict in
that it has a hierarchical structure that more closely resembles the IN.DAT
input file, and hence it is more human-readable and ready to output to file.

An example of the structure:
self.data["parameters"]["physics_variables"]["i_plasma_geometry"]["value"] = 0
"""

def __init__(self, filename: str = "IN.DAT"):
"""Use InDat to create the data dict.

Use InDat to read in an input file and store the data, then construct a
structured input data dict from it.

Parameters
----------
filename :
Input data filename, defaults to "IN.DAT"
"""
self.data = {}
# Structured input data dict

in_dat = InDat(filename)

self.data["constraint_equations"] = get_constraint_equations(in_dat.data)
self.data["iteration_variables"] = get_iteration_variables(in_dat.data)
self.data["parameters"] = get_parameters(in_dat.data, use_string_values=False)

self.unrecognised_vars = in_dat.unrecognised_vars
self.duplicates = in_dat.duplicates
# Duplicate initialisations in the input file

def get_param(self, var_name):
"""Get a parameter's dict from the data.

Parameters
----------
var_name:
The name of the parameter to be returned

Returns
-------
dict
Dictionary of parameter's information, or None if not found
"""
modules = self.data["parameters"]

for module_dict in modules.values():
var_dict = module_dict.get(var_name)
if var_dict is not None:
break

return var_dict

def is_param_defined(self, var_name):
"""Check if a parameter is defined or not in the input data.

Parameters
----------
var_name:
Name of the parameter to be checked

Returns
-------
bool
True if defined, False if not
"""
defined = False

if self.get_param(var_name):
defined = True

return defined

def get_param_value(self, var_name):
"""Gets the value of a parameter from the input data.

Parameters
----------
var_name:
The name of the parameter

Returns
-------
int, float
Value of that parameter; can be any type. None if not found.
"""
value = None
var_dict = self.get_param(var_name)
if var_dict:
value = var_dict.get("value")

return value
Loading