From 89a05e191f7b559d35666f4b1e27a5fc2866d7c7 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Wed, 6 Jul 2022 09:32:20 +0200 Subject: [PATCH] Update README, sws_ola --- olaflow/README.md | 22 ++++++++++ olaflow/processing/post.py | 90 -------------------------------------- olaflow/processing/snap.py | 79 --------------------------------- 3 files changed, 22 insertions(+), 169 deletions(-) delete mode 100644 olaflow/processing/post.py delete mode 100644 olaflow/processing/snap.py diff --git a/olaflow/README.md b/olaflow/README.md index a76ba46..9f4ad32 100644 --- a/olaflow/README.md +++ b/olaflow/README.md @@ -67,3 +67,25 @@ d'enregistrer cet objet pour une utilisation efficace avec Python. * `-i INPUT` : dossier de sortie d'Olaflow * `-o OUTPUT` : dossier de sortie à utiliser * `-z` : activer la compression gzip (déconseillé) + +### STL + +`stl.py` définit une fonction permettant de convertir un tableau de bathymétrie en fichier STL. Nécessite Openscad. + +### SWS Olaflow + +`sws_ola.py` permet de convertir les données de sortie d'un modèle Swash en données d'entrée d'un modèle Olaflow. + +```python -m processing.sws_ola -o OUTPUT [-c CONFIG]``` + +* `-o OUTPUT` : dossier de sortie à utiliser +* `-c CONFIG` : choix d'un fichier de configuration + +``` +[swash] +np_out : dossier de sortie swash + +[olaflow] +t0 : instant initial du modèle Olaflow +level : niveau d'eau dans SWASH +``` diff --git a/olaflow/processing/post.py b/olaflow/processing/post.py deleted file mode 100644 index 36e4078..0000000 --- a/olaflow/processing/post.py +++ /dev/null @@ -1,90 +0,0 @@ -import argparse -import configparser -import gzip -from itertools import starmap -import logging -import multiprocessing as mp -import pathlib -import pickle - -from cycler import cycler -import matplotlib.pyplot as plt -import matplotlib.gridspec as gridspec -import numpy as np -from scipy import interpolate - -from .olaflow import OFModel - -parser = argparse.ArgumentParser(description="Post-process olaflow results") -parser.add_argument("-v", "--verbose", action="count", default=0) -parser.add_argument("-c", "--config", default="config.ini") -args = parser.parse_args() - -logging.basicConfig(level=max((10, 20 - 10 * args.verbose))) -log = logging.getLogger("ola_post") - -log.info("Animating olaFlow output") -config = configparser.ConfigParser() -config.read(args.config) -out = pathlib.Path(config.get("post", "out")) -out.mkdir(parents=True, exist_ok=True) - -with ( - path.open("rb") - if (path := out.joinpath("pickle")).exists() - else gzip.open(path.with_suffix(".gz"), "rb") -) as f: - model = pickle.load(f) - -x0_conf = config.getfloat("post", "x") -x0_val = model.x[np.argmin(np.abs(model.x - x0_conf))] -# z0 = config.getfloat("post", "z") -# z0 = np.linspace(-5, 5, 16) -c0_ = ((model.x == x0_val)[None, :] & (model.fields["alpha.water"] > 0.95)).any(axis=0) -c0 = model.coords[c0_][:: (c0_.sum() // 8 + 1)] - -i0 = np.argmin( - np.linalg.norm(model.coords[..., None] - c0.T[None, ...], axis=1), - axis=0, -) - -aw = model.fields["alpha.water"][:, i0] - -U = np.where(aw > 0.95, np.linalg.norm(model.fields["U"][..., i0], axis=1), np.nan) -P = np.where(aw > 0.95, model.fields["p"][..., i0], np.nan) -P_rgh = np.where(aw > 0.95, model.fields["p_rgh"][..., i0], np.nan) - -with plt.rc_context( - { - "axes.prop_cycle": cycler( - color=np.linspace(0, 1, i0.size + 1)[:-1].astype("U") - ), - "axes.grid": True, - "axes.xmargin": 0, - } -): - fig, ax = plt.subplots(3, constrained_layout=True) - ax1, ax2, ax3 = ax - - ha = ax1.plot(model.t, U, lw=1) - ax1.set(xlabel="t (s)", ylabel="U (m/s)") - - ax2.plot(model.t, P * 1e-3, lw=1) - ax2.set(xlabel="t (s)", ylabel="P (kPa)") - - ax3.plot(model.t, P_rgh * 1e-3, lw=1) - ax3.set(xlabel="t (s)", ylabel="P_rgh (kPa)") - - for a in ax: - a.set(ylim=0) - - ax2.legend( - ha, - list( - starmap(lambda x, z: f"x={x:8}m; z={z:8}m", zip(model.x[i0], model.z[i0])) - ), - bbox_to_anchor=(1.05, 0.5), - loc="center left", - ) - - fig.savefig(out.joinpath("fig.pdf")) diff --git a/olaflow/processing/snap.py b/olaflow/processing/snap.py deleted file mode 100644 index 5628eed..0000000 --- a/olaflow/processing/snap.py +++ /dev/null @@ -1,79 +0,0 @@ -import argparse -import gzip -import logging -import multiprocessing as mp -import pathlib -import pickle - -import matplotlib.pyplot as plt -import matplotlib.animation as animation -from matplotlib.gridspec import GridSpec -from matplotlib.ticker import MultipleLocator -import numpy as np -from scipy import interpolate - -from .olaflow import OFModel - -parser = argparse.ArgumentParser(description="Post-process olaflow results") -parser.add_argument("-v", "--verbose", action="count", default=0) -parser.add_argument( - "-o", - "--output", - type=pathlib.Path, - help="Output directory for pickled data", - required=True, -) -parser.add_argument( - "-m", - "--max", - help="Only compute maximum rather than animation", - action="store_true", -) -parser.add_argument( - "-i", - "--initial", - help="Only compute initial domain", - action="store_true", -) -args = parser.parse_args() - -logging.basicConfig(level=max((10, 20 - 10 * args.verbose))) -log = logging.getLogger("ola_post") - -log.info("Animating olaFlow output") -out = args.output -out.mkdir(parents=True, exist_ok=True) - -with ( - path.open("rb") - if (path := out.joinpath("pickle")).exists() - else gzip.open(path.with_suffix(".gz"), "rb") -) as f: - model = pickle.load(f) - -x0, idx0 = np.unique(model.x.astype(np.half), return_inverse=True) -z0, idz0 = np.unique(model.z.astype(np.half), return_inverse=True) - -ix0 = np.argsort(x0) -iz0 = np.argsort(z0)[::-1] - -X, Z = np.meshgrid(x0, z0) - -P = np.full((model.t.size, *X.shape), np.nan) -P[:, iz0[idz0], ix0[idx0]] = model.fields["porosity"] - -AW = np.full((model.t.size, *X.shape), np.nan) -AW[:, iz0[idz0], ix0[idx0]] = model.fields["alpha.water"] - -#U = np.full((model.t.size, *X.shape), np.nan) -#U[:, iz0[idz0], ix0[idx0]] = np.linalg.norm(model.fields["U"], axis=1) - -i0 = np.argmin(np.abs(model.t[:, None] - np.asarray((102, 118, 144.5, 176.5))[None, :]), axis=0) - -fig, ax_ = plt.subplots( - 2, 2, figsize=(15 / 2.54, 4 / 2.54), dpi=200, constrained_layout=True -) -for ax, i in zip(ax_.flatten(), i0): - ax.imshow(AW[i], cmap="Blues", vmin=0, vmax=1) - -fig.savefig(out.joinpath("snap.pdf"))