From 9b642d8699c6978b27fcf4fe5448f061db12e0cb Mon Sep 17 00:00:00 2001 From: HugoFara Date: Thu, 29 Oct 2026 13:17:33 +0100 Subject: [PATCH 1/2] fix(core): create the layers a model needs in its own domain, even when added late (#236) The domain creates the altitude and wind layers its models need when it is built. Two cases slipped through: - A model registered afterwards (addLayer, or the fuel table layer from Python) never had its needs checked, so Farsite without a wind layer dereferenced a null windU layer in getNormalWind. Pending needs are now checked before the first propagation or flux data request. - The check read the static shortcuts, so while another domain was alive a new domain got no altitude or wind layer of its own (#236). It now checks the broker's own layers. Also register the "domain ownership" suite with CTest, which never ran it. --- src/DataBroker.cpp | 15 +++++--- tests/unit/CMakeLists.txt | 2 +- tests/unit/test_data_broker.cpp | 64 ++++++++++++++++++++++++++++++++- 3 files changed, 75 insertions(+), 6 deletions(-) diff --git a/src/DataBroker.cpp b/src/DataBroker.cpp index ced9227b..7c76a3c9 100644 --- a/src/DataBroker.cpp +++ b/src/DataBroker.cpp @@ -537,15 +537,16 @@ namespace libforefire { if (neededProperties.back().find("normalWind") != string::npos) { - - if (windULayer == 0) + // This broker's own layers: the static shortcuts may point + // at another domain's that is still alive. + if (!hasLayer("windU")) { double val = 0.; if (params->isValued("windU")) val = params->getDouble("windU"); addConstantLayer("windU", "data", "", val, domain->getSWCorner(), domain->getNECorner() - domain->getSWCorner()); } - if (windVLayer == 0) + if (!hasLayer("windV")) { double val = 0.; if (params->isValued("windV")) @@ -606,7 +607,7 @@ namespace libforefire } /* checking the layers that are always needed */ - if (altitudeLayer == 0) + if (!hasLayer("altitude")) { double val = 0.; if (params->isValued("altitude")) @@ -710,6 +711,10 @@ namespace libforefire void DataBroker::getPropagationData(PropagationModel *model, FireNode *fn) { + // A model registered after the domain was built (addLayer, or a fuel + // table layer) still has its needs pending: create its layers now. + if (!neededProperties.empty()) + insureLayersExistence(); size_t nfilled = 0; if (optimizedPropDataBroker[model->index]) { @@ -734,6 +739,8 @@ namespace libforefire void DataBroker::getFluxData(FluxModel *model, FFPoint &loc, const double &t) { + if (!neededProperties.empty()) + insureLayersExistence(); size_t nfilled = 0; if (optimizedFluxDataBroker[model->index]) { diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 765845b7..c74bd3a8 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -34,7 +34,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" "commands" "data broker") +foreach(_suite "model registry" "propagation models" "flux models" "http server" "topology" "fire front" "timetable" "quit command" "commands" "data broker" "domain ownership") 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 index 35048063..719f251d 100644 --- a/tests/unit/test_data_broker.cpp +++ b/tests/unit/test_data_broker.cpp @@ -1,6 +1,6 @@ /** * @file test_data_broker.cpp - * @brief DataBroker::loadFromNCFile on layers that miss the domain. + * @brief DataBroker: layers that miss the domain, and the layers a model needs. * @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). */ @@ -11,19 +11,81 @@ #include "DataBroker.h" #include "FFPoint.h" +#include "FFVector.h" #include "FireDomain.h" +#include "FireFront.h" +#include "FireNode.h" #include "FuelDataLayer.h" +#include "PropagationModel.h" +#include "TimeTable.h" #include #include +using libforefire::DataBroker; using libforefire::FFPoint; +using libforefire::FFVector; using libforefire::FireDomain; +using libforefire::FireFront; +using libforefire::FireNode; using libforefire::FuelDataLayer; +using libforefire::PropagationModel; +using libforefire::TimeTable; using ff_test::ModelSandbox; +namespace { + +/* One fire node at the centre of the sandbox's 1 km domain. */ +FireNode* addNode(FireDomain* domain) { + FireFront* front = domain->addFireFront(0.); + FFPoint loc(500., 500., 0.); + FFVector vel; + return domain->addFireNode(loc, vel, 0., 20., 0., front, 0); +} + +} + TEST_SUITE("data broker") { +TEST_CASE("a model added after the domain is built gets the wind layers it needs") { + ModelSandbox sandbox; + FireDomain* domain = sandbox.fireDomain(); + TimeTable schedule; + domain->setTimeTable(&schedule); + DataBroker* broker = domain->getDataBroker(); + REQUIRE_FALSE(broker->hasLayer("windU")); + + // The domain has already checked its layers; this model asks for normalWind afterwards. + PropagationModel* model = sandbox.propagation("TroisPourcent"); + REQUIRE(model != nullptr); + broker->getPropagationData(model, addNode(domain)); + + CHECK(broker->hasLayer("windU")); + CHECK(broker->hasLayer("windV")); +} + +TEST_CASE("a second live domain gets its own altitude and wind layers") { + // The first domain stays alive, its layers set up, while the second is built. + ModelSandbox first; + PropagationModel* firstModel = first.propagation("TroisPourcent"); + TimeTable firstSchedule; + first.fireDomain()->setTimeTable(&firstSchedule); + first.fireDomain()->getDataBroker()->getPropagationData(firstModel, addNode(first.fireDomain())); + + ModelSandbox second; + FireDomain* domain = second.fireDomain(); + TimeTable schedule; + domain->setTimeTable(&schedule); + DataBroker* broker = domain->getDataBroker(); + CHECK(broker->hasLayer("altitude")); + + PropagationModel* model = second.propagation("TroisPourcent"); + REQUIRE(model != nullptr); + broker->getPropagationData(model, addNode(domain)); + CHECK(broker->hasLayer("windU")); + CHECK(broker->hasLayer("windV")); +} + #ifndef FF_NO_NETCDF TEST_CASE("a fuel map that misses the domain is stretched over it like the other layers") { ModelSandbox sandbox; From b1c699f5a1602f4c75ab662ec79cdd6a1ddc9a56 Mon Sep 17 00:00:00 2001 From: HugoFara Date: Thu, 29 Oct 2026 13:47:31 +0100 Subject: [PATCH 2/2] fix(core): leave front depth and curvature alone when a late model's layers are created The late check processed every pending need, so a model asking for frontDepth (Balbi2015) switched front depth computation on for the whole process, overriding frontDepthComputation=0 and slowing Balbi2015 tenfold (moisture invariants CI). The late check now only creates missing layers; front depth and curvature stay as their parameters set them. --- src/DataBroker.cpp | 36 ++++++++++++++++++++------------- src/DataBroker.h | 2 +- tests/unit/test_data_broker.cpp | 16 +++++++++++++++ 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/DataBroker.cpp b/src/DataBroker.cpp index 7c76a3c9..31b7c005 100644 --- a/src/DataBroker.cpp +++ b/src/DataBroker.cpp @@ -527,7 +527,7 @@ namespace libforefire neededProperties.erase(it); } - void DataBroker::insureLayersExistence() + void DataBroker::insureLayersExistence(bool switchNodeComputations) { /* checking the layers needed for the propagation and flux models */ while (!neededProperties.empty()) @@ -576,22 +576,28 @@ namespace libforefire } else if (neededProperties.back().find("epth") != string::npos) { - int fdepth = 1; - FireNode::setFrontDepthComputation(fdepth); - /* checking that a heat flux layer is present for burn checks. - * If not, instantiating a HeatFluxBasicModel */ - if (heatFluxLayer == 0 and !domain->addFluxLayer("heatFlux")) + if (switchNodeComputations) { - cout - << "WARNING: heat flux layer could not be found within ForeFire framework, this should" - << " cause serious problems for the simulation as front depth is required" - << endl; + int fdepth = 1; + FireNode::setFrontDepthComputation(fdepth); + /* checking that a heat flux layer is present for burn checks. + * If not, instantiating a HeatFluxBasicModel */ + if (heatFluxLayer == 0 and !domain->addFluxLayer("heatFlux")) + { + cout + << "WARNING: heat flux layer could not be found within ForeFire framework, this should" + << " cause serious problems for the simulation as front depth is required" + << endl; + } } } else if (neededProperties.back().find("urvature") != string::npos) { - int curv = 1; - FireNode::setCurvatureComputation(curv); + if (switchNodeComputations) + { + int curv = 1; + FireNode::setCurvatureComputation(curv); + } } else { @@ -713,8 +719,10 @@ namespace libforefire { // A model registered after the domain was built (addLayer, or a fuel // table layer) still has its needs pending: create its layers now. + // Front depth and curvature stay as frontDepthComputation and + // curvatureComputation set them, as they did before this check. if (!neededProperties.empty()) - insureLayersExistence(); + insureLayersExistence(false); size_t nfilled = 0; if (optimizedPropDataBroker[model->index]) { @@ -740,7 +748,7 @@ namespace libforefire void DataBroker::getFluxData(FluxModel *model, FFPoint &loc, const double &t) { if (!neededProperties.empty()) - insureLayersExistence(); + insureLayersExistence(false); size_t nfilled = 0; if (optimizedFluxDataBroker[model->index]) { diff --git a/src/DataBroker.h b/src/DataBroker.h index 2c3ab066..0b88cc49 100644 --- a/src/DataBroker.h +++ b/src/DataBroker.h @@ -271,7 +271,7 @@ class DataBroker { void initializeAtmosphericLayers(const double&); /*! \brief insuring the presence of all needed layers */ - void insureLayersExistence(); + void insureLayersExistence(bool switchNodeComputations = true); /*! \brief initialize flux layers */ void initFluxLayers(const double&); diff --git a/tests/unit/test_data_broker.cpp b/tests/unit/test_data_broker.cpp index 719f251d..575c124b 100644 --- a/tests/unit/test_data_broker.cpp +++ b/tests/unit/test_data_broker.cpp @@ -64,6 +64,22 @@ TEST_CASE("a model added after the domain is built gets the wind layers it needs CHECK(broker->hasLayer("windV")); } +TEST_CASE("a model added late leaves front depth computation as the parameters set it") { + ModelSandbox sandbox; + FireDomain* domain = sandbox.fireDomain(); + TimeTable schedule; + domain->setTimeTable(&schedule); + REQUIRE(domain->getFluxLayer("heatFlux") == nullptr); + + // Balbi2015 asks for frontDepth. Switching its computation on would also + // add a heat flux layer, and change the model's speeds. + PropagationModel* model = sandbox.propagation("Balbi2015"); + REQUIRE(model != nullptr); + domain->getDataBroker()->getPropagationData(model, addNode(domain)); + + CHECK(domain->getFluxLayer("heatFlux") == nullptr); +} + TEST_CASE("a second live domain gets its own altitude and wind layers") { // The first domain stays alive, its layers set up, while the second is built. ModelSandbox first;