Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create field boundary conditions using information from grid topology #620

Merged
merged 17 commits into from
Feb 15, 2020

Conversation

ali-ramadhan
Copy link
Member

@ali-ramadhan ali-ramadhan commented Feb 11, 2020

This PR aims to create a single FieldBoundaryConditions function to replace HorizontallyPeriodicBCs and ChannelBCs. This paves the way for boundary conditions to become a Field property (#606).

It's a pretty big breaking change so would be good to agree on the design and API before refactoring.

Side note: Ideally we would set default_bc(::Flat) = nothing but until we elide operations and halo filling along Flat dimensions, I think we should use default_bc(::Flat) = PeriodicBC().

@glwagner Let me know if this looks like what we discussed. If so, I'll go ahead and change all the tests and examples to use it instead of HorizontallyPeriodicBCs and ChannelBCs.

Reminder to self: Documentation, especially model setup, will have to be revised as part of this PR.

@ali-ramadhan ali-ramadhan added cleanup 🧹 Paying off technical debt abstractions 🎨 Whatever that means labels Feb 11, 2020
function FieldBoundaryConditions(grid; kwargs...)
kws = keys(kwargs)
for kw in kws
if kw ∉ valid_directions
Copy link
Member

Choose a reason for hiding this comment

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

Another strategy would be to set all defaults in the constructor to 'nothing', and then reset them to default if they are nothing. The error the user receives would then bean ordinary KeywordError. This also may simplify subsequent validation.

Copy link
Member Author

Choose a reason for hiding this comment

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

I ended up assigning default boundary conditions in the constructor which cleaned up the function quite a bit.

e = "Cannot specify west or east boundary conditions with $TX topology in x-direction."
throw(ArgumentError(e))
else
west_bc = :west in kws ? kwargs[:west] : default_bc(TX)
Copy link
Member

Choose a reason for hiding this comment

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

could let default_bc take two arguments: The topology and the current bc. Then define a fallback that throws an error, whitelist the bcs that are valid, and define a default for ::Nothing. Might be a bit simpler and more modular, less repeated code.

@ali-ramadhan
Copy link
Member Author

ali-ramadhan commented Feb 14, 2020

I've refactored a bit more so that we can use FieldBoundaryConditions to construct velocity, tracer, diffusivity, pressure, and tendency boundary conditions. This is done by specifying the field_type required kwarg when calling FieldBoundaryConditions.

u_bcs = FieldBoundaryConditions(grid, field_type=:velocity)
T_bcs = FieldBoundaryConditions(grid, field_type=:tracer, top=FluxBoundaryCondition(0.1))

An alternative design (really a wrapper):

VelocityFieldBoundaryConditions(grid; kwargs...) =
    FieldBoundaryConditions(grid, field_type=:velocity, kwargs...)
TracerFieldBoundaryConditions(grid; kwargs...) =
    FieldBoundaryConditions(grid, field_type=:tracer, kwargs...)

This will allow us to properly set default velocity and tracer boundary conditions with a single FieldBoundaryConditions constructor. It will also allow us to clean up the code a bit and remove some other functions like PressureBoundaryConditions and DiffusivitiesBoundaryConditions from solution_and_model_boundary_conditions.jl.

@glwagner Let me know what you think.

@ali-ramadhan
Copy link
Member Author

I added tests and updated the documentation so will merge once tests pass.

I also added more readable (i.e. reads like how you would say it) boundary condition constructors, e.g.

fbc = FluxBoundaryCondition(-1e-3)
vbc = ValueBoundaryCondition(25)

@codecov
Copy link

codecov bot commented Feb 15, 2020

Codecov Report

Merging #620 into master will decrease coverage by 3.25%.
The diff coverage is 81.81%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #620      +/-   ##
==========================================
- Coverage   74.59%   71.33%   -3.26%     
==========================================
  Files         118      117       -1     
  Lines        2220     2327     +107     
==========================================
+ Hits         1656     1660       +4     
- Misses        564      667     +103
Impacted Files Coverage Δ
src/BoundaryConditions/BoundaryConditions.jl 100% <ø> (ø) ⬆️
src/Models/model.jl 100% <ø> (+8.33%) ⬆️
src/Oceananigans.jl 100% <ø> (ø) ⬆️
src/Models/Models.jl 100% <ø> (ø) ⬆️
src/Grids/Grids.jl 57.14% <0%> (ø) ⬆️
src/Logger.jl 88.88% <100%> (+7.93%) ⬆️
...nditions/solution_and_model_boundary_conditions.jl 89.18% <100%> (-5.41%) ⬇️
...rc/BoundaryConditions/field_boundary_conditions.jl 81.48% <78.26%> (-18.52%) ⬇️
src/Solvers/solver_utils.jl 0% <0%> (-100%) ⬇️
src/Solvers/channel_pressure_solver.jl 30.13% <0%> (-68.5%) ⬇️
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fb7fb70...d7753f2. Read the comment docs.

@ali-ramadhan ali-ramadhan merged commit eb9b07f into master Feb 15, 2020
@ali-ramadhan ali-ramadhan deleted the ar/bcs-from-topology branch February 15, 2020 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
abstractions 🎨 Whatever that means cleanup 🧹 Paying off technical debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants