import argparse import configparser import logging import pathlib import numpy as np from scipy import interpolate import matplotlib.pyplot as plt from .olaflow import OFModel parser = argparse.ArgumentParser( description="Convert swash output to olaFlow input" ) parser.add_argument("-v", "--verbose", action="count", default=0) parser.add_argument("-c", "--config", default="config.ini") 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(args.config) sws_out = pathlib.Path(config.get("swash", "np_out")) def data(var): return np.load(sws_out.joinpath(f"{var}.npy")) 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_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)