Calculate diffusion term in tracer conservation equations using ∇_dot_qᶜ #2801
Replies: 2 comments 5 replies
-
Your error is using sim.model.tracers.DIC[1,1,j] as an argument rather than sim.model.tracers.DIC But, I think you should use using Oceananigans
using Oceananigans.TurbulenceClosures: ∇_dot_qᶜ
"""
diffusive_flux_divergence(tracer_name, model, model=model.closure)
Returns a KernelFunctionOperation corresponding to the diffusive flux divergence
associated with `closure`, where `tracer_name` is one of `keys(model.tracers)`.
`model.closure` is used by default if `closure` is not provided.
"""
function diffusive_flux_divergence(tracer_name, model, closure=model.closure)
tracers = model.tracers
id = findfirst(name -> name === :tracer_name, keys(tracers))
c = tracers[id]
computed_dependencies = (model.diffusivity_fields, Val(id), c, model.buoyancy)
diffusion_op = KernelFunctionOperation{Center, Center, Center}(∇_dot_qᶜ, model.grid; computed_dependencies)
return diffusion_op
end You can use this as flux_div_op = diffusive_flux_divergence(:DIC, model)
Field(flux_div_op) # 3D field
Field(Average(flux_div_op, dims=1)) # Averaged over x You can also pass |
Beta Was this translation helpful? Give feedback.
-
Hi @glwagner, I implemented the above code, but again it still outputs all zeros for I put them in the one-dimensional diffusion example https://github.com/CliMA/Oceananigans.jl/blob/main/examples/one_dimensional_diffusion.jl like function diffusive_flux_divergence(tracer_name, model, closure=model.closure)
tracers = model.tracers
id = findfirst(name -> name === tracer_name, keys(tracers))
c = tracers[id]
computed_dependencies = (model.diffusivity_fields, Val(id), c, model.buoyancy)
diffusion_op = KernelFunctionOperation{Center, Center, Center}(∇_dot_qᶜ, model.grid; computed_dependencies)
return diffusion_op
end
flux_div_op = diffusive_flux_divergence(:T, model)
filename = "diffusion"
simulation.output_writers[:slices] =
JLD2OutputWriter(model, merge(model.tracers, (f=flux_div_op,)),
filename = filename * ".jld2",
schedule = TimeInterval(0.005),
overwrite_existing = true)
run!(simulation) But it is still all zeros. Did I do anything wrong? Thanks. |
Beta Was this translation helpful? Give feedback.
-
Hello,
I'd like to calculate diffusion term in tracer ( particularly DIC ) conservation equations, using the following lines of code:
My model is:
But the
∇_dot_qᶜ
outputs all zeros and I don't quite understand the syntax of∇_dot_qᶜ
. For example, is the tracer_index of DIC 12 in my model? May I have your insights what might be the problem?And is there a way to calculate the diffusion term in the postprocessing, given the DIC has been obtained and diffusivity is defined, instead of using callback as shown above?
Thank you very much.
Best,
Si
Beta Was this translation helpful? Give feedback.
All reactions