Numerical implementation of boundary conditions
We adopt a mixed approach for implementing boundary conditions that uses both halo regions and "direct" imposition of boundary conditions, depending on the condition prescribed.
We illustrate how boundary conditions are implemented by considering the tracer equation
where
See Model setup: boundary conditions for how to create and use these boundary conditions in Oceananigans.
Gradient boundary conditions
Users impose gradient boundary conditions by prescribing the gradient
where
Across the bottom boundary in
where
as prescribed by the user.
Gradient boundary conditions are represented by the Gradient type.
Value boundary conditions
Users impose value boundary conditions by prescribing
At the bottom boundary in
which is then used to set the halo point
Value boundary conditions are represented by the Value type.
Flux boundary conditions
Users impose flux boundary conditions by prescribing the flux Oceananigans.jl, we note that the average of the tracer conservation equation over a finite volume yields
where the surface integral over
An external boundary of a finite volume is associated with a no-penetration condition such that Oceananigans.jl have the property that
Oceananigans.jl exploits this fact to define an algorithm that prescribes fluxes across external boundaries
Impose a constant gradient
across external boundaries by using halo points (similar to ), which ensures that the evaluation of in boundary-adjacent cells does not include fluxes across the external boundary, and;Add the prescribed flux to the boundary-adjacent volumes prior to calculating
: , where denotes values of in boundary-adjacent volumes, is the flux prescribed along the boundary, is the volume of the boundary-adjacent cell, and is the area of the external boundary of the boundary-adjacent cell. The factor is $-$1 and $+$1 on "left" and "right" boundaries, and accounts for the fact that a positive flux on a left boundary where implies an "inward" flux of that increases interior values of , whereas a positive flux on a right boundary where implies an "outward" flux that decreases interior values of .
Flux boundary conditions are represented by the Flux type.
Normal flow boundary conditions
Normal flow boundary conditions directly specify the velocity component normal to the boundary. Typically this is used to impose no penetration boundary conditions, i.e. setting wall normal velocity components to zero on the boundary, or to prescribe the velocity of an inflow or outflow.
On the staggered grid the boundary-normal velocity lies on face points in the boundary direction. For example, the u-component of velocity lies on (Face, Center, Center) points, so on west or east boundaries the point specified by the boundary condition lies on the boundary itself. A tracer on (Center, Center, Center) points has no point on the boundary, and its boundary conditions set the halo points outside of the domain instead.
The other important detail is that normal flow boundary conditions, including no-penetration, are the only conditions used on wall normal velocities when the domain is not periodic. This means that their value affects the pressure calculation for nonhydrostatic models as it is involved in calculating the divergence in the boundary adjacent center point (as described in the fractional step method documentation). Usually boundary points are filled for the predictor velocity (i.e. before the pressure is calculated), and on the corrected field (i.e. after the pressure correction is applied), but for normal flow boundary conditions this would result in the boundary adjacent center point becoming divergent, so they are only filled for the predictor velocity and stay the same after the pressure correction (so the boundary point is filled with the final corrected velocity at the predictor step).
The restriction arises as the boundary condition is specifying the wall normal velocity,
implying that there is a pressure gradient across the boundary. Since we solve the pressure poisson equation (
This moves the boundary condition to the right hand side as
Given the boundary condition on pressure given above, we can define a new modified predictor velocity which is equal to the predictor velocity within the domain but shares boundary conditions with the corrected field,
The modified pressure Poisson equation becomes
Perhaps a more intuitive way to consider this is to recall that the corrector step projects
but we have changed
For simple normal flow boundary conditions such as no penetration or a straight forward prescription of a known velocity at scheme, calculate the boundary value based on the interior solution. As a simple example, if we wanted to set the wall normal velocity gradient to zero at the west boundary then we would set the boundary point to
but we then pressure correct the interior so a new
This is preferred to a divergent interior solution as open boundary conditions are typically already unphysical and only used in an attempt to allow information to enter or exit the domain.
Normal flow boundary conditions are represented by the NormalFlow classification.
Open boundary condition "schemes"
Except for trivial cases (i.e. no-penetration) the velocity on the boundary point has to be approximated as it is outside the computed domain. There is insufficient information to step the full equation of motion as gradients across the boundary cannot be computed and simply prescribing a boundary normal velocity is unphysical and reflects energy leaving the domain ().
An open boundary condition is a NormalFlowBoundaryCondition or a ValueBoundaryCondition with a scheme, passed through the scheme keyword argument. The scheme computes the boundary value from the interior solution and is designed to let disturbances propagate out of the domain. In the literature, open boundary conditions of this kind are sometimes called radiation boundary conditions. In a NormalFlowBoundaryCondition the scheme sets the boundary-normal velocity on the boundary face. In a ValueBoundaryCondition it sets the first halo cell of a field that is Center-located in the boundary-normal direction, such as a tracer or a boundary-tangential velocity component. The available schemes are
| Scheme | Boundary condition | Fields |
|---|---|---|
PerturbationAdvection | NormalFlowBoundaryCondition, ValueBoundaryCondition | velocities, tracers |
NormalRadiation | NormalFlowBoundaryCondition, ValueBoundaryCondition | velocities, tracers |
ObliqueRadiation | NormalFlowBoundaryCondition, ValueBoundaryCondition | velocities, tracers |
TracerReservoir | ValueBoundaryCondition | tracers |
GravityWaveRadiation | NormalFlowBoundaryCondition | barotropic transports U, V |
SurfaceWaveRadiation | ValueBoundaryCondition | free surface displacement η |
GravityWaveRadiation and SurfaceWaveRadiation apply to the barotropic state of a SplitExplicitFreeSurface.
Perturbation advection
A common method for allowing information to exit is to perform a one-sided advection operation. For example, in the boundary condition fields are advected out of the domain by a locally determined phase speed. We can show that this is the first-order approximation of the full equations of motion in the predictor velocity step. Consider a right boundary normal to the u velocity component (the east boundary):
let
then, taking only first-order terms:
Now consider the dominant forcing to be relaxation to the background state (we will explain why later) so that
where
For numerical stability, we also need to apply a CFL-like constraint and set
Previously we considered the dominant forcing to be relaxation to
The implementation neglects the terms with outflow_timescale when inflow_timescale when it points into it, and a zero time scale sets the boundary value to gravity_wave_speed adds a constant outward speed to ValueBoundaryCondition the same update applies to a tracer, with
Normal radiation
NormalRadiation is the radiation condition of with the adaptive nudging of . A field
where c_n = - \partial_t \phi / \partial_n \phi.
Let NormalFlowBoundaryCondition and the first halo cell in a ValueBoundaryCondition, and let
with NormalFlowBoundaryCondition, ValueBoundaryCondition, it is the normal velocity one face into the interior, or on the boundary face when use_boundary_velocity = true. The sign of
and outflow_timescale. On inflow inflow_timescale. A backward Euler step of
with inflow_timescale = 0 and outflow_timescale = Inf the boundary value is prescribed on inflow and radiates freely on outflow. The adaptive nudging of relaxes strongly on inflow, where the exterior data set the boundary value, and weakly on outflow, where the interior solution does.
The scheme stores
Oblique radiation
ObliqueRadiation extends normal radiation to signals that reach the boundary at an angle, following . With
A single equation does not determine both components of the phase velocity. take the phase velocity parallel to
The Courant numbers are diagnosed at the first interior point from the differences
On outflow
where
Tracer reservoir
A tracer boundary with a prescribed exterior value has no memory of the water that leaves the domain. When the boundary-normal flow reverses, the water that re-enters carries the exterior value TracerReservoir follows the tracer reservoirs of MOM6 and keeps a reservoir value
where outflow_length_scale. On inflow inflow_length_scale. A backward Euler step gives
which is stable for any inflow_length_scale. A zero length scale sets TracerReservoir reduces to a condition without memory: zero gradient on outflow and
Gravity wave radiation
A SplitExplicitFreeSurface advances the barotropic transports
whose Riemann invariants GravityWaveRadiation is the condition of , which takes the incoming invariant from the exterior state,
On west and south boundaries the incoming invariant is (U, η) value of the boundary condition, see GravityWaveRadiationBoundaryCondition. The free surface on the boundary face,
The condition is applied at every barotropic substep. A target_transport
where NormalRadiation scheme, therefore sets only the departure from the depth average.
Surface wave radiation
SurfaceWaveRadiation is the companion condition on
which is discretized implicitly as in ROMS,
where
In each barotropic substep the GravityWaveRadiation, and finally SplitExplicitFreeSurface adds SurfaceWaveRadiation on GravityWaveRadiation condition, unless boundary conditions for tidal_boundary_conditions builds both conditions on every lateral boundary from the harmonic constants of a tidal atlas.
Net transport through open boundaries
Before the pressure solve of a NonhydrostaticModel, the boundary-normal velocities set by the schemes are corrected so that the net volume transport into the domain vanishes. The target_transport keyword argument of the schemes gives the user more control on how the correction is distributed among the boundaries.
The correction has two steps. First, the normal velocity on every boundary whose scheme has a target_transport
where
A HydrostaticFreeSurfaceModel skips the second step because the free surface absorbs a net imbalance. A net transport through the open boundaries changes the mean free surface height, so the targets do not need to add up to zero net transport. With a SplitExplicitFreeSurface the transport can be controlled through the target_transport of GravityWaveRadiation on the barotropic transport.