1
Fork 0

New olaflow run processus, includeing paddle boundary condition

This commit is contained in:
Edgar P. Burkhart 2022-04-11 16:06:36 +02:00
parent 1506fd06a1
commit 02c8586672
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
12 changed files with 2671 additions and 20 deletions

View file

@ -1,11 +1,17 @@
[swash]
np_out=../swash/inp_post
np_out=../swash/inp_post/real_spec_interp
[bathy]
bathy=../data/out_of/bathy.dat
hstru=../data/out_of/hstru.dat
scale=[0.5,1,1]
out=out_bathy
level=4.5
[olaflow]
root=inp_of
path=/opt/OpenFOAM/OpenFOAM-9/bin:/opt/OpenFOAM/OpenFOAM-9/platforms/linux64GccDPInt32Opt/bin
root=of
out=out_of
t0 = 13900
tf = 14100
x0 = -150

2449
olaflow/of/constant/waveDict Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,46 @@
/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 1.3 |
| \\ / A nd | Web: http://www.openfoam.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "constant";
object waveDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
waveType wavemaker;
waveTheory tveta;
genAbs 1;
absDir 0.0;
nPaddles 1;
timeSeries
{n}
(
{t}
);
paddleVelocity
{n}
(
{v}
);
paddleEta
{n}
(
{eta}
);
// ************************************************************************* //

View file

@ -1,5 +1,4 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
/*--------------------------------*- C++ -*----------------------------------*\ | ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 1.7.1 |
| \\ / A nd | Web: www.OpenFOAM.com |
@ -48,14 +47,14 @@ boundary
(0 4 7 3)
);
}
outlet
/*outlet
{
type patch;
faces
(
(1 5 6 2)
);
}
}*/
wall1
{
type wall;
@ -70,6 +69,7 @@ boundary
faces
(
(3 2 6 7)
(1 5 6 2)
);
}
);

View file

@ -24,7 +24,7 @@ startTime 0;
stopAt endTime;
endTime 60;
endTime 200;
deltaT 0.1;

View file

@ -18,6 +18,7 @@ FoamFile
defaultFieldValues
(
volScalarFieldValue alpha.water 0
volVectorFieldValue U (0 0 0)
volScalarFieldValue porosityIndex 0
);
@ -32,6 +33,15 @@ regions
volScalarFieldValue alpha.water 1
);
}
boxToCell
{
box (-100 0 0) (-100 1 1);
fieldValues
(
volVectorFieldValue U (1 0 0)
);
}
surfaceToCell
{
file "./constant/triSurface/poro.stl";

View file

@ -0,0 +1,47 @@
import argparse
import configparser
import logging
import os
import pathlib
import shutil
from subprocess import run, STDOUT
parser = argparse.ArgumentParser(description="Run olaFlow model")
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("sws_ola")
log.info("Starting olaFlow model")
config = configparser.ConfigParser()
config.read(args.config)
root = pathlib.Path(config.get("olaflow", "root"))
out = pathlib.Path(config.get("olaflow", "out"))
logs = out.joinpath("log")
shutil.copytree(root, out)
logs.mkdir()
path = config.get("olaflow", "path")
env = {"PATH": f"{path}:{os.environ['PATH']}"}
def ola_run(cmd):
with logs.joinpath(f"{cmd[0]}.log").open("wt") as logfile:
run(
cmd,
cwd=out,
env=env,
stdout=logfile,
stderr=STDOUT,
).check_returncode()
ola_run(("blockMesh",))
ola_run(("snappyHexMesh", "-overwrite"))
shutil.copytree(root.joinpath("0.org"), root.joinpath("0"))
ola_run(("setFields",))
ola_run(("decomposePar",))
ola_run(("mpirun", "-np", "4", "olaFlow", "-parallel"))
ola_run(("reconstructPar",))

View file

@ -12,6 +12,7 @@ from .olaflow import OFModel
parser = argparse.ArgumentParser(description="Convert swash output to olaFlow input")
parser.add_argument("-v", "--verbose", action="count", default=0)
parser.add_argument("-c", "--config", default="config.ini")
parser.add_argument("-o", "--output", type=pathlib.Path)
args = parser.parse_args()
logging.basicConfig(level=max((10, 20 - 10 * args.verbose)))
@ -28,35 +29,36 @@ def data(var):
return np.load(sws_out.joinpath(f"{var}.npy"))
t0 = config.getfloat("olaflow", "t0")
x = data("x")
t = data("t")
arg_t0 = np.argmin(np.abs(t - t0*1e3))
watl = data("watl")
zk = data("zk")
velk, _ = data("velk")
vz = data("vz")
olaflow_root = pathlib.Path(config.get("olaflow", "root"))
olaflow_root = args.output
model = OFModel(olaflow_root)
model.read_mesh()
watl_t = interpolate.interp1d(x, watl[680])
watl_t = interpolate.interp1d(x, watl[arg_t0] + config.getfloat("bathy", "level", fallback=0.))
alpha_water = np.where(model.z < watl_t(model.x), 1, 0)
zk_t = interpolate.interp1d(x, zk[680])
velk_t = interpolate.interp1d(x, velk[680, :, :])(model.x)
vz_t = interpolate.interp1d(x, vz[680])(model.x)
zk_t = interpolate.interp1d(x, zk[arg_t0])
velk_t = interpolate.interp1d(x, velk[arg_t0, :, :])(model.x)
vz_t = interpolate.interp1d(x, vz[arg_t0])(model.x)
zk_tl = zk_t(model.x)
print(velk.shape)
ux = np.zeros(model.x.shape)
uy = np.zeros(model.x.shape)
uz = np.zeros(model.x.shape)
print(zk_tl.shape, velk.shape, vz.shape)
for zk_l, velk_l, vz_l in zip(zk_tl, velk_t, vz_t):
ux = np.where(model.z < zk_l, velk_l, ux)
uz = np.where(model.z < zk_l, vz_l, uz)
print(np.stack((ux, uy, uz)).T)
model.write_field("alpha.water", alpha_water)
model.write_vector_field("U", np.stack((ux, uy, uz)).T)
plt.savefig("test.pdf")

View file

@ -19,6 +19,7 @@ logging.basicConfig(level=max((10, 20 - 10 * args.verbose)))
log = logging.getLogger("sws_ola")
log.info("Starting sws -> olaFlow converter")
log.warning("This does not provide the correct boundary condition")
config = configparser.ConfigParser()
config.read(args.config)
@ -30,22 +31,22 @@ def data(var):
x = data("x")
t = data("t")
t = data("t")[-100:]
watl = data("watl")
arg_x0 = np.argmin(np.abs(x + 1250))
wl = watl[:, arg_x0]
wl = watl[-100:, arg_x0]
f = fft.rfftfreq(t.size, np.diff(t).mean())[1:]
w_fft = fft.rfft(wl)[1:]
w_fft = fft.rfft(wl, norm="forward")[1:]
amp = np.abs(w_fft)
phi = np.angle(w_fft)
olaflow_root = pathlib.Path(config.get("olaflow", "root"))
org = olaflow_root.joinpath("constant", "waveDict.org").read_text()
org = org.replace("{n}", str(t.size))
org = olaflow_root.joinpath("constant", "waveDict_irregular.org").read_text()
org = org.replace("{n}", str(f.size))
org = org.replace("{wh}", "\n".join(amp.astype(np.str_)))
org = org.replace("{wph}", "\n".join(phi.astype(np.str_)))
org = org.replace("{wper}", "\n".join((1 / f).astype(np.str_)))

View file

@ -0,0 +1,58 @@
import argparse
import configparser
import logging
import pathlib
import matplotlib.pyplot as plt
import numpy as np
from scipy import interpolate
from scipy import fft
from .olaflow import OFModel
parser = argparse.ArgumentParser(description="Convert swash output to olaFlow input")
parser.add_argument("-v", "--verbose", action="count", default=0)
parser.add_argument("-c", "--config", default="config.ini")
parser.add_argument("-o", "--output", type=pathlib.Path)
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(args.config)
level = config.getfloat("bathy", "level", fallback=0.)
sws_out = pathlib.Path(config.get("swash", "np_out"))
def data(var):
return np.load(sws_out.joinpath(f"{var}.npy"))
x = data("x")
t_ = data("t")
vel = data("vel")
watl = data("watl")
x0 = config.getfloat("olaflow", "x0")
arg_x0 = np.argmin(np.abs(x - x0))
t0 = config.getfloat("olaflow", "t0")
tf = config.getfloat("olaflow", "tf")
arg_t0 = -np.argmax(t_[::-1] < (t0 * 1e3))
arg_tf = np.argmax(t_ > (tf * 1e3)) + 1
t = t_[arg_t0:arg_tf] * 1e-3
t = t - t.min()
wl = watl[arg_t0:arg_tf, arg_x0]
v = vel[0, arg_t0:arg_tf, arg_x0]
olaflow_root = args.output
org = olaflow_root.joinpath("constant", "waveDict_paddle.org").read_text()
org = org.replace("{n}", str(t.size))
org = org.replace("{t}", "\n".join(t.astype(np.str_)))
org = org.replace("{v}", "\n".join(v.astype(np.str_)))
org = org.replace("{eta}", "\n".join(wl.astype(np.str_)))
olaflow_root.joinpath("constant", "waveDict").write_text(org)

32
olaflow/run_ola.sh Executable file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env sh
echo START
export inp="of"
read -p "Output: " out
cp -r --reflink $inp $out
cd $out
source /opt/OpenFOAM/OpenFOAM-9/etc/bashrc
mkdir log
echo Generating mesh
blockMesh > log/blockMesh.log
echo Refining mesh
snappyHexMesh -overwrite > log/snappyHexMesh.log
cp -r 0.org 0
echo Setting initial fields
setFields > log/setFields.log
pushd ..
echo Converting swash output to initial condition
python -m processing.sws_ola -o $out
echo Converting swash output to boundary condition
python -m processing.sws_wavedict_paddle -o $out
popd
echo Generating parallel cases
decomposePar > log/decomposePar.log
echo Running model
mpirun -np 4 olaFlow -parallel > log/olaFlow.log
echo Merging parallel cases
reconstructPar > log/reconstructPar.log
echo END