1
Fork 0

Post-processing: comparing with and without breakwater

This commit is contained in:
Edgar P. Burkhart 2022-03-09 15:23:06 +01:00
parent 5c05d6ea34
commit f4ccdb009a
Signed by: edpibu
GPG Key ID: 9833D3C5A25BD227
2 changed files with 59 additions and 12 deletions

View File

@ -21,6 +21,7 @@ mpi=4
[post] [post]
inp=inp_post inp=inp_post
case=sws_spec_buoy.npz case=sws_spec_buoy.npz
compare=sws_spec_buoy_nb.npz
out=out_post out=out_post
#nperseg=1024 #nperseg=1024
dt=0.25 dt=0.25

View File

@ -5,7 +5,6 @@ import pathlib
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
import pandas as pd
import scipy.signal as sgl import scipy.signal as sgl
import scipy.fft as fft import scipy.fft as fft
@ -25,7 +24,7 @@ config.read("config.ini")
inp = pathlib.Path(config.get("post", "inp")) inp = pathlib.Path(config.get("post", "inp"))
root = pathlib.Path(config.get("swash", "out")) root = pathlib.Path(config.get("swash", "out"))
log.info(f"Reading bathymetry from '{inp}'") log.info(f"Reading data from '{inp}'")
data = np.load(inp.joinpath(config.get("post", "case"))) data = np.load(inp.joinpath(config.get("post", "case")))
x, t = data["x"], data["t"] x, t = data["x"], data["t"]
@ -42,15 +41,48 @@ log.info(f"Computing reflection coefficient at x={x0}")
eta = data["watl"][t > t0, arg_x0] eta = data["watl"][t > t0, arg_x0]
u = data["vel"][t > t0, 0, arg_x0] u = data["vel"][t > t0, 0, arg_x0]
phi_eta = np.abs(sgl.welch(eta, f, nperseg=nperseg)) phi_eta = sgl.welch(eta, f, nperseg=nperseg)
phi_u = np.abs(sgl.welch(u, f, nperseg=nperseg)) phi_u = sgl.welch(u, f, nperseg=nperseg)
phi_eta_u = np.abs(sgl.csd(eta, u, f, nperseg=nperseg)) phi_eta_u = sgl.csd(eta, u, f, nperseg=nperseg)
H = np.sqrt(np.abs(phi_eta[1]))
U = np.sqrt(np.abs(phi_u[1]))
G = H / U
th_eta_u = np.angle(phi_eta_u[1])
# R1 = np.sqrt(
# (np.abs(phi_eta[1]) + np.abs(phi_u[1]) - 2 * np.abs(phi_eta_u[1]))
# / (np.abs(phi_eta[1]) + np.abs(phi_u[1]) + 2 * np.abs(phi_eta_u[1]))
# )
R = np.sqrt( R = np.sqrt(
(phi_eta[1] + phi_u[1] - 2 * phi_eta_u[1]) (1 + G**2 - 2 * G * np.cos(th_eta_u))
/ (phi_eta[1] + phi_u[1] + 2 * phi_eta_u[1]) / (1 + G**2 + 2 * G * np.cos(th_eta_u))
) )
if config.has_option("post", "compare"):
data_comp = np.load(inp.joinpath(config.get("post", "compare")))
x_, t_ = data_comp["x"], data_comp["t"]
arg_x0_ = np.abs(x_ - x0).argmin()
arg_t0_ = np.abs(t_ - t0).argmin()
eta_ = data_comp["watl"][t_ > t0, arg_x0_]
u_ = data_comp["vel"][t_ > t0, 0, arg_x0_]
phi_eta_ = sgl.welch(eta_, f, nperseg=nperseg)
phi_u_ = sgl.welch(u_, f, nperseg=nperseg)
phi_eta_u_ = sgl.csd(eta_, u_, f, nperseg=nperseg)
H_ = np.sqrt(np.abs(phi_eta_[1]))
U_ = np.sqrt(np.abs(phi_u_[1]))
G_ = H_ / U_
th_eta_u_ = np.angle(phi_eta_u_[1])
R_ = np.sqrt(
(1 + G_**2 - 2 * G_ * np.cos(th_eta_u_))
/ (1 + G_**2 + 2 * G_ * np.cos(th_eta_u_))
)
# Plotting # Plotting
log.info("Plotting results") log.info("Plotting results")
fig, (ax_watl, ax_vel) = plt.subplots(2) fig, (ax_watl, ax_vel) = plt.subplots(2)
@ -73,13 +105,21 @@ fig_r, ax_r = plt.subplots()
ax_fft = ax_r.twinx() ax_fft = ax_r.twinx()
ax_fft.plot( ax_fft.plot(
*sgl.welch(eta, 1/dt, nperseg=nperseg), *sgl.welch(eta, 1 / dt, nperseg=nperseg),
lw=1, lw=1,
c="k", c="k",
alpha=0.2, alpha=0.2,
label="PSD ($\\eta$)", label="PSD ($\\eta$, cas 1)",
) )
ax_r.plot(phi_eta[0], R, marker="+", label="R") ax_fft.plot(
*sgl.welch(eta_, 1 / dt, nperseg=nperseg),
lw=1,
c="k",
alpha=0.2,
label="PSD ($\\eta$, cas 2)",
)
ax_r.plot(phi_eta[0], R, marker="+", label="R (cas 1)")
ax_r.plot(phi_eta[0], R_, marker="+", label="R (cas 2)")
ax_r.set(xlim=(0, 0.3), ylim=(0, 1), xlabel="f (Hz)", ylabel="R") ax_r.set(xlim=(0, 0.3), ylim=(0, 1), xlabel="f (Hz)", ylabel="R")
ax_fft.set(ylim=0, ylabel="PSD (m²/Hz)") ax_fft.set(ylim=0, ylabel="PSD (m²/Hz)")
ax_r.grid() ax_r.grid()
@ -89,11 +129,16 @@ fig_r.tight_layout()
fig_x, ax_x = plt.subplots(figsize=(10, 1)) fig_x, ax_x = plt.subplots(figsize=(10, 1))
ax_x.plot(data["x"], -data["botl"], color="k") ax_x.plot(data["x"], -data["botl"], color="k")
ax_x.fill_between( ax_x.plot(data["x"], -data_comp["botl"], color="k", ls="-.")
ax_x.plot(
data["x"], data["x"],
-data["botl"],
np.maximum(data["watl"][arg_t0, :], -data["botl"]), np.maximum(data["watl"][arg_t0, :], -data["botl"]),
) )
ax_x.plot(
data["x"],
np.maximum(data_comp["watl"][arg_t0, :], -data_comp["botl"]),
ls="-."
)
ax_x.axvline(x0, c="k", alpha=0.2) ax_x.axvline(x0, c="k", alpha=0.2)
ax_x.set(xlabel="x (m)", ylabel="z (m)") ax_x.set(xlabel="x (m)", ylabel="z (m)")
ax_x.autoscale(axis="x", tight=True) ax_x.autoscale(axis="x", tight=True)
@ -107,5 +152,6 @@ out.mkdir(parents=True, exist_ok=True)
fig.savefig(out.joinpath("t.png")) fig.savefig(out.joinpath("t.png"))
fig_r.savefig(out.joinpath("R.png")) fig_r.savefig(out.joinpath("R.png"))
fig_x.savefig(out.joinpath("x.png")) fig_x.savefig(out.joinpath("x.png"))
plt.show(block=True)
log.info("Finished post-processing") log.info("Finished post-processing")