-
Notifications
You must be signed in to change notification settings - Fork 250
materialize DefaultBoundaryCondition from bcs in Field constructor
#4762
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
base: main
Are you sure you want to change the base?
Changes from 15 commits
d64fab4
4ba486f
1cafd7a
4688738
648e287
9cd7fc3
fa689f3
af6ae1a
cc033aa
b0255f8
14b3814
c997c93
d96a8f0
c1874e0
98ce374
66bf31b
8a992fc
39dc07f
2002020
de2bc90
2684601
bc2755a
d411608
b61194c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,18 +6,14 @@ using GPUArraysCore | |
| ##### Default boundary conditions | ||
| ##### | ||
|
|
||
| struct DefaultBoundaryCondition{BC} | ||
| boundary_condition :: BC | ||
| end | ||
|
|
||
| DefaultBoundaryCondition() = DefaultBoundaryCondition(NoFluxBoundaryCondition()) | ||
| struct DefaultBoundaryCondition end | ||
|
|
||
| default_prognostic_bc(::Grids.Periodic, loc, default) = PeriodicBoundaryCondition() | ||
| default_prognostic_bc(::FullyConnected, loc, default) = MultiRegionCommunicationBoundaryCondition() | ||
| default_prognostic_bc(::Flat, loc, default) = nothing | ||
| default_prognostic_bc(::Bounded, ::Center, default) = default.boundary_condition | ||
| default_prognostic_bc(::LeftConnected, ::Center, default) = default.boundary_condition | ||
| default_prognostic_bc(::RightConnected, ::Center, default) = default.boundary_condition | ||
| default_prognostic_bc(::Bounded, ::Center, default) = NoFluxBoundaryCondition() | ||
| default_prognostic_bc(::LeftConnected, ::Center, default) = NoFluxBoundaryCondition() | ||
| default_prognostic_bc(::RightConnected, ::Center, default) = NoFluxBoundaryCondition() | ||
|
|
||
| # TODO: make model constructors enforce impenetrability on velocity components to simplify this code | ||
| default_prognostic_bc(::Bounded, ::Face, default) = ImpenetrableBoundaryCondition() | ||
|
|
@@ -36,12 +32,13 @@ _default_auxiliary_bc(::Bounded, ::Face) = nothing | |
| _default_auxiliary_bc(::RightConnected, ::Face) = nothing | ||
| _default_auxiliary_bc(::LeftConnected, ::Face) = nothing | ||
|
|
||
| default_auxiliary_bc(grid, ::Val{:east}, loc) = _default_auxiliary_bc(topology(grid, 1)(), loc[1]) | ||
| default_auxiliary_bc(grid, ::Val{:west}, loc) = _default_auxiliary_bc(topology(grid, 1)(), loc[1]) | ||
| default_auxiliary_bc(grid, ::Val{:south}, loc) = _default_auxiliary_bc(topology(grid, 2)(), loc[2]) | ||
| default_auxiliary_bc(grid, ::Val{:north}, loc) = _default_auxiliary_bc(topology(grid, 2)(), loc[2]) | ||
| default_auxiliary_bc(grid, ::Val{:bottom}, loc) = _default_auxiliary_bc(topology(grid, 3)(), loc[3]) | ||
| default_auxiliary_bc(grid, ::Val{:top}, loc) = _default_auxiliary_bc(topology(grid, 3)(), loc[3]) | ||
| default_auxiliary_bc(grid, ::Val{:east}, loc) = _default_auxiliary_bc(topology(grid, 1)(), loc[1]) | ||
| default_auxiliary_bc(grid, ::Val{:west}, loc) = _default_auxiliary_bc(topology(grid, 1)(), loc[1]) | ||
| default_auxiliary_bc(grid, ::Val{:south}, loc) = _default_auxiliary_bc(topology(grid, 2)(), loc[2]) | ||
| default_auxiliary_bc(grid, ::Val{:north}, loc) = _default_auxiliary_bc(topology(grid, 2)(), loc[2]) | ||
| default_auxiliary_bc(grid, ::Val{:bottom}, loc) = _default_auxiliary_bc(topology(grid, 3)(), loc[3]) | ||
| default_auxiliary_bc(grid, ::Val{:top}, loc) = _default_auxiliary_bc(topology(grid, 3)(), loc[3]) | ||
| default_auxiliary_bc(grid, ::Val{:immersed}, loc) = nothing | ||
|
|
||
| ##### | ||
| ##### Field boundary conditions | ||
|
|
@@ -127,14 +124,13 @@ and the topology in the boundary-normal direction is used: | |
| - `ImpenetrableBoundaryCondition` for `Bounded` directions and `Face`-located fields | ||
| - `nothing` for `Flat` directions and/or `Nothing`-located fields | ||
| """ | ||
| FieldBoundaryConditions(default_bounded_bc::BoundaryCondition = NoFluxBoundaryCondition(); | ||
| west = DefaultBoundaryCondition(default_bounded_bc), | ||
| east = DefaultBoundaryCondition(default_bounded_bc), | ||
| south = DefaultBoundaryCondition(default_bounded_bc), | ||
| north = DefaultBoundaryCondition(default_bounded_bc), | ||
| bottom = DefaultBoundaryCondition(default_bounded_bc), | ||
| top = DefaultBoundaryCondition(default_bounded_bc), | ||
| immersed = DefaultBoundaryCondition(default_bounded_bc)) = | ||
| FieldBoundaryConditions(; west = DefaultBoundaryCondition(), | ||
| east = DefaultBoundaryCondition(), | ||
| south = DefaultBoundaryCondition(), | ||
| north = DefaultBoundaryCondition(), | ||
| bottom = DefaultBoundaryCondition(), | ||
| top = DefaultBoundaryCondition(), | ||
| immersed = DefaultBoundaryCondition()) = | ||
|
||
| FieldBoundaryConditions(west, east, south, north, bottom, top, immersed) | ||
|
|
||
| """ | ||
|
|
@@ -181,9 +177,37 @@ function FieldBoundaryConditions(grid::AbstractGrid, loc, indices=(:, :, :); | |
| immersed = DefaultBoundaryCondition()) | ||
|
|
||
| bcs = FieldBoundaryConditions(indices, west, east, south, north, bottom, top, immersed) | ||
| return regularize_field_boundary_conditions(bcs, grid, loc) | ||
| return materialize_default_boundary_conditions(bcs, grid, loc) | ||
| end | ||
|
|
||
| ##### | ||
| ##### Boundary condition "materialization" (materializes a `DefaultBoundaryCondition` that is grid and location dependent) | ||
| ##### | ||
|
|
||
| function materialize_default_boundary_conditions(bcs::FieldBoundaryConditions, | ||
| grid::AbstractGrid, | ||
| loc::Tuple) | ||
|
|
||
| west = materialize_default_boundary_condition(bcs.west, Val(:west), grid, loc) | ||
| east = materialize_default_boundary_condition(bcs.east, Val(:east), grid, loc) | ||
| south = materialize_default_boundary_condition(bcs.south, Val(:south), grid, loc) | ||
| north = materialize_default_boundary_condition(bcs.north, Val(:north), grid, loc) | ||
| bottom = materialize_default_boundary_condition(bcs.bottom, Val(:bottom), grid, loc) | ||
| top = materialize_default_boundary_condition(bcs.top, Val(:top), grid, loc) | ||
|
|
||
| immersed = materialize_default_boundary_condition(bcs.immersed, Val(:immersed), grid, loc) | ||
|
|
||
| return FieldBoundaryConditions(west, east, south, north, bottom, top, immersed) | ||
| end | ||
|
|
||
| # nothing and missing remain nothing and missing | ||
| materialize_default_boundary_conditions(::Nothing, args...) = nothing | ||
| materialize_default_boundary_conditions(::Missing, args...) = missing | ||
|
|
||
| # Individual materialize | ||
| materialize_default_boundary_condition(bc, args...) = bc # fallback | ||
| materialize_default_boundary_condition(::DefaultBoundaryCondition, side, grid, loc) = default_auxiliary_bc(grid, side, loc) | ||
|
|
||
| ##### | ||
| ##### Boundary condition "regularization" | ||
| ##### | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did you change this design?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought to remove it for this reason and in particular because
validate_boundary_conditionsis only grid and location dependent (not model dependent), so it basically forces a limited default choice. But of course, I am open to discuss about it and keep this feature if this is the consensus 😅There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess, what do you think about models / situations in which "no flux" is irrelevant. For example a model that has no derivatives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could have the default be a
nothinglike onFaces, this would then be general.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That isn't general because models with gradients require
NoFluxBoundaryCondition()as a default.