Solve for the geometric stretch factor that fills a domain of depth z_top with nz layers whose first is dz0 thick.
The layer thicknesses are dz0 * ratio^k, so the column depth is the geometric sum
S(ratio) = dz0 * (ratio^nz - 1) / (ratio - 1),
and the factor wanted is the root of S(ratio) = z_top, found by Newton iteration from ratio = 1.03. The derivative is analytic, so the iteration converges in a handful of passes for any physically sensible (dz0, z_top, nz).
This is the natural construction for an idealized case, where dz0 and z_top are what the user knows a priori and the vertical distribution between them is free. It is not the right construction when a file already carries a vertical distribution worth keeping – see wrf_mean_layer_thickness in ERF_InitFromWRFInput.cpp – because one constant factor cannot represent a stretch ratio that varies with height.
A dz0 at or above the uniform spacing z_top/nz cannot be stretched to fit, since the thicknesses only grow: that case returns the uniform grid with uniform = true, rather than a factor below one that would thin the layers aloft. A single layer is the same situation for a different reason – the sum of one layer is dz0 whatever the factor is, so S has no root and its derivative is identically zero – and is answered the same way.
- Parameters
-
| [in] | dz0 | requested thickness of the first layer |
| [in] | z_top | depth of the column to be filled |
| [in] | nz | number of layers |
| [in] | tol | convergence tolerance on the column depth, in the same units as z_top |
- Returns
- the stretch factor, the first-layer thickness used, and whether it converged
219 const amrex::Real Nz =
static_cast<amrex::Real
>(nz);
220 if (nz < 1 || !(z_top > amrex::Real(0.0)) || !(dz0 > amrex::Real(0.0))) {
227 if (nz == 1 || dz0 >= z_top/Nz) {
229 gs.ratio = amrex::Real(1.0);
230 gs.residual = amrex::Real(0.0);
236 amrex::Real SFact = amrex::Real(1.03);
237 amrex::Real F = dz0 * ( (std::pow(SFact,Nz) - amrex::Real(1.0)) / (SFact - amrex::Real(1.0)) ) - z_top;
239 const int max_iter = 50;
241 while (amrex::Math::abs(F) > tol && iter < max_iter) {
242 const amrex::Real dFdSF = dz0 * ( Nz * std::pow(SFact,Nz-amrex::Real(1.0)) * (SFact - amrex::Real(1.0))
243 - std::pow(SFact,Nz) + amrex::Real(1.0) ) /
244 std::pow(SFact-amrex::Real(1.0),amrex::Real(2.0));
246 const amrex::Real SFact_min = amrex::Real(1.0) + tol;
247 SFact = (SFact > SFact_min) ? SFact : SFact_min;
248 F = dz0 * ( (std::pow(SFact,Nz) - amrex::Real(1.0)) / (SFact - amrex::Real(1.0)) ) - z_top;
256 gs.converged = (amrex::Math::abs(F) <= tol);
Referenced by build_geometric_zlevels().