Merge branch 'olaflow'
This commit is contained in:
commit
5c05d6ea34
2 changed files with 44 additions and 17 deletions
38
olaflow/processing/olaflow.py
Normal file
38
olaflow/processing/olaflow.py
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
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
|
|
@ -2,13 +2,12 @@ import argparse
|
||||||
import configparser
|
import configparser
|
||||||
import logging
|
import logging
|
||||||
import pathlib
|
import pathlib
|
||||||
import re
|
|
||||||
|
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from fluidfoam import readof
|
|
||||||
from scipy import interpolate
|
from scipy import interpolate
|
||||||
|
|
||||||
|
from .olaflow import OFModel
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description="Convert swash output to olaFlow input"
|
description="Convert swash output to olaFlow input"
|
||||||
)
|
)
|
||||||
|
@ -28,20 +27,10 @@ sws = np.load(sws_out.joinpath("sws.npz"))
|
||||||
x, t = sws["x"], sws["t"]
|
x, t = sws["x"], sws["t"]
|
||||||
|
|
||||||
olaflow_root = pathlib.Path(config.get("olaflow", "root"))
|
olaflow_root = pathlib.Path(config.get("olaflow", "root"))
|
||||||
of_x, of_y, of_z = mesh = readof.readmesh(str(olaflow_root))
|
model = OFModel(olaflow_root)
|
||||||
|
model.read_mesh()
|
||||||
|
|
||||||
watl = interpolate.interp1d(x, sws["watl"][680])
|
watl = interpolate.interp1d(x, sws["watl"][680])
|
||||||
|
alpha_water = np.where(model.z < watl(model.x), 1, 0)
|
||||||
|
|
||||||
with open(olaflow_root.joinpath("0", "alpha.water"), "r") as aw_file:
|
model.write_field("alpha.water", alpha_water)
|
||||||
aw_raw = aw_file.read()
|
|
||||||
|
|
||||||
with open(olaflow_root.joinpath("0", "alpha.water"), "w") as aw_file:
|
|
||||||
aw_file.write(
|
|
||||||
re.sub(
|
|
||||||
r"(?<=\(\n).*?(?=\n\))",
|
|
||||||
"\n".join(map(str, alpha_water)),
|
|
||||||
aw_raw,
|
|
||||||
count=1,
|
|
||||||
flags=re.S,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
Loading…
Reference in a new issue