4.2 Boundary Conditions and Sponge Layers
Learning Objectives
After completing this lecture, students should be able to:
- understand the role of boundary conditions in numerical models
- distinguish among fixed, periodic, and forced boundary conditions
- explain how different boundary conditions affect numerical solutions
- understand the purpose of sponge grids and sponge layers
- apply appropriate boundary treatments in one-dimensional advection models
Concept
Types of Boundary Conditions
Boundary conditions specify how information behaves at the edge of a computational domain.
Different numerical models use different boundary treatments depending on the application and domain configuration.
Common examples include:
- fixed boundary conditions
- reflective boundary conditions
- periodic (cyclic) boundary conditions
- boundary forcing
- sponge grids
- sponge layers
The choice of boundary condition can strongly influence the numerical solution and should be selected according to the physical problem being studied.
In this chapter, we will demonstrate fixed boundaries, periodic boundaries, boundary forcing, sponge grids, and sponge layers using the one-dimensional advection equation. Reflective boundaries will be discussed conceptually but are not demonstrated because the advection equation considered here only supports one-way propagation.
Fixed Boundary Conditions
The simplest boundary treatment prescribes a constant value at the boundary.
For example, the variable may be fixed to zero throughout the simulation.
Although fixed boundaries are rarely used in realistic atmospheric models, they are useful for idealized experiments because they are easy to implement and interpret.
When an anomaly reaches the boundary, it is effectively removed from the system.
Reflective Boundary Conditions
A reflective boundary causes information reaching the boundary to be reflected back into the computational domain.
Physically, the boundary behaves like a wall that prevents disturbances from leaving the domain.
A familiar example is an ocean wave approaching a coastline or seawall. When the wave reaches the boundary, part of its energy is reflected back toward the open ocean. The interaction between the incoming and reflected waves can produce complex wave patterns and, in some cases, standing waves.
Reflective boundaries are commonly used in idealized experiments when the objective is to confine the solution within a finite domain.
Although reflective boundaries are useful for some applications, they can also introduce artificial reflections that contaminate the numerical solution. Consequently, they are rarely used in realistic atmospheric or oceanic models where disturbances are expected to leave the computational domain.
To reduce these artificial reflections, numerical models often employ sponge grids or sponge layers near the boundary.
In this chapter, we do not demonstrate reflective boundaries using the one-dimensional advection equation. Because advection with a constant velocity propagates information in only one direction, disturbances reaching the boundary do not naturally reflect back into the domain. Reflective boundaries are more commonly illustrated using wave equations or shallow-water models that support both leftward and rightward propagation.
Periodic Boundary Conditions
A periodic (or cyclic) boundary connects the two ends of the computational domain.
When an anomaly leaves the right boundary, it immediately re-enters through the left boundary.
Periodic boundaries are widely used in global atmospheric and oceanic models because there is no physical edge in the zonal direction.
They are also convenient for idealized experiments and spectral methods because the solution is continuous across the boundary.
Boundary Forcing
Regional atmospheric and oceanic models typically receive information from outside the computational domain.
Instead of connecting the two boundaries, the boundary values are prescribed using observations, reanalysis products, or larger-scale model output.
This approach is referred to as boundary forcing.
Examples include:
- regional weather prediction models
- regional climate models
- nested ocean models
Boundary forcing allows information to enter and leave the model domain while remaining consistent with the surrounding large-scale environment.
Sponge Grids and Sponge Layers
When waves or anomalies approach a model boundary, they may reflect back into the computational domain and contaminate the interior solution.
To reduce these artificial reflections, numerical models often apply damping near the boundary.
A sponge grid damps the solution at a single grid point.
A sponge layer damps the solution gradually over multiple grid points.
Sponge layers are commonly used in idealized atmospheric and oceanic experiments, regional weather models, and limited-area climate models because they absorb outgoing disturbances before they reach the boundary.
Compared with a sponge grid, a sponge layer generally produces fewer artificial reflections.
Model / Equation
Example: One-Dimensional Advection Equation
To illustrate the effects of boundary conditions, we consider the one-dimensional advection equation,
where
Here,
- \(T\) is the transported quantity,
- \(u\) is the constant advection velocity,
- \(x\) is the spatial coordinate,
- \(t\) is time.
The same governing equation can produce very different solutions depending on how the boundaries are treated.
Fixed Boundary Condition
A fixed boundary specifies the value of the variable at the edge of the domain:
In Python:
Tnew[0] = 0.0
Tnew[-1] = 0.0
Any anomaly reaching the boundary is effectively removed from the system.
Periodic Boundary Condition
A periodic boundary identifies the two ends of the computational domain:
An anomaly leaving one side of the domain immediately re-enters from the opposite side.
For simple first-order schemes such as the upwind scheme, only one neighboring value is required at the boundary. In this case, the periodic condition may be implemented as
Tnew[0] = T[-1]
Higher-order numerical schemes often require multiple neighboring grid points beyond the computational domain. To support these schemes, numerical models commonly introduce buffer points (or ghost cells) outside the physical domain.
For example, if two ghost cells are used, the periodic boundary may be implemented as
T[0] = T[-2]
T[1] = T[-1]
where the values near one boundary are copied from the opposite side of the domain.
The number of buffer points depends on the numerical stencil. Higher-order finite-difference schemes generally require more buffer points than lower-order schemes.
Periodic boundaries are widely used in global atmospheric and oceanic models because there is no physical edge in the zonal direction. They are also convenient for idealized experiments and spectral methods because the solution remains continuous across the boundary.
Boundary Forcing
Regional atmospheric and oceanic models typically receive information from outside the computational domain.
Instead of connecting the two boundaries, the boundary values are prescribed using observations, reanalysis products, or larger-scale model output.
This approach is referred to as boundary forcing.
Mathematically, boundary forcing specifies the values at one or both boundaries:
Examples include:
- regional weather prediction models
- regional climate models
- nested ocean models
Boundary forcing allows information to enter and leave the model domain while remaining consistent with the surrounding large-scale environment.
As a simple example, we prescribe a sinusoidal forcing at the left boundary:
where
- \(A\) is the forcing amplitude,
- \(\omega\) is the forcing frequency.
In Python:
T[0] = A * np.sin(omega * time)
This forcing continuously injects a wave-like disturbance into the computational domain.
For simplicity, the right boundary remains unchanged in this example. More realistic applications often prescribe boundary conditions at both boundaries using external datasets or larger-scale model output.
Sponge Grids and Sponge Layers
When waves or anomalies approach a model boundary, they may reflect back into the computational domain and contaminate the interior solution.
One simple approach is to introduce a sponge grid, where the variable is strongly damped at a single grid point:
In Python:
T[ix_sp] = 0.0
This treatment removes part of the outgoing disturbance before it reaches the boundary.
However, a sponge grid can introduce an artificial discontinuity in the solution. For example, forcing \(T\) to zero at a single grid point creates a strong local gradient,
near the sponge location.
Since the advection tendency depends on the spatial gradient,
this artificial gradient may generate unrealistic numerical responses and sometimes produce spurious oscillations or reflections.
To avoid this problem, numerical models often use a sponge layer instead of a single sponge grid.
A sponge layer gradually damps the solution over multiple grid points:
where
The damping strength increases smoothly toward the boundary, allowing outgoing disturbances to be absorbed gradually rather than abruptly.
In Python:
T[xsp:xep] = damping * T[xsp:xep]
where the damping coefficient varies smoothly across the sponge region.
Because the damping is applied gradually, sponge layers generally produce less reflection and fewer numerical artifacts than sponge grids. Consequently, sponge layers are commonly used in idealized atmospheric and oceanic experiments, regional weather models, and limited-area climate models.
Sample Code
The template file for this section is
Run the script:
python 4_2-advection2_template.py
The script produces
4_2-advection2_template.mp4
4_2-advection2_template.png
This template uses the one-dimensional advection equation with an upwind scheme. In this section, we will modify the boundary treatment and examine how it changes the solution.
Exercise
Step 1. Run the Default Boundary Setting
First, create a copy of the template script:
cp 4_2-advection2_template.py 4_2-advection2_step1.py
Modify the number of time steps:
NT = 200
Run the model:
python 4_2-advection2_step1.py
In this experiment, the bell-shaped anomaly moves toward the right boundary. Examine what happens when the anomaly reaches the edge of the domain.
Questions:
- What happens when the anomaly reaches the right boundary?
- Does the anomaly re-enter the domain?
- Does the amplitude remain conserved?
- What boundary condition is implicitly used in this default setting?
Step 2. Fixed Boundary Condition
Next, impose a fixed boundary condition at both edges of the domain.
Create a new script:
cp 4_2-advection2_step1.py 4_2-advection2_fixed.py
In the time integration loop, after updating T, add:
T[0] = 0.0
T[-1] = 0.0
The time integration section should look like:
for n in range(NT - 1):
dTdt = advection_tendency(T, x, U)
T = T + DT * dTdt
T[0] = 0.0
T[-1] = 0.0
T_save[n + 1, :] = T
Run the model:
python 4_2-advection2_fixed.py
Questions:
- What happens when the anomaly reaches the right boundary?
- How does this result differ from the default case?
- Why does the fixed boundary remove information from the domain?
Step 3. Periodic Boundary Condition
Next, impose a periodic boundary condition.
Create a new script:
cp 4_2-advection2_step1.py 4_2-advection2_periodic.py
Modify the advection tendency function as follows:
def advection_tendency(T, x, U):
dTdt = np.zeros_like(T)
dTdt[1:] = -U * np.diff(T) / DX
dTdt[0] = -U * (T[0] - T[-1]) / DX
return dTdt
Run the model:
python 4_2-advection2_periodic.py
Questions:
- What happens when the anomaly leaves the right boundary?
- Does it re-enter from the left boundary?
- How does this result differ from the fixed-boundary experiment?
- Why are periodic boundaries useful for idealized global-domain experiments?
Step 4. Boundary Forcing
Next, prescribe a time-dependent forcing at the left boundary.
Create a new script:
cp 4_2-advection2_step1.py 4_2-advection2_bforce.py
Use zero initial conditions by modifying initial_condition():
def initial_condition(x):
T0 = np.zeros_like(x)
return T0
Then, in the time integration loop, prescribe a sinusoidal boundary value at the left boundary:
for n in range(NT - 1):
dTdt = advection_tendency(T, x, U)
T = T + DT * dTdt
T[0] = 1.75 * np.sin(0.1 * time[n])
T_save[n + 1, :] = T
Run the model:
python 4_2-advection2_bforce.py
Questions:
- How does the boundary forcing enter the domain?
- What kind of disturbance is generated?
- How is this different from an initial-value problem?
- How does the signal propagate through the domain?
Step 5. Sponge Grid and Sponge Layer
Finally, test damping near the right side of the domain.
Create a new script:
cp 4_2-advection2_step1.py 4_2-advection2_sponge.py
Step 5.1 Sponge Grid
First, apply a sponge grid at a single location:
xsp = 35.0
ixsp = np.argmin(np.abs(x - xsp))
Then add this after updating T:
T[ixsp] = 0.0
To visualize the sponge location, add the following line after creating the figure:
ax.axvline(
xsp,
color='k',
linestyle='--',
linewidth=2,
label='Sponge Grid'
)
Run the model and examine the result.
Questions:
- What happens when the anomaly reaches the sponge grid?
- Does the solution remain smooth?
- Does the sponge grid create an artificial sharp gradient?
- Can you identify the location of the sponge grid in the animation?
Step 5.2 Sponge Layer
Next, replace the single sponge grid with a sponge layer:
xsp = 35.0
xep = 45.0
ixs = np.argmin(np.abs(x - xsp))
ixe = np.argmin(np.abs(x - xep))
sigma = (xep - xsp) / 1.5
damping = np.exp(
-((x[ixs:ixe+1] - x[ixs])**2)
/ (2.0 * sigma**2)
)
T[ixs:ixe+1] = damping * T[ixs:ixe+1]
T[ixe] = 0.0
To visualize the sponge layer, add the following line after creating the figure:
ax.axvspan(
xsp,
xep,
color='gray',
alpha=0.2,
label='Sponge Layer'
)
The shaded region indicates where damping is applied.
Run the model again.
Questions:
- How does the sponge layer differ from the sponge grid?
- Is the damping more gradual?
- Does the sponge layer reduce the artificial gradient?
- Which approach produces the smoother solution?
- How does the anomaly behave inside the shaded region?
Compare the results from Step 5.1 and Step 5.2 and discuss why sponge layers are often preferred in atmospheric and oceanic models.
Key Points
- Boundary conditions specify how information behaves at the edge of a computational domain.
- Different boundary treatments can produce substantially different numerical solutions, even when the governing equation remains unchanged.
- Fixed boundary conditions remove information reaching the boundary.
- Reflective boundary conditions cause disturbances to return into the domain and are commonly used in wave problems.
- Periodic boundary conditions connect the two ends of the domain, allowing information leaving one side to re-enter from the opposite side.
- Periodic boundaries are widely used in idealized experiments, global atmospheric models, and spectral methods.
- Boundary forcing prescribes information at one or both boundaries and is commonly used in regional weather and climate models.
- Sponge grids damp the solution at a single location but may create artificial gradients and numerical artifacts.
- Sponge layers gradually damp the solution over multiple grid points and generally produce fewer artificial reflections.
- Sponge layers are commonly used in atmospheric and oceanic models to absorb outgoing disturbances before they reach the boundary.
Homework
Complete the following tasks.
1. Periodic Boundary Condition
Using the periodic boundary experiment from Step 3:
python 4_2-advection2_periodic.py
Generate and submit:
4_2-advection2_periodic.mp4
In a short paragraph, describe:
- what happens when the anomaly reaches the boundary,
- why the anomaly re-enters the domain,
- advantages of periodic boundary conditions for idealized experiments.
2. Sponge Layer with Boundary Forcing
Combine the boundary-forcing experiment (Step 4) with the sponge-layer experiment (Step 5.2).
Create a new script:
cp 4_2-advection2_bforce.py 4_2-advection2_homework.py
Apply the sponge-layer damping while retaining the sinusoidal forcing at the left boundary.
Generate and submit:
4_2-advection2_homework.mp4
In a short paragraph, describe:
- how the boundary forcing enters the domain,
- how the sponge layer modifies the disturbance,
- why sponge layers are commonly used in regional atmospheric and oceanic models.
Optional Further Experiments
Students interested in further exploration may investigate one or more of the following:
- Change the forcing amplitude.
- Change the forcing frequency.
- Change the sponge-layer width.
- Change the sponge-layer location.
- Apply sponge layers at both boundaries.
- Compare sponge grids and sponge layers quantitatively.
- Investigate how different boundary conditions affect the total amount of tracer remaining in the domain.
Discussion Questions
- Which boundary condition is most appropriate for a global atmospheric model?
- Which boundary condition is most appropriate for a regional climate model?
- Why are sponge layers preferred over sponge grids?
- What are the advantages and disadvantages of periodic boundaries?
- How can boundary treatments influence the physical interpretation of numerical simulations?