ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_FireWindExtract.H
Go to the documentation of this file.
1 #ifndef ERF_FIRE_WIND_EXTRACT_H
2 #define ERF_FIRE_WIND_EXTRACT_H
3 
4 #include <AMReX_MultiFab.H>
5 #include <AMReX_Geometry.H>
6 #include <cmath>
7 #include <string>
8 #include <ERF_FireGrid.H>
9 
10 /**
11  * @file ERF_FireWindExtract.H
12  * @brief Atmospheric wind sampled onto the fire grid
13  *
14  * The atmosphere side of the fire coupling: the wind of the atmospheric
15  * columns at a height above ground (a uniform height, or one per fire cell
16  * that the fire engine supplies), interpolated linearly in height and
17  * bilinearly or nearest between the surrounding columns, with an optional
18  * two-height log-law resampling; no MOST reconstruction is involved. A fire
19  * engine may read its wind through it. What the engine does with the wind
20  * afterwards (wind adjustment factors, terrain corrections) is the engine's.
21  */
22 
23 
24 /**
25  * @brief Extract wind from direct vertical interpolation on fire grid
26  *
27  * Maps atmospheric wind to fire grid at reference height by interpolating
28  * vertically through the atmospheric column at the fire cell location.
29  * Uses cell-center wind values (averaged from face-staggered data) and
30  * linearly interpolates to the target height above terrain.
31  *
32  * When z_ref_cell_mf is non-null, each fire cell is sampled at its own height
33  * from that field (for example a per-fuel wind height, as in the WRF-SFIRE
34  * fcwh convention) instead of the global z_ref.
35  *
36  * @param[out] fire_wind_ref u,v at z_ref on fire grid [m/s]
37  * @param[out] fire_wind_extract_z_mf Wind extraction height z_target [m]
38  * @param[in] xvel_mf x-velocity (face-staggered at i+1/2, j, k)
39  * @param[in] yvel_mf y-velocity (face-staggered at i, j+1/2, k)
40  * @param[in] z_phys_cc_mf Cell-center terrain height z_phys_cc[0] on atm grid
41  * @param[in] fg Fire grid
42  * @param[in] z_ref Global fallback wind reference height [m]
43  * @param[in] nz Number of vertical levels
44  * @param[in] z_ref_cell_mf Height above ground [m] to sample each fire cell
45  * at, on the fire grid; nullptr = the global z_ref
46  * @param[in] below_first_log Target below the lowest cell center: false takes the
47  * lowest center's wind as it is; true scales it
48  * with a neutral log profile of roughness z0_log,
49  * U(z) = U(z_1) ln(z/z0)/ln(z_1/z0)
50  * @param[in] col_z0 Roughness length [m] of each atmospheric column
51  * (2D, laid out as col_open, one filled ghost
52  * cell), used in place of z0_log in both log
53  * profiles; nullptr = the scalar z0_log everywhere
54  *
55  * Algorithm per fire cell (i_f, j_f):
56  * 1. Map to atmospheric column: i_a = i_f / C, j_a = j_f / C
57  * 2. Get ground elevation: z_surf = fire_surface_z(i_f, j_f), the average of the
58  * four k = 0 nodes of atmospheric cell (i_a, j_a). Using z_phys_cc(i_a, j_a, 0)
59  * instead would sit half an atmospheric cell above the ground.
60  * 3. Lookup wind height:
61  * - If z_ref_cell_mf != nullptr: z_ref_cell = z_ref_cell_mf(i_f, j_f)
62  * - Otherwise: z_ref_cell = z_ref (global)
63  * 4. Compute target height: z_target = z_surf + z_ref_cell
64  * 5. Bisection on the column's z_phys_cc profile for k_lo such that
65  * z_phys_cc(i_a, j_a, k_lo) <= z_target < z_phys_cc(i_a, j_a, k_lo+1),
66  * clamped to [0, nz-2]; a target above the top takes the highest center,
67  * a target below the first center the lowest center's wind scaled by the
68  * log profile (below_first_log) or as it is
69  * 6. Compute interpolation weight:
70  * alpha = (z_target - z_phys_cc(i_a, j_a, k_lo)) /
71  * (z_phys_cc(i_a, j_a, k_lo+1) - z_phys_cc(i_a, j_a, k_lo))
72  * Clamp alpha to [0, 1]
73  * 7. Average u/v from bracketing face values to get cell centers:
74  * u_cc(i,j,k) = 0.5 * (xvel(i,j,k) + xvel(i+1,j,k))
75  * v_cc(i,j,k) = 0.5 * (yvel(i,j,k) + yvel(i,j+1,k))
76  * 8. Interpolate: fw(i_f,j_f,0,0) = u_cc(k_lo) + alpha*(u_cc(k_lo+1) - u_cc(k_lo))
77  * fw(i_f,j_f,0,1) = v_cc(k_lo) + alpha*(v_cc(k_lo+1) - v_cc(k_lo))
78  * 9. Store z_target in fire_wind_extract_z_mf
79  *
80  * With wind_interp = 1 (bilinear, the default) steps 3-8 run for each of the
81  * four atmospheric columns surrounding the fire cell, every one sampled at the
82  * reference height above *its own* ground, and the results are blended with
83  * bilinear weights. With wind_interp = 0 only the column containing the cell is
84  * used, which makes the fire-grid wind piecewise constant on atmospheric cells.
85  *
86  * With col_open and col_roof given (2D atmospheric-column fields, one ghost
87  * cell) each bilinear weight is multiplied by the column's open fraction when
88  * its roof is above the cell's wind height, and the four weights are
89  * renormalized, so a column inside a building does not contribute its
90  * relaxed in-building velocity to the fire cells around it. A cell whose four
91  * columns are all closed keeps the plain weights; it is inside a footprint
92  * and masked anyway.
93  *
94  * With z_sample > 0 (an engine input) every column is sampled at
95  * z_sample above its ground instead of at the target height, and the result
96  * is brought down to the target height with a neutral log profile of
97  * roughness z0_log: U(z_ref) = U(z_sample) ln(z_ref / z0) / ln(z_sample / z0).
98  * This is the second interpolation option of the Community Fire Behavior
99  * Model (Jimenez y Munoz et al. 2026), meant to drive the fire with a wind
100  * taken above its own plume. fire_wind_extract_z then records the sampled
101  * height; the open-column test uses that height as well.
102  *
103  * With col_z0 given (a 2D roughness field [m] of the atmospheric columns)
104  * both log profiles above use the roughness of the column being sampled
105  * instead of z0_log: the below-first-center scaling of each column, and with
106  * z_sample > 0 the resampling factor, which is then applied to each column
107  * before the bilinear blend. Without col_z0 the result is unchanged, bit for
108  * bit. The field is read with the fire grid's MFIter, so it must have the fire
109  * grid's boxes, in its order and with its owners: a copy of the surface
110  * layer's z_0 (SurfaceLayer::get_z0) onto the level's k = 0 slabs, the layout
111  * of col_open, works; z_0 itself does not where the fire grid covers a cropped
112  * region or the terrain is EB (z_0 is then 3D). Its ghost cell must be filled
113  * with FillBoundary before the call (interior and periodic ghosts). Across a
114  * non-periodic face of the fire grid's region (fg.geom) a column outside the
115  * region takes the edge column's roughness, so ghost cells there are never
116  * read and need no fill. Where the sea roughness varies in time
117  * (SurfaceLayer::have_variable_sea_roughness) the copy is refreshed before
118  * every call. When a log profile is evaluated (below_first_log, or
119  * z_sample > 0) the call aborts unless every valid value is positive and e
120  * times the largest does not exceed the lowest height a log profile is
121  * evaluated at (z_ref or the smallest z_ref_cell, and z_sample when
122  * resampling), the bound fire_column_z0_range_error checks; otherwise the
123  * field is not used and not checked.
124  *
125  * The per-column log law from z_sample assumes each column is in equilibrium
126  * with its own roughness up to z_sample. Across a sharp roughness change the
127  * internal boundary layer one atmospheric cell downwind is often shallower
128  * than that, so the per-column factor overstates the local effect there.
129  */
131  amrex::MultiFab& fire_wind_ref,
132  amrex::MultiFab& fire_wind_extract_z_mf,
133  const amrex::MultiFab& xvel_mf,
134  const amrex::MultiFab& yvel_mf,
135  const amrex::MultiFab& z_phys_cc_mf,
136  const amrex::MultiFab& fire_surface_z_mf,
137  const amrex::MultiFab& fire_col_ground_mf,
138  const FireGrid& fg,
139  amrex::Real z_ref,
140  int nz,
141  const amrex::MultiFab* z_ref_cell_mf = nullptr,
142  int wind_interp = 1,
143  const amrex::MultiFab* col_open = nullptr,
144  const amrex::MultiFab* col_roof = nullptr,
145  amrex::Real z_sample = 0.0,
146  amrex::Real z0_log = 0.1,
147  bool below_first_log = false,
148  const amrex::MultiFab* col_z0 = nullptr);
149 
150 /**
151  * @brief Range check of a column roughness field for the fire wind sampler
152  *
153  * @param[in] col_z0 Roughness [m] of the atmospheric columns (valid cells are checked)
154  * @param[in] z_low Lowest height [m] a log profile is evaluated at
155  * @return An empty string when every value z0 satisfies 0 < z0 and e z0 <= z_low
156  * (so ln(z_low / z0) >= 1), otherwise the reason. Collective over MPI.
157  */
158 std::string fire_column_z0_range_error (const amrex::MultiFab& col_z0, amrex::Real z_low);
159 
160 /**
161  * @brief The wind at the lowest cell center of each atmospheric column, and
162  * its height above that column's ground
163  *
164  * For an engine that drives its fire with the k = 0 wind of the atmospheric
165  * columns rather than a wind interpolated to a height (LSFIRE does). The face
166  * velocities are averaged to the k = 0 cell center; the height is that center
167  * minus the column's ground, the mean of its four k = 0 nodes (the ground
168  * compute_fire_surface_height uses), or minus the domain floor without nodal
169  * heights.
170  *
171  * @param[out] u_k0, v_k0 Wind [m/s] on the k = 0 slabs of the level (one per box of
172  * the level, the BoxArray of FireForcing::T_k0), with any
173  * ghost cells: those are filled with FillBoundary
174  * @param[out] h_k0 Height of that wind above the column's ground [m], laid out as u_k0
175  * @param[in] xvel, yvel Face velocities of the level (FireForcing::xvel, yvel)
176  * @param[in] z_phys_cc Cell-center height of the level [m]
177  * @param[in] z_phys_nd Nodal height of the level [m], or nullptr (flat floor)
178  * @param[in] geom Geometry of the level
179  */
181  amrex::MultiFab& u_k0,
182  amrex::MultiFab& v_k0,
183  amrex::MultiFab& h_k0,
184  const amrex::MultiFab& xvel,
185  const amrex::MultiFab& yvel,
186  const amrex::MultiFab& z_phys_cc,
187  const amrex::MultiFab* z_phys_nd,
188  const amrex::Geometry& geom);
189 
190 #endif
Fire grid data structure and construction.
void fill_fire_wind_from_interpolation(amrex::MultiFab &fire_wind_ref, amrex::MultiFab &fire_wind_extract_z_mf, const amrex::MultiFab &xvel_mf, const amrex::MultiFab &yvel_mf, const amrex::MultiFab &z_phys_cc_mf, const amrex::MultiFab &fire_surface_z_mf, const amrex::MultiFab &fire_col_ground_mf, const FireGrid &fg, amrex::Real z_ref, int nz, const amrex::MultiFab *z_ref_cell_mf=nullptr, int wind_interp=1, const amrex::MultiFab *col_open=nullptr, const amrex::MultiFab *col_roof=nullptr, amrex::Real z_sample=0.0, amrex::Real z0_log=0.1, bool below_first_log=false, const amrex::MultiFab *col_z0=nullptr)
Extract wind from direct vertical interpolation on fire grid.
std::string fire_column_z0_range_error(const amrex::MultiFab &col_z0, amrex::Real z_low)
Range check of a column roughness field for the fire wind sampler.
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 gro...
Definition: ERF_FireWindExtract.cpp:373
@ fg
Definition: ERF_AdvanceMorrison.cpp:111
@ xvel
Definition: ERF_IndexDefines.H:232
@ yvel
Definition: ERF_IndexDefines.H:233
2D horizontal fire computational grid
Definition: ERF_FireGrid.H:42