Simulation callback: Error encountered when updating u_s with time #4423
Unanswered
wpan081
asked this question in
Computational science!
Replies: 1 comment 3 replies
-
@wpan081 your Stokes shear are functions: @inline ∂z_uˢ(x, y, z, t) = 2k * U * exp(2k * z) * (1 - exp(-t^2 / (2 * (14400)^2)))
@inline ∂t_uˢ(x, y, z, t) = U * exp(2k * z) * exp(-t^2 / (2 * (14400)^2)) * t / (14400)^2 which cannot be updated. You can only update arrays. For the use case you describe, a function will work. The function doesn't need to be "updated", because it depends on time and is evaluated on the fly, each time step. Your functions, however, do not use the right function signature. Here's the docstring: help?> UniformStokesDrift
search: UniformStokesDrift StokesDrift
UniformStokesDrift(; ∂z_uˢ=zerofunction, ∂z_vˢ=zerofunction, ∂t_uˢ=zerofunction, ∂t_vˢ=zerofunction, parameters=nothing)
Construct a set of functions for a Stokes drift velocity field corresponding to a horizontally-uniform surface gravity wave field, with optional
parameters.
If parameters=nothing, then the functions ∂z_uˢ, ∂z_vˢ, ∂t_uˢ, ∂t_vˢ must be callable with signature (z, t). If !isnothing(parameters), then
functions must be callable with the signature (z, t, parameters).
To resolve the evolution of the Lagrangian-mean momentum, we require vertical-derivatives and time-derivatives of the horizontal components of the
Stokes drift, uˢ and vˢ.
Examples
≡≡≡≡≡≡≡≡
Exponentially decaying Stokes drift corresponding to a surface Stokes drift of uˢ(z=0) = 0.005 and decay scale h = 20:
using Oceananigans
@inline uniform_stokes_shear(z, t) = 0.005 * exp(z / 20)
stokes_drift = UniformStokesDrift(∂z_uˢ=uniform_stokes_shear)
# output
UniformStokesDrift{Nothing}:
├── ∂z_uˢ: uniform_stokes_shear
├── ∂z_vˢ: zerofunction
├── ∂t_uˢ: zerofunction
└── ∂t_vˢ: zerofunction
Exponentially-decaying Stokes drift corresponding to a surface Stokes drift of uˢ = 0.005 and decay scale h = 20, using parameters:
using Oceananigans
@inline uniform_stokes_shear(z, t, p) = p.uˢ * exp(z / p.h)
stokes_drift_parameters = (uˢ = 0.005, h = 20)
stokes_drift = UniformStokesDrift(∂z_uˢ=uniform_stokes_shear, parameters=stokes_drift_parameters)
# output
UniformStokesDrift with parameters (uˢ=0.005, h=20):
├── ∂z_uˢ: uniform_stokes_shear
├── ∂z_vˢ: zerofunction
├── ∂t_uˢ: zerofunction
└── ∂t_vˢ: zerofunction |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to replicate the swell example with variations in the article by Wagner et al. in 2021, and output the Stokes velocity u_s and the Stokes shear. Both of these two quantities are time-varying. I used the callback method to update u_s in real time, but the simulation always reports an error when I add the callback. In fact, this example can be run on the CPU, but it reports an error when I run it on the GPU (here I have already added GPU() to switch to the GPU framework). Hope someone can help me. Thanks a lot.
Beta Was this translation helpful? Give feedback.
All reactions