#include <TreePopulation.h>
Inheritance diagram for clTreePopulation:
Public Types | |
enum | iTreeType { seed, seedling, sapling, adult, stump, snag, woody_debris } |
Tree life history stages, or tree type. More... | |
enum | iWhyDead { harvest, natural, disease, fire, insects, storm, remove } |
Reason codes for why a tree died. More... | |
Public Member Functions | |
~clTreePopulation () | |
Destructor. | |
clTreePopulation (clSimManager *p_oSimManager) | |
Constructor. | |
clTreeSearch * | Find (char *args) |
Acquires trees which meet certain criteria. | |
clTree * | CreateTree (float fX, float fY, int iSp, int iType, float fDiam) |
Creates a new tree and organizes it into the hash table. | |
clTree * | KillTree (clTree *p_deadTree, unsigned short int iReason) |
Kills a tree. | |
void | BarebonesDataSetup (xercesc::DOMDocument *p_oDoc) |
Reads type and species info from the parameter file. | |
short int | TranslateSpeciesNameToCode (char *cSpeciesName) |
Translates a species name string into its code. | |
char * | TranslateSpeciesCodeToName (int iSpecies) |
Translates a species code into its name string. | |
short int | RegisterInt (char *cLabel, int iSpecies, int iType) |
Adds an integer data member to the tree data structure. | |
short int | RegisterFloat (char *cLabel, int iSpecies, int iType) |
Adds a float data member to the tree data structure. | |
short int | RegisterChar (char *cLabel, int iSpecies, int iType) |
Adds a char data member to the tree data structure. | |
short int | RegisterBool (char *cLabel, int iSpecies, int iType) |
Adds a boolean data member to the tree data structure. | |
short int | GetIntDataCode (char *cLabel, int iSpecies, int iType) |
Gets the data code for accessing an integer tree data member. | |
short int | GetFloatDataCode (char *cLabel, int iSpecies, int iType) |
Gets the data code for accessing a float tree data member. | |
short int | GetCharDataCode (char *cLabel, int iSpecies, int iType) |
Gets the data code for accessing a char tree data member. | |
short int | GetBoolDataCode (char *cLabel, int iSpecies, int iType) |
Gets the data code for accessing a bool tree data member. | |
char * | GetIntDataLabel (short int iCode, int iSpecies, int iType) |
Gets the label for an integer tree data member. | |
char * | GetFloatDataLabel (short int iCode, int iSpecies, int iType) |
Gets the label for a float tree data member. | |
char * | GetCharDataLabel (short int iCode, int iSpecies, int iType) |
Gets the label for a char tree data member. | |
char * | GetBoolDataLabel (short int iCode, int iSpecies, int iType) |
Gets the label for a bool tree data member. | |
void | DoDataUpdates () |
Determines if the hash table needs to be sorted by checking the bDoUpdates flag, and if it does, it sorts it. | |
float | GetRandomDiam10Value (float fDiam10Seed=0) |
Gets a random diameter at 10 cm value for a seedling. | |
short int | GetXCode (int iSpecies, int iType) |
Gets the code for the "X" data member, which is registered by the tree population. | |
short int | GetYCode (int iSpecies, int iType) |
Gets the code for the "Y" data member, which is registered by the tree population. | |
short int | GetHeightCode (int iSpecies, int iType) |
Gets the code for the "Height" data member, which is registered by the tree population. | |
short int | GetDbhCode (int iSpecies, int iType) |
Gets the code for the "DBH" data member, which is registered by the tree population. | |
short int | GetDiam10Code (int iSpecies, int iType) |
Gets the code for the "Diam10" data member, which is registered by the tree population. | |
short int | GetWhyDeadCode (int iSpecies) |
Gets the code for the "Why dead" snag data member, which is registered by the tree population. | |
short int | GetAgeCode (int iSpecies) |
Gets the code for the "Age" snag data member, which is registered by the tree population. | |
float | GetMinAdultDBH (int iSpecies) |
Gets the minimum adult DBH. | |
clAllometry * | GetAllometryObject () |
Gets the allometry object. | |
int | GetNumberOfSpecies () |
Gets the total number of species. | |
int | GetNumberOfTypes () |
Gets the total number of tree types (life history stages). | |
int | GetGridCellSize () |
Gets the tree population internal grid cell size (grids are square). | |
int | GetNumXCells () |
Gets the number of cells in the X direction for the tree population's internal tree organizational grid. | |
int | GetNumYCells () |
Gets the number of cells in the Y direction for the tree population's internal tree organizational grid. | |
bool | GetUsesSnags () |
Gets whether or not this run uses snags. | |
float | GetXPlotLength () |
Gets the length in the X direction of the tree's internal grid (should match the value received from the plot object). | |
float | GetYPlotLength () |
Gets the length in the Y direction of the tree's internal grid (should match the value received from the plot object). | |
float | GetMaxSeedlingHeight (int iSpecies) |
Gets the maximum possible seedling height for a species. | |
float | GetMinimumAdultHeight () |
Gets the minimum possible adult height. | |
float | GetNewSeedlingDiam10 () |
Gets the default new seedling diameter at 10 cm. | |
clTree * | GetShortestTreeInCell (int iX, int iY) |
Allows direct access to the tree hash table. | |
clTree * | GetTallestTreeInCell (int iX, int iY) |
Allows direct access to the tree hash table. | |
clTree * | GetFirstStump () |
Gets first stump in the stump linked list. | |
Protected Member Functions | |
void | DataMemberRegistrations () |
Triggers the tree data member registration process for all behaviors. | |
void | GetData (xercesc::DOMDocument *p_oDoc) |
Performs setup. | |
void | TimestepCleanup () |
Performs end-of-timestep cleanup tasks. | |
void | GetPlotDimensions () |
Retrieves the plot dimensions. | |
void | SetupCalculations () |
Performs setup calculations. | |
void | CreateHashTable () |
Allocates memory for the hash table. | |
short int | RegisterDataMember (char *cLabel, int iSpecies, int iType, short int **p_iNumTreeVals, char ****p_cLabels) |
Core function for registering new tree data members. | |
void | DoTreeDataStructureSetup () |
Queries all behaviors for data members that they wish to add to the tree's data structure. | |
void | ReadParameters (xercesc::DOMDocument *p_oDoc) |
Allocates memory and reads data from the parameter file into arrays. | |
void | CreateTreesFromInitialDensities (xercesc::DOMDocument *p_oDoc) |
Creates trees according to initial density information in an input file. | |
void | CreateTreesFromTreeMap (xercesc::DOMDocument *p_oDoc) |
Creates trees according to tree map information in an input file. | |
void | AddTreeToHashTable (clTree *p_oNewTree) |
Adds a tree to the hash table. | |
void | UpdateTreeInHashTable (clTree *p_oChangedTree) |
Updates a tree's position in the hash table. | |
void | RemoveTreeFromHashTable (clTree *p_oByeTree) |
Removes a tree from the hash table. | |
void | EmptyHashTable () |
Deletes all trees from the hash table without deleting the table itself. | |
void | DeleteStumps () |
Deletes stumps from the stump linked list and sets the linked list pointer to NULL. | |
void | ChangeTreeType (clTree *p_oTree, enum iTreeType iNewType) |
Changes a tree's type (life history stage). | |
void | SortHashTable () |
Sorts the hash table by height. | |
void | UpdateTree (clTree *p_oTree, short int iCode, int iValue) |
Updates an integer data member of a tree. | |
void | UpdateTree (clTree *p_oTree, short int iCode, float fValue, bool bUpdateNow, bool bUpdateAllometry) |
Updates a float data member of a tree. | |
void | UpdateTree (clTree *p_oTree, short int iCode, char *cValue) |
Updates a char data member of a tree. | |
void | UpdateTree (clTree *p_oTree, short int iCode, bool bValue) |
Updates a bool data member of a tree. | |
Protected Attributes | |
clTreePopulation::stcOpenSearches * | mp_openSearches |
Holds open tree searches.The linked list of open search requests. | |
float | m_fNewSeedlingDiam10 |
New diameter at 10 cm for seedlings. | |
float | m_fMinAdultHeight |
Shortest possible adult tree height, in meters. | |
float | m_fMaxSaplingHeight |
Maximum possible height a sapling can have, in meters. | |
float * | mp_fMaxSeedlingHeight |
Maximum possible seedling height, in meters. | |
float * | mp_fMinAdultDbh |
Minimum adult DBH, in cm, for each species. | |
float | m_fPlotLengthX |
Plot length in X dimension, in meters. | |
float | m_fPlotLengthY |
Plot length in Y dimension, in meters. | |
float * | mp_fSizeClasses |
Size classes for live trees. | |
int | m_iNumHeightDivs |
Number of height divisions in tree hash table. | |
int | m_iSizeHeightDivs |
size of height divisions in tree hash table, in meters. | |
int | m_iNumSpecies |
Number of species. | |
int | m_iNumTypes |
Number of tree types (life history stages). | |
int | m_iNumXCells |
Mumber of tree population internal grid cells in the X direction. | |
int | m_iNumYCells |
Mumber of tree population internal grid cells in the Y direction. | |
int | m_iNumSizeClasses |
Number of tree size classes defined. | |
int | m_iLengthGrids |
Length of internal grid cells, in meters. | |
bool | bDoUpdates |
Whether or not to sort the hash table when DoDataUpdates is called. | |
bool * | mp_bMakeStump |
Whether a harvested tree should be made into a stump, for each species. | |
bool | m_bMakeSnag |
Whether a dead adult should be made into a snag. | |
short int ** | mp_iNumTreeIntVals |
Number of tree integer data members that have been defined for this run. | |
short int ** | mp_iNumTreeFloatVals |
Number of tree float data members that have been defined for this run. | |
short int ** | mp_iNumTreeCharVals |
Number of tree char data members that have been defined for this run. | |
short int ** | mp_iNumTreeBoolVals |
Number of tree bool data members that have been defined for this run. | |
char **** | mp_cIntLabels |
List of tree integer data member labels. | |
char **** | mp_cFloatLabels |
List of tree float data member labels. | |
char **** | mp_cCharLabels |
List of tree char data member labels. | |
char **** | mp_cBoolLabels |
List of tree bool data member labels. | |
short int ** | mp_iXCode |
Codes for "X" tree data member. | |
short int ** | mp_iYCode |
Codes for "Y" tree data member. | |
short int ** | mp_iHeightCode |
Codes for "Height" tree data member. | |
short int ** | mp_iDiam10Code |
Codes for "Diam10" tree data member. | |
short int ** | mp_iDbhCode |
Codes for "DBH" tree data member. | |
short int * | mp_iAgeCode |
Codes for "Age" snag tree data member. | |
short int * | mp_iWhyDeadCode |
Codes for "Why dead" snag tree data member. | |
speciesCodes * | mp_speciesCodes |
List of species codes and names. | |
clAllometry * | mp_oAllom |
Allometry object. | |
clTree **** | mp_oTreeTallest |
Hash table of tallest tree links. | |
clTree **** | mp_oTreeShortest |
Hash table of shortest tree links. | |
clTree * | mp_oStumps |
Linked list of stumps. | |
Friends | |
class | clTreeSearch |
class | clTree |
class | clTestTreePopulation |
For testing purposes. | |
class | clTestTreePopulation2 |
For testing purposes. | |
class | clAllometry |
Classes | |
struct | speciesCodes |
For maintaining a list of species and their codes. More... | |
struct | stcOpenSearches |
Holds open tree searches. More... |
The tree population class encapsulates all the types of trees and provides a common interface for accessing them. The trees are organized into a hash table. The trees are organized spatially in an internal grid and then by height within that grid. All seedlings, saplings, adults, and snags appear in the hash table. Stumps are organized separately since they have no height (if they are even used at all); seeds and woody debris currently don't exist.
When behavior objects operate on trees, they receive a pointer to the tree population in order to do so. Then they use the search method to get the trees they need.
Plot trees can only be created by the tree population class (if other objects want to create their own local trees for some reason, that's fine). Behaviors can ask the pop. to create seedlings (i.e. as a reproduction calculation). If it turns out to be necessary for other kinds of trees to be created then we can add those methods.
The population takes care of all organization and housekeeping skills related to trees. When a tree dies it tells the population so that the population can remove it. When a tree changes its height it tells the population so that the population can update its position in the hash table.
The hash table array holding the trees is based on grid cells of 8X8 m (no matter what the user has them set to), and the trees within each grid cell are organized by height. By far, the greatest number of searches that SORTIE has to do are distance and height searches (neighborhood searches) so the table is optimized for this. This class keeps some shortcut values calculated in order to handle other types of searches more quickly. The reason the grid is 8X8 m is because since 8 is a power of two, we can do very fast bitwise shifts instead of very slow division when we're doing grid cell calculations. (I leave it to the compiler to turn my divisions into shifts - makes the code easier to read.)
Copyright 2003 Charles D. Canham.
|
|
Reason codes for why a tree died. This controls the life history stage they pass to as dead trees. |
|
Constructor.
|
|
Adds a tree to the hash table.
|
|
Reads type and species info from the parameter file. This function should be called before GetData. This is because behaviors need to validate against species and type in the CreateObjects phase.
|
|
Changes a tree's type (life history stage). This will change a tree's type and copy over all the applicable variables. If a variable has no counterpart in the new type, it will be discarded. Allometric values will not be recalculated (with the exception of the seedling to sapling transition, where the new dbh value will be calculated and assigned).
|
|
Allocates memory for the hash table. GetPlotDimensions() must be called first. |
|
Creates a new tree and organizes it into the hash table. If this is supposed to be a seedling, and the diam10 creates a height taller than 1.35 m, the tree becomes a sapling. If the dbh is larger than the min adult dbh and the type is given as sapling, the tree is created as an adult.
|
|
Creates trees according to initial density information in an input file. If initial density information it is not present, no trees are created. This is not considered an error condition. In addition to as many DBH size classes as the user wants, this can also handle three height classes for seedling initial densities.
|
|
Creates trees according to tree map information in an input file. If tree map information it is not present, no trees are created. This is not considered an error condition.
|
|
Queries all behaviors for data members that they wish to add to the tree's data structure. The data members to be added are only added for the species and types that the behavior works on. This will also check for any behaviors that work on stumps and snags. If any are found, the appropriate bucket in mp_bMakeStump is set to true or m_bMakeSnag is set to true, respectively. The tree population also uses this opportunity to add its own tree data member registrations. It registers "Diam10" for seedlings and saplings; "DBH" for saplings, adults, stumps, and snags; "Height" for seedlings, saplings, adults, and snags; "Age" and "Why dead" for snags; and "X" and "Y" for seedlings, saplings, adults, stumps, and snags. |
|
Acquires trees which meet certain criteria. Any function needing to act on trees uses this function to find them. A clTreeSearch object is returned, and the trees can then be accessed repeatedly by calling the clTreeSearch object's NextTree() method. Stumps are not returned by this method. Use the GetFirstStump() method to access them directly. To set up a search, a search string is passed to Find(). The string is formatted as follows: search term 1search term 2:: ... search term n where the search terms are described below. Only those terms of interest are used; when a search term is ommitted, it is assumed that any value for that term is acceptable. Valid terms:
Example: Find("species=0,2,3::type=1") or Find("distance=10.5 FROM x=5.5,y=5.6::height=4.5") If no trees are found as the result of a search, the NextTree() method of the returned treeSearch object returns NULL.
|
|
Gets the code for the "Age" snag data member, which is registered by the tree population.
|
|
Gets the allometry object.
|
|
Gets the data code for accessing a bool tree data member. This code can be used for accessing its value through the tree's GetValue() and SetValue() functions. This function will not be responsible for duplicate labels.
|
|
Gets the label for a bool tree data member. This function will not be responsible for duplicate labels.
|
|
Gets the data code for accessing a char tree data member. This code can be used for accessing its value through the tree's GetValue() and SetValue() functions. This function will not be responsible for duplicate labels.
|
|
Gets the label for a char tree data member. This function will not be responsible for duplicate labels.
|
|
Performs setup. If the input file is a parameter file, this calls:
If the input file is a tree map or detailed output file, only the CreateTrees... functions are called.
Implements clWorkerBase. |
|
Gets the code for the "DBH" data member, which is registered by the tree population.
|
|
Gets the code for the "Diam10" data member, which is registered by the tree population.
|
|
Gets first stump in the stump linked list.
|
|
Gets the data code for accessing a float tree data member. This code can be used for accessing its value through the tree's GetValue() and SetValue() functions. This function will not be responsible for duplicate labels.
|
|
Gets the label for a float tree data member. This function will not be responsible for duplicate labels.
|
|
Gets the tree population internal grid cell size (grids are square).
|
|
Gets the code for the "Height" data member, which is registered by the tree population.
|
|
Gets the data code for accessing an integer tree data member. This code can be used for accessing its value through the tree's GetValue() and SetValue() functions. This function will not be responsible for duplicate labels.
|
|
Gets the label for an integer tree data member. This function will not be responsible for duplicate labels.
|
|
Gets the maximum possible seedling height for a species.
|
|
Gets the minimum adult DBH.
|
|
Gets the minimum possible adult height.
|
|
Gets the default new seedling diameter at 10 cm.
|
|
Gets the total number of species.
|
|
Gets the total number of tree types (life history stages).
|
|
Gets the number of cells in the X direction for the tree population's internal tree organizational grid.
|
|
Gets the number of cells in the Y direction for the tree population's internal tree organizational grid.
|
|
Retrieves the plot dimensions.
|
|
Gets a random diameter at 10 cm value for a seedling. This function slightly randomizes the diameter at 10 cm value around a "seed" value.
|
|
Allows direct access to the tree hash table.
|
|
Allows direct access to the tree hash table.
|
|
Gets whether or not this run uses snags.
|
|
Gets the code for the "Why dead" snag data member, which is registered by the tree population.
|
|
Gets the code for the "X" data member, which is registered by the tree population.
|
|
Gets the length in the X direction of the tree's internal grid (should match the value received from the plot object).
|
|
Gets the code for the "Y" data member, which is registered by the tree population.
|
|
Gets the length in the Y direction of the tree's internal grid (should match the value received from the plot object).
|
|
Kills a tree. What happens to the tree depends on what kind it is, why it died, and what behaviors are set up.
|
|
Adds a boolean data member to the tree data structure. A behavior must only register as many data members as it indicated that it wanted to add in its new data member variables. This does not check to make sure that there is not already a variable registered with that name.
|
|
Adds a char data member to the tree data structure. A behavior must only register as many data members as it indicated that it wanted to add in its new data member variables. This does not check to make sure that there is not already a variable registered with that name.
|
|
Core function for registering new tree data members.
|
|
Adds a float data member to the tree data structure. A behavior must only register as many data members as it indicated that it wanted to add in its new data member variables. This does not check to make sure that there is not already a variable registered with that name.
|
|
Adds an integer data member to the tree data structure. A behavior must only register as many data members as it indicated that it wanted to add in its new data member variables. This does not check to make sure that there is not already a variable registered with that name.
|
|
Removes a tree from the hash table. The gap it left in the linked list is closed and the tallest/shortest markers are updated as necessary.
|
|
Performs setup calculations. This function creates the clAllometry object, and calculates m_fMinAdultHeight and m_fMaxSaplingHeight. |
|
Sorts the hash table by height. This does a complete sort of the entire hash table using the Insertion Sort algorithm, which is good for almost-sorted datasets, which the hash table probably will be. This function will be used to sort the hash table if a behavior has been updating trees and has let them get out of order. |
|
Performs end-of-timestep cleanup tasks.
Reimplemented from clWorkerBase. |
|
Translates a species code into its name string.
|
|
Translates a species name string into its code. This is useful when parsing the XML file.
|
|
Updates a bool data member of a tree. If a tree receives a request to be updated, it passes it off to the tree population using this function.
|
|
Updates a char data member of a tree. If a tree receives a request to be updated, it passes it off to the tree population using this function.
|
|
Updates a float data member of a tree. If a tree receives a request to be updated, it passes it off to the tree population using this function. The default is for this function to update the other parameters based on allometric relationships (for instance, if DBH is changed, height will automatically be updated too). If the update causes a tree move to a new life history stage, it will automatically be transitioned. So, if setting a value of either diam10 or height on a seedling causes it to be greater than the seedling height cutoff, the tree will become a sapling and all of its allometric parameters will be recalculated to match the value that was set. You can override automatic allometry updating. If you do that, be aware that none of the other tree data members will be updated and you will need to do that yourself. (THERE IS ONE EXCEPTION. For saplings, DBH and diam10 are always kept in sync.) Be especially careful when there is a possibility of tree type transition. If the tree is a seedling and you set its height to a value greater than the height cutoff, it will transition, but its diam10 will not change. If the tree is a sapling and you set its DBH to be greater than the minimum adult DBH, it will transition. The setting of any other value will not cause transition. So, if you give a seedling a diam10 value that would, under automatic allometry updating, give it a height greater than the cutoff and cause it to become a sapling, the seedling will not become a sapling unless you explicitly set the height too.
|
|
Updates an integer data member of a tree. If a tree receives a request to be updated, it passes it off to the tree population using this function.
|
|
Updates a tree's position in the hash table. p_oChangedTree Tree whose position is to be updated. |
|
Maximum possible height a sapling can have, in meters. In practice this number is actually a smidge taller than the tallest height. |
|
New diameter at 10 cm for seedlings. Actual values are randomized around this value. From the parameter file. |
|
Length of internal grid cells, in meters. Make this always a power of 2! |
|
Number of species. From parameter file. |
|
List of tree bool data member labels. Array size is number of species by number of types by number of integer data members. The code for a data member equals the third array index. |
|
List of tree char data member labels. Array size is number of species by number of types by number of integer data members. The code for a data member equals the third array index. |
|
List of tree float data member labels. Array size is number of species by number of types by number of integer data members. The code for a data member equals the third array index. |
|
List of tree integer data member labels. Array size is number of species by number of types by number of integer data members. The code for a data member equals the third array index. |
|
Minimum adult DBH, in cm, for each species. From parameter file. |
|
Size classes for live trees. Number of size classes is user-settable. The value in each bin of the array is the upper limit in cm of the dbh for that class. There can also be a size class each for seeds and seedlings. |
|
Codes for "Age" snag tree data member. Array size is number of species. |
|
Codes for "DBH" tree data member. Array size is number of species by number of types. |
|
Codes for "Diam10" tree data member. Array size is number of species by number of types. |
|
Codes for "Height" tree data member. Array size is number of species by number of types. |
|
Number of tree bool data members that have been defined for this run. Array size is number of species by number of types. |
|
Number of tree char data members that have been defined for this run. Array size is number of species by number of types. |
|
Number of tree float data members that have been defined for this run. Array size is number of species by number of types. |
|
Number of tree integer data members that have been defined for this run. Array size is number of species by number of types. |
|
Codes for "Why dead" snag tree data member. Array size is number of species. |
|
Codes for "X" tree data member. Array size is number of species by number of types. |
|
Codes for "Y" tree data member. Array size is number of species by number of types. |
|
Holds open tree searches.The linked list of open search requests. The first record is always a dummy record. |
|
Linked list of stumps. Not sorted in any way. |
|
Hash table of shortest tree links. Array size is number of X grid cells by number of Y grid cells by number of height divisions. For instance, [2][3] is the grid cell which runs from X = 16-23 m and Y = 24-31 m. The tree pointer starts at the shortest, and the tree's "taller" pointer can be used to run downwards through all the trees in the cell. Tree taller pointers run across height divisions. |
|
Hash table of tallest tree links. Array size is number of X grid cells by number of Y grid cells by number of height divisions. For instance, [2][3] is the grid cell which runs from X = 16-23 m and Y = 24-31 m. The tree pointer starts at the tallest, and the tree's "shorter" pointer can be used to run downwards through all the trees in the cell. Tree shorter pointers run across height divisions. |