Skip to content
Discussion options

You must be logged in to vote

This requires defining the average in advance, and then updating it in a callback. Like this:

Ub_forcing = Ref(zero(grid)) # can also use Field{Nothing, Nothing, Nothing}(grid)
u_forcing_func(x, z, t, u, Ub) = -u / Ub[]
u_forcing = Forcing(u_forcing_func, field_dependencies=:u, parameters=Ub_forcing)

# define model and simulation

Ub = Field(Average(model.velocities.u))

using GPUArrays: @allowscalar # req for GPU

function update_forcing!(sim)
    compute!(Ub)
    # update Ub used in the forcing function
    Ub_forcing[] = @allowscalar first(Ub)
    return nothing
end

add_callback!(simulation, update_forcing!)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@andrewooish
Comment options

Answer selected by glwagner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants