Commit 7fa2c5a1 authored by Simeon Doetsch's avatar Simeon Doetsch

Add definitions.h reading (not finished)

parent 4a7da193
......@@ -85,3 +85,52 @@ def lpad(text, colwidth, spacer=2):
pad = col - len(txt) + spacer
out += " " * pad + txt
return out
class Definitions_h(OrderedDict):
base_opt = ['physics', 'dimensions', 'components', 'geometry', 'body_force',
'forced_turb', 'cooling', 'reconstruction', 'time_stepping',
'dimensional_splitting', 'ntracer', 'user_def_parameters']
physics_dep = {'hd': ['eos', 'entropy_switch', 'thermal_conduction', 'viscosity', 'rotating_frame'],
'rhd': ['eos', 'entropy_switch'],
'mhd': ['eos', 'entropy_switch', 'divb_control', 'background_field',
'ambipolar_diffusion', 'resistivity', 'hall_mhd',
'thermal_conduction', 'viscosity', 'rotating_frame'],
'rmhd': ['eos', 'entropy_switch', 'divb_control', 'resistivity'],
'cr_transport': ['eos', 'anisotropy'],
'advection': []}
def __init__(self, path: str):
super().__init__()
self.path = path
self.base = OrderedDict()
self.phys_dep = OrderedDict()
self.parse()
# self.general = OrderedDict()
# self.physics_dep = OrderedDict()
# self.userdef = OrderedDict()
## TODO
def _parse_def(self, txt):
if not line:
continue
segments = line.split()
if segments[0] == "#define":
return segments[1].lower(), segments[2].lower()
def parse(self, txt: str=None) -> None:
if txt is None:
with open(self.path, 'r') as f:
lines = [l.strip() for l in f.readlines()]
else:
lines = [l.strip() for l in txt.split("\n")]
for line in lines:
key, value = _parse_def(line)
if key in self.base_opt:
self.base[key], value
elif key in self.physics_dep[self.base['physics']]:
self.phys_dep[key] = value
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment