diff --git a/src/Particles/Particles.jl b/src/Particles/Particles.jl index e1d733c8d..c15faffcd 100644 --- a/src/Particles/Particles.jl +++ b/src/Particles/Particles.jl @@ -134,8 +134,11 @@ const MODEL_WITH_BGC_PARTICLES = @inline function update_lagrangian_particle_properties!(particles::BiogeochemicalParticles, model, bgc, Δt) advect_particles!(particles.advection, particles, model, Δt) time_step_particle_fields!(particles.timestepper, particles, model, Δt) + update_particle_state!(particles, model, Δt) end +@inline update_particle_state!(particles, model, Δt) = nothing + size(particles::BiogeochemicalParticles) = (length(particles), ) length(::BiogeochemicalParticles{N}) where N = N diff --git a/src/Particles/tendencies.jl b/src/Particles/tendencies.jl index 5e747f0c0..05b50d4fa 100644 --- a/src/Particles/tendencies.jl +++ b/src/Particles/tendencies.jl @@ -29,7 +29,7 @@ end field_values = ntuple(nf->particles.fields[nf][n], Val(Nf)) - tracer_values = extract_tracer_values(particles.field_interpolation, particles, grid, fields, n) + tracer_values = extract_tracer_values(val_field_name, particles.field_interpolation, particles, grid, fields, n) tendencies[field_name][n] = particles.biogeochemistry(val_field_name, t, field_values..., tracer_values...) end diff --git a/src/Particles/tracer_interpolation.jl b/src/Particles/tracer_interpolation.jl index 9c9489c80..e176cced5 100644 --- a/src/Particles/tracer_interpolation.jl +++ b/src/Particles/tracer_interpolation.jl @@ -2,6 +2,7 @@ using Oceananigans.Operators: volume using Oceananigans.Fields: fractional_indices, _interpolate, interpolator, Center using Oceananigans.Grids: AbstractGrid, Flat, Bounded, Periodic +@inline get_node(::Flat, i, N) = one(i) @inline get_node(::Bounded, i, N) = min(max(i, 1), N) @inline get_node(::Periodic, i, N) = ifelse(i < 1, N, ifelse(i > N, 1, i)) @@ -12,7 +13,7 @@ Specifies that tracer values should be taken from the nearst center point. """ struct NearestPoint end -@inline function extract_tracer_values(::NearestPoint, particles, grid, fields, n) +@inline function extract_tracer_values(val_field_name, ::NearestPoint, particles, grid, fields, n) x = @inbounds particles.x[n] y = @inbounds particles.y[n] z = @inbounds particles.z[n] @@ -29,11 +30,21 @@ struct NearestPoint end return field_values end +# feels like fractional_indices could work more intuativly +@inline collapse_position(x, y, z, ℓx, ℓy, ℓz) = (x, y, z) +@inline collapse_position(x, y, z, ::Nothing, ℓy, ℓz) = (y, z) +@inline collapse_position(x, y, z, ℓx, ::Nothing, ℓz) = (x, z) +@inline collapse_position(x, y, z, ℓx, ℓy, ::Nothing) = (x, y) +@inline collapse_position(x, y, z, ℓx, ::Nothing, ::Nothing) = (x, ) +@inline collapse_position(x, y, z, ::Nothing, ℓy, ::Nothing) = (y, ) +@inline collapse_position(x, y, z, ::Nothing, ::Nothing, ℓz) = (z, ) + @inline function nearest_node(x, y, z, grid::AbstractGrid{FT, TX, TY, TZ}) where {FT, TX, TY, TZ} # messy - ii, jj, kk = fractional_indices((x, y, z), grid, ifelse(isa(TX(), Flat), nothing, Center()), - ifelse(isa(TY(), Flat), nothing, Center()), - ifelse(isa(TZ(), Flat), nothing, Center())) + ℓx = ifelse(isa(TX(), Flat), nothing, Center()) + ℓy = ifelse(isa(TY(), Flat), nothing, Center()) + ℓz = ifelse(isa(TZ(), Flat), nothing, Center()) + ii, jj, kk = fractional_indices(collapse_position(x, y, z, ℓx, ℓy, ℓz), grid, ℓx, ℓy, ℓz) ix = interpolator(ii) iy = interpolator(jj) diff --git a/src/Particles/update_tracer_tendencies.jl b/src/Particles/update_tracer_tendencies.jl index 65df9b225..4c8b71623 100644 --- a/src/Particles/update_tracer_tendencies.jl +++ b/src/Particles/update_tracer_tendencies.jl @@ -36,7 +36,7 @@ possible_tuple_value(::Tuple, field_name) = field_name field_values = ntuple(nf->particles.fields[nf][n], Val(Nf)) - tracer_values = extract_tracer_values(particles.field_interpolation, particles, grid, fields, n) + tracer_values = extract_tracer_values(val_field_name, particles.field_interpolation, particles, grid, fields, n) particle_tendency = particles.biogeochemistry(val_field_name, t, field_values..., tracer_values...)