-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add equation example #25
Comments
Hi @tomsail, In 2D, The handling of variables and equations is optimized and quite complex in PyTelTools, it requires some more files (I am not the original developper of this part). import xarray as xr
from xarray_selafin.variable.variables_2d import get_US_equation, NIKURADSE_ID
from xarray_selafin.variables import do_calculation, get_necessary_equations
from xarray_selafin.xarray_backend import SelafinBackendEntrypoint
slf_in = "tests/data/r2d_tidal_flats.slf"
ds = xr.open_dataset(slf_in, engine=SelafinBackendEntrypoint)
# https://gitlab.pam-retd.fr/otm/telemac-mascaret/-/blob/main/examples/telemac3d/tidal_flats/t3d_tidal_flats.cas
# LAW OF BOTTOM FRICTION = 5
# FRICTION COEFFICIENT FOR THE BOTTOM = 0.01
ds = ds.assign(W=0.01) # Add a constant Nikuradse of 0.01 (Is it the best way to assign it?)
us_equation = get_US_equation(NIKURADSE_ID)
is_2d = "plan" not in ds.dims
necessary_equations = get_necessary_equations(
ds.attrs["variables"].keys(),
["TAU"], # Some new variables to add
is_2d=is_2d,
us_equation=us_equation
)
for equation in necessary_equations:
input_var_IDs = list(map(lambda x: x.ID(), equation.input))
if is_2d:
# handle the special case for US (user-specified equation)
if equation.output.ID() == 'US':
ds['US'] = xr.Variable(
dims=("time", "node"),
data=do_calculation(us_equation, [ds['W'], ds['H'], ds['M']])
)
# Clean US values in case of negative or null water depth
xr.where(ds["H"] > 0, ds["US"], 0.0)
# handle the normal case (if not already done)
if equation.output.ID() not in ds.data_vars:
ds[equation.output.ID()] = xr.Variable(
dims=("time", "node"),
data=do_calculation(equation, [ds[var_ID] for var_ID in input_var_IDs])
)
print(ds)
ds.selafin.write("r2d_with_new_variables.slf") This script will rewrite original variables but add some computed variables:
Sorry I do not have much time to integrate it properly, but I am available to help if required. Hope it helps, |
Ok thanks for taking the time. I was interested in varying bottom friction. manning = 0.027 #
bf = (abs(ds['B']) ** (1 / 6)) / manning
ds['W'] = xr.Variable(dims=["node"], data=bf) (for the complete code) No rush for this, it can be done down the line. |
I am not used to Chézy but is it not |
Indeed you use the hydraulic radius in manning formula. However when it comes to ocean modeling, you are in the configuration of a stream whose width is much greater than the depth. |
Ok, I understand. |
Hi @lucduron,
I see you added lots of tools to calculate parameters (in variable).
Could you provide a simple example in order to calculate CHEZY BOTTOM FRICTION and add it in a geo file?
I think I could add it in the README then.
Thanks
The text was updated successfully, but these errors were encountered: