Repository navigation
Gridded rain and a moving rain cell - #13
Merged
Merged
Conversation
Adds flume.rain.type = gridded (ESRI ASCII rain grids listed with their times in an index file, mapped to the solver cells by exact cell means and weighted in time by differences of cumulative step or linear weights) and flume.rain.type = moving_cell (a Gaussian cell moving at constant velocity: exact erf cell means, 4-point Gauss-Legendre in time on sub-intervals of at most sigma/4 of travel). Both return the depth of a step, so a closed domain receives the integral of the input to round-off. A grid that does not cover the domain, a NODATA cell read, a negative rate read, a bad index line and every out-of-range cell key stop the run with a message naming the input. Raster edges within 16 epsilons of a whole raster unit are snapped to it (also in holding_cell, bit-identical there). Ghost cells and NaNs: both providers write valid cells only and the rain source reads valid cells only; raster values are checked for NODATA and negative rates before they enter a sum. Runs with none, constant or hyetograph rain are bit-identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The rain documentation of this branch moves to the new pages: inputs in Inputs.rst, the index file format in InputFiles.rst, the model in theory/SourceTerms.rst (Rain that varies in space), the tests in TestCatalog.rst and the measured errors in Verification.rst. Model.rst stays deleted as on development. README and the index page list gridded rain and the moving cell as available. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #11
Summary
#11 added rain that is the same in every cell. This PR adds two kinds of rain that change from place to place:
flume.rain.type = gridded): a time series of rain grids, for example from a radar or a weather model. Each grid is an ESRI ASCII file of the rate in mm/h, on its own cells. An index file lists the grids with their times.flume.rain.type = moving_cell): a storm cell whose rate falls off as a Gaussian from a centre that moves at a constant velocity. It is analytic, so tests can check a field that varies in space and time against a closed form.Both use the forcing interface of #11. The solver asks for the depth of rain over a step, and the providers return the integral of the rate over each cell and over the step. A closed domain therefore receives the integral of the input over the domain and over the run to round-off, whatever the grid sizes and the steps are.
Each grid is mapped to the solver's cells by the mean over each cell (the area each grid cell shares with the solver cell). A grid that does not cover the domain stops the run. Grids are read again when a step needs them. The run keeps only the grids a later step can still use, plus one grid at a time that only the current step uses, so a long series is not held in memory.
Runs with
none,constantorhyetographrain are bit-identical todevelopment: their code path is unchanged.Theory
Gridded rain, space. Entry$k$ of the index is a time $T_k$ and a grid of rates $g_{k,m}$ (m/s) on cells $A_m$ . On a solver cell $\Omega_{ij}$ of area $|\Omega_{ij}|$ the mapped rate is
Why: the sum of$M_{k,ij},|\Omega_{ij}|$ over the domain is the integral of the grid over the domain. The cell edges are computed in grid units by one formula, so neighbouring cells share each edge bit for bit and the overlaps along a row add up to the row's width. An edge within 16 epsilons of a whole grid unit is set to that whole number, so a solver edge that lies on a grid edge does not reach a sliver of the next grid cell (a NODATA cell there would otherwise stop the run).
Gridded rain, time. The depth of a step from$t^n$ to $t^{n+1}$ is
where$W_k(t)$ is the integral up to $t$ of the weight of entry $k$ in the rate: 1 from $T_k$ to $T_{k+1}$ ($T_k$ and 0 at $T_{k\pm1}$ ($T_0$ the first grid holds, and after $T_N$ the last. Why a difference: the end of one step is the start of the next, so the weights of all the steps add up to those of the whole run.
step), or the hat function that is 1 atlinear). BeforeMoving cell. With peak rate$P$ , standard deviation $\sigma$ , centre $\mathbf{c}_0$ at $t = 0$ and velocity $\mathbf{v}$ ,
The mean over the cell$[x_a, x_b] \times [y_a, y_b]$ at one time is exact:
Each difference is formed from$\mathrm{erfc}$ on the side away from the centre, so a cell far from the centre keeps its digits. The time integral uses the 4-point Gauss-Legendre rule on $n = \max(1, \lceil 4|\mathbf{v}|,\Delta t/\sigma \rceil)$ sub-intervals, so the centre moves at most $\sigma/4$ in each. A cell at rest needs one sub-interval and is exact. A cell of peak 0 delivers no rain and skips the work. A step that would need more than $10^4$ sub-intervals (the centre moves more than $2500\sigma$ ) stops the run with a message naming
flume.rain.cell.sigmaand the step controls.Changes
Conservative raster mapping (
Source/FLUME_Raster.cpp:478)sample_conservative: the mean of a raster over each cell. ANODATA_valuecell that shares area with a solver cell is counted and stops the run, as for the other rasters.snap_whole: the 16-epsilon snap of an edge to a whole raster unit.holding_cellnow uses it too (same formula as before, bit-identical).Gridded rain (
Source/FLUME_RainField.H:66,Source/FLUME_RainField.cpp:193)read_rain_index: parsed on the I/O rank, then broadcast. Every line is checked (two items, a finite time, times strictly increasing;#starts a comment). A relative grid path is taken from the index file's directory.GriddedRain: reads and maps every grid at start-up to check it (covers the domain, no NODATA read, no rate below 0 in the part read) and keeps its largest mapped rate for the step bound. During the run each grid is read again when a step needs it. Grids that no later step can use are dropped; a grid only the current step uses is read into a temporary and freed at once. Grids whose largest rate is 0 are not read during the run.entry_weights: the time weights above.Moving cell (
Source/FLUME_RainField.H:111,Source/FLUME_RainField.cpp:311)MovingCellRain: the exact cell mean and the Gauss-Legendre time rule. Centre positions are formed in double precision relative toflume.prob_loand passed to the device.Provider selection (
Source/FLUME_Forcing.cpp:225,Source/FLUME_Flood.cpp:147)make_forcingnow takes the geometry, boxes and distribution of the run.Inputs (
Source/FLUME_Inputs.cpp:462)flume.rain.typenonegriddedandmoving_cell.microphysicsstill stops the run (reserved).flume.rain.filehyetographorgriddedgridded: the index file, lines of a time (s) and a grid path.flume.rain.interpolationstepgridded.flume.rain.cell.peak_ratemoving_cellflume.rain.cell.sigmamoving_cellflume.rain.cell.centermoving_cellflume.rain.cell.velocity0 0Each
flume.rain.cell.*key withoutmoving_cell, andflume.rain.interpolationwithmoving_cell, stops the run with a message naming the key.Inputs.rst(input rows),InputFiles.rst("Gridded rain index files"),theory/SourceTerms.rst("Rain that varies in space"),TestCatalog.rst(the new tests),Verification.rst(the measured differences).README.mdand the index page list gridded rain and the moving cell as available.Tests/RainField/: decks, synthetic grids and index files with the script that writes them, bad files,check_rain_field.py,RainFieldTests.cmakeand aREADME.md. The reserved-type abort tests inTests/Rain/RainTests.cmakenow covermicrophysicsonly.Ghost cells and NaNs: both providers write valid cells only; the rain source reads valid cells only. A raster value is checked for NODATA and for a negative rate before it enters a sum.
Results
Closed, flat, dry domain of 24 × 16 cells of 2 m in 6 boxes, against a reference computed independently from the files (areas in metres, time split at the index times; error functions and adaptive Simpson quadrature for the cell):
Cost: runs without gridded or cell rain do the same work as before. A gridded run reads each grid twice (once at start-up, once when used). It keeps the grids a later step can use plus one temporary grid. A moving cell evaluates$4n$ error-function products per cell per step.
Test(s)
Built with
-j 2, tests run withctest -j 2and at most 2 MPI ranks (tests that need 4 ranks were not run locally).developmentwith #12)FLUME_TESTING=ON, warnings as errors)rain_plane_kinematic_wave_order2times out, as ondevelopmentin Debug (not changed here)CPU runs in the style of GPU CI (
amrex.the_arena_init_size=0 amrex.init_snan=1 fab.do_initval=1 amrex.fpe_trap_invalid=1, 2 ranks), with one box per rank (fabarray.mfiter_tile_size=1024 1024 1024) and again with 4 × 4 tiles: the linear, volume, aligned-grid, cell and cell-volume decks all passcheck_rain_field.py.make -C Docs/sphinx_doc htmlwith-W,codespellandgit diff --checkare clean.rain_gridded_cells_linear_np1,_np2,rain_gridded_cells_finerain_gridded_volume_step,rain_gridded_volume_linear_shiftedrain_gridded_dry_burst_no_stop_timerain_gridded_cells_aligned_nodata_ringrain_cell_at_rest_np1,_np2,rain_cell_fast_step,rain_cell_volumerain_cell_zero_peak_long_stepabort_rain_gridded_*abort_rain_cell_*flume.rain.filewith the wrong type; a step that needs more thanabort_rain_type_microphysicsEach test was shown to fail on a one-line change to the code (all 21 caught):
abort_rain_gridded_negative,rain_gridded_dry_burst_no_stop_timesigma > 0as>= 0; velocity key allowed without its typeabort_rain_cell_*rain_gridded_cells_aligned_nodata_ringrain_cell_zero_peak_long_step,abort_rain_cell_step_too_longcentermessage, cell key andfilechecks with another type, infinite-time checkabort_rain_*testsVariations from the plan
Not in this PR
🤖 Generated with Claude Code