From ef2e23ab15d36d871517331cf6ae108da9ae5074 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Mon, 7 Mar 2022 11:10:01 +0100 Subject: [PATCH 1/4] Fixed sws_ola conversion --- olaflow/processing/sws_ola.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/olaflow/processing/sws_ola.py b/olaflow/processing/sws_ola.py index f0083e2..0eb4ddb 100644 --- a/olaflow/processing/sws_ola.py +++ b/olaflow/processing/sws_ola.py @@ -32,6 +32,8 @@ of_x, of_y, of_z = mesh = readof.readmesh(str(olaflow_root)) watl = interpolate.interp1d(x, sws["watl"][680]) +alpha_water = np.where(of_z < watl(of_x), "1", "0") + with open(olaflow_root.joinpath("0", "alpha.water"), "r") as aw_file: aw_raw = aw_file.read() @@ -39,7 +41,7 @@ with open(olaflow_root.joinpath("0", "alpha.water"), "w") as aw_file: aw_file.write( re.sub( r"(?<=\(\n).*?(?=\n\))", - "\n".join(map(str, alpha_water)), + "\n".join(alpha_water), aw_raw, count=1, flags=re.S, From 62af6a03ed6ebbc7645d1da45ded79e04a9fc559 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Mon, 7 Mar 2022 11:19:37 +0100 Subject: [PATCH 2/4] Added OFModel class to write fields --- olaflow/processing/olaflow.py | 21 +++++++++++++++++++++ olaflow/processing/sws_ola.py | 19 +++++-------------- 2 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 olaflow/processing/olaflow.py diff --git a/olaflow/processing/olaflow.py b/olaflow/processing/olaflow.py new file mode 100644 index 0000000..9556a84 --- /dev/null +++ b/olaflow/processing/olaflow.py @@ -0,0 +1,21 @@ +import re + + +class OFModel: + def __init__(self, root): + self._root = root + + def write_field(self, field, values): + with open(self._root.joinpath("0", field), "r") as aw_file: + aw_raw = aw_file.read() + + with open(self._root.joinpath("0", field), "w") as aw_file: + aw_file.write( + re.sub( + r"(?<=\(\n).*?(?=\n\))", + "\n".join(values.astype(str)), + aw_raw, + count=1, + flags=re.S, + ) + ) diff --git a/olaflow/processing/sws_ola.py b/olaflow/processing/sws_ola.py index 0eb4ddb..97940ec 100644 --- a/olaflow/processing/sws_ola.py +++ b/olaflow/processing/sws_ola.py @@ -9,6 +9,8 @@ import numpy as np from fluidfoam import readof from scipy import interpolate +from .olaflow import OFModel + parser = argparse.ArgumentParser( description="Convert swash output to olaFlow input" ) @@ -32,18 +34,7 @@ of_x, of_y, of_z = mesh = readof.readmesh(str(olaflow_root)) watl = interpolate.interp1d(x, sws["watl"][680]) -alpha_water = np.where(of_z < watl(of_x), "1", "0") +alpha_water = np.where(of_z < watl(of_x), 1, 0) -with open(olaflow_root.joinpath("0", "alpha.water"), "r") as aw_file: - aw_raw = aw_file.read() - -with open(olaflow_root.joinpath("0", "alpha.water"), "w") as aw_file: - aw_file.write( - re.sub( - r"(?<=\(\n).*?(?=\n\))", - "\n".join(alpha_water), - aw_raw, - count=1, - flags=re.S, - ) - ) +model = OFModel(olaflow_root) +model.write_field("alpha.water", alpha_water) From 4869c982bb7c07fd7bd54d378e1ea4e4bb5756cc Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Mon, 7 Mar 2022 11:30:53 +0100 Subject: [PATCH 3/4] Moved fluidfoam to olaflow file --- olaflow/processing/olaflow.py | 17 +++++++++++++++++ olaflow/processing/sws_ola.py | 8 +++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/olaflow/processing/olaflow.py b/olaflow/processing/olaflow.py index 9556a84..520289b 100644 --- a/olaflow/processing/olaflow.py +++ b/olaflow/processing/olaflow.py @@ -1,10 +1,15 @@ import re +from fluidfoam import readof + class OFModel: def __init__(self, root): self._root = root + def read_mesh(self): + self._x, self._y, self._z = readof.readmesh(str(self._root)) + def write_field(self, field, values): with open(self._root.joinpath("0", field), "r") as aw_file: aw_raw = aw_file.read() @@ -19,3 +24,15 @@ class OFModel: flags=re.S, ) ) + + @property + def x(self): + return self._x + + @property + def y(self): + return self._y + + @property + def z(self): + return self._z diff --git a/olaflow/processing/sws_ola.py b/olaflow/processing/sws_ola.py index 97940ec..7b416be 100644 --- a/olaflow/processing/sws_ola.py +++ b/olaflow/processing/sws_ola.py @@ -6,7 +6,6 @@ import re import matplotlib.pyplot as plt import numpy as np -from fluidfoam import readof from scipy import interpolate from .olaflow import OFModel @@ -30,11 +29,10 @@ sws = np.load(sws_out.joinpath("sws.npz")) x, t = sws["x"], sws["t"] olaflow_root = pathlib.Path(config.get("olaflow", "root")) -of_x, of_y, of_z = mesh = readof.readmesh(str(olaflow_root)) +model = OFModel(olaflow_root) +model.read_mesh() watl = interpolate.interp1d(x, sws["watl"][680]) +alpha_water = np.where(model.z < watl(model.x), 1, 0) -alpha_water = np.where(of_z < watl(of_x), 1, 0) - -model = OFModel(olaflow_root) model.write_field("alpha.water", alpha_water) From 434db6af7c19f0e1aeef77ed204293adda446c80 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Mon, 7 Mar 2022 11:34:32 +0100 Subject: [PATCH 4/4] Removed unused imports --- olaflow/processing/sws_ola.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/olaflow/processing/sws_ola.py b/olaflow/processing/sws_ola.py index 7b416be..578d92c 100644 --- a/olaflow/processing/sws_ola.py +++ b/olaflow/processing/sws_ola.py @@ -2,9 +2,7 @@ import argparse import configparser import logging import pathlib -import re -import matplotlib.pyplot as plt import numpy as np from scipy import interpolate