Construction of hydrostatically stratified base state
Here we describe how ERF initializes base state values of density and potential temperature such that the density, pressure and potential temperature satisfy both the hydrostatic balance and the equation of state. The base-state density stored in ERF is the dry-air density \(\rho_{d,0}\). The only moisture variable carried in the base state is the water vapor mixing ratio \(q_{v,0}\); when total base-state density is needed, ERF forms \(\rho_{d,0}(1 + q_{v,0})\).
Users have the option to define a dry or moist background state.
Computation of the dry density
We express the total pressure \(p\) as:
By definition, we have:
This gives:
which, on rearranging, yields:
To obtain \(\theta_m\), consider the density of dry air:
Substituting for \(\rho_d\) from the above equation, we get:
which implies:
We also have:
where \(p_v\) is the partial pressure of water vapor, \(r = R_d/R_v \approx 0.622\), and \(q_v\) is the vapor mass mixing ratio—the ratio of the mass of vapor to the mass of dry air. Rearranging and using \(q_v \ll r\), we get:
which, on substitution in the equation for \(\frac{T_v}{T}\), gives:
As \(q_v \ll 1\), a binomial expansion, ignoring higher-order terms, gives:
Hence, the density of dry air is given by:
Initialization with a second-order integration of the hydrostatic equation
We have the hydrostatic equation given by
where \(\rho = \rho_d(1 + q_v)\), \(\rho_d\) is the dry density, and \(q_v\) is the water vapor mixing ratio carried in the base state. Using an average value of \(\rho\) for the integration from \(z = z(k-1)\) to \(z(k)\), we get
The density at a point is a function of the pressure, potential temperature, and relative humidity. The latter two quantities are computed using user-specified profiles, and hence, for simplicity, we write \(\rho(k) = f(p(k))\). Hence
Now, we define
This is a non-linear equation in \(p(k)\). Consider a Newton-Raphson iteration (where \(n\) denotes the iteration number) procedure
which implies
with the gradient being evaluated as
and the iteration update is given by
For the first cell (\(k=0\)), which is at a height of \(z = \frac{\Delta z}{2}\) from the base, we have
where \(p_0 = 1e5 \, \text{N/m}^2\) is the pressure at the base. Hence, we define
and the Newton-Raphson procedure is the same.
The base state on a refined mesh
With mesh refinement, the base state is constructed independently on each level, against that level’s own cell-centered heights \(z_{cc}\), by the same procedure described above. Running the same construction on every level, rather than interpolating the coarse answer, is what leaves each level in discrete hydrostatic balance on its own mesh.
Before that construction runs, the base state on a refined level is filled by conservative interpolation from its parent, and the physical boundary conditions for the base state are applied. That is what gives values to the part of the refined level that lies inside the domain but outside the refined grids, and to the ghost cells; the per-level construction then overwrites only the refined grids.
Two consequences are worth stating explicitly.
A refined level need not span the depth of the domain. The vertical integration is
causal upward: the value in a cell depends only on the cells at or below it. A refined
region that stops partway up the domain therefore gets exactly the base state it would
have had if it had been refined all the way to the model top – the values in the cells it
does contain are unchanged. What the integration does require is a valid starting value
in the lowest cell of each column, which is why the grids must not be decomposed in the
vertical (see Avoiding Decomposition in the Vertical Direction); amr.refine_grid_layout_z
defaults to 0 in ERF, so this holds unless it is overridden.
The base state does not depend on the coupling type. Under two-way coupling ERF averages \(\det J\) down from fine to coarse, so that the volume weighting used when averaging the state down telescopes and remains conservative. The cell-centered heights \(z_{cc}\) are deliberately not averaged down. Were they, the coarse heights would change after the coarse base state had already been built against them, leaving that base state out of hydrostatic balance with the heights the dynamics subsequently use for vertical gradients, Rayleigh damping and the sponge zones. Not averaging them also keeps \(z_{cc}\) consistent with the nodal heights \(z_{nd}\) it is derived from, which are not averaged down either.
Note that the base states of two levels will not be identical to one another wherever their terrain differs – for instance when a finer level resolves topography that its parent does not, either because it re-reads a terrain file at its own resolution or because it reads a nested wrfinput file. Each level is individually hydrostatic; the difference between them is set by the difference in surface elevation and is carried up the column as an essentially constant offset in pressure.
Horizontal pressure gradient over terrain
With terrain-fitted coordinates the two cell centers that straddle a lateral face sit at different physical heights, so the horizontal pressure gradient cannot be formed by differencing the two cell values directly. Writing the face-normal gradient at an \(x\)-face \((i,j,k)\) in terms of the coordinate metric
both options ERF offers have the same algebraic form,
and differ only in the estimate \(S\) of \(\partial p^\prime / \partial z\) used to carry each cell value the signed distance
to the height of the face. The choice is made with erf.gradp_type. It applies only
to fully compressible runs; in anelastic and pseudo-incompressible runs the pressure
gradient comes from the projection and erf.gradp_type is not used.
erf.gradp_type = ChainRule(default) takes \(S\) from a centered difference of \(p^\prime\) in each column, and at the bottom and top of the domain from a two-point one-sided difference. Witherf.gradp_2nd_order_bndry = true(default false) it uses there instead the second-order one-sided difference through the three nearest cells. The two-point difference is only first-order accurate, and since the bottom cell is where the metric term is largest that error can dominate the horizontal force over steep terrain.erf.gradp_type = HydrostaticHybridsplits \(S\) into its hydrostatic part, which it integrates exactly over the segment, and a non-hydrostatic remainder, which alone it differences. It is described below.
(These replace the former integer values 0 and 2, which are still accepted with a
warning. A former erf.gradp_type = 1, the interpolated-pressure gradient of
Klemp (2011), has been removed: in tests over steep terrain it was less accurate than
both options above and less stable than either.)
Why the hydrostatic part matters
“Nearly hydrostatic” means that \(\partial p / \partial z \approx -\rho g\) at all times. Because the base state is itself hydrostatic, that property transfers to the deviation: \(\partial p^\prime / \partial z \approx -\rho^\prime g\). The metric term above is therefore not small compared with the answer – relative to the true horizontal pressure-gradient force it scales as the terrain slope times \(L/D\), the aspect ratio of the flow feature. Over steep terrain one is differencing two terms that are individually larger than their difference, even after the base state has been subtracted, and the truncation error in \(S\) appears directly in the horizontal force. Subtracting a fixed \(p_0\) removes the balance of \(p^\prime\) against \(\rho_0\); it does nothing about the balance of \(p^\prime\) against \(\rho^\prime\), which is a property of the instantaneous solution and so cannot be removed by any stored base state.
The hydrostatic hybrid
erf.gradp_type = HydrostaticHybrid removes that second balance where and when the gradient is
taken. It writes
carries each cell value to the height of the face by integrating the first term exactly and differencing only the remainder \(r\), so that
Here \(\rho^\prime\) is the same quantity that enters the buoyancy term when
erf.buoyancy_type = 1, namely \(\rho (1 + q_t) - \rho_0 (1 + q_{v,0})\), and
\(\tilde\rho^\prime\) is \(\rho^\prime\) reconstructed linearly and evaluated at
the midpoint of the extrapolation segment,
with the vertical derivatives taken as centered differences in the interior of the domain and one-sided differences at the bottom and top. On the \(w\)-face \(k-\tfrac{1}{2}\) the remainder is formed exactly as the \(w\)-momentum equation forms the sum of the vertical pressure gradient and the buoyancy term,
and \(\hat r\) brings it to the cell center with the same \(\Delta z\) weighting that the centered difference of ChainRule implies, \(\hat r_k = (\Delta z^+ r_{k+1/2} + \Delta z^- r_{k-1/2}) / (\Delta z^+ + \Delta z^-)\), using the single interior face at the bottom and top of the domain. Two properties follow.
It is well balanced. If \(r_{k-1/2} = 0\) on every face – the state in which the \(w\)-equation sees no net vertical force – then \(\hat r = 0\) and the horizontal gradient is the pure hydrostatic reconstruction. In particular, if \(\rho^\prime\) is a linear function of \(z\) and \(p^\prime\) is its hydrostatic integral, the same profile in both columns, the computed horizontal gradient vanishes identically, whatever the terrain slope. This is the finite-difference analog of the local hydrostatic reconstruction of Botta, Klein, Langenberg & Lützenkirchen (2004), with \(\rho^\prime\) playing the role of their locally assumed entropy profile.
It is consistent in non-hydrostatic flow. Substituting the definition of \(\hat r\) shows that HydrostaticHybrid is ChainRule plus \(g\,(\partial z/\partial\xi)\,(\tilde\rho^\prime - \hat\rho^\prime)\), where \(\hat\rho^\prime\) is the \(\Delta z\)-weighted average of the two face values of \(\rho^\prime\) (a 1-2-1 filter on a uniform column). That correction vanishes as the mesh is refined, so HydrostaticHybrid converges to the true horizontal gradient whether or not the flow is hydrostatic, and its truncation error acts only on \(r\) rather than on the whole of \(\partial p^\prime / \partial z\).
The remainder is essential. A reconstruction that used \(-g\rho^\prime\) alone in place of \(S\) would discard the non-hydrostatic part of \(\partial p^\prime / \partial z\), and since the metric factor tends to the terrain slope rather than to zero, that error would not shrink with resolution. In a narrow, strongly buoyant plume – a fire, a convective core – the non-hydrostatic pressure largely cancels the hydrostatic integral of \(\rho^\prime\), and the resulting spurious force along the slope is of order \(g\,(\rho^\prime/\rho)\) times the slope. Such a reconstruction also proved unstable at the time steps the other options allow, since its lateral gradient no longer responds to the vertical pressure perturbations the acoustic substep carries.
Two caveats are worth stating. The exact well-balancing relies on \(\rho^\prime\)
being the quantity the buoyancy term uses, i.e. on erf.buoyancy_type = 1; with
another buoyancy formulation HydrostaticHybrid remains consistent but is no longer exactly
balanced. And because the hybrid integrates
\(\partial p^\prime / \partial z = -g \rho^\prime\), it relies on \(p_0\) being
the hydrostatic integral of \(\rho_0\), which is how ERF constructs it. At a state
of rest with \(p = p_0\) and \(\rho = \rho_0\) both options give
identically zero.
Only the lateral gradients are affected. The vertical component \(\partial
p^\prime / \partial z\) used in the \(w\)-momentum equation is computed identically
for both options, which is what keeps it an exact algebraic complement of the
buoyancy term. HydrostaticHybrid always uses the perturbational pressure, regardless of
the setting of erf.use_pert_pres_gradient, and is not currently implemented for
the embedded-boundary terrain representation.
The base state in the lateral ghost cells
At a lateral boundary that is not periodic, the base state has to be given values in the ghost cells outside the domain. Where the boundary reflects – a symmetry or slip wall – the nodal mesh is extended by mirroring, so a ghost cell sits at exactly the height of the cell it reflects, and reflecting the base state with it is right.
Where the boundary is outflow or open, the nodal mesh is instead extrapolated past the domain, and a ghost cell does not sit at the height of the cell just inside it whenever the terrain has a slope where it meets the boundary. Copying the base state outward at constant index, as a zero-gradient condition would, therefore leaves values that belong to a different height than the one the mesh assigns to the cell: the base state there is neither the hydrostatic profile at that height nor in hydrostatic balance along the ghost column, while \(\det J\) and the metric terms in the same column are height-consistent.
ERF instead builds the base state in those ghost cells as the same reference atmosphere sampled at the height the mesh puts them at. Writing \(z_g\) for the height of the ghost cell and \(z_r\) for the height of the cell inside the domain it would otherwise have copied – the nearest cell that is inside the domain laterally, which for a corner means the nearest corner cell – and \(\delta z = z_g - z_r\):
\(p_0\) is carried across the height offset by the hydrostatic relation, using the scale height of the cell it came from,
\[p_0(z_g) = p_0(z_r)\, \exp\!\left(-\frac{g\, \delta z}{R_d T_v}\right), \qquad R_d T_v = \frac{p_0(z_r)}{\rho_0(z_r)}.\]\(\theta_0\) and \(q_{v,0}\) carry over unchanged. Reconstructing them at \(z_g\) would need the profile of the column above and below the cell, and the cells that can be read there are the ones the box in hand happens to hold, so the stencil – and with it the answer – would depend on where the grids are split in the vertical. Holding them fixed leaves an error of \((\partial\theta_0/\partial z)\,\delta z\), which for the offsets a terrain-fitted mesh produces is a few thousandths of a kelvin, against the several pascals in \(p_0\) that the transfer above removes.
\(\rho_0\) and \(\pi_0\) then follow from the equation of state, so that it holds exactly in the ghost cell.
The construction is local to each ghost cell, so it applies to any number of ghost layers and to the corners, and it reduces to the plain copy – bit for bit – wherever the two heights agree. That covers every constant-\(\Delta z\) mesh and any terrain that is flat where it meets the boundary, so runs that were not affected by the height offset in the first place are unchanged.
When terrain is built from a WRF input or metgrid file, the heights the file supplies live at w-faces, while ERF stores terrain at nodes. The nodal heights are obtained by inverting the four-node averaging operator exactly, so that the average of the four nodes around each w-face reproduces the file’s w-face height to round-off; the cell-centered heights, each being the average of the two w-faces that bracket it, then agree with the source as well. That operator is a tensor product of two one-dimensional two-point averages and is surjective, so an exact solution always exists; the remaining freedom is a sawtooth, which is fixed by minimizing the first-difference energy along each line. Should the exact heights fall outside the range of the source data, which very rough terrain can force, ERF warns and falls back to a regularized least-squares fit that stays bounded but no longer reproduces the source exactly.