From 114cbe02f16a38b156a103a70703aa96410ba797 Mon Sep 17 00:00:00 2001 From: Joshua Rady Date: Wed, 2 Aug 2023 08:56:52 -0400 Subject: [PATCH 01/23] Add switches to turn wildfire off and on for each run stage. --- config/config.js | 10 +++++++++- include/ModelData.h | 8 ++++++++ include/WildFire.h | 3 ++- src/ModelData.cpp | 7 +++++++ src/TEM.cpp | 15 ++++++++++----- src/WildFire.cpp | 16 ++++++++++++---- 6 files changed, 48 insertions(+), 11 deletions(-) diff --git a/config/config.js b/config/config.js index 90b1e56d5..49c546da0 100644 --- a/config/config.js +++ b/config/config.js @@ -70,11 +70,19 @@ }, "model_settings": { - "dynamic_lai": 1 // from model (1) or from input (0) + "dynamic_lai": 1, // from model (1) or from input (0) // //"dynamic_climate": 0, // //"varied_co2": 0, // //"fire_severity_as_input": 0, // fire sev. as input or ?? // //"output_starting_year": -9999 + // FW_MOD_START: + // Switches to turn fire off (0) or on (1) for each run stage: + "fire_on_PR": 0, + "fire_on_EQ": 0, + "fire_on_SP": 0, + "fire_on_TR": 0, + "fire_on_SC": 0 + // FW_MOD_END. } // "output_switches": { diff --git a/include/ModelData.h b/include/ModelData.h index c9e6749e3..981c70241 100644 --- a/include/ModelData.h +++ b/include/ModelData.h @@ -87,6 +87,14 @@ class ModelData { bool dynamic_LAI; // True: calculate LAI as a function of vegc, False: use static_lai from CohortLookup bool useseverity; // using fire severity inputs + // FW_MOD_START: + bool fire_on_PR; + bool fire_on_EQ; + bool fire_on_SP, + bool fire_on_TR; + bool fire_on_SC; + // FW_MOD_END. + bool outSiteDay; bool get_envmodule(); diff --git a/include/WildFire.h b/include/WildFire.h index 93fbf6675..2ec6795a8 100644 --- a/include/WildFire.h +++ b/include/WildFire.h @@ -47,7 +47,8 @@ class WildFire { void initializeState(); void set_state_from_restartdata(const RestartData & rdata); - bool should_ignite(const int yr, const int midx, const std::string& stage); + //bool should_ignite(const int yr, const int midx, const std::string& stage); + bool should_ignite(const int yr, const int midx, const std::string& stage, const ModelData* md);// FW_MOD // not used or fully implemented yet... //int lookup_severity(const int yr, const int midx, const std::string& stage); diff --git a/src/ModelData.cpp b/src/ModelData.cpp index 4160f32df..ee3cc7240 100644 --- a/src/ModelData.cpp +++ b/src/ModelData.cpp @@ -69,6 +69,13 @@ ModelData::ModelData(Json::Value controldata):force_cmt(-1) { //changeco2 = controldata["model_settings"]["varied_co2"].asInt(); //useseverity = controldata["model_settings"]["fire_severity_as_input"].asInt(); + // FW_MOD_START: + fire_on_PR = controldata["model_settings"]["fire_on_PR"].asBool(); + fire_on_EQ = controldata["model_settings"]["fire_on_EQ"].asBool(); + fire_on_SP = controldata["model_settings"]["fire_on_SP"].asBool(); + fire_on_TR = controldata["model_settings"]["fire_on_TR"].asBool(); + fire_on_SC = controldata["model_settings"]["fire_on_SC"].asBool(); + // FW_MOD_END. } /** Update all the appropriate fields in ModelData from an ArgHandler object. diff --git a/src/TEM.cpp b/src/TEM.cpp index f52680013..d84d21999 100755 --- a/src/TEM.cpp +++ b/src/TEM.cpp @@ -583,7 +583,8 @@ void advance_model(const int rowidx, const int colidx, runner.cohort.md->set_nfeed(false); runner.cohort.md->set_avlnflg(false); runner.cohort.md->set_baseline(false); - runner.cohort.md->set_dsbmodule(false); + //runner.cohort.md->set_dsbmodule(false); + runner.cohort.md->set_dsbmodule(runner.cohort.md.fire_on_PR);// FW_MOD: Would make sense to move into ModelData class. runner.cohort.md->set_dslmodule(false); runner.cohort.md->set_dynamic_lai_module(false); @@ -629,7 +630,8 @@ void advance_model(const int rowidx, const int colidx, runner.cohort.md->set_avlnflg(true); runner.cohort.md->set_baseline(true); - runner.cohort.md->set_dsbmodule(false); + //runner.cohort.md->set_dsbmodule(false); + runner.cohort.md->set_dsbmodule(runner.cohort.md.fire_on_EQ);// FW_MOD: Would make sense to move into ModelData class. // This variable ensures that OpenMP threads do not modify // the shared modeldata.eq_yrs value. @@ -692,7 +694,8 @@ void advance_model(const int rowidx, const int colidx, runner.cohort.md->set_nfeed(true); runner.cohort.md->set_avlnflg(true); runner.cohort.md->set_baseline(true); - runner.cohort.md->set_dsbmodule(false); + //runner.cohort.md->set_dsbmodule(false); + runner.cohort.md->set_dsbmodule(runner.cohort.md.fire_on_SP);// FW_MOD: Would make sense to move into ModelData class. runner.cohort.md->set_dslmodule(true); runner.cohort.md->set_dynamic_lai_module(true); @@ -746,7 +749,8 @@ void advance_model(const int rowidx, const int colidx, runner.cohort.md->set_nfeed(true); runner.cohort.md->set_avlnflg(true); runner.cohort.md->set_baseline(true); - runner.cohort.md->set_dsbmodule(false); + //runner.cohort.md->set_dsbmodule(false); + runner.cohort.md->set_dsbmodule(runner.cohort.md.fire_on_TR);// FW_MOD: Would make sense to move into ModelData class. runner.cohort.md->set_dslmodule(true); runner.cohort.md->set_dynamic_lai_module(true); @@ -796,7 +800,8 @@ void advance_model(const int rowidx, const int colidx, runner.cohort.md->set_nfeed(true); runner.cohort.md->set_avlnflg(true); runner.cohort.md->set_baseline(true); - runner.cohort.md->set_dsbmodule(false); + //runner.cohort.md->set_dsbmodule(false); + runner.cohort.md->set_dsbmodule(runner.cohort.md.fire_on_SC);// FW_MOD: Would make sense to move into ModelData class. runner.cohort.md->set_dslmodule(true); runner.cohort.md->set_dynamic_lai_module(true); diff --git a/src/WildFire.cpp b/src/WildFire.cpp index 3ffb036d6..409fea9b2 100644 --- a/src/WildFire.cpp +++ b/src/WildFire.cpp @@ -136,15 +136,21 @@ void WildFire::set_state_from_restartdata(const RestartData & rdata) { * NOTE: how to handle fire severity, to be determined. * */ -bool WildFire::should_ignite(const int yr, const int midx, const std::string& stage) { +//bool WildFire::should_ignite(const int yr, const int midx, const std::string& stage) { +bool WildFire::should_ignite(const int yr, const int midx, const std::string& stage, + //const ModelData md) {// FW_MOD: Add ModelData. Pointer? + const ModelData* md) {// FW_MOD BOOST_LOG_SEV(glg, note) << "determining fire ignition for yr:" << yr << ", monthidx:" << midx << ", stage:" << stage; bool ignite = false; - bool fri_derived = false; + //bool fri_derived = false;// FW_NOTE: Not actually used! - if ( stage.compare("pre-run") == 0 || stage.compare("eq-run") == 0 || stage.compare("sp-run") == 0 ) { + //if ( stage.compare("pre-run") == 0 || stage.compare("eq-run") == 0 || stage.compare("sp-run") == 0 ) { + if ( (stage.compare("pre-run") == 0 && md->fire_on_PR) || + (stage.compare("eq-run") == 0 && md->fire_on_EQ) || + (stage.compare("sp-run") == 0 && md->fire_on_SP)) {// FW_MOD this->fri_derived = true; BOOST_LOG_SEV(glg, debug) << "Determine fire from FRI."; @@ -156,7 +162,9 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st // do nothing: correct year, wrong month. } - } else if ( stage.compare("tr-run") == 0 || stage.compare("sc-run") == 0 ) { + //} else if ( stage.compare("tr-run") == 0 || stage.compare("sc-run") == 0 ) { + } else if ( (stage.compare("tr-run") == 0 && md->fire_on_TR) || + (stage.compare("sc-run") == 0 && md->fire_on_SC) {// FW_MOD this->fri_derived = false; BOOST_LOG_SEV(glg, debug) << "Determine fire from explicit fire regime."; From 7d1422c02b34ace91543a7a1135207df27f5e290 Mon Sep 17 00:00:00 2001 From: Joshua Rady Date: Wed, 2 Aug 2023 09:18:58 -0400 Subject: [PATCH 02/23] Add commnent to ModelData.h. --- include/ModelData.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/ModelData.h b/include/ModelData.h index 981c70241..5789e782d 100644 --- a/include/ModelData.h +++ b/include/ModelData.h @@ -88,6 +88,7 @@ class ModelData { bool useseverity; // using fire severity inputs // FW_MOD_START: + // Switches to turn fire off (0) or on (1) for each run stage: bool fire_on_PR; bool fire_on_EQ; bool fire_on_SP, From f8d1d5800573acb65827cb22e534d3da99748126 Mon Sep 17 00:00:00 2001 From: Joshua Rady Date: Wed, 2 Aug 2023 10:07:46 -0400 Subject: [PATCH 03/23] Add alternate igntions mode switch and placeholder in WildFire::should_ignite(). --- config/config.js | 4 +++- include/ModelData.h | 4 ++++ src/ModelData.cpp | 1 + src/WildFire.cpp | 28 +++++++++++++++++++--------- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/config/config.js b/config/config.js index 49c546da0..37850e1eb 100644 --- a/config/config.js +++ b/config/config.js @@ -81,7 +81,9 @@ "fire_on_EQ": 0, "fire_on_SP": 0, "fire_on_TR": 0, - "fire_on_SC": 0 + "fire_on_SC": 0, + // Wildfire ignitions: 1: default/old, 2 for revised (placeholder currently): + "fire_ignition_mode": 1 // FW_MOD_END. } diff --git a/include/ModelData.h b/include/ModelData.h index 5789e782d..9d494702e 100644 --- a/include/ModelData.h +++ b/include/ModelData.h @@ -94,6 +94,10 @@ class ModelData { bool fire_on_SP, bool fire_on_TR; bool fire_on_SC; + // FW_NOTE: Wildfire ignitions is only a placeholder at this point s and likely to change. + // Wildfire ignitions: 1: default/old, FIR or prescribed by file depending on the stage. + // 2 for revised fire ignitions (calculated?): + int fire_ignition_mode; // FW_MOD_END. bool outSiteDay; diff --git a/src/ModelData.cpp b/src/ModelData.cpp index ee3cc7240..e9c1e5014 100644 --- a/src/ModelData.cpp +++ b/src/ModelData.cpp @@ -75,6 +75,7 @@ ModelData::ModelData(Json::Value controldata):force_cmt(-1) { fire_on_SP = controldata["model_settings"]["fire_on_SP"].asBool(); fire_on_TR = controldata["model_settings"]["fire_on_TR"].asBool(); fire_on_SC = controldata["model_settings"]["fire_on_SC"].asBool(); + fire_ignition_type = controldata["model_settings"]["fire_ignition_type"].asInt(); // FW_MOD_END. } diff --git a/src/WildFire.cpp b/src/WildFire.cpp index 409fea9b2..2ddb1907b 100644 --- a/src/WildFire.cpp +++ b/src/WildFire.cpp @@ -150,7 +150,7 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st //if ( stage.compare("pre-run") == 0 || stage.compare("eq-run") == 0 || stage.compare("sp-run") == 0 ) { if ( (stage.compare("pre-run") == 0 && md->fire_on_PR) || (stage.compare("eq-run") == 0 && md->fire_on_EQ) || - (stage.compare("sp-run") == 0 && md->fire_on_SP)) {// FW_MOD + (stage.compare("sp-run") == 0 && md->fire_on_SP) ) {// FW_MOD this->fri_derived = true; BOOST_LOG_SEV(glg, debug) << "Determine fire from FRI."; @@ -164,19 +164,29 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st //} else if ( stage.compare("tr-run") == 0 || stage.compare("sc-run") == 0 ) { } else if ( (stage.compare("tr-run") == 0 && md->fire_on_TR) || - (stage.compare("sc-run") == 0 && md->fire_on_SC) {// FW_MOD + (stage.compare("sc-run") == 0 && md->fire_on_SC) ) {// FW_MOD this->fri_derived = false; - BOOST_LOG_SEV(glg, debug) << "Determine fire from explicit fire regime."; - - if ( this->exp_burn_mask[yr] == 1 ){ - if ( temutil::doy2month(this->exp_jday_of_burn[yr]) == midx ) { - ignite = true; + + if (md->fire_ignition_mode == 1)// FW_MOD + { + BOOST_LOG_SEV(glg, debug) << "Determine fire from explicit fire regime."; + + if ( this->exp_burn_mask[yr] == 1 ){ + if ( temutil::doy2month(this->exp_jday_of_burn[yr]) == midx ) { + ignite = true; + } + // do nothing: correct year, wrong month } - // do nothing: correct year, wrong month } + else//md->fire_ignition_mode == 2// FW_MOD_START: + { + BOOST_LOG_SEV(glg, debug) << "Alternate ignition modes are not yet implemented. Set fire_ignition_mode = 1."; + // Should probably terminate here. + ignite = false + }// FW_MOD_END. } else { - BOOST_LOG_SEV(glg, err) << "Unknown stage! (" << stage << ")"; + BOOST_LOG_SEV(glg, err) << "Unknown stage! (" << stage << ")";// FW_NOTE: This check may be partially broken now due to fire switch checks! } BOOST_LOG_SEV(glg, debug) << "Should we ignite a fire?:" << ignite; From 0f3f65d85eed777fa35249b4a73b6a8679daaf5d Mon Sep 17 00:00:00 2001 From: Joshua Rady Date: Wed, 2 Aug 2023 10:39:10 -0400 Subject: [PATCH 04/23] Update call to fire.should_ignite() with added ModelData parameter. --- src/Cohort.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Cohort.cpp b/src/Cohort.cpp index ec8e4b0b9..1d38eaa9d 100644 --- a/src/Cohort.cpp +++ b/src/Cohort.cpp @@ -771,7 +771,8 @@ void Cohort::updateMonthly_Fir(const int & year, const int & midx, std::string s } // see if it is an appropriate time to burn - if ( fire.should_ignite(year, midx, stage) ) { + //if ( fire.should_ignite(year, midx, stage) ) { + if ( fire.should_ignite(year, midx, stage, md) ) {//FW_MOD. BOOST_LOG_SEV(glg, debug) << "Right before fire.burn(..) " << ground.layer_report_string(); From b2cbe9876114a8862f6065a7a35fd1caa3aedd2b Mon Sep 17 00:00:00 2001 From: Joshua Rady Date: Wed, 2 Aug 2023 18:11:56 -0400 Subject: [PATCH 05/23] Add ignition mode setting that enables fire return interval based wildfire fire in the transient and scenario run stages. --- config/config.js | 7 ++- include/ModelData.h | 7 +-- include/WildFire.h | 1 + src/WildFire.cpp | 101 ++++++++++++++++++++++++++++++++++---------- 4 files changed, 88 insertions(+), 28 deletions(-) diff --git a/config/config.js b/config/config.js index 37850e1eb..b6bf494da 100644 --- a/config/config.js +++ b/config/config.js @@ -82,8 +82,11 @@ "fire_on_SP": 0, "fire_on_TR": 0, "fire_on_SC": 0, - // Wildfire ignitions: 1: default/old, 2 for revised (placeholder currently): - "fire_ignition_mode": 1 + // Wildfire ignitions modes: [Note: In development. Numbers will likely change!] + // 0: Default/old: FRI for PR/EQ/SP, explicit for TR/SC. + // 1: Use fire return interval for all stages with fire on. + // 2; Revised (placeholder only currently) + "fire_ignition_mode": 0 // FW_MOD_END. } diff --git a/include/ModelData.h b/include/ModelData.h index 9d494702e..93d98437b 100644 --- a/include/ModelData.h +++ b/include/ModelData.h @@ -94,9 +94,10 @@ class ModelData { bool fire_on_SP, bool fire_on_TR; bool fire_on_SC; - // FW_NOTE: Wildfire ignitions is only a placeholder at this point s and likely to change. - // Wildfire ignitions: 1: default/old, FIR or prescribed by file depending on the stage. - // 2 for revised fire ignitions (calculated?): + // Wildfire ignitions modes: [Note: In development. Numbers will likely change!] + // 0: Default/old: FRI for PR/EQ/SP, explicit for TR/SC. + // 1: Use fire return interval for all stages with fire on. + // 2; Revised (placeholder only currently) int fire_ignition_mode; // FW_MOD_END. diff --git a/include/WildFire.h b/include/WildFire.h index 2ec6795a8..71327b630 100644 --- a/include/WildFire.h +++ b/include/WildFire.h @@ -117,6 +117,7 @@ class WildFire { BgcData * bd[NUM_PFT]; BgcData * bdall; + bool is_fire_return_date(const int yr, const int midx); double getBurnOrgSoilthick(const int year); void getBurnAbgVegetation(const int ipft, const int year); diff --git a/src/WildFire.cpp b/src/WildFire.cpp index 2ddb1907b..ddf0576c9 100644 --- a/src/WildFire.cpp +++ b/src/WildFire.cpp @@ -148,43 +148,81 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st //bool fri_derived = false;// FW_NOTE: Not actually used! //if ( stage.compare("pre-run") == 0 || stage.compare("eq-run") == 0 || stage.compare("sp-run") == 0 ) { + // FW_MOD_START: + // Check that fire is on for the current run stage: if ( (stage.compare("pre-run") == 0 && md->fire_on_PR) || (stage.compare("eq-run") == 0 && md->fire_on_EQ) || - (stage.compare("sp-run") == 0 && md->fire_on_SP) ) {// FW_MOD + (stage.compare("sp-run") == 0 && md->fire_on_SP) ) + { + // Currently for the PR, EQ, and SP stages only fire return interval based fire is implemented + // so there is no need to check fire_ignition_mode. If fire is on it is FRI based. + // This could change in the future. + // FW_MOD_END. this->fri_derived = true; BOOST_LOG_SEV(glg, debug) << "Determine fire from FRI."; - if ( (yr % this->fri) == 0 && yr > 0 ) { - if (midx == temutil::doy2month(this->fri_jday_of_burn)) { - ignite = true; - } - // do nothing: correct year, wrong month. +// if ( (yr % this->fri) == 0 && yr > 0 ) { +// if (midx == temutil::doy2month(this->fri_jday_of_burn)) { +// ignite = true; +// } +// // do nothing: correct year, wrong month. +// } + // Extracted to: + if (is_fire_return_date(yr, midx)) + { + ignite = true; } + // FW_MOD_START: //} else if ( stage.compare("tr-run") == 0 || stage.compare("sc-run") == 0 ) { - } else if ( (stage.compare("tr-run") == 0 && md->fire_on_TR) || - (stage.compare("sc-run") == 0 && md->fire_on_SC) ) {// FW_MOD - - this->fri_derived = false; + } + else if ( (stage.compare("tr-run") == 0 && md->fire_on_TR) || + (stage.compare("sc-run") == 0 && md->fire_on_SC) ) + { + //this->fri_derived = false; + // FW_MOD_END. - if (md->fire_ignition_mode == 1)// FW_MOD + //if (md->fire_ignition_mode == 1)// FW_MOD + switch (fire_ignition_mode) { - BOOST_LOG_SEV(glg, debug) << "Determine fire from explicit fire regime."; - - if ( this->exp_burn_mask[yr] == 1 ){ - if ( temutil::doy2month(this->exp_jday_of_burn[yr]) == midx ) { + case 0:// Default (old) fire behavior, use explicit fire from input file: + { + this->fri_derived = false; + BOOST_LOG_SEV(glg, debug) << "Determine fire from explicit fire regime."; + + if ( this->exp_burn_mask[yr] == 1 ){ + if ( temutil::doy2month(this->exp_jday_of_burn[yr]) == midx ) { + ignite = true; + } + // do nothing: correct year, wrong month + } + break; + } + case 1:// Use fire return interval: + { + this->fri_derived = true; + BOOST_LOG_SEV(glg, debug) << "Determine fire from FRI."; + if (is_fire_return_date(yr, midx)) + { ignite = true; } - // do nothing: correct year, wrong month + break; } - } - else//md->fire_ignition_mode == 2// FW_MOD_START: - { - BOOST_LOG_SEV(glg, debug) << "Alternate ignition modes are not yet implemented. Set fire_ignition_mode = 1."; - // Should probably terminate here. - ignite = false - }// FW_MOD_END. + case 2://Placeholder for future dynamic ignition mode... + { + BOOST_LOG_SEV(glg, debug) << "Alternate ignition modes are not yet implemented. Set fire_ignition_mode = 1."; + // Should probably terminate here. + this->fri_derived = false; + ignite = false + break; + } + default: + { + BOOST_LOG_SEV(glg, err) << "Undefined ignition mode! (" << stage << ")"; + break; + } + // FW_MOD_END. } else { BOOST_LOG_SEV(glg, err) << "Unknown stage! (" << stage << ")";// FW_NOTE: This check may be partially broken now due to fire switch checks! } @@ -194,6 +232,23 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st return ignite; } +// FW_MOD_START: +/** Determine if the current date, by year and month midpoint?, aligns with a fire return date. + * Removed from should_ignite() to avoid code repetition. + * Should this be moved? The private functions don't seem to be in a particular place.*/ +bool WildFire::is_fire_return_date(const int yr, const int midx) +{ + if ( (yr % this->fri) == 0 && yr > 0 ) + { + if (midx == temutil::doy2month(this->fri_jday_of_burn)) + { + return true; + } + // do nothing: correct year, wrong month. + } + return false; +}// FW_MOD_END. + /** Burning vegetation and soil organic C */ void WildFire::burn(int year) { BOOST_LOG_NAMED_SCOPE("burning"); From daacde006355c56b9b2dc88288d06b5c0fca86ae Mon Sep 17 00:00:00 2001 From: Joshua Rady Date: Wed, 25 Oct 2023 10:01:19 -0400 Subject: [PATCH 06/23] Cleanup comments and fix missing pointer in WildFire::should_ignite(). --- src/WildFire.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/WildFire.cpp b/src/WildFire.cpp index ddf0576c9..0d6af5461 100644 --- a/src/WildFire.cpp +++ b/src/WildFire.cpp @@ -162,6 +162,7 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st this->fri_derived = true; BOOST_LOG_SEV(glg, debug) << "Determine fire from FRI."; + // FW_MOD_START: // if ( (yr % this->fri) == 0 && yr > 0 ) { // if (midx == temutil::doy2month(this->fri_jday_of_burn)) { // ignite = true; @@ -174,17 +175,14 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st ignite = true; } - // FW_MOD_START: //} else if ( stage.compare("tr-run") == 0 || stage.compare("sc-run") == 0 ) { } else if ( (stage.compare("tr-run") == 0 && md->fire_on_TR) || (stage.compare("sc-run") == 0 && md->fire_on_SC) ) { //this->fri_derived = false; - // FW_MOD_END. - //if (md->fire_ignition_mode == 1)// FW_MOD - switch (fire_ignition_mode) + switch (md->fire_ignition_mode) { case 0:// Default (old) fire behavior, use explicit fire from input file: { @@ -233,9 +231,9 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st } // FW_MOD_START: -/** Determine if the current date, by year and month midpoint?, aligns with a fire return date. - * Removed from should_ignite() to avoid code repetition. - * Should this be moved? The private functions don't seem to be in a particular place.*/ +/** Determine if the current date, by year and month midpoint, aligns with a fire return date. + * This code was extracted from should_ignite() to avoid code repetition due to other changes. + * Should this be moved? The private functions don't seem to be in a particular place.*/ bool WildFire::is_fire_return_date(const int yr, const int midx) { if ( (yr % this->fri) == 0 && yr > 0 ) From 45a873ca61cfa394f1e50ba663059d6cb485faa1 Mon Sep 17 00:00:00 2001 From: Joshua Rady Date: Wed, 25 Oct 2023 10:08:34 -0400 Subject: [PATCH 07/23] Change WildFire::is_fire_return_date() to WildFire::isFireReturnDate(). --- include/WildFire.h | 2 +- src/WildFire.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/WildFire.h b/include/WildFire.h index 71327b630..d326c1f15 100644 --- a/include/WildFire.h +++ b/include/WildFire.h @@ -117,7 +117,7 @@ class WildFire { BgcData * bd[NUM_PFT]; BgcData * bdall; - bool is_fire_return_date(const int yr, const int midx); + bool isFireReturnDate(const int yr, const int midx);// FW_MOD double getBurnOrgSoilthick(const int year); void getBurnAbgVegetation(const int ipft, const int year); diff --git a/src/WildFire.cpp b/src/WildFire.cpp index 0d6af5461..0784e5ffb 100644 --- a/src/WildFire.cpp +++ b/src/WildFire.cpp @@ -170,7 +170,7 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st // // do nothing: correct year, wrong month. // } // Extracted to: - if (is_fire_return_date(yr, midx)) + if (isFireReturnDate(yr, midx)) { ignite = true; } @@ -201,7 +201,7 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st { this->fri_derived = true; BOOST_LOG_SEV(glg, debug) << "Determine fire from FRI."; - if (is_fire_return_date(yr, midx)) + if (isFireReturnDate(yr, midx)) { ignite = true; } @@ -234,7 +234,7 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st /** Determine if the current date, by year and month midpoint, aligns with a fire return date. * This code was extracted from should_ignite() to avoid code repetition due to other changes. * Should this be moved? The private functions don't seem to be in a particular place.*/ -bool WildFire::is_fire_return_date(const int yr, const int midx) +bool WildFire::isFireReturnDate(const int yr, const int midx) { if ( (yr % this->fri) == 0 && yr > 0 ) { From 3bcea422dfbba752cce4898c138aea172405b67d Mon Sep 17 00:00:00 2001 From: Joshua Rady Date: Wed, 8 Nov 2023 16:25:28 -0500 Subject: [PATCH 08/23] Fix , -> : in ModelData.h. --- include/ModelData.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ModelData.h b/include/ModelData.h index dc4a84a84..f4ef640b6 100644 --- a/include/ModelData.h +++ b/include/ModelData.h @@ -109,7 +109,7 @@ class ModelData { // Switches to turn fire off (0) or on (1) for each run stage: bool fire_on_PR; bool fire_on_EQ; - bool fire_on_SP, + bool fire_on_SP; bool fire_on_TR; bool fire_on_SC; // Wildfire ignitions modes: [Note: In development. Numbers will likely change!] From 3008ebfaee630fd674f418327d017f1ead05c424 Mon Sep 17 00:00:00 2001 From: Joshua Rady Date: Mon, 13 Nov 2023 11:07:41 -0500 Subject: [PATCH 09/23] Add missing semicolon. --- src/WildFire.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WildFire.cpp b/src/WildFire.cpp index 0784e5ffb..02f5e14fa 100644 --- a/src/WildFire.cpp +++ b/src/WildFire.cpp @@ -212,7 +212,7 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st BOOST_LOG_SEV(glg, debug) << "Alternate ignition modes are not yet implemented. Set fire_ignition_mode = 1."; // Should probably terminate here. this->fri_derived = false; - ignite = false + ignite = false; break; } default: From e3e36ab9989f637720a3f466bd9f8a3a30d53a78 Mon Sep 17 00:00:00 2001 From: Joshua Rady Date: Mon, 13 Nov 2023 11:30:14 -0500 Subject: [PATCH 10/23] Add missing closing bracket. --- src/WildFire.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/WildFire.cpp b/src/WildFire.cpp index 02f5e14fa..c54e8c862 100644 --- a/src/WildFire.cpp +++ b/src/WildFire.cpp @@ -220,7 +220,8 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st BOOST_LOG_SEV(glg, err) << "Undefined ignition mode! (" << stage << ")"; break; } - // FW_MOD_END. + } + // FW_MOD_END. } else { BOOST_LOG_SEV(glg, err) << "Unknown stage! (" << stage << ")";// FW_NOTE: This check may be partially broken now due to fire switch checks! } From d18f5a5df9cd32d75058f760d886df5a688ecf59 Mon Sep 17 00:00:00 2001 From: Joshua Rady Date: Mon, 13 Nov 2023 11:46:02 -0500 Subject: [PATCH 11/23] Correct variable name. --- src/ModelData.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ModelData.cpp b/src/ModelData.cpp index fc56385b6..0b9b5e93c 100644 --- a/src/ModelData.cpp +++ b/src/ModelData.cpp @@ -124,7 +124,8 @@ ModelData::ModelData(Json::Value controldata):force_cmt(-1) { fire_on_SP = controldata["model_settings"]["fire_on_SP"].asBool(); fire_on_TR = controldata["model_settings"]["fire_on_TR"].asBool(); fire_on_SC = controldata["model_settings"]["fire_on_SC"].asBool(); - fire_ignition_type = controldata["model_settings"]["fire_ignition_type"].asInt(); + //fire_ignition_type = controldata["model_settings"]["fire_ignition_type"].asInt(); + fire_ignition_mode = controldata["model_settings"]["fire_ignition_mode"].asInt(); // FW_MOD_END. } From 1c76a2a4053a64d63dea9b283c9e88d5e6a42263 Mon Sep 17 00:00:00 2001 From: Joshua Rady Date: Thu, 18 Jan 2024 11:18:14 -0500 Subject: [PATCH 12/23] Add missing thises and clean up code. --- src/WildFire.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/WildFire.cpp b/src/WildFire.cpp index c54e8c862..c95061a0c 100644 --- a/src/WildFire.cpp +++ b/src/WildFire.cpp @@ -138,7 +138,6 @@ void WildFire::set_state_from_restartdata(const RestartData & rdata) { */ //bool WildFire::should_ignite(const int yr, const int midx, const std::string& stage) { bool WildFire::should_ignite(const int yr, const int midx, const std::string& stage, - //const ModelData md) {// FW_MOD: Add ModelData. Pointer? const ModelData* md) {// FW_MOD BOOST_LOG_SEV(glg, note) << "determining fire ignition for yr:" << yr @@ -170,7 +169,7 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st // // do nothing: correct year, wrong month. // } // Extracted to: - if (isFireReturnDate(yr, midx)) + if (this->isFireReturnDate(yr, midx)) { ignite = true; } @@ -180,8 +179,6 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st else if ( (stage.compare("tr-run") == 0 && md->fire_on_TR) || (stage.compare("sc-run") == 0 && md->fire_on_SC) ) { - //this->fri_derived = false; - switch (md->fire_ignition_mode) { case 0:// Default (old) fire behavior, use explicit fire from input file: @@ -200,16 +197,16 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st case 1:// Use fire return interval: { this->fri_derived = true; - BOOST_LOG_SEV(glg, debug) << "Determine fire from FRI."; - if (isFireReturnDate(yr, midx)) + BOOST_LOG_SEV(glg, debug) << "fire_ignition_mode = 1. Determine fire from FRI."; + if (this->isFireReturnDate(yr, midx)) { ignite = true; } break; } - case 2://Placeholder for future dynamic ignition mode... + case 2://Placeholder for future dynamic ignition mode: { - BOOST_LOG_SEV(glg, debug) << "Alternate ignition modes are not yet implemented. Set fire_ignition_mode = 1."; + BOOST_LOG_SEV(glg, debug) << "Alternate ignition modes are not yet implemented. Set fire_ignition_mode = 0 or 1."; // Should probably terminate here. this->fri_derived = false; ignite = false; @@ -237,13 +234,13 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st * Should this be moved? The private functions don't seem to be in a particular place.*/ bool WildFire::isFireReturnDate(const int yr, const int midx) { - if ( (yr % this->fri) == 0 && yr > 0 ) + if ((yr % this->fri) == 0 && yr > 0) { if (midx == temutil::doy2month(this->fri_jday_of_burn)) { return true; } - // do nothing: correct year, wrong month. + // Do nothing: correct year, wrong month. } return false; }// FW_MOD_END. From 1df33d82df53b77013122d35c1633bd0616cbd9d Mon Sep 17 00:00:00 2001 From: Joshua Rady Date: Thu, 18 Jan 2024 15:35:11 -0500 Subject: [PATCH 13/23] Change logic in WildFire::isFireReturnDate() to protect against a divide by zero. --- src/WildFire.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/WildFire.cpp b/src/WildFire.cpp index c95061a0c..765e4d64c 100644 --- a/src/WildFire.cpp +++ b/src/WildFire.cpp @@ -234,7 +234,10 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st * Should this be moved? The private functions don't seem to be in a particular place.*/ bool WildFire::isFireReturnDate(const int yr, const int midx) { - if ((yr % this->fri) == 0 && yr > 0) + // The original conditional will fail with a divide by zero error when yr = 0: + //if ((yr % this->fri) == 0 && yr > 0) + // This is safe: + if (yr > 0 && (yr % this->fri) == 0) { if (midx == temutil::doy2month(this->fri_jday_of_burn)) { From 3f987da8d5d9b698842efce485494c3e9dfcc20a Mon Sep 17 00:00:00 2001 From: Joshua Rady Date: Thu, 18 Jan 2024 16:39:35 -0500 Subject: [PATCH 14/23] Add debug reporting to WildFire::isFireReturnDate(). --- src/WildFire.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/WildFire.cpp b/src/WildFire.cpp index 765e4d64c..7679f3125 100644 --- a/src/WildFire.cpp +++ b/src/WildFire.cpp @@ -234,13 +234,21 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st * Should this be moved? The private functions don't seem to be in a particular place.*/ bool WildFire::isFireReturnDate(const int yr, const int midx) { + BOOST_LOG_SEV(glg, debug) << "Entering WildFire::isFireReturnDate()." + BOOST_LOG_SEV(glg, debug) << "yr = " << yr << "midx =" << midx + BOOST_LOG_SEV(glg, debug) << "yr > 0" << (yr > 0) + // The original conditional will fail with a divide by zero error when yr = 0: //if ((yr % this->fri) == 0 && yr > 0) // This is safe: if (yr > 0 && (yr % this->fri) == 0) { + BOOST_LOG_SEV(glg, debug) << "Passed 1st if()." + if (midx == temutil::doy2month(this->fri_jday_of_burn)) { + BOOST_LOG_SEV(glg, debug) << "Passed 2nd if()." + return true; } // Do nothing: correct year, wrong month. From b1b51f79d2623f2e2cd64f8f161d758cd2b5b6fd Mon Sep 17 00:00:00 2001 From: Joshua Rady Date: Thu, 18 Jan 2024 16:47:25 -0500 Subject: [PATCH 15/23] Add missing semicolons. --- src/WildFire.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/WildFire.cpp b/src/WildFire.cpp index 7679f3125..71109a1fa 100644 --- a/src/WildFire.cpp +++ b/src/WildFire.cpp @@ -234,20 +234,20 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st * Should this be moved? The private functions don't seem to be in a particular place.*/ bool WildFire::isFireReturnDate(const int yr, const int midx) { - BOOST_LOG_SEV(glg, debug) << "Entering WildFire::isFireReturnDate()." - BOOST_LOG_SEV(glg, debug) << "yr = " << yr << "midx =" << midx - BOOST_LOG_SEV(glg, debug) << "yr > 0" << (yr > 0) + BOOST_LOG_SEV(glg, debug) << "Entering WildFire::isFireReturnDate()."; + BOOST_LOG_SEV(glg, debug) << "yr = " << yr << "midx =" << midx; + BOOST_LOG_SEV(glg, debug) << "yr > 0" << (yr > 0); // The original conditional will fail with a divide by zero error when yr = 0: //if ((yr % this->fri) == 0 && yr > 0) // This is safe: if (yr > 0 && (yr % this->fri) == 0) { - BOOST_LOG_SEV(glg, debug) << "Passed 1st if()." + BOOST_LOG_SEV(glg, debug) << "Passed 1st if()."; if (midx == temutil::doy2month(this->fri_jday_of_burn)) { - BOOST_LOG_SEV(glg, debug) << "Passed 2nd if()." + BOOST_LOG_SEV(glg, debug) << "Passed 2nd if()."; return true; } From 4ca12dd22489a131be4646c6694dc096214de799 Mon Sep 17 00:00:00 2001 From: Joshua Rady Date: Thu, 18 Jan 2024 17:28:38 -0500 Subject: [PATCH 16/23] More handing of divide by zero issues. --- src/WildFire.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/WildFire.cpp b/src/WildFire.cpp index 71109a1fa..743528da3 100644 --- a/src/WildFire.cpp +++ b/src/WildFire.cpp @@ -235,13 +235,15 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st bool WildFire::isFireReturnDate(const int yr, const int midx) { BOOST_LOG_SEV(glg, debug) << "Entering WildFire::isFireReturnDate()."; - BOOST_LOG_SEV(glg, debug) << "yr = " << yr << "midx =" << midx; - BOOST_LOG_SEV(glg, debug) << "yr > 0" << (yr > 0); + BOOST_LOG_SEV(glg, debug) << "yr =" << yr << ", midx =" << midx; + BOOST_LOG_SEV(glg, debug) << "yr > 0 " << (yr > 0); + BOOST_LOG_SEV(glg, debug) << "this->fri " << this->fri; + BOOST_LOG_SEV(glg, debug) << "this->fri_jday_of_burn " << this->fri_jday_of_burn // The original conditional will fail with a divide by zero error when yr = 0: //if ((yr % this->fri) == 0 && yr > 0) // This is safe: - if (yr > 0 && (yr % this->fri) == 0) + if (yr > 0 && midx > 0 && (yr % this->fri) == 0) { BOOST_LOG_SEV(glg, debug) << "Passed 1st if()."; @@ -253,6 +255,7 @@ bool WildFire::isFireReturnDate(const int yr, const int midx) } // Do nothing: correct year, wrong month. } + BOOST_LOG_SEV(glg, debug) << "Completing WildFire::isFireReturnDate()."; return false; }// FW_MOD_END. From 07a7ff27331cc173a1e1f53e7ea6ee4a10632c30 Mon Sep 17 00:00:00 2001 From: Joshua Rady Date: Thu, 18 Jan 2024 17:45:07 -0500 Subject: [PATCH 17/23] Add missing semicolon. --- src/WildFire.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WildFire.cpp b/src/WildFire.cpp index 743528da3..29ee3f7dd 100644 --- a/src/WildFire.cpp +++ b/src/WildFire.cpp @@ -238,7 +238,7 @@ bool WildFire::isFireReturnDate(const int yr, const int midx) BOOST_LOG_SEV(glg, debug) << "yr =" << yr << ", midx =" << midx; BOOST_LOG_SEV(glg, debug) << "yr > 0 " << (yr > 0); BOOST_LOG_SEV(glg, debug) << "this->fri " << this->fri; - BOOST_LOG_SEV(glg, debug) << "this->fri_jday_of_burn " << this->fri_jday_of_burn + BOOST_LOG_SEV(glg, debug) << "this->fri_jday_of_burn " << this->fri_jday_of_burn; // The original conditional will fail with a divide by zero error when yr = 0: //if ((yr % this->fri) == 0 && yr > 0) From 49904a4e2cf33793089e05330bc158fc23f86da3 Mon Sep 17 00:00:00 2001 From: Joshua Rady Date: Thu, 18 Jan 2024 18:08:39 -0500 Subject: [PATCH 18/23] More handing of divide by zero issues. --- src/WildFire.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WildFire.cpp b/src/WildFire.cpp index 29ee3f7dd..69f2bcc6a 100644 --- a/src/WildFire.cpp +++ b/src/WildFire.cpp @@ -243,7 +243,7 @@ bool WildFire::isFireReturnDate(const int yr, const int midx) // The original conditional will fail with a divide by zero error when yr = 0: //if ((yr % this->fri) == 0 && yr > 0) // This is safe: - if (yr > 0 && midx > 0 && (yr % this->fri) == 0) + if (yr > 0 && this->fri > 0 && (yr % this->fri) == 0) { BOOST_LOG_SEV(glg, debug) << "Passed 1st if()."; From 3057e2b044a81d3d7e17819141a5518c967cf301 Mon Sep 17 00:00:00 2001 From: Joshua Rady Date: Fri, 19 Jan 2024 12:00:03 -0500 Subject: [PATCH 19/23] Remove temporary reporting and clean up. --- src/WildFire.cpp | 57 ++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/src/WildFire.cpp b/src/WildFire.cpp index 69f2bcc6a..f34c3c3f1 100644 --- a/src/WildFire.cpp +++ b/src/WildFire.cpp @@ -127,7 +127,11 @@ void WildFire::set_state_from_restartdata(const RestartData & rdata) { * There are two modes of operation: "FRI" (fire recurrence interval) and * "exp". Pre-run, equilibrium, and spin-up stages all use the FRI settings * for determining whether or not a fire should ignite, while transient and - * scenario stages use explicit dates for fire occurrence. + * scenario stages use explicit dates for fire occurrence. + FW_MOD: + * scenario stages traditionally used explicit dates for fire occurrence. This + * remains the default behavior but fire return interval may also be specified + * for all run stages. * * The settings for FRI and the data for explicit fire dates are held in data * members of this (WildFire) object. This function looks at those data @@ -156,19 +160,10 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st // Currently for the PR, EQ, and SP stages only fire return interval based fire is implemented // so there is no need to check fire_ignition_mode. If fire is on it is FRI based. // This could change in the future. - // FW_MOD_END. this->fri_derived = true; BOOST_LOG_SEV(glg, debug) << "Determine fire from FRI."; - // FW_MOD_START: -// if ( (yr % this->fri) == 0 && yr > 0 ) { -// if (midx == temutil::doy2month(this->fri_jday_of_burn)) { -// ignite = true; -// } -// // do nothing: correct year, wrong month. -// } - // Extracted to: if (this->isFireReturnDate(yr, midx)) { ignite = true; @@ -198,6 +193,7 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st { this->fri_derived = true; BOOST_LOG_SEV(glg, debug) << "fire_ignition_mode = 1. Determine fire from FRI."; + if (this->isFireReturnDate(yr, midx)) { ignite = true; @@ -218,10 +214,19 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st break; } } - // FW_MOD_END. - } else { - BOOST_LOG_SEV(glg, err) << "Unknown stage! (" << stage << ")";// FW_NOTE: This check may be partially broken now due to fire switch checks! + //} else {// FW_NOTE: This check is broken now due to fire switch checks. It requires more logic. } + // FW_NOTE: This will work: + //else if (stage.compare("pre-run") != 0 && stage.compare("eq-run") != 0 && + // stage.compare("sp-run") != 0 && stage.compare("tr-run") != 0 && + // stage.compare("sc-run") != 0) + // FW_NOTE: But this will be more efficient: + else if (!(stage.compare("pre-run") == 0 || stage.compare("eq-run") == 0 || + stage.compare("sp-run") == 0 || stage.compare("tr-run") == 0 || + stage.compare("sc-run") == 0)) + { + BOOST_LOG_SEV(glg, err) << "Unknown stage! (" << stage << ")"; + }// FW_MOD_END. BOOST_LOG_SEV(glg, debug) << "Should we ignite a fire?:" << ignite; @@ -229,33 +234,27 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st } // FW_MOD_START: -/** Determine if the current date, by year and month midpoint, aligns with a fire return date. - * This code was extracted from should_ignite() to avoid code repetition due to other changes. +/** Determine if the current date, by year and month (index), aligns with the fire return interval. + * + * FW_NOTE: + * This code was extracted from should_ignite() to avoid code repetition due to other changesĀ in the + * function. * Should this be moved? The private functions don't seem to be in a particular place.*/ bool WildFire::isFireReturnDate(const int yr, const int midx) { - BOOST_LOG_SEV(glg, debug) << "Entering WildFire::isFireReturnDate()."; - BOOST_LOG_SEV(glg, debug) << "yr =" << yr << ", midx =" << midx; - BOOST_LOG_SEV(glg, debug) << "yr > 0 " << (yr > 0); - BOOST_LOG_SEV(glg, debug) << "this->fri " << this->fri; - BOOST_LOG_SEV(glg, debug) << "this->fri_jday_of_burn " << this->fri_jday_of_burn; - - // The original conditional will fail with a divide by zero error when yr = 0: - //if ((yr % this->fri) == 0 && yr > 0) - // This is safe: + // The original conditional checks for years that are multiples of the fire return interval: + // if ((yr % this->fri) == 0 && yr > 0) + // Year zero is ignored to prevent fires from occurring right at the start of the run. If FRI = 0 + // a divide by zero error will result. It makes sense to all accept 0 values for FRI for locations + // where fire should not occur. The following logic handles this safely: if (yr > 0 && this->fri > 0 && (yr % this->fri) == 0) { - BOOST_LOG_SEV(glg, debug) << "Passed 1st if()."; - if (midx == temutil::doy2month(this->fri_jday_of_burn)) { - BOOST_LOG_SEV(glg, debug) << "Passed 2nd if()."; - return true; } // Do nothing: correct year, wrong month. } - BOOST_LOG_SEV(glg, debug) << "Completing WildFire::isFireReturnDate()."; return false; }// FW_MOD_END. From 09b4a3b396b21d54981701e16baaec65c563f323 Mon Sep 17 00:00:00 2001 From: Joshua Rady Date: Tue, 16 Apr 2024 12:31:56 -0400 Subject: [PATCH 20/23] Remove fire_on_PR switch from config file and code. --- config/config.js | 1 - include/ModelData.h | 1 - src/ModelData.cpp | 1 - src/TEM.cpp | 3 +-- src/WildFire.cpp | 3 +-- 5 files changed, 2 insertions(+), 7 deletions(-) diff --git a/config/config.js b/config/config.js index a1b2c38c9..1c8bd564e 100644 --- a/config/config.js +++ b/config/config.js @@ -128,7 +128,6 @@ // //"output_starting_year": -9999 // FW_MOD_START: // Switches to turn fire off (0) or on (1) for each run stage: - "fire_on_PR": 0, "fire_on_EQ": 0, "fire_on_SP": 0, "fire_on_TR": 0, diff --git a/include/ModelData.h b/include/ModelData.h index f4ef640b6..cd02485b2 100644 --- a/include/ModelData.h +++ b/include/ModelData.h @@ -107,7 +107,6 @@ class ModelData { // FW_MOD_START: // Switches to turn fire off (0) or on (1) for each run stage: - bool fire_on_PR; bool fire_on_EQ; bool fire_on_SP; bool fire_on_TR; diff --git a/src/ModelData.cpp b/src/ModelData.cpp index 0b9b5e93c..963527bca 100644 --- a/src/ModelData.cpp +++ b/src/ModelData.cpp @@ -119,7 +119,6 @@ ModelData::ModelData(Json::Value controldata):force_cmt(-1) { //useseverity = controldata["model_settings"]["fire_severity_as_input"].asInt(); // FW_MOD_START: - fire_on_PR = controldata["model_settings"]["fire_on_PR"].asBool(); fire_on_EQ = controldata["model_settings"]["fire_on_EQ"].asBool(); fire_on_SP = controldata["model_settings"]["fire_on_SP"].asBool(); fire_on_TR = controldata["model_settings"]["fire_on_TR"].asBool(); diff --git a/src/TEM.cpp b/src/TEM.cpp index 623f35555..b7cd9a0e9 100755 --- a/src/TEM.cpp +++ b/src/TEM.cpp @@ -587,8 +587,7 @@ void advance_model(const int rowidx, const int colidx, runner.cohort.md->set_nfeed(runner.cohort.md->pr_nfeed); runner.cohort.md->set_avlnflg(runner.cohort.md->pr_avln); runner.cohort.md->set_baseline(runner.cohort.md->pr_baseline); - //runner.cohort.md->set_dsbmodule(runner.cohort.md->pr_dsb); - runner.cohort.md->set_dsbmodule(runner.cohort.md->fire_on_PR);// FW_MOD: Preceded runner.cohort.md->pr_dsb. + runner.cohort.md->set_dsbmodule(runner.cohort.md->pr_dsb); runner.cohort.md->set_dslmodule(runner.cohort.md->pr_dsl); runner.cohort.md->set_dynamic_lai_module(runner.cohort.md->pr_dyn_lai); diff --git a/src/WildFire.cpp b/src/WildFire.cpp index f34c3c3f1..ca3ae0dd3 100644 --- a/src/WildFire.cpp +++ b/src/WildFire.cpp @@ -153,8 +153,7 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st //if ( stage.compare("pre-run") == 0 || stage.compare("eq-run") == 0 || stage.compare("sp-run") == 0 ) { // FW_MOD_START: // Check that fire is on for the current run stage: - if ( (stage.compare("pre-run") == 0 && md->fire_on_PR) || - (stage.compare("eq-run") == 0 && md->fire_on_EQ) || + if ( (stage.compare("eq-run") == 0 && md->fire_on_EQ) || (stage.compare("sp-run") == 0 && md->fire_on_SP) ) { // Currently for the PR, EQ, and SP stages only fire return interval based fire is implemented From e7f729144006ed813b5349284e3e4d7adcf5a4d4 Mon Sep 17 00:00:00 2001 From: Joshua Rady Date: Tue, 16 Apr 2024 14:16:02 -0400 Subject: [PATCH 21/23] Restore orignal check for PR stage. --- src/WildFire.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/WildFire.cpp b/src/WildFire.cpp index ca3ae0dd3..d78e363b7 100644 --- a/src/WildFire.cpp +++ b/src/WildFire.cpp @@ -153,7 +153,8 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st //if ( stage.compare("pre-run") == 0 || stage.compare("eq-run") == 0 || stage.compare("sp-run") == 0 ) { // FW_MOD_START: // Check that fire is on for the current run stage: - if ( (stage.compare("eq-run") == 0 && md->fire_on_EQ) || + if ( stage.compare("pre-run") == 0 || + (stage.compare("eq-run") == 0 && md->fire_on_EQ) || (stage.compare("sp-run") == 0 && md->fire_on_SP) ) { // Currently for the PR, EQ, and SP stages only fire return interval based fire is implemented From 08881d7e3ac81f157b0c1c6ca0ea3a9a16432b6c Mon Sep 17 00:00:00 2001 From: Joshua Rady Date: Tue, 16 Apr 2024 14:25:24 -0400 Subject: [PATCH 22/23] Change config flags of the form 'model_settings: fire_on_XX = 0' to 'stage_settings: sc: fire = false'. --- config/config.js | 11 +++++------ include/ModelData.h | 2 +- src/ModelData.cpp | 8 ++++---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/config/config.js b/config/config.js index 1c8bd564e..2e4a184d7 100644 --- a/config/config.js +++ b/config/config.js @@ -68,6 +68,7 @@ "baseline": false, "dsb": false, "dsl": false, + //FW_NOTES: Fire will never be on in the pre-run so we don't need a switch? "dyn_lai": false }, "eq": { @@ -78,6 +79,7 @@ "baseline": true, "dsb": false, "dsl": true, + "fire": false, "dyn_lai": true }, "sp": { @@ -88,6 +90,7 @@ "baseline": true, "dsb": false, "dsl": true, + "fire": false, "dyn_lai": true }, "tr": { @@ -98,6 +101,7 @@ "baseline": true, "dsb": false, "dsl": true, + "fire": false, "dyn_lai": true }, "sc": { @@ -108,6 +112,7 @@ "baseline": true, "dsb": false, "dsl": true, + "fire": false, "dyn_lai": true } @@ -126,12 +131,6 @@ // //"varied_co2": 0, // //"fire_severity_as_input": 0, // fire sev. as input or ?? // //"output_starting_year": -9999 - // FW_MOD_START: - // Switches to turn fire off (0) or on (1) for each run stage: - "fire_on_EQ": 0, - "fire_on_SP": 0, - "fire_on_TR": 0, - "fire_on_SC": 0, // Wildfire ignitions modes: [Note: In development. Numbers will likely change!] // 0: Default/old: FRI for PR/EQ/SP, explicit for TR/SC. // 1: Use fire return interval for all stages with fire on. diff --git a/include/ModelData.h b/include/ModelData.h index cd02485b2..ca70676de 100644 --- a/include/ModelData.h +++ b/include/ModelData.h @@ -106,7 +106,7 @@ class ModelData { bool useseverity; // using fire severity inputs // FW_MOD_START: - // Switches to turn fire off (0) or on (1) for each run stage: + // Switches to turn fire off for each run stage. Fire in never on the pre-run stage: bool fire_on_EQ; bool fire_on_SP; bool fire_on_TR; diff --git a/src/ModelData.cpp b/src/ModelData.cpp index 963527bca..08bb2a90e 100644 --- a/src/ModelData.cpp +++ b/src/ModelData.cpp @@ -119,10 +119,10 @@ ModelData::ModelData(Json::Value controldata):force_cmt(-1) { //useseverity = controldata["model_settings"]["fire_severity_as_input"].asInt(); // FW_MOD_START: - fire_on_EQ = controldata["model_settings"]["fire_on_EQ"].asBool(); - fire_on_SP = controldata["model_settings"]["fire_on_SP"].asBool(); - fire_on_TR = controldata["model_settings"]["fire_on_TR"].asBool(); - fire_on_SC = controldata["model_settings"]["fire_on_SC"].asBool(); + fire_on_EQ = controldata["stage_settings"]["eq"]["fire"].asBool(); + fire_on_SP = controldata["stage_settings"]["sp"]["fire"].asBool(); + fire_on_TR = controldata["stage_settings"]["tr"]["fire"].asBool(); + fire_on_SC = controldata["stage_settings"]["sc"]["fire"].asBool(); //fire_ignition_type = controldata["model_settings"]["fire_ignition_type"].asInt(); fire_ignition_mode = controldata["model_settings"]["fire_ignition_mode"].asInt(); // FW_MOD_END. From 64eaca5335e2167d3093bd965b6d7ef3d1d98ab3 Mon Sep 17 00:00:00 2001 From: Joshua Rady Date: Tue, 16 Apr 2024 15:16:28 -0400 Subject: [PATCH 23/23] Change the 'model_settings: fire_ignition_mode' flag to two 'module_settings: dsb: fire: ignition_XX' flags and update code to reflect this. --- config/config.js | 29 +++++++++++++++++++++++------ include/ModelData.h | 8 +++----- src/ModelData.cpp | 4 ++-- src/WildFire.cpp | 19 +++++++++++++++---- 4 files changed, 43 insertions(+), 17 deletions(-) diff --git a/config/config.js b/config/config.js index 2e4a184d7..27555717b 100644 --- a/config/config.js +++ b/config/config.js @@ -125,18 +125,35 @@ }, + "module_settings" { + "dsb": { + "fire": { + // Wildfire ignitions modes: [Note: In development. Numbers may change!] + // 0: Default/old: FRI for [PR/]EQ/SP, explicit for TR/SC. + // 1: Use fire return interval for this stage if fire is on. + // 2+: Reserved for future use. + // Fire is alway off in the PR stage and can only be FRI for EQ/SP so no switches are + // provided for these stages. + "ignition_tr": 0 + "ignition_sc": 0 + + // More future controls per stage can go here... + //"severity_pr": + //"severity_eq": + // ... + }, + // Future disturbances go here... + //"insect": { ... }, + //"thermokarst":{ ... }, + } + }, + "model_settings": { "dynamic_lai": 1, // from model (1) or from input (0) // //"dynamic_climate": 0, // //"varied_co2": 0, // //"fire_severity_as_input": 0, // fire sev. as input or ?? // //"output_starting_year": -9999 - // Wildfire ignitions modes: [Note: In development. Numbers will likely change!] - // 0: Default/old: FRI for PR/EQ/SP, explicit for TR/SC. - // 1: Use fire return interval for all stages with fire on. - // 2; Revised (placeholder only currently) - "fire_ignition_mode": 0 - // FW_MOD_END. } // "output_switches": { diff --git a/include/ModelData.h b/include/ModelData.h index ca70676de..1929072eb 100644 --- a/include/ModelData.h +++ b/include/ModelData.h @@ -111,11 +111,9 @@ class ModelData { bool fire_on_SP; bool fire_on_TR; bool fire_on_SC; - // Wildfire ignitions modes: [Note: In development. Numbers will likely change!] - // 0: Default/old: FRI for PR/EQ/SP, explicit for TR/SC. - // 1: Use fire return interval for all stages with fire on. - // 2; Revised (placeholder only currently) - int fire_ignition_mode; + // Wildfire ignitions modes: 0: explicit for TR/SC. 1: Use fire return interval, 2+: Reserved for future use. + int fire_ignition_tr; + int fire_ignition_sc; // FW_MOD_END. bool outSiteDay; diff --git a/src/ModelData.cpp b/src/ModelData.cpp index 08bb2a90e..3c7501257 100644 --- a/src/ModelData.cpp +++ b/src/ModelData.cpp @@ -123,8 +123,8 @@ ModelData::ModelData(Json::Value controldata):force_cmt(-1) { fire_on_SP = controldata["stage_settings"]["sp"]["fire"].asBool(); fire_on_TR = controldata["stage_settings"]["tr"]["fire"].asBool(); fire_on_SC = controldata["stage_settings"]["sc"]["fire"].asBool(); - //fire_ignition_type = controldata["model_settings"]["fire_ignition_type"].asInt(); - fire_ignition_mode = controldata["model_settings"]["fire_ignition_mode"].asInt(); + fire_ignition_tr = controldata["module_settings"]["dsb"]["fire"]["ignition_tr"].asInt(); + fire_ignition_sc = controldata["module_settings"]["dsb"]["fire"]["ignition_sc"].asInt(); // FW_MOD_END. } diff --git a/src/WildFire.cpp b/src/WildFire.cpp index d78e363b7..7d160aac6 100644 --- a/src/WildFire.cpp +++ b/src/WildFire.cpp @@ -158,7 +158,7 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st (stage.compare("sp-run") == 0 && md->fire_on_SP) ) { // Currently for the PR, EQ, and SP stages only fire return interval based fire is implemented - // so there is no need to check fire_ignition_mode. If fire is on it is FRI based. + // so there is no need to check te fire ignition mode. If fire is on it is FRI based. // This could change in the future. this->fri_derived = true; @@ -174,7 +174,18 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st else if ( (stage.compare("tr-run") == 0 && md->fire_on_TR) || (stage.compare("sc-run") == 0 && md->fire_on_SC) ) { - switch (md->fire_ignition_mode) + int fire_ignition_mode; + + if (stage.compare("tr-run") + { + fire_ignition_mode = md->fire_ignition_tr + } + else + { + fire_ignition_mode = md->fire_ignition_sc + } + + switch (fire_ignition_mode) { case 0:// Default (old) fire behavior, use explicit fire from input file: { @@ -192,7 +203,7 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st case 1:// Use fire return interval: { this->fri_derived = true; - BOOST_LOG_SEV(glg, debug) << "fire_ignition_mode = 1. Determine fire from FRI."; + BOOST_LOG_SEV(glg, debug) << "Fire ignition mode = 1. Determine fire from FRI."; if (this->isFireReturnDate(yr, midx)) { @@ -202,7 +213,7 @@ bool WildFire::should_ignite(const int yr, const int midx, const std::string& st } case 2://Placeholder for future dynamic ignition mode: { - BOOST_LOG_SEV(glg, debug) << "Alternate ignition modes are not yet implemented. Set fire_ignition_mode = 0 or 1."; + BOOST_LOG_SEV(glg, debug) << "Alternate ignition modes are not yet implemented. Set ignition_XX = 0 or 1."; // Should probably terminate here. this->fri_derived = false; ignite = false;