Added OFModel class to write fields
This commit is contained in:
parent
ef2e23ab15
commit
62af6a03ed
|
@ -0,0 +1,21 @@
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
class OFModel:
|
||||||
|
def __init__(self, root):
|
||||||
|
self._root = 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,
|
||||||
|
)
|
||||||
|
)
|
|
@ -9,6 +9,8 @@ import numpy as np
|
||||||
from fluidfoam import readof
|
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"
|
||||||
)
|
)
|
||||||
|
@ -32,18 +34,7 @@ of_x, of_y, of_z = mesh = readof.readmesh(str(olaflow_root))
|
||||||
|
|
||||||
watl = interpolate.interp1d(x, sws["watl"][680])
|
watl = interpolate.interp1d(x, sws["watl"][680])
|
||||||
|
|
||||||
alpha_water = np.where(of_z < watl(of_x), "1", "0")
|
alpha_water = np.where(of_z < watl(of_x), 1, 0)
|
||||||
|
|
||||||
with open(olaflow_root.joinpath("0", "alpha.water"), "r") as aw_file:
|
model = OFModel(olaflow_root)
|
||||||
aw_raw = aw_file.read()
|
model.write_field("alpha.water", alpha_water)
|
||||||
|
|
||||||
with open(olaflow_root.joinpath("0", "alpha.water"), "w") as aw_file:
|
|
||||||
aw_file.write(
|
|
||||||
re.sub(
|
|
||||||
r"(?<=\(\n).*?(?=\n\))",
|
|
||||||
"\n".join(alpha_water),
|
|
||||||
aw_raw,
|
|
||||||
count=1,
|
|
||||||
flags=re.S,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
Loading…
Reference in New Issue