From b6577f467994ed92e884ca0a3bd085973ef2f8c8 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Fri, 4 Mar 2022 15:00:35 +0100 Subject: [PATCH] Added conversion of initial water level from swash to olaFlow --- olaflow/processing/sws_ola.py | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 olaflow/processing/sws_ola.py diff --git a/olaflow/processing/sws_ola.py b/olaflow/processing/sws_ola.py new file mode 100644 index 0000000..f0083e2 --- /dev/null +++ b/olaflow/processing/sws_ola.py @@ -0,0 +1,47 @@ +import argparse +import configparser +import logging +import pathlib +import re + +import matplotlib.pyplot as plt +import numpy as np +from fluidfoam import readof +from scipy import interpolate + +parser = argparse.ArgumentParser( + description="Convert swash output to olaFlow input" +) +parser.add_argument("-v", "--verbose", action="count", default=0) +args = parser.parse_args() + +logging.basicConfig(level=max((10, 20 - 10 * args.verbose))) +log = logging.getLogger("sws_ola") + +log.info("Starting sws -> olaFlow converter") +config = configparser.ConfigParser() +config.read("config.ini") + +sws_out = pathlib.Path(config.get("swash", "npz_out")) +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)) + +watl = interpolate.interp1d(x, sws["watl"][680]) + +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(map(str, alpha_water)), + aw_raw, + count=1, + flags=re.S, + ) + )