Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/FireDomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@
size_t maxI = (size_t) ((nec.getX() - SWCornerX())/burningMatrixResX) + 1;
if ( maxI > globalBMapSizeX - 1 ) maxI = globalBMapSizeX - 1;
size_t minJ = 1;
if ( swc.getY() > SWCornerY()/burningMatrixResY )
if ( swc.getY() > SWCornerY()+burningMatrixResY )
minJ = (size_t) ((swc.getY() - SWCornerY())/burningMatrixResY);
size_t maxJ = (size_t) ((nec.getY() - SWCornerY())/burningMatrixResY) + 1;
if ( maxJ > globalBMapSizeY - 1 ) maxJ = globalBMapSizeY - 1;
Expand Down
2 changes: 2 additions & 0 deletions src/FireNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ void FireNode::timeAdvance(){
}
// obtaining the speed from the propagation model
double localSpeed = domain->getPropagationSpeed(this);
// No data here (outside a layer, no fuel): the node stops
if ( std::isnan(localSpeed) ) localSpeed = 0.;
double newSpeed = localSpeed;
/*if(newSpeed > minSpeed){
double prevSpeed, nextSpeed;
Expand Down
5 changes: 5 additions & 0 deletions src/GradientDataLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ T GradientDataLayer<T>::getValueAt(FireNode* fn){
T nextValue;
FFPoint nextLoc = fn->getLoc() + dx*(fn->getNormal().toPoint());
nextValue = parent->getValueAt(nextLoc,fn->getUpdateTime());
if ( std::isnan(nextValue) ){
// Ahead is outside the data (domain edge): look behind instead
FFPoint prevLoc = fn->getLoc() - dx*(fn->getNormal().toPoint());
return (currentValue - parent->getValueAt(prevLoc,fn->getUpdateTime()))/dx;
}
return (nextValue - currentValue)/dx;
}

Expand Down
18 changes: 10 additions & 8 deletions src/NCXYZTDataLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,21 +320,23 @@ T XYZTDataLayer<T>::getValueAt(FFPoint loc, const double& t){



double ud = indices.getX() + EPSILONX;
double vd = indices.getY() + EPSILONX;
// No data outside the layer. Values sit at cell centres: between
// the layer edge and the outermost centres, the outermost cells hold.
if ( nx < 2 or ny < 2 ) return NAN;
if ( indices.getX() < -0.5 - EPSILONX ) return NAN;
if ( indices.getX() > nx - 0.5 + EPSILONX ) return NAN;
if ( indices.getY() < -0.5 - EPSILONX ) return NAN;
if ( indices.getY() > ny - 0.5 + EPSILONX ) return NAN;

double ud = min(max(indices.getX() + EPSILONX, 0.), nx - 1.);
double vd = min(max(indices.getY() + EPSILONX, 0.), ny - 1.);

int uu = (int) ceil(ud-1);
int vv = (int) ceil(vd-1);
/*
if ( uu < 0 ) uu = 0;
if ( uu > ((int) nx) - 2 ) uu = ((int) nx) - 2;
if ( vv < 0 ) vv = 0;
if ( vv > ((int) ny) - 2 ) vv = ((int) ny) - 2;
*/
if (uu < 0) return NAN;
if (uu > ((int) nx) - 2) return NAN;
if (vv < 0) return NAN;
if (vv > ((int) ny) - 2) return NAN;

double udif = ud - ((double) uu);
double vdif = vd - ((double) vv);
Expand Down
4 changes: 4 additions & 0 deletions src/propagation/FarsitePropagationModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ namespace libforefire
if (fuel_lw > 0.0)
nlive++;

// No fuel (non-burnable cell): no spread, rather than 0/0 below
if (ndead == 0 && nlive == 0)
return 0.0;

if (nlive == 0)
fuel_dynamic = false;

Expand Down
37 changes: 37 additions & 0 deletions tests/unit/test_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
* The arrival times can be read two ways, and both used to be wrong: the BMap
* layer was never filled, and plot[...;filename=*.asc] wrote one row per x,
* at six significant digits, instead of an ASCII grid.
*
* A front reaching the domain edge over a gridded altitude used to fill the
* whole arrival map at one time: the slope past the edge was NaN, and so
* were the node positions it moved.
*/

#include "doctest/doctest.h"
Expand Down Expand Up @@ -175,4 +179,37 @@ TEST_CASE("plot writes arrival times as an ASCII grid, north row first") {
CHECK(inexact == 0);
}

TEST_CASE("a front that reaches the edge on sloping ground leaves the far side unburnt") {
Command executor;
run(executor, "clear[]");
run(executor, "FireDomain[sw=(0,0,0);ne=(1000,1000,0);t=0]");
auto* domain = Command::getDomain();
REQUIRE(domain != nullptr);
REQUIRE(domain->addPropagativeLayer("Iso"));

/* 2 x 2 altitude rising 100 m to the east, cell centres at 250 and 750 */
std::vector<double> altitude = {0., 0., 100., 100.};
double x0 = 0, y0 = 0, t0 = 0, width = 1000, height = 1000, timespan = 0;
size_t nx = 2, ny = 2, nz = 1, nt = 1;
REQUIRE(domain->addScalarLayer("data", "altitude", x0, y0, t0, width, height, timespan,
nx, ny, nz, nt, altitude.data()));

run(executor, "startFire[loc=(900,500,0)]");
run(executor, "goTo[t=200]");

/* Iso spreads at 1 m/s: the front is past the east edge, 300 m short of
* the west third. */
auto matrix = domain->getDataMatrix("arrival_time");
size_t burnt = 0, burntInWestThird = 0;
for (size_t i = 0; i < matrix.size(); i++) {
for (size_t j = 0; j < matrix[i].size(); j++) {
if (!std::isfinite(matrix[i][j])) continue;
burnt++;
if (i < matrix.size() / 3) burntInWestThird++;
}
}
CHECK(burnt > 0);
CHECK(burntInWestThird == 0);
}

} /* TEST_SUITE */
31 changes: 30 additions & 1 deletion tests/unit/test_data_layers.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file test_data_layers.cpp
* @brief XYZTDataLayer interpolation in time.
* @brief XYZTDataLayer interpolation in time and near its edges.
* @copyright Copyright (C) 2025 ForeFire, Fire Team, SPE, CNRS/Universita di Corsica.
* @license This program is free software; See LICENSE file for details. (See LICENSE file).
*/
Expand All @@ -10,6 +10,7 @@
#include "FFPoint.h"
#include "NCXYZTDataLayer.h"

#include <cmath>
#include <cstddef>
#include <vector>

Expand All @@ -30,6 +31,17 @@ double valueAt(const std::vector<double>& slices, double t0, double timespan, do
return layer.getValueAt(FFPoint(500., 500., 0.), t);
}

// A 2x2 layer over 2 km, 0 in the west cells and 10 in the east ones.
// Values sit at the cell centres, x = 500 and x = 1500.
double eastRampAt(double x, double y) {
std::vector<double> vals = {0., 0., 10., 10.}; // x is the slowest index
FFPoint sw(0., 0., 0.), extent(2000., 2000., 0.);
double t0 = 0., timespan = 0.;
std::size_t nx = 2, ny = 2, nz = 1, nt = 1;
XYZTDataLayer<double> layer("altitude", sw, t0, extent, timespan, nx, ny, nz, nt, vals.data());
return layer.getValueAt(FFPoint(x, y, 0.), 0.);
}

}

TEST_SUITE("data layers") {
Expand Down Expand Up @@ -58,4 +70,21 @@ TEST_CASE("outside its time axis a layer holds the first or last slice") {
CHECK(valueAt(ramp, 1000., 2000., 5000.) == doctest::Approx(8.));
}

TEST_CASE("between its edge and the outermost cell centres a layer holds the edge cells") {
// This band used to return NaN: half a cell along every edge, a quarter
// of a 2x2 layer. A slope taken there turned the front geometry to NaN.
// Lookups are nudged by EPSILONX, hence the tolerance mid-ramp.
CHECK(eastRampAt(1000., 1000.) == doctest::Approx(5.).epsilon(0.01));
CHECK(eastRampAt(1900., 1000.) == doctest::Approx(10.));
CHECK(eastRampAt(2000., 1000.) == doctest::Approx(10.));
CHECK(eastRampAt(100., 1900.) == doctest::Approx(0.));
CHECK(eastRampAt(0., 0.) == doctest::Approx(0.));
}

TEST_CASE("outside its extent a layer has no data") {
CHECK(std::isnan(eastRampAt(2100., 1000.)));
CHECK(std::isnan(eastRampAt(-100., 1000.)));
CHECK(std::isnan(eastRampAt(1000., 2100.)));
}

}
18 changes: 18 additions & 0 deletions tests/unit/test_propagation_models.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,24 @@ TEST_CASE("Farsite reads the wind in m/s") {
CHECK(oneMetrePerSecond / calm == doctest::Approx(1.0 + phiw).epsilon(1e-6));
}

TEST_CASE("Farsite does not spread over a cell with no fuel") {
// A non-burnable cell has no fuel load at all, and Farsite divided zero
// by zero for it. The NaN stopped the node for good, even if fuel was
// one step further on.
ModelSandbox sandbox;
PropagationModel* model = sandbox.propagation("Farsite");
REQUIRE(model != 0);

Inputs inputs(model);
inputs.set("normalWind", 1.0);
inputs.set("slope", 0.2);
inputs.set("moist.ones", 0.05);

const double ros = speedOf(model, inputs);
CHECK(std::isfinite(ros));
CHECK(ros == doctest::Approx(0.0));
}

TEST_CASE("spread is finite and non-negative over a wind and slope sweep") {
ModelSandbox sandbox;
const std::vector<std::string>& names = standardFuelModels();
Expand Down
Loading