From 7cda40ffc952e8e06c1d1a7a4c6dc5b09ac70b4a Mon Sep 17 00:00:00 2001 From: joergbuchwald Date: Fri, 12 Nov 2021 18:49:08 +0100 Subject: [PATCH 1/3] add switch for writing logfiles --- ogs6py/ogs.py | 59 ++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/ogs6py/ogs.py b/ogs6py/ogs.py index bb580b3..9e75f91 100644 --- a/ogs6py/ogs.py +++ b/ogs6py/ogs.py @@ -421,7 +421,7 @@ def replace_medium_property(self, mediumid=None, name=None, value=None, property parameterpointer = self._get_parameter_pointer(mediumpointer, name, xpathparameter) self._set_type_value(parameterpointer, value, propertytype, valuetag=valuetag) - def run_model(self, **args): + def run_model(self, logfile="out.log", path=None, args=None, container_path=None, wrapper=None, write_logs=True): """Command to run OGS. Runs OGS with the project file specified as PROJECT_FILE @@ -435,42 +435,38 @@ def run_model(self, **args): Path of the directory in which the ogs executable can be found. If ``container_path`` is given: Path to the directory in which the Singularity executable can be found - container_path : `str`, optional - Path of the OGS container file. args : `str`, optional additional arguments for the ogs executable + container_path : `str`, optional + Path of the OGS container file. wrapper : `str`, optional add a wrapper command. E.g. mpirun + write_logs: `bolean`, optional + set False to omit logging """ ogs_path = "" - container_path = "" - container = False if self.threads is None: env_export = "" else: env_export = f"export OMP_NUM_THREADS={self.threads} && " - if "container_path" in args: - container = True - args["container_path"] = os.path.expanduser(args["container_path"]) - if os.path.isfile(args["container_path"]) is False: + if not container_path is None: + container_path = os.path.expanduser(container_path) + if os.path.isfile(container_path) is False: raise RuntimeError('The specific container-path is not a file. Please provide a path to the OGS container.') - if not args["container_path"].endswith(".sif"): + if not container_path.endswith(".sif"): raise RuntimeError('The specific file is not a Singularity container. Please provide a *.sif file containing OGS.') - container_path = args["container_path"] - if "path" in args: - args["path"] = os.path.expanduser(args["path"]) - if os.path.isdir(args["path"]) is False: - if container: + if not path is None: + path = os.path.expanduser(path) + if os.path.isdir(path) is False: + if not container_path is None: raise RuntimeError('The specified path is not a directory. Please provide a directory containing the Singularity executable.') else: raise RuntimeError('The specified path is not a directory. Please provide a directory containing the OGS executable.') - ogs_path += args["path"] - if "logfile" in args: - self.logfile = args["logfile"] - else: - self.logfile = "out" - if container: + ogs_path += path + if not logfile is None: + self.logfile = logfile + if not container_path is None: if sys.platform == "win32": raise RuntimeError('Running OGS in a Singularity container is only possible in Linux. See https://sylabs.io/guides/3.0/user-guide/installation.html for Windows solutions.') else: @@ -485,19 +481,22 @@ def run_model(self, **args): if shutil.which(ogs_path) is None: raise RuntimeError('The OGS executable was not found. See https://www.opengeosys.org/docs/userguide/basics/introduction/ for installation instructions.') cmd = env_export - if "wrapper" in args: - cmd += args['wrapper'] + " " + if not wrapper is None: + cmd += wrapper + " " cmd += f"{ogs_path} " - if container: + if not container_path is None: cmd += "exec " + f"{container_path} " + "ogs " - if "args" in args: - cmd += f"{args['args']} " - cmd += f"{self.prjfile} > {self.logfile}" + if not args is None: + cmd += f"{args} " + if write_logs is True: + cmd += f"{self.prjfile} > {self.logfile}" + else: + cmd += f"{self.prjfile}" startt = time.time() if sys.platform == "win32": - returncode = subprocess.run([cmd], shell=True) + returncode = subprocess.run([cmd], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) else: - returncode = subprocess.run([cmd], shell=True, executable="/bin/bash") + returncode = subprocess.run([cmd], shell=True, executable="/bin/bash", stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) stopt = time.time() self.exec_time = stopt - startt if returncode.returncode == 0: @@ -505,6 +504,8 @@ def run_model(self, **args): print(f"Execution took {self.exec_time} s") else: print(f"Error code: {returncode.returncode}") + if write_logs is False: + raise RuntimeError('OGS execution was not successfull. Please set write_logs to True to obtain more information.') num_lines = sum(1 for line in open(self.logfile)) with open(self.logfile) as file: for i, line in enumerate(file): From 69b1105b9e1b0d0e05131ff29901621c71134742 Mon Sep 17 00:00:00 2001 From: joergbuchwald Date: Fri, 12 Nov 2021 19:56:25 +0100 Subject: [PATCH 2/3] update example_THM.py --- examples/example_THM.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/example_THM.py b/examples/example_THM.py index e7a7115..6430ec3 100644 --- a/examples/example_THM.py +++ b/examples/example_THM.py @@ -10,7 +10,6 @@ type="THERMO_HYDRO_MECHANICS", integration_order="4", dimension="2", - reference_temperature="T0", specific_body_force="0 0") model.processes.set_constitutive_relation(type="LinearElasticIsotropic", youngs_modulus="E", @@ -90,6 +89,9 @@ name="thermal_expansivity", type="Constant", value="1.5e-5") +model.media.add_property(medium_id="0", + name="thermal_conductivity", + type="EffectiveThermalConductivityPorosityMixing") model.timeloop.add_process(process="THERMO_HYDRO_MECHANICS", nonlinear_solver_name="basic_newton", convergence_type="PerComponentDeltaX", @@ -187,7 +189,7 @@ error_tolerance="1e-16") model.linsolvers.add_lin_solver(name="general_linear_solver", kind="eigen", - solver_type="PardisoLU", + solver_type="SparseLU", precon_type="DIAGONAL", max_iteration_step="10000", error_tolerance="1e-8", From a7ea1fd2c9c6aecdba490062adfca39d7c377556 Mon Sep 17 00:00:00 2001 From: joergbuchwald Date: Fri, 12 Nov 2021 20:02:00 +0100 Subject: [PATCH 3/3] remove unnecessary else --- ogs6py/ogs.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ogs6py/ogs.py b/ogs6py/ogs.py index 9e75f91..e357d85 100644 --- a/ogs6py/ogs.py +++ b/ogs6py/ogs.py @@ -461,16 +461,14 @@ def run_model(self, logfile="out.log", path=None, args=None, container_path=None if os.path.isdir(path) is False: if not container_path is None: raise RuntimeError('The specified path is not a directory. Please provide a directory containing the Singularity executable.') - else: - raise RuntimeError('The specified path is not a directory. Please provide a directory containing the OGS executable.') + raise RuntimeError('The specified path is not a directory. Please provide a directory containing the OGS executable.') ogs_path += path if not logfile is None: self.logfile = logfile if not container_path is None: if sys.platform == "win32": raise RuntimeError('Running OGS in a Singularity container is only possible in Linux. See https://sylabs.io/guides/3.0/user-guide/installation.html for Windows solutions.') - else: - ogs_path = os.path.join(ogs_path, "singularity") + ogs_path = os.path.join(ogs_path, "singularity") if shutil.which(ogs_path) is None: raise RuntimeError('The Singularity executable was not found. See https://www.opengeosys.org/docs/userguide/basics/container/ for installation instructions.') else: