1
Fork 0

Merge branch 'olaflow'

This commit is contained in:
Edgar P. Burkhart 2022-03-28 17:07:31 +02:00
commit 6f3425ae94
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
32 changed files with 311505 additions and 55 deletions

2
data/.gitignore vendored
View file

@ -1 +1 @@
/out
/out*

26
data/config-of.ini Normal file
View file

@ -0,0 +1,26 @@
[inp]
root=data
base=Database_20220224.xyz
hires=bathyhires.dat
hstru=Hstru.dat
poro=Poro.dat
psize=Psize.dat
hires_step=0.5
[out]
#no_breakwater=True
root=out_of
sub=bathy_sub.npy
out=bathy.npy
step=0.5
left=0
right=-1000
plot=True
[artha]
lat=43.398450
lon=-1.673097
[buoy]
lat=43.408333
lon=-1.681667

View file

@ -1,11 +1,10 @@
[swash]
npz_out=../swash/inp_post
np_out=../swash/inp_post
[bathy]
bathy=../swash/data/bathyhires.dat
hstru=../swash/data/Hstru.dat
bathy=../data/out_of/bathy.dat
hstru=../data/out_of/hstru.dat
scale=[0.5,1,1]
translate=[-149,0,0]
out=out_bathy
[olaflow]

View file

@ -0,0 +1,53 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 9
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class polyBoundaryMesh;
location "constant/polyMesh";
object boundary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
5
(
inlet
{
type patch;
nFaces 77;
startFace 38318;
}
outlet
{
type patch;
nFaces 34;
startFace 38395;
}
atmosphere
{
type patch;
nFaces 300;
startFace 38429;
}
defaultFaces
{
type empty;
inGroups List<word> 1(empty);
nFaces 38698;
startFace 38729;
}
bathy
{
type wall;
inGroups List<word> 1(wall);
nFaces 349;
startFace 77427;
}
)
// ************************************************************************* //

View file

@ -0,0 +1,19 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 9
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class labelList;
location "constant/polyMesh";
object cellLevel;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
19349{0}
// ************************************************************************* //

View file

@ -0,0 +1,20 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 9
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class regIOobject;
location "constant/polyMesh";
object cellZones;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
0
()
// ************************************************************************* //

View file

@ -0,0 +1,20 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 9
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class regIOobject;
location "constant/polyMesh";
object faceZones;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
0
()
// ************************************************************************* //

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,22 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 9
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class uniformDimensionedScalarField;
location "constant/polyMesh";
object level0Edge;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 1 0 0 0 0 0];
value 0.5;
// ************************************************************************* //

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,19 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 9
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class labelList;
location "constant/polyMesh";
object pointLevel;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39460{0}
// ************************************************************************* //

View file

@ -0,0 +1,20 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 9
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class regIOobject;
location "constant/polyMesh";
object pointZones;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
0
()
// ************************************************************************* //

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1 @@
../../out_bathy/

View file

@ -19,14 +19,14 @@ scale 1;
vertices
(
(-150 0 -30)
(0 0 -30)
(150 0 -30)
(150 0 20)
(0 0 20)
(0 0 30)
(-150 0 30)
(-150 1 -30)
(0 1 -30)
(150 1 -30)
(150 1 20)
(0 1 20)
(0 1 30)
(-150 1 30)
);
blocks

View file

@ -25,7 +25,7 @@ regions
(
boxToCell
{
box (-10 -10 -100) (500 10 5);
box (-200 -100 -100) (100 100 4.5);
fieldValues
(
@ -34,8 +34,8 @@ regions
}
surfaceToCell
{
file "./constant/triSurface/rubble.stl";
outsidePoints ((0 0 0)); // definition of outside
file "./constant/triSurface/poro.stl";
outsidePoints ((-100 0 0)); // definition of outside
includeCut true; // cells cut by surface
includeInside true; // cells not on outside of surf
includeOutside false; // cells on outside of surf

View file

@ -29,16 +29,6 @@ addLayers false;
geometry
{
bloc0.stl
{
type triSurfaceMesh;
name bloc0;
}
bloc1.stl
{
type triSurfaceMesh;
name bloc1;
}
bathy.stl
{
@ -125,14 +115,6 @@ castellatedMeshControls
{
level ( 0 0 );
}
bloc0
{
level ( 0 0 );
}
bloc1
{
level ( 0 0 );
}
}
@ -172,7 +154,7 @@ castellatedMeshControls
// section reachable from the locationInMesh is kept.
// NOTE: This point should never be on a face, always inside a cell, even
// after refinement.
locationInMesh (0.25 0.01 0.25);
locationInMesh (-100 0 0);
// Whether any faceZones (as specified in the refinementSurfaces)
// are only on the boundary of corresponding cellZones or also allow

View file

@ -20,8 +20,9 @@ log.info("Starting sws -> olaFlow converter")
config = configparser.ConfigParser()
config.read("config.ini")
bathy = np.loadtxt(config.get("bathy", "bathy"))
poro = bathy + np.loadtxt(config.get("bathy", "hstru"))
bathy = np.loadtxt(config.get("bathy", "bathy"))[::-1]
hstru = np.loadtxt(config.get("bathy", "hstru"))[::-1]
poro = bathy + np.where(hstru == 0, -5, hstru)
out = pathlib.Path(config.get("bathy", "out"))
out.mkdir(exist_ok=True)

View file

@ -25,6 +25,21 @@ class OFModel:
)
)
def write_vector_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(map(lambda x: f"({' '.join(x.astype('str'))})", values)),
aw_raw,
count=1,
flags=re.S,
)
)
@property
def x(self):
return self._x

View file

@ -12,6 +12,7 @@ def stl_from_1d(data, output, scale=[1, 1, 1], translate=[0, 0, 0]):
np.savetxt(tmpdir.joinpath("data.dat"), np.stack((data, data)))
with open(tmpdir.joinpath("scad"), "wt") as scad:
scad.write(
f"mirror([1, 0, 0])"
f"translate({translate})"
f"scale({scale})"
f"""surface("data.dat");"""

View file

@ -5,6 +5,7 @@ import pathlib
import numpy as np
from scipy import interpolate
import matplotlib.pyplot as plt
from .olaflow import OFModel
@ -21,16 +22,39 @@ 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"))
sws_out = pathlib.Path(config.get("swash", "np_out"))
def data(var):
return np.load(sws_out.joinpath(f"{var}.npy"))
x, t = sws["x"], sws["t"]
x = data("xp")
t = data("tsec")
watl = data("watl")
zk = data("zk")
velk = data("velk")
vz = data("vz")
olaflow_root = pathlib.Path(config.get("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)
watl_t = interpolate.interp1d(x, watl[680])
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,:,0,:])(model.x)
vz_t = interpolate.interp1d(x, vz[680])(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)

0
swash/data/Hstru.dat Executable file → Normal file
View file

0
swash/data/Poro.dat Executable file → Normal file
View file

0
swash/data/Psize.dat Executable file → Normal file
View file

0
swash/data/bathyhires.dat Executable file → Normal file
View file

0
swash/data/buoyarthabathy.dat Executable file → Normal file
View file

View file

@ -23,11 +23,9 @@ root = pathlib.Path(config.get("swash", "out"))
out = pathlib.Path(config.get("plot", "out"))
out.mkdir(exist_ok=True)
def data(var):
return np.load(inp.joinpath(f"{var}.npy"))
x = data("xp")
t = data("tsec")

View file

@ -6,6 +6,10 @@ import pathlib
import matplotlib.animation as animation
import matplotlib.pyplot as plt
import numpy as np
<<<<<<< HEAD
=======
import pandas as pd
>>>>>>> olaflow
parser = argparse.ArgumentParser(description="Animate swash output")
parser.add_argument("-v", "--verbose", action="count", default=0)
@ -23,7 +27,6 @@ root = pathlib.Path(config.get("swash", "out"))
out = pathlib.Path(config.get("plot", "out"))
out.mkdir(exist_ok=True)
def data(var):
return np.load(inp.joinpath(f"{var}.npy"))

View file

@ -1,19 +1,19 @@
$************************* GENERAL ***************************************
PROJ 'GW' 'T1'
SET NAUT
SET LEVEL 4.5
SET LEVEL 0.5
SET MAXERR 1
SET DEPMIN 0.001
MODE DYN ONED
$************************ GRIDS ***************************************
CGRID REG -1250 0 0 1250 0 1250 0
INPGRID BOT REG -1250 0 0 1250 0 1 0 $x0 y0 theta nx-1 ny-1 dx dy
CGRID REG -1450 0 0 1450 0 1450 0
INPGRID BOT REG -1450 0 0 1450 0 1 0 $x0 y0 theta nx-1 ny-1 dx dy
VERT 10 $nb couches
READ BOTTOM -1 'bathy.dat' 3 0 FREE
INPGRID PORO REG -1251 0 0 1250 0 1 0
INPGRID PSIZ REG -1251 0 0 1250 0 1 0
INPGRID HSTRUC REG -1251 0 0 1250 0 1 0
INPGRID PORO REG -1450 0 0 1450 0 1 0
INPGRID PSIZ REG -1450 0 0 1450 0 1 0
INPGRID HSTRUC REG -1450 0 0 1450 0 1 0
READINP PORO 1 'poro.dat' 3 0 FREE
READINP PSIZ 1 'psize.dat' 3 0 FREE
@ -47,6 +47,8 @@ BLOCK 'COMPGRID' NOHEAD 'dep.dat' DEP OUTPUT 000000.00 0.25 SEC
BLOCK 'COMPGRID' NOHEAD 'botl.dat' BOTL OUTPUT 000000.00 0.25 SEC
BLOCK 'COMPGRID' NOHEAD 'watl.dat' WATL OUTPUT 000000.00 0.25 SEC
BLOCK 'COMPGRID' NOHEAD 'press.dat' PRESS OUTPUT 000000.00 0.25 SEC
BLOCK 'COMPGRID' NOHEAD 'nhprsk.dat' NHPRSK OUTPUT 000000.00 0.25 SEC
BLOCK 'COMPGRID' NOHEAD 'pressk.dat' PRESSK OUTPUT 000000.00 0.25 SEC
BLOCK 'COMPGRID' NOHEAD 'disch.dat' DISCH OUTPUT 000000.00 0.25 SEC
BLOCK 'COMPGRID' NOHEAD 'ustar.dat' USTAR OUTPUT 000000.00 0.25 SEC
BLOCK 'COMPGRID' NOHEAD 'vel.dat' VEL OUTPUT 000000.00 0.25 SEC

View file

@ -1,19 +1,19 @@
$************************* GENERAL ***************************************
PROJ 'GW' 'T1'
SET NAUT
SET LEVEL 4.5
SET LEVEL 0.5
SET MAXERR 1
SET DEPMIN 0.001
MODE DYN ONED
$************************ GRIDS ***************************************
CGRID REG -1250 0 0 1250 0 1250 0
INPGRID BOT REG -1250 0 0 1250 0 1 0 $x0 y0 theta nx-1 ny-1 dx dy
CGRID REG -1450 0 0 1450 0 1450 0
INPGRID BOT REG -1450 0 0 1450 0 1 0 $x0 y0 theta nx-1 ny-1 dx dy
VERT 10 $nb couches
READ BOTTOM -1 'bathy.dat' 3 0 FREE
INPGRID PORO REG -1251 0 0 1250 0 1 0
INPGRID PSIZ REG -1251 0 0 1250 0 1 0
INPGRID HSTRUC REG -1251 0 0 1250 0 1 0
INPGRID PORO REG -1450 0 0 1450 0 1 0
INPGRID PSIZ REG -1450 0 0 1450 0 1 0
INPGRID HSTRUC REG -1450 0 0 1450 0 1 0
READINP PORO 1 'poro.dat' 3 0 FREE
READINP PSIZ 1 'psize.dat' 3 0 FREE
@ -48,6 +48,8 @@ BLOCK 'COMPGRID' NOHEAD 'dep.dat' DEP OUTPUT 000000.00 0.25 SEC
BLOCK 'COMPGRID' NOHEAD 'botl.dat' BOTL OUTPUT 000000.00 0.25 SEC
BLOCK 'COMPGRID' NOHEAD 'watl.dat' WATL OUTPUT 000000.00 0.25 SEC
BLOCK 'COMPGRID' NOHEAD 'press.dat' PRESS OUTPUT 000000.00 0.25 SEC
BLOCK 'COMPGRID' NOHEAD 'nhprsk.dat' NHPRSK OUTPUT 000000.00 0.25 SEC
BLOCK 'COMPGRID' NOHEAD 'pressk.dat' PRESSK OUTPUT 000000.00 0.25 SEC
BLOCK 'COMPGRID' NOHEAD 'disch.dat' DISCH OUTPUT 000000.00 0.25 SEC
BLOCK 'COMPGRID' NOHEAD 'ustar.dat' USTAR OUTPUT 000000.00 0.25 SEC
BLOCK 'COMPGRID' NOHEAD 'vel.dat' VEL OUTPUT 000000.00 0.25 SEC