Rev 671 | Rev 713 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | |||
671 | werner | 2 | /******************************************************************************************** |
3 | ** iLand - an individual based forest landscape and disturbance model |
||
4 | ** http://iland.boku.ac.at |
||
5 | ** Copyright (C) 2009- Werner Rammer, Rupert Seidl |
||
6 | ** |
||
7 | ** This program is free software: you can redistribute it and/or modify |
||
8 | ** it under the terms of the GNU General Public License as published by |
||
9 | ** the Free Software Foundation, either version 3 of the License, or |
||
10 | ** (at your option) any later version. |
||
11 | ** |
||
12 | ** This program is distributed in the hope that it will be useful, |
||
13 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
14 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
15 | ** GNU General Public License for more details. |
||
16 | ** |
||
17 | ** You should have received a copy of the GNU General Public License |
||
18 | ** along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
19 | ********************************************************************************************/ |
||
20 | |||
3 | Werner | 21 | #ifndef TREE_H |
22 | #define TREE_H |
||
23 | #include <QPointF> |
||
24 | |||
83 | Werner | 25 | #include "grid.h" |
158 | werner | 26 | // forwards |
90 | Werner | 27 | class Species; |
38 | Werner | 28 | class Stamp; |
187 | iland | 29 | class ResourceUnit; |
151 | iland | 30 | struct HeightGridValue; |
159 | werner | 31 | struct TreeGrowthData; |
264 | werner | 32 | class TreeOut; |
3 | Werner | 33 | |
34 | class Tree |
||
35 | { |
||
36 | public: |
||
141 | Werner | 37 | // lifecycle |
3 | Werner | 38 | Tree(); |
141 | Werner | 39 | void setup(); |
40 | |||
41 | // access to properties |
||
145 | Werner | 42 | int id() const { return mId; } |
169 | werner | 43 | int age() const { return mAge; } |
156 | werner | 44 | /// @property position The tree does not store the floating point coordinates but only the index of pixel on the LIF grid |
45 | const QPointF position() const { Q_ASSERT(mGrid!=0); return mGrid->cellCenterPoint(mPositionIndex); } |
||
544 | werner | 46 | const QPoint positionIndex() const { return mPositionIndex; } |
158 | werner | 47 | const Species* species() const { Q_ASSERT(mRU!=0); return mSpecies; } ///< pointer to the tree species of the tree. |
187 | iland | 48 | const ResourceUnit *ru() const { Q_ASSERT(mRU!=0); return mRU; } ///< pointer to the ressource unit the tree belongs to. |
158 | werner | 49 | |
234 | werner | 50 | // properties |
51 | float dbh() const { return mDbh; } ///< dimater at breast height in cm |
||
52 | float height() const { return mHeight; } ///< tree height in m |
||
53 | float lightResourceIndex() const { return mLRI; } ///< LRI of the tree (updated during readStamp()) |
||
54 | float leafArea() const { return mLeafArea; } ///< leaf area (m2) of the tree |
||
158 | werner | 55 | double volume() const; ///< volume (m3) of stem volume based on geometry and density calculated on the fly. |
180 | werner | 56 | double basalArea() const; ///< basal area of the tree at breast height in m2 |
158 | werner | 57 | bool isDead() const { return flag(Tree::TreeDead); } ///< returns true if the tree is already dead. |
407 | werner | 58 | float crownRadius() const; ///< fetch crown radius (m) from the attached stamp |
449 | werner | 59 | // biomass properties |
60 | float biomassFoliage() const { return mFoliageMass; } ///< mass (kg) of foliage |
||
476 | werner | 61 | float biomassBranch() const; ///< mass (kg) of branches |
449 | werner | 62 | float biomassFineRoot() const { return mFineRootMass; } ///< mass (kg) of fine roots |
63 | float biomassCoarseRoot() const { return mCoarseRootMass; } ///< mass (kg) of coarse roots |
||
64 | float biomassStem() const { return mWoodyMass; } ///< mass (kg) of stem |
||
667 | werner | 65 | double barkThickness() const; ///< thickness of the bark (cm) |
449 | werner | 66 | |
158 | werner | 67 | // actions |
277 | werner | 68 | void die(TreeGrowthData *d=0); ///< kills the tree. |
564 | werner | 69 | /// remove the tree (management). removalFractions for tree compartments: if 0: all biomass stays in the system, 1: all is "removed" |
70 | /// default values: all biomass remains in the forest (i.e.: kill()). |
||
71 | void remove(double removeFoliage=0., double removeBranch=0., double removeStem=0. ); |
||
158 | werner | 72 | void enableDebugging(const bool enable=true) {setFlag(Tree::TreeDebugging, enable); } |
668 | werner | 73 | /// removes fractions (0..1) for foliage, branches, stem from a tree, e.g. due to a fire. |
74 | /// values of "0" remove nothing, "1" removes the full compartent. |
||
75 | void removeBiomass(const double removeFoliageFraction, const double removeBranchFraction, const double removeStemFraction); |
||
158 | werner | 76 | |
77 | // setters for initialization |
||
78 | void setNewId() { mId = m_nextId++; } ///< force a new id for this object (after copying trees) |
||
247 | werner | 79 | void setId(const int id) { mId = id; } ///< set a spcific ID (if provided in stand init file). |
156 | werner | 80 | void setPosition(const QPointF pos) { Q_ASSERT(mGrid!=0); mPositionIndex = mGrid->indexAt(pos); } |
287 | werner | 81 | void setPosition(const QPoint posIndex) { mPositionIndex = posIndex; } |
106 | Werner | 82 | void setDbh(const float dbh) { mDbh=dbh; } |
83 | void setHeight(const float height) { mHeight=height; } |
||
84 | void setSpecies(Species *ts) { mSpecies=ts; } |
||
187 | iland | 85 | void setRU(ResourceUnit *ru) { mRU = ru; } |
388 | werner | 86 | void setAge(const int age, const float treeheight); |
158 | werner | 87 | |
107 | Werner | 88 | // grid based light-concurrency functions |
158 | werner | 89 | void applyLIP(); ///< apply LightInfluencePattern onto the global grid |
187 | iland | 90 | void readLIF(); ///< calculate the lightResourceIndex with multiplicative approach |
107 | Werner | 91 | void heightGrid(); ///< calculate the height grid |
39 | Werner | 92 | |
158 | werner | 93 | void applyLIP_torus(); ///< apply LightInfluencePattern on a closed 1ha area |
94 | void readLIF_torus(); ///< calculate LRI from a closed 1ha area |
||
95 | void heightGrid_torus(); ///< calculate the height grid |
||
155 | werner | 96 | |
251 | werner | 97 | void calcLightResponse(); ///< calculate light response |
107 | Werner | 98 | // growth, etc. |
158 | werner | 99 | void grow(); ///< main growth function to update the tree state. |
107 | Werner | 100 | |
101 | // static functions |
||
151 | iland | 102 | static void setGrid(FloatGrid* gridToStamp, Grid<HeightGridValue> *dominanceGrid); |
40 | Werner | 103 | // statistics |
104 | static void resetStatistics(); |
||
145 | Werner | 105 | static int statPrints() { return m_statPrint; } |
106 | static int statCreated() { return m_statCreated; } |
||
40 | Werner | 107 | |
135 | Werner | 108 | QString dump(); |
145 | Werner | 109 | void dumpList(QList<QVariant> &rTargetList); |
135 | Werner | 110 | |
3 | Werner | 111 | private: |
110 | Werner | 112 | // helping functions |
159 | werner | 113 | void partitioning(TreeGrowthData &d); ///< split NPP into various plant pools. |
158 | werner | 114 | double relative_height_growth(); ///< estimate height growth based on light status. |
159 | werner | 115 | void grow_diameter(TreeGrowthData &d); ///< actual growth of the tree's stem. |
116 | void mortality(TreeGrowthData &d); ///< main function that checks whether trees is to die |
||
117 | |||
107 | Werner | 118 | // state variables |
169 | werner | 119 | int mId; ///< unique ID of tree |
120 | int mAge; ///< age of tree in years |
||
125 | Werner | 121 | float mDbh; ///< diameter at breast height [cm] |
122 | float mHeight; ///< tree height [m] |
||
156 | werner | 123 | QPoint mPositionIndex; ///< index of the trees position on the basic LIF grid |
107 | Werner | 124 | // biomass compartements |
149 | werner | 125 | float mLeafArea; ///< m2 leaf area |
126 | float mOpacity; ///< multiplier on LIP weights, depending on leaf area status (opacity of the crown) |
||
449 | werner | 127 | float mFoliageMass; // kg of foliage (dry) |
668 | werner | 128 | float mWoodyMass; // kg biomass of aboveground stem biomass |
449 | werner | 129 | float mFineRootMass; // kg biomass of fine roots (linked to foliage mass) |
130 | float mCoarseRootMass; // kg biomass of coarse roots (allometric equation) |
||
116 | Werner | 131 | // production relevant |
132 | float mNPPReserve; // kg |
||
187 | iland | 133 | float mLRI; ///< resulting lightResourceIndex |
212 | werner | 134 | float mLightResponse; ///< light response used for distribution of biomass on RU level |
159 | werner | 135 | // auxiliary |
125 | Werner | 136 | float mDbhDelta; ///< diameter growth [cm] |
159 | werner | 137 | float mStressIndex; ///< stress index (used for mortality) |
138 | |||
187 | iland | 139 | // Stamp, Species, Resource Unit |
106 | Werner | 140 | const Stamp *mStamp; |
141 | Species *mSpecies; |
||
187 | iland | 142 | ResourceUnit *mRU; |
107 | Werner | 143 | |
157 | werner | 144 | // various flags |
145 | int mFlags; |
||
388 | werner | 146 | enum Flags { TreeDead=1, TreeDebugging=2 }; ///< (binary coded) tree flags |
157 | werner | 147 | void setFlag(const Tree::Flags flag, const bool value) { if (value) mFlags |= flag; else mFlags &= (flag ^ 0xffffff );} |
148 | bool flag(const Tree::Flags flag) const { return mFlags & flag; } |
||
139 | Werner | 149 | |
117 | Werner | 150 | // special functions |
157 | werner | 151 | bool isDebugging() { return flag(Tree::TreeDebugging); } |
135 | Werner | 152 | |
107 | Werner | 153 | // static data |
106 | Werner | 154 | static FloatGrid *mGrid; |
151 | iland | 155 | static Grid<HeightGridValue> *mHeightGrid; |
53 | Werner | 156 | |
40 | Werner | 157 | // statistics |
158 | static int m_statPrint; |
||
48 | Werner | 159 | static int m_statAboveZ; |
105 | Werner | 160 | static int m_statCreated; |
40 | Werner | 161 | static int m_nextId; |
148 | iland | 162 | |
163 | // friends |
||
164 | friend class TreeWrapper; |
||
180 | werner | 165 | friend class StandStatistics; |
264 | werner | 166 | friend class TreeOut; |
675 | werner | 167 | friend class Snapshot; |
3 | Werner | 168 | }; |
169 | |||
257 | werner | 170 | /// internal data structure which is passed between function and to statistics |
171 | struct TreeGrowthData |
||
172 | { |
||
261 | werner | 173 | double NPP; ///< total NPP (kg) |
174 | double NPP_above; ///< NPP aboveground (kg) (NPP - fraction roots), no consideration of tree senescence |
||
257 | werner | 175 | double NPP_stem; ///< NPP used for growth of stem (dbh,h) |
176 | double stress_index; ///< stress index used for mortality calculation |
||
262 | werner | 177 | TreeGrowthData(): NPP(0.), NPP_above(0.), NPP_stem(0.) {} |
257 | werner | 178 | }; |
3 | Werner | 179 | #endif // TREE_H |