diff --git a/CHANGELOG.md b/CHANGELOG.md index 96665830..e79beb22 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. ([#220]) - `Rothermel` wrote the wind exponent coefficient as `3.59*10E-4`, which is 3.59e-3 in C++, ten times the 3.59e-4 of Rothermel (1972), so wind raised the rate of spread too little. Results with wind @@ -267,6 +271,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 [#195]: https://github.com/forefireAPI/forefire/pull/195 [#202]: https://github.com/forefireAPI/forefire/pull/202 [#199]: https://github.com/forefireAPI/forefire/pull/199 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 + +}