iLand
tree.h
Go to the documentation of this file.
1/********************************************************************************************
2** iLand - an individual based forest landscape and disturbance model
3** http://iland-model.org
4** Copyright (C) 2009- Werner Rammer, Rupert Seidl
5**
6** This program is free software: you can redistribute it and/or modify
7** it under the terms of the GNU General Public License as published by
8** the Free Software Foundation, either version 3 of the License, or
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
16** You should have received a copy of the GNU General Public License
17** along with this program. If not, see <http://www.gnu.org/licenses/>.
18********************************************************************************************/
19
20#ifndef TREE_H
21#define TREE_H
22#include <QPointF>
23
24#include "grid.h"
25
26
27// mortality workshop 2015 / COST Action with H. Bugmann
28//#define ALT_TREE_MORTALITY
29
30
31// forwards
32class Species;
33class Stamp;
34class ResourceUnit;
35struct HeightGridValue;
36struct TreeGrowthData;
37class TreeOut;
38class TreeRemovedOut;
40class Saplings;
41class ScriptTree;
42
43class Tree
44{
45public:
46 // lifecycle
47 Tree();
48 void setup();
49
50 // access to properties
51 int id() const { return mId; }
52 int age() const { return mAge; }
54 const QPointF position() const { Q_ASSERT(mGrid!=0); return mGrid->cellCenterPoint(mPositionIndex); }
55
57 const QPoint positionIndex() const { return mPositionIndex; }
58 const Species* species() const { Q_ASSERT(mRU!=0); return mSpecies; }
59 const ResourceUnit *ru() const { Q_ASSERT(mRU!=0); return mRU; }
60
61 // properties
62 float dbh() const { return mDbh; }
63 float height() const { return mHeight; }
64 float lightResourceIndex() const { return mLRI; }
65 float leafArea() const { return mLeafArea; }
66 double volume() const;
67 double basalArea() const;
68 bool isDead() const { return flag(Tree::TreeDead); }
69 float crownRadius() const;
70 // biomass properties
71 float biomassFoliage() const { return mFoliageMass; }
72 float biomassBranch() const { return mBranchMass; }
73 float biomassFineRoot() const { return mFineRootMass; }
74 float biomassCoarseRoot() const { return mCoarseRootMass; }
75 float biomassStem() const { return mStemMass + mNPPReserve; }
76 float biomassReserve() const { return mNPPReserve; }
77 double barkThickness() const;
78 float stressIndex() const { return mStressIndex; }
79
80 // actions
83 void die(TreeGrowthData *d=nullptr);
86 void remove(double removeFoliage=0., double removeBranch=0., double removeStem=0. );
94 void removeDisturbance(const double stem_to_soil_fraction, const double stem_to_snag_fraction,
95 const double branch_to_soil_fraction, const double branch_to_snag_fraction,
96 const double foliage_to_soil_fraction);
97
98 void enableDebugging(const bool enable=true) {setFlag(Tree::TreeDebugging, enable); }
101 void removeBiomassOfTree(const double removeFoliageFraction, const double removeBranchFraction, const double removeStemFraction);
103 void removeRootBiomass(const double removeFineRootFraction, const double removeCoarseRootFraction);
104
105 // setters for initialization
106 void setNewId() { mId = m_nextId++; }
107 void setId(const int id) { mId = id; }
108 void setPosition(const QPointF pos) { Q_ASSERT(mGrid!=nullptr); mPositionIndex = mGrid->indexAt(pos); }
109 void setPosition(const QPoint posIndex) { mPositionIndex = posIndex; }
110 void setDbh(const float dbh) { mDbh=dbh; }
111 void setHeight(const float height);
112 void setSpecies(Species *ts) { mSpecies=ts; }
113 void setRU(ResourceUnit *ru) { mRU = ru; }
114 void setAge(const int age, const float treeheight);
115
116 // management flags (used by ABE management system)
117 void markForHarvest(bool do_mark) { setFlag(Tree::MarkForHarvest, do_mark);}
118 bool isMarkedForHarvest() const { return flag(Tree::MarkForHarvest);}
119 void markForCut(bool do_mark) { setFlag(Tree::MarkForCut, do_mark);}
120 bool isMarkedForCut() const { return flag(Tree::MarkForCut);}
121 void markCropTree(bool do_mark) { setFlag(Tree::MarkCropTree, do_mark);}
122 bool isMarkedAsCropTree() const { return flag(Tree::MarkCropTree);}
123 void markCropCompetitor(bool do_mark) { setFlag(Tree::MarkCropCompetitor, do_mark);}
124 bool isMarkedAsCropCompetitor() const { return flag(Tree::MarkCropCompetitor);}
125 // death reasons
126 void setDeathReasonWind() { setFlag(Tree::TreeDeadWind, true); }
127 void setDeathReasonBarkBeetle() { setFlag(Tree::TreeDeadBarkBeetle, true); }
128 void setDeathReasonFire() { setFlag(Tree::TreeDeadFire, true); }
129 void setDeathCutdown() { setFlag(Tree::TreeDeadKillAndDrop, true); }
130 void setAffectedBite() { setFlag(Tree::TreeAffectedBite, true); }
131 void setIsHarvested() { setFlag(Tree::TreeHarvested, true); }
132
133 bool isDeadWind() const { return flag(Tree::TreeDeadWind);}
134 bool isDeadBarkBeetle() const { return flag(Tree::TreeDeadBarkBeetle);}
135 bool isDeadFire() const { return flag(Tree::TreeDeadFire);}
136 bool isAffectedBite() const { return flag(Tree::TreeAffectedBite); }
137 bool isCutdown() const { return flag(Tree::TreeDeadKillAndDrop);}
138 bool isHarvested() const { return flag(Tree::TreeHarvested);}
139
140 // grid based light-concurrency functions
141 void applyLIP();
142 void readLIF();
143 void heightGrid();
144
145 void applyLIP_torus();
146 void readLIF_torus();
147 void heightGrid_torus();
148
149 void calcLightResponse();
150 // growth, etc.
151 void grow();
152
153 // static functions
154 static void setGrid(FloatGrid* gridToStamp, Grid<HeightGridValue> *dominanceGrid);
155 // statistics
156 static void resetStatistics();
157 static int statPrints() { return m_statPrint; }
158 static int statCreated() { return m_statCreated; }
159#ifdef ALT_TREE_MORTALITY
160 static void mortalityParams(double dbh_inc_threshold, int stress_years, double stress_mort_prob);
161#endif
162
163 QString dump();
164 void dumpList(QList<QVariant> &rTargetList);
165 const Stamp *stamp() const { return mStamp; }
166
167private:
168 // helping functions
169 void partitioning(TreeGrowthData &d);
170 double relative_height_growth();
171 void grow_diameter(TreeGrowthData &d);
172 void mortality(TreeGrowthData &d);
173
174#ifdef ALT_TREE_MORTALITY
175 void altMortality(TreeGrowthData &d);
176#endif
177 void notifyTreeRemoved(TreeRemovalType reason);
178
179 // state variables
180 int mId;
181 int mAge;
182 float mDbh;
183 float mHeight;
184 QPoint mPositionIndex;
185 // biomass compartements
186 float mLeafArea;
187 float mOpacity;
188 float mFoliageMass;
189 float mStemMass;
190 float mBranchMass;
191 float mFineRootMass;
192 float mCoarseRootMass;
193 // production relevant
194 float mNPPReserve;
195 float mLRI;
196 float mLightResponse;
197 // auxiliary
198 float mDbhDelta;
199 float mStressIndex;
200
201 // Stamp, Species, Resource Unit
202 const Stamp *mStamp;
203 Species *mSpecies;
204 ResourceUnit *mRU;
205
206 // various flags
207 int mFlags;
209 enum Flags { TreeDead=1, TreeDebugging=2,
210 TreeDeadBarkBeetle=16, TreeDeadWind=32, TreeDeadFire=64, TreeDeadKillAndDrop=128, TreeHarvested=256,
211 MarkForCut=512, // mark tree for being cut down
212 MarkForHarvest=1024, // mark tree for being harvested
213 MarkCropTree=2048, // mark as crop tree
214 MarkCropCompetitor=4096, // mark as competitor for a crop tree
215 TreeAffectedBite=8192 // affected or killed by biotic disturbance module (BITE)
216 };
218 void setFlag(const Tree::Flags flag, const bool value) { if (value) mFlags |= flag; else mFlags &= (flag ^ 0xffffff );}
220 void setFlag(const int flag, const bool value) { if (value) mFlags |= flag; else mFlags &= (flag ^ 0xffffff );}
222 bool flag(const Tree::Flags flag) const { return mFlags & flag; }
224 int flags() const {return mFlags; }
225
226 // special functions
227 bool isDebugging() { return flag(Tree::TreeDebugging); }
228
229 // static data
230 static FloatGrid *mGrid;
231 static Grid<HeightGridValue> *mHeightGrid;
232 static TreeRemovedOut *mRemovalOutput;
233 static void setTreeRemovalOutput(TreeRemovedOut *rout) { mRemovalOutput=rout; }
234 static LandscapeRemovedOut *mLSRemovalOutput;
235 static void setLandscapeRemovalOutput(LandscapeRemovedOut *rout) { mLSRemovalOutput=rout; }
236 static Saplings *saps;
237
238 // statistics
239 static int m_statPrint;
240 static int m_statAboveZ;
241 static int m_statCreated;
242 static int m_nextId;
243
244 // friends
245 friend class TreeWrapper;
246 friend class StandStatistics;
247 friend class TreeOut;
248 friend class TreeRemovedOut;
250 friend class Snapshot;
251 friend class SnapshotItem;
252 friend class ScriptTree;
253};
254
257{
258 double NPP;
259 double NPP_above;
260 double NPP_stem;
263};
264#endif // TREE_H
QPointF cellCenterPoint(const QPoint &pos) const
get the (metric) centerpoint of cell with index pos
Definition: grid.h:141
QPoint indexAt(const QPointF &pos) const
get index of value at position pos (metric)
Definition: grid.h:125
LandscapeRemovedOut is aggregated output for removed trees on the full landscape.
Definition: landscapeout.h:43
ResourceUnit is the spatial unit that encapsulates a forest stand and links to several environmental ...
Definition: resourceunit.h:49
The Saplings class the container for the establishment and sapling growth in iLand.
Definition: saplings.h:192
Definition: scripttree.h:10
way to save/load the current state of the model to a database.
Definition: snapshot.h:35
Definition: snapshot.cpp:42
The behavior and general properties of tree species.
Definition: species.h:75
Stamp is the basic class for the LIP field of a individual tree.
Definition: stamp.h:32
Collects information on stand level for each tree species.
Definition: standstatistics.h:28
A tree is the basic simulation entity of iLand and represents a single tree.
Definition: tree.h:44
const QPoint positionIndex() const
the x/y indicies (2m grid) of the tree
Definition: tree.h:57
void readLIF_torus()
calculate LRI from a closed 1ha area
Definition: tree.cpp:529
const QPointF position() const
metric coordinates of the tree
Definition: tree.h:54
void applyLIP()
apply LightInfluencePattern onto the global grid
Definition: tree.cpp:176
float height() const
tree height in m
Definition: tree.h:63
void markForHarvest(bool do_mark)
Definition: tree.h:117
static void resetStatistics()
Definition: tree.cpp:603
double volume() const
volume (m3) of stem volume based on geometry and density calculated on the fly.
Definition: tree.cpp:1164
void removeRootBiomass(const double removeFineRootFraction, const double removeCoarseRootFraction)
remove root biomass of trees (e.g. due to funghi)
Definition: tree.cpp:1069
double barkThickness() const
mass (kg) of the reserve pool
Definition: tree.cpp:112
void removeBiomassOfTree(const double removeFoliageFraction, const double removeBranchFraction, const double removeStemFraction)
removes fractions (0..1) for foliage, branches, stem, and roots from a tree, e.g.
Definition: tree.cpp:1055
bool isAffectedBite() const
Definition: tree.h:136
void setSpecies(Species *ts)
Definition: tree.h:112
void enableDebugging(const bool enable=true)
Definition: tree.h:98
void readLIF()
calculate the lightResourceIndex with multiplicative approach
Definition: tree.cpp:464
void setDeathReasonFire()
Definition: tree.h:128
float biomassBranch() const
mass (kg) of branches
Definition: tree.h:72
void applyLIP_torus()
apply LightInfluencePattern on a closed 1ha area
Definition: tree.cpp:231
void setHeight(const float height)
Definition: tree.cpp:1083
bool isMarkedAsCropTree() const
Definition: tree.h:122
float leafArea() const
leaf area (m2) of the tree
Definition: tree.h:65
int id() const
numerical unique ID of the tree
Definition: tree.h:51
bool isDeadFire() const
Definition: tree.h:135
float crownRadius() const
fetch crown radius (m) from the attached stamp
Definition: tree.cpp:97
void setDeathReasonWind()
Definition: tree.h:126
void setAge(const int age, const float treeheight)
Definition: tree.cpp:159
void setIsHarvested()
Definition: tree.h:131
static int statPrints()
Definition: tree.h:157
void setPosition(const QPointF pos)
Definition: tree.h:108
void markForCut(bool do_mark)
Definition: tree.h:119
static void setGrid(FloatGrid *gridToStamp, Grid< HeightGridValue > *dominanceGrid)
Definition: tree.cpp:106
void markCropTree(bool do_mark)
Definition: tree.h:121
void setDeathReasonBarkBeetle()
Definition: tree.h:127
const Species * species() const
pointer to the tree species of the tree.
Definition: tree.h:58
void setAffectedBite()
Definition: tree.h:130
void setPosition(const QPoint posIndex)
Definition: tree.h:109
bool isDeadWind() const
Definition: tree.h:133
void setDbh(const float dbh)
Definition: tree.h:110
void heightGrid_torus()
calculate the height grid
Definition: tree.cpp:365
float biomassCoarseRoot() const
mass (kg) of coarse roots
Definition: tree.h:74
void dumpList(QList< QVariant > &rTargetList)
Definition: tree.cpp:127
bool isDead() const
returns true if the tree is already dead.
Definition: tree.h:68
void heightGrid()
calculate the height grid
Definition: tree.cpp:284
bool isDeadBarkBeetle() const
Definition: tree.h:134
float biomassFoliage() const
mass (kg) of foliage
Definition: tree.h:71
float biomassFineRoot() const
mass (kg) of fine roots
Definition: tree.h:73
QString dump()
dumps some core variables of a tree to a string.
Definition: tree.cpp:118
bool isMarkedAsCropCompetitor() const
Definition: tree.h:124
float biomassStem() const
mass (kg) of stem, conceputally stem biomass + reserve pool
Definition: tree.h:75
void die(TreeGrowthData *d=nullptr)
the tree dies (is killed)
Definition: tree.cpp:997
void calcLightResponse()
calculate light response
Definition: tree.cpp:621
float biomassReserve() const
Definition: tree.h:76
int age() const
the tree age (years)
Definition: tree.h:52
void setId(const int id)
set a spcific ID (if provided in stand init file).
Definition: tree.h:107
bool isHarvested() const
Definition: tree.h:138
void setRU(ResourceUnit *ru)
Definition: tree.h:113
void setNewId()
force a new id for this object (after copying trees)
Definition: tree.h:106
bool isCutdown() const
Definition: tree.h:137
float stressIndex() const
the scalar stress rating (0..1)
Definition: tree.h:78
static int statCreated()
Definition: tree.h:158
void grow()
main growth function to update the tree state.
Definition: tree.cpp:643
Tree()
Definition: tree.cpp:79
const ResourceUnit * ru() const
pointer to the ressource unit the tree belongs to.
Definition: tree.h:59
double basalArea() const
basal area of the tree at breast height in m2
Definition: tree.cpp:1173
bool isMarkedForHarvest() const
Definition: tree.h:118
void removeDisturbance(const double stem_to_soil_fraction, const double stem_to_snag_fraction, const double branch_to_soil_fraction, const double branch_to_snag_fraction, const double foliage_to_soil_fraction)
remove the tree due to an special event (disturbance) the part of the biomass that goes not to soil/s...
Definition: tree.cpp:1030
void setup()
calculates initial values for biomass pools etc. after dimensions are set.
Definition: tree.cpp:133
void setDeathCutdown()
Definition: tree.h:129
TreeRemovalType
Definition: tree.h:81
@ TreeKilled
Definition: tree.h:81
@ TreeDeath
Definition: tree.h:81
@ TreeHarvest
Definition: tree.h:81
@ TreeSalavaged
Definition: tree.h:81
@ TreeCutDown
Definition: tree.h:81
@ TreeDisturbance
Definition: tree.h:81
void remove(double removeFoliage=0., double removeBranch=0., double removeStem=0.)
remove the tree (management).
Definition: tree.cpp:1009
float dbh() const
dimater at breast height in cm
Definition: tree.h:62
float lightResourceIndex() const
LRI of the tree (updated during readStamp())
Definition: tree.h:64
const Stamp * stamp() const
TODO: only for debugging purposes.
Definition: tree.h:165
bool isMarkedForCut() const
Definition: tree.h:120
void markCropCompetitor(bool do_mark)
Definition: tree.h:123
Definition: treeout.h:28
Definition: treeout.h:38
Definition: expressionwrapper.h:42
double removeBranch()
Definition: fmtreelist.cpp:50
double removeFoliage()
Definition: fmtreelist.cpp:48
double removeStem()
Definition: fmtreelist.cpp:49
Definition: model.h:51
internal data structure which is passed between function and to statistics
Definition: tree.h:257
double stress_index
stress index used for mortality calculation
Definition: tree.h:261
double NPP
total NPP (kg)
Definition: tree.h:258
double NPP_above
NPP aboveground (kg) (NPP - fraction roots), no consideration of tree senescence.
Definition: tree.h:259
TreeGrowthData()
Definition: tree.h:262
double NPP_stem
NPP used for growth of stem (dbh,h)
Definition: tree.h:260