From 803afdaa9966b50727a63a084896e61972bc26d9 Mon Sep 17 00:00:00 2001 From: Yanis Srairi <115394890+yanissrairi@users.noreply.github.com> Date: Tue, 27 Oct 2026 17:38:16 +0100 Subject: [PATCH 1/2] fix: stretch a fuel map that misses the domain, like the other layers When a NetCDF layer does not overlap the domain, DataBroker warns "Failsafe Reprojection to whole domain extent" and builds the layer on the domain extent. The fuel branch, added in c3a30da, computes that extent but passes the file's own one to FuelDataLayer, so the map stays outside the domain and every point reads its first cell. --- CHANGELOG.md | 4 +++ src/DataBroker.cpp | 2 +- tests/unit/CMakeLists.txt | 5 +-- tests/unit/test_data_broker.cpp | 63 +++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 tests/unit/test_data_broker.cpp diff --git a/CHANGELOG.md b/CHANGELOG.md index 88bd1c31..d7799056 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -102,6 +102,10 @@ Merged since v2.5.0, not yet released. dividing by it in eq. C7, which drove the radiant fraction to zero. It now matches `Balbi2020.py` in `wildfire_ROS_models`, and its rate of spread is floored at zero on a downslope with no wind. ([#196]) +- A fuel map loaded with `loadData` that does not overlap the domain is now + stretched over it, as the warning says and as the other layers already were. + It was left at its own extent, so the whole domain read the fuel of its first + cell. ### Changed diff --git a/src/DataBroker.cpp b/src/DataBroker.cpp index 0413490d..3c30fe8f 100644 --- a/src/DataBroker.cpp +++ b/src/DataBroker.cpp @@ -1506,7 +1506,7 @@ namespace libforefire domain->NECornerY() - domain->SWCornerY(), 10000.); double t0 = 0; double Dt = 10000000.; - FuelDataLayer *newlayer = new FuelDataLayer(property, SWCorner, timeOrigin, spatialExtent, Lt, nx, ny, nz, nt, fuelMap); + FuelDataLayer *newlayer = new FuelDataLayer(property, SWC, t0, ext, Dt, nx, ny, nz, nt, fuelMap); delete[] fuelMap; return newlayer; } diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 4b99bc37..a973a266 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -17,7 +17,8 @@ add_executable(forefire_unit_tests test_propagation_models.cpp test_topology.cpp test_timetable.cpp - test_quit_command.cpp) + test_quit_command.cpp + test_data_broker.cpp) target_link_libraries(forefire_unit_tests PRIVATE forefireL) target_include_directories(forefire_unit_tests PRIVATE @@ -32,7 +33,7 @@ endif() # doctest groups its cases into suites; registering one CTest entry per suite # keeps `ctest` output useful without needing doctest's CMake integration. -foreach(_suite "model registry" "propagation models" "flux models" "http server" "topology" "fire front" "timetable" "quit command") +foreach(_suite "model registry" "propagation models" "flux models" "http server" "topology" "fire front" "timetable" "quit command" "data broker") string(REPLACE " " "_" _suite_id "${_suite}") add_test(NAME "unit.${_suite_id}" COMMAND forefire_unit_tests --test-suite=${_suite} --no-skipped-summary) diff --git a/tests/unit/test_data_broker.cpp b/tests/unit/test_data_broker.cpp new file mode 100644 index 00000000..35048063 --- /dev/null +++ b/tests/unit/test_data_broker.cpp @@ -0,0 +1,63 @@ +/** + * @file test_data_broker.cpp + * @brief DataBroker::loadFromNCFile on layers that miss the domain. + * @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). + */ + +#include "doctest/doctest.h" + +#include "model_sandbox.h" + +#include "DataBroker.h" +#include "FFPoint.h" +#include "FireDomain.h" +#include "FuelDataLayer.h" + +#include +#include + +using libforefire::FFPoint; +using libforefire::FireDomain; +using libforefire::FuelDataLayer; +using ff_test::ModelSandbox; + +TEST_SUITE("data broker") { + +#ifndef FF_NO_NETCDF +TEST_CASE("a fuel map that misses the domain is stretched over it like the other layers") { + ModelSandbox sandbox; + sandbox.propagation("Rothermel"); + FireDomain* domain = sandbox.fireDomain(); + + // 2x2 fuel map 100 km away from the 1 km domain: no overlap, so the + // failsafe reprojection applies. Its first cell is fuel 0, the others 1. + const std::string path = "test_data_broker_fuel.nc"; + { + NcFile file(path, NcFile::replace); + NcVar dom = file.addVar("domain", ncInt); + dom.putAtt("type", "domain"); + dom.putAtt("SWx", ncDouble, 100000.); + dom.putAtt("SWy", ncDouble, 100000.); + dom.putAtt("Lx", ncDouble, 1000.); + dom.putAtt("Ly", ncDouble, 1000.); + std::vector dims = {file.addDim("ft", 1), file.addDim("fz", 1), + file.addDim("fy", 2), file.addDim("fx", 2)}; + NcVar fuel = file.addVar("fuel", ncShort, dims); + fuel.putAtt("type", "fuel"); + const short cells[4] = {0, 1, 1, 1}; + fuel.putVar(cells); + } + domain->getDataBroker()->loadFromNCFile(path); + std::remove(path.c_str()); + + FuelDataLayer* layer = + dynamic_cast*>(domain->getDataBroker()->getLayer("fuel")); + REQUIRE(layer != nullptr); + // Stretched over the domain, (750, 750) falls in the last cell. Left at + // its own extent the map is outside the domain and every point reads cell 0. + CHECK(layer->getValueAt(FFPoint(750., 750., 0.), 0.) == 1.); +} +#endif + +} From b889d199620f9ad6758a4a74fc941e5e90cde120 Mon Sep 17 00:00:00 2001 From: Yanis Srairi <115394890+yanissrairi@users.noreply.github.com> Date: Tue, 27 Oct 2026 17:43:18 +0100 Subject: [PATCH 2/2] changelog: link #220 --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7799056..3e885de2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -105,7 +105,7 @@ Merged since v2.5.0, not yet released. - A fuel map loaded with `loadData` that does not overlap the domain is now stretched over it, as the warning says and as the other layers already were. It was left at its own extent, so the whole domain read the fuel of its first - cell. + cell. ([#220]) ### Changed @@ -259,6 +259,7 @@ repository stays easy to return to. [#197]: https://github.com/forefireAPI/forefire/pull/197 [#194]: https://github.com/forefireAPI/forefire/pull/194 [#196]: https://github.com/forefireAPI/forefire/issues/196 +[#220]: https://github.com/forefireAPI/forefire/pull/220 [#202]: https://github.com/forefireAPI/forefire/pull/202 [#199]: https://github.com/forefireAPI/forefire/pull/199 [#179]: https://github.com/forefireAPI/forefire/pull/179