GCBM
Public Member Functions | Public Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
CBMSpinupSequencer Class Reference

#include <cbmspinupsequencer.h>

Inherits SequencerModuleBase.

Collaboration diagram for CBMSpinupSequencer:
Collaboration graph

Public Member Functions

 CBMSpinupSequencer ()
 
virtual ~CBMSpinupSequencer ()
 
void configure (const DynamicObject &config) override
 
void configure (flint::ITiming &timing) override
 
bool Run (NotificationCenter &_notificationCenter, flint::ILandUnitController &luc) override
 

Public Attributes

const std::string returnInverval = "return_interval"
 
const std::string maxRotation = "max_rotations"
 
const std::string historicDistType = "historic_disturbance_type"
 
const std::string lastDistType = "last_pass_disturbance_type"
 
const std::string delay = "delay"
 
const std::string inventoryDelay = "inventory_delay"
 

Private Types

typedef std::tuple< int, std::string, int, int, double > CacheKey
 

Private Member Functions

bool getSpinupParameters (flint::ILandUnitDataWrapper &landUnitData)
 
void runRegularSpinup (NotificationCenter &notificationCenter, flint::ILandUnitController &luc, bool runMoss)
 
void runPeatlandSpinup (NotificationCenter &notificationCenter, flint::ILandUnitController &luc)
 
bool isSlowPoolStable (double lastSlowPoolValue, double currentSlowPoolValue)
 
bool isPeatlandApplicable ()
 
bool isMossApplicable (bool runPeatland)
 
void fireSpinupSequenceEvent (NotificationCenter &notificationCenter, flint::ILandUnitController &luc, int maximumSteps, bool incrementStep)
 
void fireHistoricalLastDisturbanceEvent (NotificationCenter &notificationCenter, flint::ILandUnitController &luc, std::string disturbanceName)
 

Private Attributes

const flint::IPool * _aboveGroundSlowSoil
 
const flint::IPool * _belowGroundSlowSoil
 
const flint::IPool * _featherMossSlow
 
const flint::IPool * _sphagnumMossSlow
 
const std::set< std::string > _biomassPools
 
flint::IVariable * _age
 
flint::IVariable * _shrubAge
 
flint::IVariable * _smallTreeAge
 
flint::IVariable * _delay
 
flint::IVariable * _mat
 
flint::IVariable * _spu
 
flint::IVariable * _isDecaying
 
flint::IVariable * _lastPassDisturbanceTimeseries = nullptr
 
flint::IVariable * _spinupMossOnly
 
flint::IVariable * _regenDelay
 
int _maxRotationValue { 0 }
 
int _minimumRotation { 0 }
 
int _ageReturnInterval { 0 }
 
int _standAge { 0 }
 
int _standRegenDelay { 0 }
 
int _standDelay { 0 }
 
int _spinupGrowthCurveID { -1 }
 
std::string _historicDistType
 
std::string _lastPassDistType
 
std::unordered_map< std::string, int > _disturbanceOrder
 
Poco::Nullable< DateTime > _rampStartDate
 
std::unordered_map< CacheKey, std::vector< double >, moja::Hash > _cache
 

Member Typedef Documentation

◆ CacheKey

typedef std::tuple<int, std::string, int, int, double> CacheKey
private

Constructor & Destructor Documentation

◆ CBMSpinupSequencer()

◆ ~CBMSpinupSequencer()

virtual ~CBMSpinupSequencer ( )
virtual

Member Function Documentation

◆ configure() [1/2]

void configure ( const DynamicObject &  config)
override

◆ configure() [2/2]

void configure ( flint::ITiming &  timing)
override

◆ fireHistoricalLastDisturbanceEvent()

void fireHistoricalLastDisturbanceEvent ( NotificationCenter &  notificationCenter,
flint::ILandUnitController &  luc,
std::string  disturbanceName 
)
private

Create a placeholder vector transfer to keep the event pool transfers and fire the disturbance with the transfers vector to be filled in by any modules that build the disturbance matrix
Post the notification DisturbanceEvent with the data about the disturbance and the transfers

Parameters
notificationCenterNotificationCenter&
lucILandUnitController&
disturbanceDisturbance&
Returns
void

◆ fireSpinupSequenceEvent()

void fireSpinupSequenceEvent ( NotificationCenter &  notificationCenter,
flint::ILandUnitController &  luc,
int  maximumSteps,
bool  incrementStep 
)
private

For each step in the range 0 to parameter maximumSteps, if parameter incrementStep is true, increment the timing step, start step date, end step date, current start and end date by 1 (one year)
Post notifications TimingStep, TimingPreEndStep, TimingEndStep and TimingPostStep
Invoke applyOperations() to apply the operations in the current step and clearAllOperationResults() to clear the results on _landUnitData

Parameters
maximumStepsint
incrementStepbool
notificationCenterNotificationCenter&
lucILandUnitController&
Returns
void

◆ getSpinupParameters()

bool getSpinupParameters ( flint::ILandUnitDataWrapper &  landUnitData)
private

Initialise constant variable spinup as variable "spinup_parameters" in landUnitData.
If spinup is empty, it will return false.
Assign CBMSpinupSequencer._ageReturnInterval as "return_interval" in spinup,
CBMSpinupSequencer._maxRotationValue as "max_rotations" in spinup,
CBMSpinupSequencer._historicDistType as "historic_disturbance_type" in spinup,
CBMSpinupSequencer._lastPassDistType as "last_pass_disturbance_type" in spinup,
CBMSpinupSequencer._standDelay as "inventory_delay" in spinup, if empty assign as "delay" in spinup.

If variable "growth_curve_id" in landUnitData is empty, assign CBMSpinupSequencer._spinupGrowthCurveID as -1,
else assign CBMSpinupSequencer._spinupGrowthCurveID as variable "growth_curve_id" in landUnitData.
If variable "minimum_rotation" in landUnitData is not empty, assign CBMSpinupSequencer._minimumRotation as variable "minimum_rotation" in landUnitData,
else return false.
Assign CBMSpinupSequencer._age as variable "age" in landUnitData,
CBMSpinupSequencer._mat as "mean_annual_temperature" in landUnitData,
CBMSpinupSequencer._spu as "spatial_unit_id" in landUnitData,
CBMSpinupSequencer._isDecaying as "is_decaying" in landUnitData and
CBMSpinupSequencer._spinupMossOnly as "spinup_moss_only" in landUnitData. if _landUnitData has variable "enable_peatland" and variable "enable_peatland" value,
Assign CBMSpinupSequencer._shrubAge as variable "peatland_shrub_age" in landUnitData and
CBMSpinupSequencer._smallTreeAge as variable "peatland_smalltree_age" in landUnitData.
if variable "initial_age" in landUnitData is not empty,
assign CBMSpinupSequencer._standAge as variable "initial_age" in landUnitData.
else assign CBMSpinupSequencer._standAge as 0 and
if _landUnitData does not have variable "enable_peatland" and variable "enable_peatland" value,
return false.
Set "delay" in landUnitData as CBMSpinupSequencer._standDelay.
Assign CBMSpinupSequencer._aboveGroundSlowSoil as pool variable "AboveGroundSlowSoil" in landUnitData and
CBMSpinupSequencer._belowGroundSlowSoil as pool variable "BelowGroundSlowSoil" in landUnitData.
if landUnitData has variable "last_pass_disturbance_timeseries", assign CBMSpinupSequencer._lastPassDisturbanceTimeseries as variable "last_pass_disturbance_timeseries" in landUnitData.
Initialise integer Variable order as 1.
if landUnitData has variable "user_disturbance_order",
for every orderedDistType in variable "user_disturbance_order" in landUnitData,
iterate order by 1 and store the value in orderedDistType of CBMSpinupSequencer._disturbanceOrder.
if landUnitData has variable "default_disturbance_order", for every orderedDistType in "default_disturbance_order" in landUnitData, if orderedDistType of CBMSpinupSequencer._disturbanceOrder is equal to the last element of CBMSpinupSequencer._disturbanceOrder,
iterate order by 1 and store the value in orderedDistType of CBMSpinupSequencer._disturbanceOrder.

return true.

Parameters
landUnitDataflint::ILandUnitDataWrapper&
Returns
bool

◆ isMossApplicable()

bool isMossApplicable ( bool  runPeatland)
private

Determine whether the moss needs to be simulated

If _landUnitData does not have the variable "enable_moss", the moss will not be simulated and false is returned
If _landUnitData has the variable "enable_moss" and the value is not null, if the value of variable "growth_curve_id" in _landUnitData is not empty, return true if parameter runPeatland is false and the value of variable "leading_species" in _landUnitData contains the value of variable "moss_leading_species" in _landUnitData.
Else return false

Parameters
runPeatlandbool
Returns
bool

◆ isPeatlandApplicable()

bool isPeatlandApplicable ( )
private

Determine whether peatland has to be simulated

If _landUnitData does not have the variables "peatland_class" and "enable_peatland", return false
Else, if the value of variable "enable_peatland" in _landUnitData is not null, if value of variable "inventory_over_peatland" in _landUnitData > 0, value of variable "peatland" in _landUnitData > 0 and CBMSpinupSequencer._spinupGrowthCurveID > 0, determine if any species in variable "forest_peatland_leading_species" of _landUnitData is contained in variable "leading_species" of _landUnitData
If peatlandId is not Peatlands::FOREST_PEATLAND_BOG, Peatlands::FOREST_PEATLAND_POORFEN, Peatlands::FOREST_PEATLAND_RICHFEN or Peatlands::FOREST_PEATLAND_SWAMP return true, indicating that the peatland is to be simulated
In any other case, return false, indicating that the peatland is not to be simulated

Returns
bool

◆ isSlowPoolStable()

bool isSlowPoolStable ( double  lastSlowPoolValue,
double  currentSlowPoolValue 
)
private

If parameter lastSlowPoolValue != 0, returns if the the ratio currentSlowPoolValue / lastSlowPoolValue is greater than 0.999 and less than 1.001, else returns True.

Parameters
lastSlowPoolValuedouble
currentSlowPoolValuedouble
Returns
bool

◆ Run()

bool Run ( NotificationCenter &  _notificationCenter,
flint::ILandUnitController &  luc 
)
override

If the spinup parameters for _landUnitData is false return false.
Get variable "run_delay" in _landUnitData and assing the value as "false"
Check if to run peatland module and assign the value to a boolean Variable runPeatland.
Check if to run moss module and assign the value to a boolean Variable runMoss.
If runMoss is true, assign CBMSpinupSequencer._featherMossSlow as pool "FeatherMossSlow" in _landUnitData and
CBMSpinupSequencer._sphagnumMossSlow as pool "SphagnumMossSlow" in _landUnitData.
Get the timing in _landUnitData and assign the value to constant variable timing
Set timing stepping to TimeStepping::Annual.
If CBMSpinupSequencer._rampStartDate is not null,
Set Start date as CBMSpinupSequencer._rampStartDate, End date as start date in parameter luc, Start step date, end step date,cure start date and cur end date as timing start date in timing.
Post notification of signals TimingInit and TimingPostInit.
Set CBMSpinupSequencer._isDecaying as true.
if runPeatland is true, Invoke runPeatlandSpinup() using notificationCenter and luc as parameters.
else if variables "softwood_yield_table" and "hardwood_yield_table" in _landUnitData are empty,
set CBMSpinupSequencer._age as 0, else invoke runRegularSpinup() using notificationCenter, luc and runMoss as parameters.
If any pool has a user-provided value, override the spinup value with it.
return true.

Parameters
notificationCenterNotificationCenter&
lucILandUnitController&
Exceptions
std::exceptionHandles error
VariableNotFoundExceptionHandles error when variable is not found
VariableEmptyWhenValueExpectedExceptionHandles error when variable is empty
SimulationErrorHandles error during the simulation
Returns
bool

◆ runPeatlandSpinup()

void runPeatlandSpinup ( NotificationCenter &  notificationCenter,
flint::ILandUnitController &  luc 
)
private

Run Peatland Spinup

Create a variable poolCached, set it to False

Assign the value of variable "default_mean_annual_temperature" in _landUnitData to variable meanAnualTemperature if CBMSpinupSequencer._mat is empty
Set variable lastFireYearValue to the value of variable "default_last_fire_year" in _landUnitData if variable "last_fire_year" in _landUnitData is empty,
Set variable maxReturnInterval to the maximum of value of variable "maximum_fire_return_interval" in _landUnitData and variable "default_fire_return_interval" in _landUnitData, if variable "fire_return_interval" in _landUnitData is empty,
else set maxReturnInterval to the maximum of value of variable "maximum_fire_return_interval" in _landUnitData and variable "fire_return_interval" in _landUnitData

If the cache object consisting of { CBMSpinupSequencer._spu, CBMSpinupSequencer._historicDistType, peatlandId, variable fireReturnIntervalValue and variable meanAnualTemperature }, is present in CBMSpinupSequencer._cache, set value of variable "peat_pool_cached" in _landUnitData to true and set poolCached to true
Reset the ages CBMSpinupSequencer._shrubAge, CBMSpinupSequencer._smallTreeAge, CBMSpinupSequencer._age to zero before the spinup procedure

If the variable poolCached is false, in production/removal mode, only run one rotation is performed and live biomass value at minimum spinup time steps is 200. set the value of variable "peatland_spinup_rotation" in _landUnitData to 0 for spinup output to record the rotation
Invoke CBMSpinupSequencer.fireSpinupSequenceEvent(), set 200 years for spinupnext to use the removal values at this age
Post a special pre-disturbance signal to trigger peatland spinup next call
one rotation of spinup is done, invoke CBMSpinupSequencer.fireSpinupSequenceEvent() to simulate the historic fire disturbance. Reset the ages CBMSpinupSequencer._shrubAge, CBMSpinupSequencer._smallTreeAge, CBMSpinupSequencer._age to zero

If value of variable "peatland_fire_regrow" in _landUnitData is true, regrow to minimum peatland woody age. If CBMSpinupSequencer._standAge > 0, for forest peatland, just regrow to initial stand age and invoke CBMSpinupSequencer.fireSpinupSequenceEvent()

Parameters
notificationCenterNotificationCenter&
lucILandUnitController&
Returns
void

◆ runRegularSpinup()

void runRegularSpinup ( NotificationCenter &  notificationCenter,
flint::ILandUnitController &  luc,
bool  runMoss 
)
private

Perform Regular Spinup

Parameters
notificationCenterNotificationCenter&
lucILandUnitController&
runMossint
Returns
void

Member Data Documentation

◆ _aboveGroundSlowSoil

const flint::IPool* _aboveGroundSlowSoil
private

◆ _age

flint::IVariable* _age
private

◆ _ageReturnInterval

int _ageReturnInterval { 0 }
private

◆ _belowGroundSlowSoil

const flint::IPool* _belowGroundSlowSoil
private

◆ _biomassPools

const std::set<std::string> _biomassPools
private
Initial value:
{
"SoftwoodMerch",
"SoftwoodFoliage",
"SoftwoodOther",
"SoftwoodCoarseRoots",
"SoftwoodFineRoots",
"HardwoodMerch",
"HardwoodFoliage",
"HardwoodOther",
"HardwoodCoarseRoots",
"HardwoodFineRoots"
}

◆ _cache

std::unordered_map<CacheKey, std::vector<double>, moja::Hash> _cache
private

◆ _delay

flint::IVariable* _delay
private

◆ _disturbanceOrder

std::unordered_map<std::string, int> _disturbanceOrder
private

◆ _featherMossSlow

const flint::IPool* _featherMossSlow
private

◆ _historicDistType

std::string _historicDistType
private

◆ _isDecaying

flint::IVariable* _isDecaying
private

◆ _lastPassDistType

std::string _lastPassDistType
private

◆ _lastPassDisturbanceTimeseries

flint::IVariable* _lastPassDisturbanceTimeseries = nullptr
private

◆ _mat

flint::IVariable* _mat
private

◆ _maxRotationValue

int _maxRotationValue { 0 }
private

◆ _minimumRotation

int _minimumRotation { 0 }
private

◆ _rampStartDate

Poco::Nullable<DateTime> _rampStartDate
private

◆ _regenDelay

flint::IVariable* _regenDelay
private

◆ _shrubAge

flint::IVariable* _shrubAge
private

◆ _smallTreeAge

flint::IVariable* _smallTreeAge
private

◆ _sphagnumMossSlow

const flint::IPool* _sphagnumMossSlow
private

◆ _spinupGrowthCurveID

int _spinupGrowthCurveID { -1 }
private

◆ _spinupMossOnly

flint::IVariable* _spinupMossOnly
private

◆ _spu

flint::IVariable* _spu
private

◆ _standAge

int _standAge { 0 }
private

◆ _standDelay

int _standDelay { 0 }
private

◆ _standRegenDelay

int _standRegenDelay { 0 }
private

◆ delay

const std::string delay = "delay"

◆ historicDistType

const std::string historicDistType = "historic_disturbance_type"

◆ inventoryDelay

const std::string inventoryDelay = "inventory_delay"

◆ lastDistType

const std::string lastDistType = "last_pass_disturbance_type"

◆ maxRotation

const std::string maxRotation = "max_rotations"

◆ returnInverval

const std::string returnInverval = "return_interval"

The documentation for this class was generated from the following files: