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
47 changes: 31 additions & 16 deletions src/DataBroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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"))
Expand Down Expand Up @@ -575,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
{
Expand All @@ -606,7 +613,7 @@ namespace libforefire
}

/* checking the layers that are always needed */
if (altitudeLayer == 0)
if (!hasLayer("altitude"))
{
double val = 0.;
if (params->isValued("altitude"))
Expand Down Expand Up @@ -710,6 +717,12 @@ 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.
// Front depth and curvature stay as frontDepthComputation and
// curvatureComputation set them, as they did before this check.
if (!neededProperties.empty())
insureLayersExistence(false);
size_t nfilled = 0;
if (optimizedPropDataBroker[model->index])
{
Expand All @@ -734,6 +747,8 @@ namespace libforefire

void DataBroker::getFluxData(FluxModel *model, FFPoint &loc, const double &t)
{
if (!neededProperties.empty())
insureLayersExistence(false);
size_t nfilled = 0;
if (optimizedFluxDataBroker[model->index])
{
Expand Down
2 changes: 1 addition & 1 deletion src/DataBroker.h
Original file line number Diff line number Diff line change
Expand Up @@ -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&);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
80 changes: 79 additions & 1 deletion tests/unit/test_data_broker.cpp
Original file line number Diff line number Diff line change
@@ -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).
*/
Expand All @@ -11,19 +11,97 @@

#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 <cstdio>
#include <string>

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 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;
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;
Expand Down
Loading