Comments (9)
I like the idea adding a method for tuples and named tuples. It seems to be the behavior we want when compute!
ing on collection of fields.
from oceananigans.jl.
So basically we could add two methods
compute!(tup::Tuple) = Tuple(compute!(t) for t in tup)
compute!(nt::NamedTuple) = NamedTuple(name => compute!(nt[name]) for name in keys(nt))
as a convenience to auto-compute Field
s that are embedded in tuples or named tuples that are arguments to KernelFunctionOperation
(which I think is the main application that I can see)
from oceananigans.jl.
I'm having trouble following your example. Can you come up with a simpler illustration of the issue and avoid constructions with many operations on a line?
from oceananigans.jl.
Does this illustrate the problem?
using Oceananigans
using Oceananigans.AbstractOperations: KernelFunctionOperation
using Oceananigans.Fields: @compute
grid = RectilinearGrid(size = (1, 1, 1), extent = (1, 1, 1))
model = NonhydrostaticModel(; grid)
set!(model, u=2)
get_u(i, j, k, grid, velocities) = velocities.u[i, j, k]
f_op = KernelFunctionOperation{Face, Center, Center}(get_u, model.grid, velocities)
# f_op[1, 1, 1] works?
u_avg = Field(Average(u))
u_prime = u - u_avg
perturbation_velocities = (; u = u_prime)
f_perturbation_op = KernelFunctionOperation{Face, Center, Center}(get_u, model.grid, perturbation_velocities)
# f_perturbation_op[1, 1, 1] doesn't work?
If so, check that u_avg
is actually computed.
from oceananigans.jl.
Yes, that's the core of it. I modified your example a bit to make it run and I'm posting it here for completeness:
using Oceananigans
grid = RectilinearGrid(size = (1, 1, 1), extent = (1, 1, 1))
model = NonhydrostaticModel(; grid)
set!(model, u=2)
get_u(i, j, k, grid, velocities) = velocities.u[i, j, k]
f_op = KernelFunctionOperation{Face, Center, Center}(get_u, model.grid, model.velocities)
u_avg = Field(Average(model.velocities.u))
u_prime = model.velocities.u - u_avg
perturbation_velocities = (; u = u_prime)
f_perturbation_op = KernelFunctionOperation{Face, Center, Center}(get_u, model.grid, perturbation_velocities)
Then f_op
gives the correct answer, but f_perturbation_op
does not.
And yes, I agree the core of the issue is that u_avg
isn't computed before. If I first compute u_avg
, then f_perturbation_op
also produces the correct result.
But is that the expected behavior? I'd expect either u_avg
to be computed before computing f_perturbation_op
or for a warning/error to be thrown.
from oceananigans.jl.
Hmm, well it looks like we do compute arguments:
But if the arguments are themselves wrapped inside a NamedTuple
--- or any other object --- then they won't be computed. In other words compute!(perturbation_velocities)
does not compute the elements of perturbation_velocities
.
We could add a method compute!(tup::Tuple) = Tuple(compute!(t) for t in tup)
and also for NamedTuple
. But I'm not sure this is the best API. Maybe it's better to require that arguments that need to be computed should be included directly as arguments. Seems like its up for debate.
PS it does seem to test this correctly then we need to further evaluate
f_perturbation = Field(f_perturbation_op)
compute!(f_perturbation)
from oceananigans.jl.
This seems reasonable. I'm not sure if there are performance implications. @navidcy @simone-silvestri any thoughts?
from oceananigans.jl.
Perhaps a more concise and extendable implementation would be
compute!(collection::Union{Tuple, NamedTuple}) = map(compute!, collection)
inspired by Adapt
from oceananigans.jl.
test
grid = RectilinearGrid(size = (1, 1, 1), extent = (1, 1, 1))
c = CenterField(grid)
set!(c, 1)
at_ijk(i, j, k, grid, a) = a[i, j, k]
one_c = Field(1 * c)
two_c = tuple(Field(2 * c))
ten_c = (; ten_c = Field(10 * c))
one_c_op = KernelFunctionOperation{Center, Center, Center}(at_ijk, grid, one_c)
two_c_op = KernelFunctionOperation{Center, Center, Center}(at_ijk, grid, two_c)
ten_c_op = KernelFunctionOperation{Center, Center, Center}(at_ijk, grid, ten_c)
one_c_field = Field(one_c_op)
two_c_field = Field(two_c_op)
ten_c_field = Field(ten_c_op)
compute!(one_c_field)
compute!(two_c_field)
compute!(ten_c_field)
@test all(interior(one_c) .== 1)
@test all(interior(two_c) .== 2)
@test all(interior(ten_c) .== 10)
from oceananigans.jl.
Related Issues (20)
- `bottom_heights` from the immersed boundary method don't look right with a coarse grid HOT 1
- 2D turbulence example is outputting `NaNs` HOT 1
- Doing better than `overwriting_existing=true` with output? HOT 5
- Lagrangian particles on Flat topology HOT 3
- `ImmersedPoissonSolver` is slow HOT 10
- `@eval` considered harmful HOT 3
- Noise below the mixed layer when using `AnisotropicMinimumDissipation` HOT 7
- `Clock` and `QuasiAdamsBashforth2` both have a property representing the previous time-step
- What's the point of neglecting the computation of tendencies when taking a time-step?
- Boundary conditions and diffusion with background fields HOT 17
- Bug in determination of indices of parent array by `parent_index_range` HOT 14
- Broadcasting over regions for `MultiRegionField`s HOT 2
- Forcing functions that depend on internal model fields besides velocities and tracers HOT 18
- Typo in docs on callbacks
- Call it "Simulation setup" in the docs, not "Model setup"
- `BackgroundField` is a confusing name HOT 2
- Derivatives of a reduced field over an Immersed boundary HOT 5
- Pressure has extremely high gradients in random chunks of simulation using `NonhydrostaticModel` with `ImmersedBoundaryGrid` and `BuoyancyTracer` HOT 17
- Simulation tips may be a little misleading
- Lagrangian_particles (tracked_fields and using immersed boundaries) HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
đ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. đđđ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google â€ïž Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from oceananigans.jl.