Primitive equation model
The primitive equations are a hydrostatic approximation of the compressible Navier-Stokes equations for an ideal gas on a rotating sphere. We largely follow the idealised spectral dynamical core developed by GFDL[^GFDL1] and documented therein[^GFDL2].
The primitive equations solved by SpeedyWeather.jl for relative vorticity
with velocity
The parameterizations for the tendencies of
SpeedyWeather.jl implements a PrimitiveWet and a PrimitiveDry dynamical core. For a dry atmosphere, we have
Virtual temperature
In short: Virtual temperature
Virtual temperature is the temperature dry air would need to have to be as light as moist air. It is used in the dynamical core to include the effect of humidity on the density while replacing density through the ideal gas law with temperature.
We assume the atmosphere to be composed of two ideal gases: Dry air and water vapor. Given a specific humidity
with the respective specific gas constants
We ultimately want to replace the density
Starting with the last equation, with some manipulation we can write the ideal gas law as total density
Now we identify
as some constant that is positive for water vapor being lighter than dry air (
as the specific humidity. Given temperature
For completeness we want to mention here that the above product, because it is a product of two variables
with a global constant temperature
Vertical coordinates
We start with some general considerations that apply when changing the vertical coordinate from height
So you can think of
But for derivatives with respect to
So we first take the derivative of
Sigma coordinates
The problem with pure pressure coordinates is that they are not terrain-following. For example, the 1000 hPa level in the Earth's atmosphere cuts through mountains. A flow field on such a level is therefore not continuous and one would need to deal with boundaries. Especially with spherical harmonics we need a terrain-following vertical coordinate to transform between continuous fields in grid-point space and spectral space.
SpeedyWeather.jl currently uses so-called sigma coordinates for the vertical. This coordinate system uses fraction of surface pressure in the vertical, i.e.
with
Vertical indexing
Pressure, sigma, or hybrid coordinates in the vertical range from lowest values at the top to highest values at the surface. Consistently, we also index the vertical dimension top to surface. This means that
Sigma coordinates are therefore terrain-following, as
One chooses
The layer thickness in terms of pressure is
which can also be expressed with the layer thickness in sigma coordinates
Geopotential
In the hydrostatic approximation the vertical momentum equation becomes
meaning that the (negative) vertical pressure gradient is given by the density in that layer times the gravitational acceleration. The heavier the fluid the more the pressure will increase below. Inserting the ideal gas law
with the geopotential
Note that we use the Virtual temperature here as we replaced the density through the ideal gas law with temperature. Given a vertical temperature profile
or onto full levels with
We use this last formula first to get from
Semi-implicit time integration: Geopotential
With the semi-implicit time integration in SpeedyWeather the Geopotential is not calculated from the spectral temperature at the current, but at the previous time step. This is because this is a linear term that we solve implicitly to avoid instabilities from gravity waves. For details see section Semi-implicit time stepping.
Surface pressure tendency
The surface pressure increases with a convergence of the flow above. Written in terms of the surface pressure directly, and not its logarithm
For
which can be thought of as a vertical integration of the pressure thickness-weighted divergence. In
Using the logarithm of pressure
The second term is the divergence
which is form used by SpeedyWeather.jl to calculate the tendency of (the logarithm of) surface pressure.
As we will have
But note that it would also be possible to do
Meaning that we would compute the vertical average in grid-point space, subtract from the pressure gradient flux before transforming to spectral space. The same amount of transforms are performed but in the latter, the vertical averaging is done in grid-point space.
Semi-implicit time integration: Surface pressure tendency
With the semi-implicit time integration in SpeedyWeather the
Vertical advection
The advection equation
Starting from this equation in pressure layer
In sigma coordinates, the vertical mass flux can be expressed as
We now expand the horizontal divergence term using the product rule, thus:
From the continuity equation in sigma coordinates (mass conservation):
Substituting this into the equation:
Rearranging terms, we obtain:
With the reconstruction at the faces,
However, note that this scheme is dispersive and easily leads to instabilities at higher resolution, where a more advanced vertical advection scheme becomes necessary. For convenience, we may write
Vertical velocity
In the section Surface pressure tendency we used that the surface pressure changes with the convergence of the flow above, which derives from the conservation of mass. Similarly, the conservation of mass for layer
Meaning that the pressure thickness
When integrating from the top down to layer
In sigma coordinates we have
With
See also Hoskins and Simmons, 1975[^HS75]. These vertical averages are the same as required by the Surface pressure tendency and in the Temperature equation, they are therefore all calculated at once, storing the partial averages
Pressure gradient
The pressure gradient term in the primitive equations is
with density
Using the hydrostatic equation
Or, in terms of the geopotential
which is the actual reason why we use pressure coordinates: As density
where the last step inserts the hydrostatic equation again. With the ideal gas law, and note that we use Virtual temperature
Combining the pressure in denominator and gradient to the logarithm and with
From left to right: The pressure gradient force in
In our vorticity-divergence formulation and with sigma coordinates.
Semi-implicit pressure gradient
With the semi-implicit time integration in SpeedyWeather.jl the pressure gradient terms are further modified as follows. See that section for details why, but here is just to mention that we need to split the terms into linear and non-linear terms. The linear terms are then evaluated at the previous time step for the implicit scheme such that we can avoid instabilities from gravity waves.
We split the (virtual) temperature into a reference vertical profile
In the vorticity equation the term with the reference profile drops out as
Vorticity advection
Vorticity advection in the primitive equation takes the form
Meaning that we add the Coriolis parameter
with
Humidity equation
The dynamical core treats humidity as an (active) tracer, meaning that after the physical parameterizations for humidity
With
A very similar equation is solved for (absolute) temperature as described in the following.
Temperature equation
The first law of thermodynamic states that the internal energy
For fluids we replace the differential
Using the ideal gas law to replace
we have
And further, with
This is the form of the temperature equation that SpeedyWeather.jl uses. Temperature is advected through the material derivative and first term on the right-hand side represents an adiabatic conversion term describing how the temperature changes with changes in pressure. Recall that this term originated from the work term in the first law of thermodynamics. The forcing term
Similar to the Humidity equation we write the equation for (absolute) temperature
with
In sigma coordinates this simplifies to, following similar steps as in Surface pressure tendency
Let
The
Semi-implicit temperature equation
For the semi-implicit scheme we need to split the temperature equation into linear and non-linear terms, as the linear terms need to be evaluated at the previous time step. Decomposing temperature
Note that we do not change the adiabatic conversion term. While its linear component
Semi-implicit time stepping
Conceptually, the semi-implicit time stepping in the Primitive equation model is the same as in the Shallow water model, but
tendencies for divergence
, logarithm of surface pressure but also temperature are computed semi-implicitly,the vertical layers are coupled, creating a linear equation system that is solved via matrix inversion.
The linear terms of the primitive equations follow a linearization around a state of rest without orography and a reference vertical temperature profile. The scheme described here largely follows Hoskins and Simmons [^HS75], which has also been used in Simmons and Burridge [^SB81].
As before, let
with
where we gathered the uncorrected right-hand side as
So for every linear term in
Evaluate it at the previous time step
Or, evaluate it at the current time step
as , but then move it back to the previous time step by adding (in spectral space) the linear operator evaluated with the difference between the two time steps.
If there is a tendency that is easily evaluated in spectral space it is easier to follow 1. However, a term that is costly to evaluate in grid-point space should usually follow the latter. The reason is that the previous time step is generally not available in grid-point space (unless recalculated through a costly transform or stored with additional memory requirements) so it is easier to follow 2 where the
So what is
For the pressure tendency, the subtraction with the thickness-weighted vertical average
The operators
With the
Solving for
via
(
The other tendencies
through
on the time step ,through
on the vertical level spacingthrough
on the reference temperature profile
so for any changes of these the matrix inversion of
- Precompute the linear operators
and with them the matrix inversion .
Then for every time step
Compute the uncorrected tendencies evaluated at the current time step for the explicit terms and the previous time step for the implicit terms.
Exception in SpeedyWeather.jl is the adiabatic conversion term, which is, using
moved afterwards from the current to the previous time step .Compute the combined tendency
from the uncorrected tendencies , , .With the inverted operator get the corrected tendency for divergence,
.Obtain the corrected tendencies for temperature
and surface pressure from .Apply Horizontal diffusion (which is only mentioned here as it further updates the tendencies).
Use
, and in the Leapfrog time integration.
Horizontal diffusion
Horizontal diffusion in the primitive equations is applied to vorticity
The horizontal diffusion is applied implicitly in spectral space, as already described in Horizontal diffusion for the barotropic vorticity equation.
Algorithm
The following algorithm describes a time step of the PrimitiveWetModel, for the PrimitiveDryModel humidity can be set to zero and respective steps skipped.
- Start with initial conditions of relative vorticity
, divergence , temperature , humidity and the logarithm of surface pressure in spectral space. Variables are defined on all vertical levels, the logarithm of surface pressure only at the surface. Transform this model state to grid-point space, obtaining velocities is done as in the shallow water model
Invert the Laplacian of
to obtain the stream function in spectral spaceInvert the Laplacian of
to obtain the velocity potential in spectral spaceobtain velocities
fromTransform velocities
, to grid-point spaceUnscale the
factor to obtain
Additionally we
Transform
, , to in grid-point spaceCompute the (non-linearized) Virtual temperature in grid-point space.
Now loop over
Compute all tendencies of
due to physical parameterizations in grid-point space.Compute the gradient of the logarithm of surface pressure
in spectral space and convert the two fields to grid-point space. Unscale the on the fly.For every layer
compute the pressure flux in grid-point space.For every layer
compute a linearized Virtual temperature in spectral space.For every layer
compute a temperature anomaly (virtual and absolute) relative to a vertical reference profile in grid-point space.Compute the Geopotential
by integrating the virtual temperature vertically in spectral space from surface to top.Integrate
vertically to obtain in grid-point space and also in spectral space. Store on the fly also for every layer the partial integration from 1 to (top to layer above). These will be used in the adiabatic term of the Temperature equation.Compute the Surface pressure tendency with the vertical averages from the previous step. For the semi-implicit time stepping
For every layer
compute the Vertical velocity.For every layer
add the linear contribution of the Pressure gradient to the geopotential in spectral space.For every layer
compute the Vertical advection for and add it to the respective tendency.For every layer
compute the tendency of due to Vorticity advection and the Pressure gradient and add to the respective existing tendency. Unscale , transform to spectral space, take curl and divergence to obtain tendencies for .For every layer
compute the adiabatic term and the horizontal advection in the Temperature equation in grid-point space, add to existing tendency and transform to spectral.For every layer
compute the horizontal advection of humidity in the Humidity equation in grid-point space, add to existing tendency and transform to spectral.For every layer
compute the kinetic energy , transform to spectral and add to the Geopotential. For the semi-implicit time stepping also add the linear pressure gradient calculated from the previous time step. Now apply the Laplace operator and subtract from the divergence tendency.Correct the tendencies following the semi-implicit time integration to prevent fast gravity waves from causing numerical instabilities.
Compute the horizontal diffusion for the advected variables
Compute a leapfrog time step as described in Time integration with a Robert-Asselin and Williams filter
Transform the new spectral state of
, , , and to grid-point as described in 0.Possibly do some output
Repeat from 1.
Scaled primitive equations
TODO
References
[^GFDL1]: Geophysical Fluid Dynamics Laboratory, Idealized models with spectral dynamics
[^GFDL2]: Geophysical Fluid Dynamics Laboratory, The Spectral Dynamical Core
[^Vallis]: GK Vallis, 2006. Atmopsheric and Ocean Fluid Dynamics, Cambridge University Press.
[^SB81]: Simmons and Burridge, 1981. An Energy and Angular-Momentum Conserving Vertical Finite-Difference Scheme and Hybrid Vertical Coordinates, Monthly Weather Review. DOI: 10.1175/1520-0493(1981)109<0758:AEAAMC>2.0.CO;2.
[^HS75]: Hoskins and Simmons, 1975. A multi-layer spectral model and the semi-implicit method, Quart. J. R. Met. Soc. DOI: 10.1002/qj.49710142918