Skip to content

Commit

Permalink
Fix various bugs in auto adding bgc tracers and setting up field depe…
Browse files Browse the repository at this point in the history
…ndant forcing (#3323)

* Fixed bug in auto adding of tracers

* Bug in regularizing user function

* keys not names

* measure once cut twice

* Same for hydrostatic

* tried to make tidier

* fixed hydrostatic model

* added error if a field dependancy does not exist

* Update src/Biogeochemistry.jl

Co-authored-by: Gregory L. Wagner <wagner.greg@gmail.com>

* Bump patch version

---------

Co-authored-by: Gregory L. Wagner <wagner.greg@gmail.com>
  • Loading branch information
jagoosw and glwagner committed Oct 12, 2023
1 parent 82e4660 commit 4512252
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Oceananigans"
uuid = "9e8cae18-63c1-5223-a75c-80ca9d6e9a09"
authors = ["Climate Modeling Alliance and contributors"]
version = "0.89.1"
version = "0.89.2"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
2 changes: 1 addition & 1 deletion src/Biogeochemistry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ tracernames(tracers) = keys(tracers)
tracernames(tracers::Tuple) = tracers

add_biogeochemical_tracer(tracers::Tuple, name, grid) = tuple(tracers..., name)
add_biogeochemical_tracer(tracers::NamedTuple, name, grid) = merge(tracers, NamedTuple(name => CenterField(grid)))
add_biogeochemical_tracer(tracers::NamedTuple, name, grid) = merge(tracers, (; name => CenterField(grid)))

@inline function has_biogeochemical_tracers(fields, required_fields, grid)
user_specified_tracers = [name in tracernames(fields) for name in required_fields]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function HydrostaticFreeSurfaceModel(; grid,
extract_boundary_conditions(diffusivity_fields))

# Next, we form a list of default boundary conditions:
prognostic_field_names = (:u, :v, :η, tracernames(tracers)...)
prognostic_field_names = (:u, :v, :w, tracernames(tracers)..., , keys(auxiliary_fields)...)
default_boundary_conditions = NamedTuple{prognostic_field_names}(Tuple(FieldBoundaryConditions() for name in prognostic_field_names))

# Then we merge specified, embedded, and default boundary conditions. Specified boundary conditions
Expand Down Expand Up @@ -175,7 +175,7 @@ function HydrostaticFreeSurfaceModel(; grid,
G⁻ = HydrostaticFreeSurfaceTendencyFields(velocities, free_surface, grid, tracernames(tracers)))

# Regularize forcing for model tracer and velocity fields.
model_fields = hydrostatic_prognostic_fields(velocities, free_surface, tracers)
model_fields = merge(hydrostatic_prognostic_fields(velocities, free_surface, tracers), auxiliary_fields)
forcing = model_forcing(model_fields; forcing...)

default_tracer_advection, tracer_advection = validate_tracer_advection(tracer_advection, grid)
Expand Down
4 changes: 3 additions & 1 deletion src/Models/NonhydrostaticModels/nonhydrostatic_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ function NonhydrostaticModel(; grid,
extract_boundary_conditions(diffusivity_fields))

# Next, we form a list of default boundary conditions:
prognostic_field_names = (:u, :v, :w, tracernames(tracers)...)

# Next, we form a list of default boundary conditions:
prognostic_field_names = (:u, :v, :w, tracernames(tracers)..., keys(auxiliary_fields)...)
default_boundary_conditions = NamedTuple{prognostic_field_names}(FieldBoundaryConditions() for name in prognostic_field_names)

# Finally, we merge specified, embedded, and default boundary conditions. Specified boundary conditions
Expand Down
2 changes: 2 additions & 0 deletions src/Operators/interpolation_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ function index_and_interp_dependencies(X, Y, Z, dependencies, model_field_names)
findfirst(isequal(name), model_field_names)
end

!any(isnothing.(indices)) || error("$dependencies are required to be model fields but only $model_field_names are present")

return indices, interps
end

Expand Down

2 comments on commit 4512252

@jagoosw
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/93273

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.89.2 -m "<description of version>" 4512252e00b755f03a57a41f8cc26191ebd69d75
git push origin v0.89.2

Please sign in to comment.