ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_FireWindExtract.cpp File Reference
Include dependency graph for ERF_FireWindExtract.cpp:

Functions

AMREX_GPU_DEVICE AMREX_FORCE_INLINE void column_wind_at_height (const Array4< const Real > &xvel, const Array4< const Real > &yvel, const Array4< const Real > &z_cc, int ia, int ja, int nz, Real z_target, Real z_ground, Real &u_out, Real &v_out, bool below_first_log=false, Real z0_log=Real(0.1)) noexcept
 Wind at a target height within one atmospheric column. More...
 
AMREX_GPU_DEVICE AMREX_FORCE_INLINE Real log_law_factor (Real z_to, Real z_from, Real z0) noexcept
 Neutral log-law factor ln(z_to / z0) / ln(z_from / z0) More...
 
std::string fire_column_z0_range_error (const MultiFab &col_z0, Real z_low)
 
void fill_fire_wind_from_interpolation (MultiFab &fire_wind_ref, MultiFab &fire_wind_extract_z_mf, const MultiFab &xvel_mf, const MultiFab &yvel_mf, const MultiFab &z_phys_cc_mf, const MultiFab &fire_surface_z_mf, const MultiFab &fire_col_ground_mf, const FireGrid &fg, Real z_ref, int nz, const MultiFab *z_ref_cell_mf, int wind_interp, const MultiFab *col_open, const MultiFab *col_roof, Real z_sample, Real z0_log, bool below_first_log, const MultiFab *col_z0)
 
void extract_fire_wind_k0 (amrex::MultiFab &u_k0, amrex::MultiFab &v_k0, amrex::MultiFab &h_k0, const amrex::MultiFab &xvel, const amrex::MultiFab &yvel, const amrex::MultiFab &z_phys_cc, const amrex::MultiFab *z_phys_nd, const amrex::Geometry &geom)
 The wind at the lowest cell center of each atmospheric column, and its height above that column's ground. More...
 

Function Documentation

◆ column_wind_at_height()

AMREX_GPU_DEVICE AMREX_FORCE_INLINE void column_wind_at_height ( const Array4< const Real > &  xvel,
const Array4< const Real > &  yvel,
const Array4< const Real > &  z_cc,
int  ia,
int  ja,
int  nz,
Real  z_target,
Real  z_ground,
Real &  u_out,
Real &  v_out,
bool  below_first_log = false,
Real  z0_log = Real(0.1) 
)
noexcept

Wind at a target height within one atmospheric column.

Brackets the target height by bisection on the column's terrain-following cell-center heights, averages the face velocities to cell centers at the two bracketing levels, and interpolates linearly between them. A target above the highest cell center takes that level's wind. A target below the lowest cell center takes the lowest center's wind as it is (below_first_log = false, which with a 20 m first cell hands the fire the 10 m wind as its 6.1 m wind, 12 % high at z0 = 0.1 m), or scaled down a neutral log profile of roughness z0_log (below_first_log = true), U(z) = U(z_1) ln(z/z0) / ln(z_1/z0), the better form for a first cell above the reference height. z_ground is the ground height the column heights are measured from; z_target - z_ground is the height above ground.

27 {
28  // Bracket by bisection; z_cc is monotonically increasing in k.
29  int k_lo;
30  // Log-profile factor for a target below the lowest center, from floored
31  // heights (both arguments valid whether or not the branch is taken, so
32  // nothing speculated under the fpe traps can raise a flag).
33  Real below_scale = Real(1.0);
34  if (z_target <= z_cc(ia, ja, 0)) {
35  k_lo = 0;
36  if (below_first_log) {
37  constexpr Real z_tiny = Real(1.0e-30);
38  const Real z0 = std::abs(z0_log) + z_tiny;
39  const Real z1 = amrex::max(z_cc(ia, ja, 0) - z_ground, z0 * Real(1.000001));
40  const Real zt = amrex::max(amrex::min(z_target - z_ground, z1), z0);
41  below_scale = std::log(zt / z0) / std::log(z1 / z0);
42  }
43  } else if (z_target >= z_cc(ia, ja, nz - 1)) {
44  k_lo = nz - 2;
45  } else {
46  int lo = 0;
47  int hi = nz - 1;
48  while (hi - lo > 1) {
49  const int mid = (lo + hi) / 2;
50  if (z_cc(ia, ja, mid) <= z_target) { lo = mid; } else { hi = mid; }
51  }
52  k_lo = lo;
53  }
54  k_lo = amrex::max(0, amrex::min(k_lo, nz - 2));
55  const int k_hi = k_lo + 1;
56 
57  const Real z_lo = z_cc(ia, ja, k_lo);
58  const Real z_hi = z_cc(ia, ja, k_hi);
59  Real alpha = Real(0.0);
60  if (z_hi > z_lo) {
61  alpha = (z_target - z_lo) / (z_hi - z_lo);
62  alpha = amrex::max(Real(0.0), amrex::min(Real(1.0), alpha));
63  }
64 
65  const Real u_lo = Real(0.5) * (xvel(ia, ja, k_lo) + xvel(ia + 1, ja, k_lo));
66  const Real v_lo = Real(0.5) * (yvel(ia, ja, k_lo) + yvel(ia, ja + 1, k_lo));
67  const Real u_hi = Real(0.5) * (xvel(ia, ja, k_hi) + xvel(ia + 1, ja, k_hi));
68  const Real v_hi = Real(0.5) * (yvel(ia, ja, k_hi) + yvel(ia, ja + 1, k_hi));
69 
70  u_out = below_scale * (u_lo + alpha * (u_hi - u_lo));
71  v_out = below_scale * (v_lo + alpha * (v_hi - v_lo));
72 }
Real z0
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:12
@ alpha
Definition: ERF_SLM.H:153
@ xvel
Definition: ERF_IndexDefines.H:232
@ yvel
Definition: ERF_IndexDefines.H:233

Referenced by fill_fire_wind_from_interpolation().

Here is the caller graph for this function:

◆ extract_fire_wind_k0()

void extract_fire_wind_k0 ( amrex::MultiFab &  u_k0,
amrex::MultiFab &  v_k0,
amrex::MultiFab &  h_k0,
const amrex::MultiFab &  xvel,
const amrex::MultiFab &  yvel,
const amrex::MultiFab &  z_phys_cc,
const amrex::MultiFab *  z_phys_nd,
const amrex::Geometry &  geom 
)

The wind at the lowest cell center of each atmospheric column, and its height above that column's ground.

For an engine that drives its fire with the k = 0 wind of the atmospheric columns rather than a wind interpolated to a height (LSFIRE does). The face velocities are averaged to the k = 0 cell center; the height is that center minus the column's ground, the mean of its four k = 0 nodes (the ground compute_fire_surface_height uses), or minus the domain floor without nodal heights.

Parameters
[out]u_k0,v_k0Wind [m/s] on the k = 0 slabs of the level (one per box of the level, the BoxArray of FireForcing::T_k0), with any ghost cells: those are filled with FillBoundary
[out]h_k0Height of that wind above the column's ground [m], laid out as u_k0
[in]xvel,yvelFace velocities of the level (FireForcing::xvel, yvel)
[in]z_phys_ccCell-center height of the level [m]
[in]z_phys_ndNodal height of the level [m], or nullptr (flat floor)
[in]geomGeometry of the level
382 {
383  using namespace amrex;
384  const int k0 = geom.Domain().smallEnd(2);
385  const Real z_floor = geom.ProbLo(2);
386  const bool use_znd = (z_phys_nd != nullptr);
387  for (MFIter mfi(u_k0); mfi.isValid(); ++mfi) {
388  const Box bx = mfi.validbox();
389  const auto u = xvel.const_array(mfi);
390  const auto v = yvel.const_array(mfi);
391  const auto zcc = z_phys_cc.const_array(mfi);
392  const Array4<Real const> znd = use_znd ? z_phys_nd->const_array(mfi) : Array4<Real const>{};
393  const auto us = u_k0.array(mfi);
394  const auto vs = v_k0.array(mfi);
395  const auto hs = h_k0.array(mfi);
396  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int) noexcept
397  {
398  us(i,j,0) = Real(0.5) * (u(i,j,k0) + u(i+1,j,k0));
399  vs(i,j,0) = Real(0.5) * (v(i,j,k0) + v(i,j+1,k0));
400  const Real zsfc = use_znd ? Real(0.25) * (znd(i,j,k0) + znd(i+1,j,k0) + znd(i,j+1,k0) + znd(i+1,j+1,k0))
401  : z_floor;
402  hs(i,j,0) = zcc(i,j,k0) - zsfc;
403  });
404  }
405  u_k0.FillBoundary(geom.periodicity());
406  v_k0.FillBoundary(geom.periodicity());
407  h_k0.FillBoundary(geom.periodicity());
408 }
ParallelFor(fab_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) { qrcuten_arr(i, j, k)=Real(0);qscuten_arr(i, j, k)=Real(0);qicuten_arr(i, j, k)=Real(0);})
Definition: ERF_ConsoleIO.cpp:17
Here is the call graph for this function:

◆ fill_fire_wind_from_interpolation()

void fill_fire_wind_from_interpolation ( MultiFab &  fire_wind_ref,
MultiFab &  fire_wind_extract_z_mf,
const MultiFab &  xvel_mf,
const MultiFab &  yvel_mf,
const MultiFab &  z_phys_cc_mf,
const MultiFab &  fire_surface_z_mf,
const MultiFab &  fire_col_ground_mf,
const FireGrid &  fg,
Real  z_ref,
int  nz,
const MultiFab *  z_ref_cell_mf,
int  wind_interp,
const MultiFab *  col_open,
const MultiFab *  col_roof,
Real  z_sample,
Real  z0_log,
bool  below_first_log,
const MultiFab *  col_z0 
)
134 {
135  const int C = fg.C;
136  // Fire cell (i_f, j_f) lies in atmospheric cell (i_f / C + lo_x, j_f / C + lo_y)
137  const int lo_x = fg.atm_lo[0];
138  const int lo_y = fg.atm_lo[1];
139  const bool bilinear = (wind_interp == 1);
140  const bool open_weights = bilinear && (col_open != nullptr) && (col_roof != nullptr);
141  const bool resample = (z_sample > Real(0.0));
142  const bool z0_cols = (col_z0 != nullptr);
143 
144  // The column roughness is read with the fire grid's MFIter, on its own
145  // k slab, and every value must leave both log profiles well defined.
146  if (z0_cols) {
148  col_z0->size() == fire_wind_ref.size() &&
149  col_z0->DistributionMap() == fire_wind_ref.DistributionMap(),
150  "fill_fire_wind_from_interpolation: col_z0 must have the fire grid's boxes, in its"
151  " order and with its owners (a copy on the level's k = 0 slabs)");
152  for (int n = 0; n < col_z0->size(); ++n) {
153  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(col_z0->boxArray()[n].length(2) == 1 &&
154  col_z0->nGrowVect()[2] == 0,
155  "fill_fire_wind_from_interpolation: col_z0 must be a 2D field, one cell in z");
156  }
157  // Only a run that evaluates a log profile depends on the field
158  if (below_first_log || resample) {
159  Real z_low = (z_ref_cell_mf != nullptr) ? z_ref_cell_mf->min(0) : z_ref;
160  if (resample) { z_low = amrex::min(z_low, z_sample); }
161  const std::string err = fire_column_z0_range_error(*col_z0, z_low);
162  if (!err.empty()) { amrex::Abort("fill_fire_wind_from_interpolation: " + err); }
163  }
164  }
165 
166  // Atmospheric columns the fire grid covers. Across a non-periodic face of
167  // that region the column roughness is taken from the edge column, so only
168  // valid cells of col_z0 are read: FillBoundary does not fill a ghost cell
169  // there, and the range check sees valid cells only.
170  const Box& fire_dom = fg.geom.Domain();
171  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(!z0_cols || fire_dom.ok(),
172  "fill_fire_wind_from_interpolation: col_z0 needs the fire grid's Geometry (create_fire_grid)");
173  const int z0_reg_ilo = lo_x;
174  const int z0_reg_ihi = lo_x + (fire_dom.bigEnd(0) + 1) / C - 1;
175  const int z0_reg_jlo = lo_y;
176  const int z0_reg_jhi = lo_y + (fire_dom.bigEnd(1) + 1) / C - 1;
177  const bool z0_per_x = fg.geom.isPeriodic(0);
178  const bool z0_per_y = fg.geom.isPeriodic(1);
179 
180  for (MFIter mfi(fire_wind_ref, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
181  const Box& bx = mfi.tilebox();
182  Array4<Real> fire_wind = fire_wind_ref.array(mfi);
183  Array4<Real> extract_z = fire_wind_extract_z_mf.array(mfi);
184  Array4<const Real> xvel = xvel_mf.array(mfi);
185  Array4<const Real> yvel = yvel_mf.array(mfi);
186  Array4<const Real> z_phys_cc = z_phys_cc_mf.array(mfi);
187  Array4<const Real> z_surf_arr = fire_surface_z_mf.const_array(mfi);
188  Array4<const Real> z_col_arr = fire_col_ground_mf.const_array(mfi);
189 
190  // Per-cell sampling height, when the engine supplies one
191  Array4<const Real> z_ref_cell_arr;
192  if (z_ref_cell_mf != nullptr) {
193  z_ref_cell_arr = z_ref_cell_mf->const_array(mfi);
194  }
195  const bool per_cell_ht = (z_ref_cell_mf != nullptr);
196 
197  // Open-column weights: the 2D fields carry one ghost cell, which is
198  // all the bilinear stencil reaches; clamp to their box regardless.
199  Array4<const Real> open_arr, roof_arr;
200  int io_min = 0, io_max = 0, jo_min = 0, jo_max = 0;
201  if (open_weights) {
202  open_arr = col_open->const_array(mfi);
203  roof_arr = col_roof->const_array(mfi);
204  const Box& obox = Box(open_arr);
205  io_min = obox.smallEnd(0); io_max = obox.bigEnd(0);
206  jo_min = obox.smallEnd(1); jo_max = obox.bigEnd(1);
207  }
208 
209  // Column roughness: same layout as the open-column fields, read on
210  // the field's own k slab; clamped to the fab and, across a
211  // non-periodic face of the fire grid's region, to its edge column
212  Array4<const Real> z0_arr;
213  int iz_min = 0, iz_max = 0, jz_min = 0, jz_max = 0, kz = 0;
214  if (z0_cols) {
215  z0_arr = col_z0->const_array(mfi);
216  const Box& z0box = Box(z0_arr);
217  iz_min = z0box.smallEnd(0); iz_max = z0box.bigEnd(0);
218  jz_min = z0box.smallEnd(1); jz_max = z0box.bigEnd(1);
219  kz = z0box.smallEnd(2);
220  if (!z0_per_x) {
221  iz_min = amrex::max(iz_min, z0_reg_ilo);
222  iz_max = amrex::min(iz_max, z0_reg_ihi);
223  }
224  if (!z0_per_y) {
225  jz_min = amrex::max(jz_min, z0_reg_jlo);
226  jz_max = amrex::min(jz_max, z0_reg_jhi);
227  }
228  }
229 
230  // Bilinear reaches one atmospheric cell beyond the column holding the
231  // fire cell, and the face average reaches one further in x or y. Both
232  // land in the atmospheric fab's ghost region, which carries two cells
233  // for z_phys_cc and more for the velocities; clamp anyway so a fab
234  // without them degrades to one-sided rather than reading past the end.
235  const Box& zbox = Box(z_phys_cc);
236  const int ia_min = zbox.smallEnd(0);
237  const int ia_max = zbox.bigEnd(0) - 1;
238  const int ja_min = zbox.smallEnd(1);
239  const int ja_max = zbox.bigEnd(1) - 1;
240 
241  amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE (const IntVect& iv) {
242  const int i_f = iv[0];
243  const int j_f = iv[1];
244 
245  // Wind reference height for this cell: its own, or the global one
246  Real z_ref_cell = z_ref;
247  if (per_cell_ht) { z_ref_cell = z_ref_cell_arr(i_f, j_f, 0); }
248 
249  // Height actually sampled and the log-law factor that brings the
250  // sampled wind down to the target height (1 without resampling).
251  // With column roughness the factor is taken per column below and
252  // this one is not applied.
253  const Real z_at = resample ? z_sample : z_ref_cell;
254  const Real f_ref = log_law_factor(z_ref_cell, z_sample, z0_log);
255  const Real scale = (resample && !z0_cols) ? f_ref : Real(1.0);
256 
257  if (!bilinear) {
258  // Nearest atmospheric column: every fire cell in a column shares
259  // one wind vector, so the fire-grid wind is piecewise constant
260  // on atmospheric cells.
261  const int i_a = amrex::max(ia_min, amrex::min(i_f / C + lo_x, ia_max));
262  const int j_a = amrex::max(ja_min, amrex::min(j_f / C + lo_y, ja_max));
263 
264  // Ground elevation of this fire cell's atmospheric column. This
265  // is the terrain surface, not the first cell center, which sits
266  // half an atmospheric cell higher and would push the extraction
267  // height up by an amount that varies with vertical resolution.
268  const Real z_target = z_surf_arr(i_f, j_f, 0) + z_at;
269  extract_z(i_f, j_f, 0) = z_target;
270 
271  // Roughness of this column, and its resampling factor
272  Real z0_c = z0_log;
273  Real s_col = Real(1.0);
274  if (z0_cols) {
275  z0_c = z0_arr(amrex::max(iz_min, amrex::min(i_a, iz_max)),
276  amrex::max(jz_min, amrex::min(j_a, jz_max)), kz);
277  const Real f_c = log_law_factor(z_ref_cell, z_sample, z0_c);
278  s_col = resample ? f_c : Real(1.0);
279  }
280 
281  Real u_out, v_out;
282  column_wind_at_height(xvel, yvel, z_phys_cc, i_a, j_a, nz,
283  z_target, z_surf_arr(i_f, j_f, 0), u_out, v_out,
284  below_first_log, z0_c);
285  fire_wind(i_f, j_f, 0, 0) = scale * (s_col * u_out);
286  fire_wind(i_f, j_f, 0, 1) = scale * (s_col * v_out);
287  return;
288  }
289 
290  // Bilinear between the four surrounding atmospheric columns. The
291  // fire cell center sits at continuous atmospheric cell-center
292  // coordinate (i_f + 0.5)/C - 0.5 relative to the region's corner; the
293  // weights come from that, the column indices add the corner.
294  const Real gx = (Real(i_f) + Real(0.5)) / Real(C) - Real(0.5);
295  const Real gy = (Real(j_f) + Real(0.5)) / Real(C) - Real(0.5);
296  const int i0_local = static_cast<int>(std::floor(gx));
297  const int j0_local = static_cast<int>(std::floor(gy));
298  const Real wx = gx - Real(i0_local);
299  const Real wy = gy - Real(j0_local);
300  const int i0 = i0_local + lo_x;
301  const int j0 = j0_local + lo_y;
302 
303  Real u_sum = Real(0.0);
304  Real v_sum = Real(0.0);
305  Real z_sum = Real(0.0);
306 
307  // Open-column factors and their bilinear sum; fall back to the
308  // plain weights when every column is closed.
309  Real f_open[4] = {Real(1.0), Real(1.0), Real(1.0), Real(1.0)};
310  Real w_norm = Real(1.0);
311  if (open_weights) {
312  Real wsum = Real(0.0);
313  for (int c = 0; c < 4; ++c) {
314  const int di = (c & 1);
315  const int dj = ((c >> 1) & 1);
316  const int io = amrex::max(io_min, amrex::min(i0 + di, io_max));
317  const int jo = amrex::max(jo_min, amrex::min(j0 + dj, jo_max));
318  const Real w = (di ? wx : (Real(1.0) - wx)) * (dj ? wy : (Real(1.0) - wy));
319  f_open[c] = (roof_arr(io, jo, 0) > z_at) ? open_arr(io, jo, 0) : Real(1.0);
320  wsum += w * f_open[c];
321  }
322  if (wsum > Real(1.0e-6)) {
323  w_norm = Real(1.0) / wsum;
324  } else {
325  for (int c = 0; c < 4; ++c) { f_open[c] = Real(1.0); }
326  }
327  }
328 
329  for (int c = 0; c < 4; ++c) {
330  const int di = (c & 1);
331  const int dj = ((c >> 1) & 1);
332  const int ia = amrex::max(ia_min, amrex::min(i0 + di, ia_max));
333  const int ja = amrex::max(ja_min, amrex::min(j0 + dj, ja_max));
334 
335  const Real w = (di ? wx : (Real(1.0) - wx)) * (dj ? wy : (Real(1.0) - wy))
336  * f_open[c] * w_norm;
337 
338  // Each column is sampled at the same height above *its own*
339  // ground: near the surface the profile is anchored to the local
340  // terrain, so blending at one absolute height would sample an
341  // upslope neighbor far higher above ground than asked for.
342  const Real z_target_c = z_col_arr(i_f, j_f, 0, c) + z_at;
343 
344  // Roughness of this column, and its resampling factor
345  Real z0_c = z0_log;
346  Real s_col = Real(1.0);
347  if (z0_cols) {
348  // The wind's column (ia, ja, already clamped), so the
349  // roughness never comes from a different column
350  z0_c = z0_arr(amrex::max(iz_min, amrex::min(ia, iz_max)),
351  amrex::max(jz_min, amrex::min(ja, jz_max)), kz);
352  const Real f_c = log_law_factor(z_ref_cell, z_sample, z0_c);
353  s_col = resample ? f_c : Real(1.0);
354  }
355 
356  Real u_c, v_c;
357  column_wind_at_height(xvel, yvel, z_phys_cc, ia, ja, nz,
358  z_target_c, z_col_arr(i_f, j_f, 0, c), u_c, v_c,
359  below_first_log, z0_c);
360 
361  u_sum += w * (s_col * u_c);
362  v_sum += w * (s_col * v_c);
363  z_sum += w * z_target_c;
364  }
365 
366  extract_z(i_f, j_f, 0) = z_sum;
367  fire_wind(i_f, j_f, 0, 0) = scale * u_sum;
368  fire_wind(i_f, j_f, 0, 1) = scale * v_sum;
369  });
370  }
371 }
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void column_wind_at_height(const Array4< const Real > &xvel, const Array4< const Real > &yvel, const Array4< const Real > &z_cc, int ia, int ja, int nz, Real z_target, Real z_ground, Real &u_out, Real &v_out, bool below_first_log=false, Real z0_log=Real(0.1)) noexcept
Wind at a target height within one atmospheric column.
Definition: ERF_FireWindExtract.cpp:20
std::string fire_column_z0_range_error(const MultiFab &col_z0, Real z_low)
Definition: ERF_FireWindExtract.cpp:98
AMREX_GPU_DEVICE AMREX_FORCE_INLINE Real log_law_factor(Real z_to, Real z_from, Real z0) noexcept
Neutral log-law factor ln(z_to / z0) / ln(z_from / z0)
Definition: ERF_FireWindExtract.cpp:88
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
@ fg
Definition: ERF_AdvanceMorrison.cpp:111
real(c_double), private di
Definition: ERF_module_mp_morr_two_moment.F90:203
Here is the call graph for this function:

◆ fire_column_z0_range_error()

std::string fire_column_z0_range_error ( const MultiFab &  col_z0,
Real  z_low 
)
99 {
100  const Real z0_min = col_z0.min(0);
101  const Real z0_max = col_z0.max(0);
102  if (!(z0_min > Real(0.0))) {
103  return "the column roughness passed to the fire wind sampler has a minimum of "
104  + std::to_string(z0_min) + " m; every value must be positive";
105  }
106  if (!(z0_max * std::exp(Real(1.0)) <= z_low)) {
107  return "the column roughness passed to the fire wind sampler has a maximum of "
108  + std::to_string(z0_max) + " m; e times it must not exceed the lowest height the"
109  " log profile is evaluated at, " + std::to_string(z_low)
110  + " m (the reference height, or the sampling height when that is lower)";
111  }
112  return {};
113 }

Referenced by fill_fire_wind_from_interpolation().

Here is the caller graph for this function:

◆ log_law_factor()

AMREX_GPU_DEVICE AMREX_FORCE_INLINE Real log_law_factor ( Real  z_to,
Real  z_from,
Real  z0 
)
noexcept

Neutral log-law factor ln(z_to / z0) / ln(z_from / z0)

Every argument of the logarithms is kept valid whether or not the caller uses the result: clang evaluates a ternary's arm speculatively in Release, and with resampling off z_from is 0, so log(0) raised the divide-by-zero flag and tripped amrex.fpe_trap_zero on the first step. abs and the tiny offset are not selects, so nothing is folded back into the arm; for positive heights and roughness the values are unchanged. ln(z_to / z0) is floored at zero, so a roughness at or above z_to gives no wind rather than a reversed one, as the clamp below the first center does; the callers keep z0 well below both heights, where the floor is never reached.

89 {
90  constexpr Real z_tiny = Real(1.0e-30);
91  const Real z0_safe = std::abs(z0) + z_tiny;
92  const Real log_to = amrex::max(std::log((std::abs(z_to) + z_tiny) / z0_safe), Real(0.0));
93  const Real log_from = std::log((std::abs(z_from) + z_tiny) / z0_safe);
94  return log_to / (log_from + z_tiny);
95 }

Referenced by fill_fire_wind_from_interpolation().

Here is the caller graph for this function: