Switched to new storage convention for swash output in sws_ola
This commit is contained in:
parent
b557712372
commit
71049d49ea
63 changed files with 174 additions and 5717 deletions
|
|
@ -1,39 +1,3 @@
|
|||
import argparse
|
||||
import configparser
|
||||
import logging
|
||||
import pathlib
|
||||
|
||||
import numpy as np
|
||||
|
||||
from .stl import stl_from_1d
|
||||
|
||||
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")
|
||||
|
||||
bathy = np.loadtxt(config.get("bathy", "bathy"))
|
||||
poro = bathy + np.loadtxt(config.get("bathy", "hstru"))
|
||||
|
||||
out = pathlib.Path(config.get("bathy", "out"))
|
||||
out.mkdir(exist_ok=True)
|
||||
stl_from_1d(
|
||||
bathy,
|
||||
out.joinpath("bathy.stl"),
|
||||
config.get("bathy", "scale", fallback=[1, 1, 1]),
|
||||
config.get("bathy", "translate", fallback=[0, 0, 0]),
|
||||
)
|
||||
stl_from_1d(
|
||||
poro,
|
||||
out.joinpath("poro.stl"),
|
||||
config.get("bathy", "scale", fallback=[1, 1, 1]),
|
||||
config.get("bathy", "translate", fallback=[0, 0, 0]),
|
||||
)
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:3f12d83a60bae2c19ae50e105a1b2176d5d35cb17d9e9d73f10aefdf225a4003
|
||||
size 1024
|
||||
|
|
|
|||
|
|
@ -1,38 +1,3 @@
|
|||
import re
|
||||
|
||||
from fluidfoam import readof
|
||||
|
||||
|
||||
class OFModel:
|
||||
def __init__(self, root):
|
||||
self._root = root
|
||||
|
||||
def read_mesh(self):
|
||||
self._x, self._y, self._z = readof.readmesh(str(self._root))
|
||||
|
||||
def write_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(values.astype(str)),
|
||||
aw_raw,
|
||||
count=1,
|
||||
flags=re.S,
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def x(self):
|
||||
return self._x
|
||||
|
||||
@property
|
||||
def y(self):
|
||||
return self._y
|
||||
|
||||
@property
|
||||
def z(self):
|
||||
return self._z
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:2ec88dc3c20627b5f6d383e748ac7876415cacd4aff2cce3cb39bfdeb713b858
|
||||
size 857
|
||||
|
|
|
|||
|
|
@ -1,22 +1,3 @@
|
|||
import pathlib
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
||||
def stl_from_1d(data, output, scale=[1, 1, 1], translate=[0, 0, 0]):
|
||||
with tempfile.TemporaryDirectory() as tmppath:
|
||||
tmpdir = pathlib.Path(tmppath)
|
||||
np.savetxt(tmpdir.joinpath("data.dat"), np.stack((data, data)))
|
||||
with open(tmpdir.joinpath("scad"), "wt") as scad:
|
||||
scad.write(
|
||||
f"translate({translate})"
|
||||
f"scale({scale})"
|
||||
f"""surface("data.dat");"""
|
||||
)
|
||||
|
||||
subprocess.run(("openscad", "scad", "-o", "data.stl"), cwd=tmpdir)
|
||||
|
||||
shutil.copy2(tmpdir.joinpath("data.stl"), output)
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:673dcc99b9926720c32ee396b49a6599a28b9066812c7b651f2289d1527fe089
|
||||
size 667
|
||||
|
|
|
|||
|
|
@ -1,36 +1,3 @@
|
|||
import argparse
|
||||
import configparser
|
||||
import logging
|
||||
import pathlib
|
||||
|
||||
import numpy as np
|
||||
from scipy import interpolate
|
||||
|
||||
from .olaflow import OFModel
|
||||
|
||||
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"))
|
||||
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)
|
||||
|
||||
model.write_field("alpha.water", alpha_water)
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:f12e993be338666db237374bcef3d50b16fe8c8f24f96425bdffb8d0adb47917
|
||||
size 977
|
||||
|
|
|
|||
Reference in a new issue