1
Fork 0
internship/olaflow/processing/sws_ola.py

41 lines
1 KiB
Python
Raw Normal View History

import argparse
import configparser
import logging
import pathlib
import re
import matplotlib.pyplot as plt
import numpy as np
from fluidfoam import readof
from scipy import interpolate
2022-03-07 11:19:37 +01:00
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"))
of_x, of_y, of_z = mesh = readof.readmesh(str(olaflow_root))
watl = interpolate.interp1d(x, sws["watl"][680])
2022-03-07 11:19:37 +01:00
alpha_water = np.where(of_z < watl(of_x), 1, 0)
model = OFModel(olaflow_root)
model.write_field("alpha.water", alpha_water)