Skip to content

Commit

Permalink
Merge pull request #91 from joergbuchwald/ogs6py_ng
Browse files Browse the repository at this point in the history
preserve tag order
  • Loading branch information
joergbuchwald authored Jul 4, 2024
2 parents 9198e39 + 2f33708 commit 59dcc2b
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ogs6py/classes/geo.py
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ class Geo(build_tree.BuildTree):
def __init__(self, tree):
self.tree = tree
self.root = self._get_root()

self.populate_tree(self.root, "geometry", overwrite=True)

def add_geometry(self, filename):
"""
8 changes: 4 additions & 4 deletions ogs6py/classes/timeloop.py
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ def __init__(self, tree):
self.tree = tree
self.root = self._get_root()
self.time_loop = self.populate_tree(self.root, 'time_loop', overwrite=True)
self.gpc = self.populate_tree(self.time_loop, "global_process_coupling", overwrite=True)
self.processes = self.populate_tree(self.time_loop, 'processes', overwrite=True)
self.output = self.populate_tree(self.time_loop, 'output', overwrite=True)

@@ -341,10 +342,9 @@ def add_global_process_coupling(self, **args):
local_coupling_processes_max_iter : `str`
"""
self._convertargs(args)
gpc = self.populate_tree(self.time_loop, "global_process_coupling", overwrite=True)
if "max_iter" in args:
self.populate_tree(gpc, "max_iter", text=args['max_iter'], overwrite=True)
convergence_criteria = self.populate_tree(gpc, "convergence_criteria", overwrite=True)
self.populate_tree(self.gpc, "max_iter", text=args['max_iter'], overwrite=True)
convergence_criteria = self.populate_tree(self.gpc, "convergence_criteria", overwrite=True)
if "convergence_type" not in args:
raise KeyError("No convergence criterion given. \
Specify convergence_type.")
@@ -372,7 +372,7 @@ def add_global_process_coupling(self, **args):
if "local_coupling_processes" in args:
if "local_coupling_processes_max_iter" not in args:
raise KeyError("local_coupling_processes_max_iter parameter is missing")
lcp = self.populate_tree(gpc, "local_coupling_processes")
lcp = self.populate_tree(self.gpc, "local_coupling_processes")
self.populate_tree(lcp, "max_iter", text=args['local_coupling_processes_max_iter'])
for name in args["local_coupling_processes"]:
self.populate_tree(lcp, "process_name", text=name)
14 changes: 14 additions & 0 deletions ogs6py/ogs.py
Original file line number Diff line number Diff line change
@@ -144,6 +144,19 @@ def _get_root(self, remove_blank_text=False, remove_comments=False):
self.include_elements.append(child)
return root

def _remove_empty_elements(self):
root = self._get_root()
empty_text_list = ["./geometry"]
empty_el_list = ["./time_loop/global_process_coupling"]
for element in empty_text_list:
entry = root.find(element)
if entry.text == "":
self.remove_element(element)
for element in empty_el_list:
entry = root.find(element)
if len(entry.getchildren()) == 0:
self.remove_element(element)

@classmethod
def _get_parameter_pointer(cls, root, name, xpath):
params = root.findall(xpath)
@@ -750,6 +763,7 @@ def write_input(self, keep_includes=False):
keep_includes : `boolean`, optional
"""
if not self.tree is None:
self._remove_empty_elements()
if keep_includes is True:
self.__replace_blocks_by_includes()
root = self.tree.getroot()

0 comments on commit 59dcc2b

Please sign in to comment.