#include <MastingSpatialDisperse.h>
Public Member Functions | |
clMastingSpatialDisperse (clSimManager *p_oSimManager) | |
Constructor. | |
~clMastingSpatialDisperse () | |
Destructor. | |
mastEvent | GetMastEvent (int iSp) |
Get whether a given species masted this timestep. | |
Protected Member Functions | |
void | DoShellSetup (xercesc::DOMDocument *p_oDoc) |
Does setup. | |
void | CalcMastCDF (xercesc::DOMDocument *p_oDoc) |
Calculates the masting cumulative distribution function. | |
void | CalcSeedCDF (xercesc::DOMDocument *p_oDoc, clTreePopulation *p_oPop) |
Calculates the cumulative distribution functions for seed dispersal. | |
void | FormatQueryString (clTreePopulation *p_oPop) |
Formats the string in m_cQuery. | |
void | DisperseOneParentSeeds (clTree *p_oTree, clTreePopulation *p_oPop, clPlot *p_oPlot, float fDbh) |
Performs dispersal of seeds for one tree. | |
void | GetParameterFileData (xercesc::DOMDocument *p_oDoc, clTreePopulation *p_oPop) |
Extracts needed parameter file data. | |
void | PopulateUsedTable (clTreePopulation *p_oPop) |
Declares and populates the mp_bIsUsed array. | |
void | SetGetSeedsFunctionPointers () |
This figures out how each species's number of seeds is calculated. | |
void | CalculateProbabilityDistribution (float *p_fProbArray, const int &iMaxDistance, const function &iFunction, const float &fDispersalX0, const float &fThetaXb) |
Calculates the normalized probability distribution for a function for one species. | |
void | AddSeeds () |
Performs disperse. | |
void | DecideMast () |
Decides whether masting events occur for each species. | |
float | GetNumberOfSeedsNoDraw (const float &fDbh, const short int &iSp) |
Gets the number of seeds for a tree when there does not need to be an STR draw. | |
float | GetNumberOfSeedsDrawNormal (const float &fDbh, const short int &iSp) |
Gets the number of seeds for a tree when the tree needs a normal STR draw. | |
float | GetNumberOfSeedsDrawLognormal (const float &fDbh, const short int &iSp) |
Gets the number of seeds for a tree when the tree needs a lognormal STR draw. | |
Protected Attributes | |
float *** | mp_fSeedCDF |
For testing. | |
float ** | mp_fStrMean |
STR mean (or STR value if deterministic). | |
float ** | mp_fStrStdDev |
STR standard deviation. | |
float ** | mp_fBeta |
Beta parameter. | |
float ** | mp_fMastCDF |
Masting cumulative distribution function. | |
float ** | mp_fFractionParticipating |
Fraction participating in disperse. | |
bool ** | mp_bIsUsed |
Whether this behavior is used by a species/type combo. | |
float * | mp_fFecundity |
Fecundity, if it is possible to pre-calculate it. | |
int * | mp_iTimestepsSinceLastMast |
Number of years since the last mast for each species. | |
short int * | mp_iIndexes |
This will speed access to the other arrays by storing each species' array index so the other arrays only have to be as big as the number of unique species for this behavior. | |
short int * | mp_iGroup |
Group affiliation of the species. | |
pdf * | mp_iWhatPDFForSTR |
What PDF is used to draw the STR. | |
function * | mp_iWhatFunction |
Which function is used by species. | |
bool * | mp_bDrawSTRPerSpecies |
Whether to draw STR once per species (true) or once per tree (false). | |
enum mastEvent *mp_iEvent char *m_cQuery typedef float(clMastingSpatialDisperse::* | Ptr2GetNumberOfSeeds )(const float &, const short int &) |
Which event is occurring in the current timestep for each species. | |
Ptr2GetNumberOfSeeds * | mp_GetSeeds |
Function pointer array for the appropriate function for calculating the number of seeds. | |
float | m_fNumYearsPerTimestep |
Number of years per timestep. | |
int | m_iMaxDistance |
Maximum distance, in meters, a seed can disperse - which is the maximum dimension of the grid with max of 1000 m. | |
int | m_iMaxTimesteps |
Maximum timesteps before a masting event occurs after a first masting event. | |
Friends | |
class | clTestMastingSpatialDisperse |
This class creates and disperses seeds according to the spatially-explicit model, allowing for masting events.
Masting is controlled by the cumulative distribution function: y = 1/(1 + (X / a)^b) where X is the time in years since the last mast, and a and b are parameters. The first timestep, X = 1. A random number compared to the probability distribution decides whether a mast has occurred.
The species may be organized into groups to create synchrony in masting. There can be up to N groups, where N is the number of species. If one species in a group masts, all species in the group do. Each group's mast decision is made separately, so sometimes more than one group may mast at a time.
There is a parameter for each species with the percentage of trees that participate in disperse (as a separate percentage for masting and non- masting). The set of trees, from those of above the minimum reproductive DBH, is randomly chosen each timestep.
The STR for trees can be chosen from a probability distribution function or not. It can be drawn once per species or once per tree. There are different STRs for masting and non-masting timesteps.
Once the number of seeds for a given tree has been calculated, the seeds are dispersed around the plot according to either the Weibull or Lognormal probability distribution functions.
The "seeds" are actually tallies by species in a grid. This behavior does not produce any seedlings. A separate recruitment behavior must "germinate" the seeds into seedlings according to its own rules.
The parameter file call string and namestring are both "masting spatial disperse".
Copyright 2007 Charles D. Canham.
clMastingSpatialDisperse::clMastingSpatialDisperse | ( | clSimManager * | p_oSimManager | ) |
Constructor.
p_oSimManager | Sim Manager object. |
clMastingSpatialDisperse::~clMastingSpatialDisperse | ( | ) |
Destructor.
mastEvent clMastingSpatialDisperse::GetMastEvent | ( | int | iSp | ) | [inline] |
Get whether a given species masted this timestep.
iSp | Species to check |
void clMastingSpatialDisperse::DoShellSetup | ( | xercesc::DOMDocument * | p_oDoc | ) | [protected, virtual] |
Does setup.
This sets all values in mp_iTimestepsSinceLastMast to 1. Then it calls:
p_oDoc | DOM tree of parsed input file. |
Implements clDisperseBase.
void clMastingSpatialDisperse::CalcMastCDF | ( | xercesc::DOMDocument * | p_oDoc | ) | [protected] |
Calculates the masting cumulative distribution function.
This reads in the appropriate parameter values, finds the maximum number of years between mast events, then creates the CDF array. The parameters are thrown away because they are no longer needed.
p_oDoc | DOM tree of parsed input file. |
void clMastingSpatialDisperse::CalcSeedCDF | ( | xercesc::DOMDocument * | p_oDoc, | |
clTreePopulation * | p_oPop | |||
) | [protected] |
Calculates the cumulative distribution functions for seed dispersal.
This reads in the appropriate parameter values, finds the maximum seed dispersal distance, then creates the CDF array. The parameters are thrown away because they are no longer needed.
p_oDoc | DOM tree of parsed input file. | |
p_oPop | Tree population object. |
stcErr | if a weibull theta value is not less than 50 (to prevent pow overflows) |
void clMastingSpatialDisperse::FormatQueryString | ( | clTreePopulation * | p_oPop | ) | [protected] |
Formats the string in m_cQuery.
This value will be used in AddSeeds() in order to get the trees to act on.
p_oPop | Tree Population object |
void clMastingSpatialDisperse::DisperseOneParentSeeds | ( | clTree * | p_oTree, | |
clTreePopulation * | p_oPop, | |||
clPlot * | p_oPlot, | |||
float | fDbh | |||
) | [protected] |
Performs dispersal of seeds for one tree.
The number of seeds is calculated by using the pointer in mp_GetSeeds. Each seed is given a random azimuth direction from the parent. Then each seed is given a random distance from the parent that conforms to the chosen probability distribution function. This is done by comparing a random value to successive values in the cumulative probability array until the first array bucket that has a greater value than the random number. Once the seed has an azimuth direction and a distance, it is added to the species total in the appropriate grid cell.
p_oTree | Tree for which to perform dispersal. | |
fDbh | DBH of the tree, in cm. | |
p_oPlot | Plot object | |
p_oPop | Tree Population object |
void clMastingSpatialDisperse::GetParameterFileData | ( | xercesc::DOMDocument * | p_oDoc, | |
clTreePopulation * | p_oPop | |||
) | [protected] |
Extracts needed parameter file data.
(Some parameters are extracted by other setup functions and thrown away - this gets all other, permanent parameters.)
p_oDoc | Parsed parameter file document. |
stcErr | if:
|
p_oPop | Tree population object. |
void clMastingSpatialDisperse::PopulateUsedTable | ( | clTreePopulation * | p_oPop | ) | [protected] |
Declares and populates the mp_bIsUsed array.
p_oPop | Tree Population object |
void clMastingSpatialDisperse::SetGetSeedsFunctionPointers | ( | ) | [protected] |
This figures out how each species's number of seeds is calculated.
It sets the appropriate function pointers in mp_GetSeeds.
void clMastingSpatialDisperse::CalculateProbabilityDistribution | ( | float * | p_fProbArray, | |
const int & | iMaxDistance, | |||
const function & | iFunction, | |||
const float & | fDispersalX0, | |||
const float & | fThetaXb | |||
) | [protected] |
Calculates the normalized probability distribution for a function for one species.
p_fProbArray | The array into which to put the normalized values. | |
iMaxDistance | The maximum distance out to which to calculate the function - which must equal the size of p_fProbArray. | |
iFunction | Function flag. | |
fDispersalX0 | Dispersal or X0 of the species in question, depending on the function | |
fThetaXb | Theta or Xb of the species in question, depending on the function |
void clMastingSpatialDisperse::AddSeeds | ( | ) | [protected, virtual] |
Performs disperse.
First, DecideMast() is called to determine which species mast this timestep. Then, for any species with STRs that are drawn per species, fecundity is calculated. Then this gets the group of trees to which this behavior applies. For each, a random number is compared to the appropriate value in mp_fFractionParticipating to determine whether this tree will produce seeds. That tree is passed to DisperseOneParentSeeds() for seed creation and distribution.
Implements clDisperseBase.
void clMastingSpatialDisperse::DecideMast | ( | ) | [protected] |
Decides whether masting events occur for each species.
This takes the time since last mast and compares a random number to the value for that time in the mp_fMastCDF array. It then uses that decision to set the appropriate event flag in mp_iEvent. Then the counter value for each species in m_iTimestepsSinceLastMast is set appropriately; incremented if no mast occurred, or set to 0 if it did.
If species have group affiliations, the mast decision is made for the first species. Then all other species in that group get the same value.
float clMastingSpatialDisperse::GetNumberOfSeedsNoDraw | ( | const float & | fDbh, | |
const short int & | iSp | |||
) | [protected] |
Gets the number of seeds for a tree when there does not need to be an STR draw.
seeds = fecundity * DBHβ, Fecundity should have already been calculated.
fDbh | DBH of the tree, in cm | |
iSp | Tree species number |
float clMastingSpatialDisperse::GetNumberOfSeedsDrawNormal | ( | const float & | fDbh, | |
const short int & | iSp | |||
) | [protected] |
Gets the number of seeds for a tree when the tree needs a normal STR draw.
seeds = STR * (DBH / 30)β
fDbh | DBH of the tree, in cm | |
iSp | Tree species number |
float clMastingSpatialDisperse::GetNumberOfSeedsDrawLognormal | ( | const float & | fDbh, | |
const short int & | iSp | |||
) | [protected] |
Gets the number of seeds for a tree when the tree needs a lognormal STR draw.
seeds = STR * (DBH / 30)β
fDbh | DBH of the tree, in cm | |
iSp | Tree species number |
friend class clTestMastingSpatialDisperse [friend] |
float*** clMastingSpatialDisperse::mp_fSeedCDF [protected] |
For testing.
Cumulative probability array for seed dispersal. Array size is mast or non-mast by # species by max distance. The 0th bucket will never be accessed.
float** clMastingSpatialDisperse::mp_fStrMean [protected] |
STR mean (or STR value if deterministic).
The array is 2D - the first index is masting or non-masting. The second index is species. This value comes from the parameter file.
float** clMastingSpatialDisperse::mp_fStrStdDev [protected] |
STR standard deviation.
The array is 2D - the first index is masting or non-masting. The second index is species. This value comes from the parameter file.
float** clMastingSpatialDisperse::mp_fBeta [protected] |
Beta parameter.
The array is 2D - the first index is masting or non-masting. The second index is species. This value comes from the parameter file.
float** clMastingSpatialDisperse::mp_fMastCDF [protected] |
Masting cumulative distribution function.
Array size is number of species by m_iMaxYears.
float** clMastingSpatialDisperse::mp_fFractionParticipating [protected] |
Fraction participating in disperse.
Array is 2D. First index is masting or non-masting. The second index is species. This value comes from the parameter file.
bool** clMastingSpatialDisperse::mp_bIsUsed [protected] |
Whether this behavior is used by a species/type combo.
First array index is species, second is type.
float* clMastingSpatialDisperse::mp_fFecundity [protected] |
Fecundity, if it is possible to pre-calculate it.
int* clMastingSpatialDisperse::mp_iTimestepsSinceLastMast [protected] |
Number of years since the last mast for each species.
short int* clMastingSpatialDisperse::mp_iIndexes [protected] |
This will speed access to the other arrays by storing each species' array index so the other arrays only have to be as big as the number of unique species for this behavior.
short int* clMastingSpatialDisperse::mp_iGroup [protected] |
Group affiliation of the species.
Any species with the same group number will always mast together. Array size is species.
pdf* clMastingSpatialDisperse::mp_iWhatPDFForSTR [protected] |
What PDF is used to draw the STR.
Only deterministic, normal, and lognormal are supported.
function* clMastingSpatialDisperse::mp_iWhatFunction [protected] |
Which function is used by species.
bool* clMastingSpatialDisperse::mp_bDrawSTRPerSpecies [protected] |
Whether to draw STR once per species (true) or once per tree (false).
This is from the parameter file.
enum mastEvent* mp_iEvent char* m_cQuery typedef float(clMastingSpatialDisperse::* clMastingSpatialDisperse::Ptr2GetNumberOfSeeds)(const float &, const short int &) [protected] |
Which event is occurring in the current timestep for each species.
Query to perform to search for treesDefine a type for pointers to functions of the GetNumberOfSeeds type
Function pointer array for the appropriate function for calculating the number of seeds.
Array size is number of species to which this behavior applies.
float clMastingSpatialDisperse::m_fNumYearsPerTimestep [protected] |
Number of years per timestep.
int clMastingSpatialDisperse::m_iMaxDistance [protected] |
Maximum distance, in meters, a seed can disperse - which is the maximum dimension of the grid with max of 1000 m.
int clMastingSpatialDisperse::m_iMaxTimesteps [protected] |
Maximum timesteps before a masting event occurs after a first masting event.
This is calculated to be the value at which all species have a prob of 0.9999, or the number of timesteps in the run, whichever is smaller.