FFSM++
1.1.0
French Forest Sector Model ++
|
Class responsable to keep the logbook of the Carbon Balance. More...
#include <Carbon.h>
Public Member Functions | |
Carbon (ThreadManager *MTHREAD_h) | |
Constructor. More... | |
~Carbon () | |
double | getStock (const int ®Id, const int &stock_type) const |
Returns the current stock of carbon [Mt CO2]. More... | |
double | getCumSavedEmissions (const int ®Id, const int &em_type) const |
Returns the current cumulative saved emissions by type [Mt CO2]. More... | |
void | registerHarvesting (const double &value, const int ®Id, const string &fType) |
Registers the harvesting of trees increasing the value of cumEmittedForOper. More... | |
void | registerDeathBiomass (const double &value, const int ®Id, const string &fType) |
Registers the "death" of a given amount of biomass, storing it in the deathBiomass map. More... | |
void | registerProducts (const double &value, const int ®Id, const string &productName) |
Registers the production of a given amount of products, storing it in the products maps. Also increase material substitution. More... | |
void | registerTransports (const double &distQ, const int ®Id) |
Registers the quantities emitted by transport of wood FROM a given region. More... | |
void | initialiseDeathBiomassStocks (const vector< double > &deathByFt, const int ®Id) |
Initialises the stocks of death biomass for the avgLive_* years before the simulation starts. More... | |
void | initialiseProductsStocks (const vector< double > &qByProduct, const int ®Id) |
Initialises the stocks of products for the avgLive_* years before the simulation starts. More... | |
void | initialiseEmissionCounters () |
Initialises the emission counters to zero. More... | |
void | HWP_eol2energy () |
Computes the energy substitution for the quota of HWP that reachs end of life and doesn't go to landfill. More... | |
Public Member Functions inherited from BaseClass | |
BaseClass () | |
~BaseClass () | |
void | msgOut (const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const |
Overloaded function to print the output log. More... | |
void | msgOut (const int &msgCode_h, const int &msg_h, const bool &refreshGUI_h=true) const |
Overloaded function to print the output log. More... | |
void | msgOut (const int &msgCode_h, const double &msg_h, const bool &refreshGUI_h=true) const |
Overloaded function to print the output log. More... | |
int | s2i (const string &string_h) const |
string to integer conversion More... | |
double | s2d (const string &string_h) const |
string to double conversion More... | |
double | s2d (const string &string_h, const bool &replaceComma) const |
string to double conversion More... | |
bool | s2b (const string &string_h) const |
string to bool conversion More... | |
string | i2s (const int &int_h) const |
integer to string conversion More... | |
string | d2s (const double &double_h) const |
double to string conversion More... | |
string | b2s (const bool &bool_h) const |
bool to string conversion More... | |
vector< int > | s2i (const vector< string > &string_h) const |
string to integer conversion (vector) More... | |
vector< double > | s2d (const vector< string > &string_h, const bool &replaceComma=false) const |
string to double conversion (vector) More... | |
vector< bool > | s2b (const vector< string > &string_h) const |
string to bool conversion (vector) More... | |
vector< string > | i2s (const vector< int > &int_h) const |
integer to string conversion (vector) More... | |
vector< string > | d2s (const vector< double > &double_h) const |
double to string conversion (vector) More... | |
vector< string > | b2s (const vector< bool > &bool_h) const |
bool to string conversion (vector) More... | |
int | getType (const string &type_h) const |
Return a type according to enum TYPE_* from a string (eg: "string" -> TYPE_STRING (2)) More... | |
void | refreshGUI () const |
Ping to periodically return the control to the GUI. More... | |
template<typename T > | |
string | toString (const T &x) const |
template<typename T > | |
T | stringTo (const std::string &s) const |
int | vSum (const vector< int > &vector_h) const |
double | vSum (const vector< double > &vector_h) const |
int | vSum (const vector< vector< int > > &vector_h) const |
double | vSum (const vector< vector< double > > &vector_h) const |
void | tokenize (const string &str, vector< string > &tokens, const string &delimiter=" ") const |
Tokenize a string using a delimiter (default is space) More... | |
void | untokenize (string &str, vector< string > &tokens, const string &delimiter=" ") const |
template<typename K , typename V > | |
V | findMap (const map< K, V > &mymap, const K &key, const int &error_level=MSG_CRITICAL_ERROR, const V ¬FoundValue=numeric_limits< V >::min()) const |
Lookup a map for a value. Return the value starting from the key. More... | |
template<typename K , typename V > | |
void | changeMapValue (map< K, V > &mymap, const K &key, const V &value, const int &error_level=MSG_CRITICAL_ERROR) |
Change the value stored in a map given the key and the new value. More... | |
template<typename K , typename V > | |
void | incrMapValue (map< K, V > &mymap, const K &key, const V &value, const int &error_level=MSG_CRITICAL_ERROR) |
Increments a value stored in a map of the specified value, given the key. More... | |
template<typename K , typename V > | |
void | incrOrAddMapValue (map< K, V > &mymap, const K &key, const V &value) |
Increments a value stored in a map of the specified value, given the key. More... | |
template<typename K , typename V > | |
void | resetMapValues (map< K, V > &mymap, const V &value) |
Reset all values stored in a map to the specified one. More... | |
template<typename K , typename V > | |
map< K, V > | vectorToMap (const vector< K > &keys, const V &value=0.0) |
Returns a map built using the given vector and the given (scalar) value as keys/values pairs. More... | |
template<typename T > | |
vector< T > | positionsToContent (const vector< T > &vector_h, const vector< int > &positions) |
Return a vector of content from a vector and a vector of positions (int) More... | |
template<typename V > | |
void | debugMap (const map< iisskey, V > &mymap) |
Debug a map. More... | |
template<typename K , typename V > | |
void | debugMap (const map< K, V > &mymap, const K &key) |
template<typename K > | |
int | getMaxPos (const vector< K > &v) |
Returns the position of the maximum element in the vector (the last one in case of multiple equivalent maxima) More... | |
template<typename K > | |
int | getMinPos (const vector< K > &v) |
Returns the position of the minimum element in the vector (the first one in case of multiple equivalent minima) More... | |
template<typename K > | |
K | getMax (const vector< K > &v) |
Returns the value of the maximum element in the vector (the last one in case of multiple equivalent maxima) More... | |
template<typename K > | |
K | getMin (const vector< K > &v) |
Returns the value of the minimum element in the vector (the first one in case of multiple equivalent minima) More... | |
template<typename K > | |
double | getAvg (const vector< K > &v) |
Returns the average of the elements in the vector. More... | |
template<typename K > | |
double | getSd (const vector< K > &v, bool sample=true) |
template<typename K > | |
int | getPos (const K &element, const vector< K > &v, const int &msgCode_h=MSG_CRITICAL_ERROR) |
template<typename K > | |
bool | inVector (const K &element, const vector< K > &v) |
double | normSample (const double &avg, const double &stdev, const double &minval=NULL, const double &maxval=NULL) const |
Sample from a normal distribution with bounds. Slower (double time, but still you see the diff only after milion of loops). More... | |
template<typename K > | |
K | normSample (normal_distribution< K > &d, std::mt19937 &gen, const K &minval=NULL, const K &maxval=NULL) const |
Sample from a normal distribution with bounds. Faster (half time) as the normal_distribution is made only once. More... | |
template<typename T > | |
std::string | toString (const T &x) const |
Private Member Functions | |
void | addSavedEmissions (const double &value, const int ®Id, const int &em_type) |
Increases the value to the saved emissions for a given type and region. More... | |
double | getRemainingStock (const double &initialValue, const double &halfLife, const double &years) const |
Apply a single exponential decay model to retrieve the remining stock given the initial stock, the half life and the time passed from stock formation. More... | |
Private Attributes | |
map< iiskey, double > | deathBiomassInventory |
Map that register the death of biomass by year, l2_region and forest type (inventoried)[Mm^3 wood]. More... | |
map< iiskey, double > | deathBiomassExtra |
Map that register the death of biomass by year, l2_region and forest type (non-inventoried biomass: branches, roots..) [Mm^3 wood]. More... | |
map< iiskey, double > | products |
Map that register the production of a given product by year, l2_region and product [Mm^3 wood]. More... | |
map< int, double > | cumSubstitutedEnergy |
Map that store the cumulative CO2 substituted for energy consumption, by l2_region [Mt CO2]. More... | |
map< int, double > | cumSubstitutedMaterial |
Map that store the cumulative CO2 substituted using less energivory material, by l2_region [Mt CO2]. More... | |
map< int, double > | cumEmittedForOper |
Map that store emissions for forest operations, including transport, by l2_region [Mt CO2]. More... | |
Additional Inherited Members | |
Protected Attributes inherited from BaseClass | |
ThreadManager * | MTHREAD |
Pointer to the Thread manager. More... | |
Class responsable to keep the logbook of the Carbon Balance.
A single istance of this class exists and is available trought the global MTHREAD->CBAL pointer.
It consits of functions to track a carbon-related event and store the information in STL maps that either register the events (for the stocks) or contain the cumulated carbon (for emission flows).
Carbon pools are stored as Mm^3 wood while and emission cumulated counters are directly in Mt CO2.
getStock() and getCumSavedEmissions() are then used to report the current levels of carbon in the stock or emitted/substituted.
Carbon | ( | ThreadManager * | MTHREAD_h | ) |
~Carbon | ( | ) |
Definition at line 36 of file Carbon.cpp.
|
private |
Increases the value to the saved emissions for a given type and region.
Definition at line 324 of file Carbon.cpp.
Referenced by HWP_eol2energy(), registerHarvesting(), registerProducts(), and registerTransports().
double getCumSavedEmissions | ( | const int & | regId, |
const int & | em_type | ||
) | const |
Returns the current cumulative saved emissions by type [Mt CO2].
Definition at line 138 of file Carbon.cpp.
Referenced by Output::printCarbonBalance().
|
private |
Apply a single exponential decay model to retrieve the remining stock given the initial stock, the half life and the time passed from stock formation.
Definition at line 341 of file Carbon.cpp.
Referenced by getStock(), and HWP_eol2energy().
double getStock | ( | const int & | regId, |
const int & | stock_type | ||
) | const |
Returns the current stock of carbon [Mt CO2].
reg | |
stock_type |
For product sink:
Definition at line 53 of file Carbon.cpp.
Referenced by Output::printCarbonBalance().
void HWP_eol2energy | ( | ) |
Computes the energy substitution for the quota of HWP that reachs end of life and doesn't go to landfill.
Definition at line 288 of file Carbon.cpp.
Referenced by ModelCoreSpatial::registerCarbonEvents().
void initialiseDeathBiomassStocks | ( | const vector< double > & | deathByFt, |
const int & | regId | ||
) |
Initialises the stocks of death biomass for the avgLive_* years before the simulation starts.
Definition at line 169 of file Carbon.cpp.
Referenced by ModelCoreSpatial::initialiseCarbonModule().
void initialiseEmissionCounters | ( | ) |
Initialises the emission counters to zero.
Definition at line 158 of file Carbon.cpp.
Referenced by ModelCoreSpatial::initialiseCarbonModule().
void initialiseProductsStocks | ( | const vector< double > & | qByProduct, |
const int & | regId | ||
) |
Initialises the stocks of products for the avgLive_* years before the simulation starts.
Definition at line 203 of file Carbon.cpp.
Referenced by ModelCoreSpatial::initialiseCarbonModule().
void registerDeathBiomass | ( | const double & | value, |
const int & | regId, | ||
const string & | fType | ||
) |
Registers the "death" of a given amount of biomass, storing it in the deathBiomass map.
Definition at line 243 of file Carbon.cpp.
Referenced by ModelCoreSpatial::registerCarbonEvents().
void registerHarvesting | ( | const double & | value, |
const int & | regId, | ||
const string & | fType | ||
) |
Registers the harvesting of trees increasing the value of cumEmittedForOper.
Definition at line 225 of file Carbon.cpp.
Referenced by ModelCoreSpatial::registerCarbonEvents().
void registerProducts | ( | const double & | value, |
const int & | regId, | ||
const string & | productName | ||
) |
Registers the production of a given amount of products, storing it in the products maps. Also increase material substitution.
Definition at line 257 of file Carbon.cpp.
Referenced by ModelCoreSpatial::registerCarbonEvents().
void registerTransports | ( | const double & | distQ, |
const int & | regId | ||
) |
Registers the quantities emitted by transport of wood FROM a given region.
Definition at line 277 of file Carbon.cpp.
Referenced by ModelCoreSpatial::registerCarbonEvents().
|
private |
Map that store emissions for forest operations, including transport, by l2_region [Mt CO2].
Definition at line 78 of file Carbon.h.
Referenced by addSavedEmissions(), getCumSavedEmissions(), and initialiseEmissionCounters().
|
private |
Map that store the cumulative CO2 substituted for energy consumption, by l2_region [Mt CO2].
Definition at line 76 of file Carbon.h.
Referenced by addSavedEmissions(), getCumSavedEmissions(), and initialiseEmissionCounters().
|
private |
Map that store the cumulative CO2 substituted using less energivory material, by l2_region [Mt CO2].
Definition at line 77 of file Carbon.h.
Referenced by addSavedEmissions(), getCumSavedEmissions(), and initialiseEmissionCounters().
|
private |
Map that register the death of biomass by year, l2_region and forest type (non-inventoried biomass: branches, roots..) [Mm^3 wood].
Definition at line 74 of file Carbon.h.
Referenced by getStock(), initialiseDeathBiomassStocks(), registerDeathBiomass(), and registerHarvesting().
|
private |
Map that register the death of biomass by year, l2_region and forest type (inventoried)[Mm^3 wood].
Definition at line 73 of file Carbon.h.
Referenced by getStock(), initialiseDeathBiomassStocks(), and registerDeathBiomass().
|
private |
Map that register the production of a given product by year, l2_region and product [Mm^3 wood].
Definition at line 75 of file Carbon.h.
Referenced by getStock(), HWP_eol2energy(), initialiseProductsStocks(), and registerProducts().