Rev 257 | Rev 262 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | |||
3 | Werner | 2 | #ifndef TREE_H |
3 | #define TREE_H |
||
4 | #include <QPointF> |
||
5 | |||
83 | Werner | 6 | #include "grid.h" |
158 | werner | 7 | // forwards |
90 | Werner | 8 | class Species; |
38 | Werner | 9 | class Stamp; |
187 | iland | 10 | class ResourceUnit; |
151 | iland | 11 | struct HeightGridValue; |
159 | werner | 12 | struct TreeGrowthData; |
3 | Werner | 13 | |
14 | class Tree |
||
15 | { |
||
16 | public: |
||
141 | Werner | 17 | // lifecycle |
3 | Werner | 18 | Tree(); |
141 | Werner | 19 | void setup(); |
20 | |||
21 | // access to properties |
||
145 | Werner | 22 | int id() const { return mId; } |
169 | werner | 23 | int age() const { return mAge; } |
156 | werner | 24 | /// @property position The tree does not store the floating point coordinates but only the index of pixel on the LIF grid |
25 | const QPointF position() const { Q_ASSERT(mGrid!=0); return mGrid->cellCenterPoint(mPositionIndex); } |
||
158 | werner | 26 | const Species* species() const { Q_ASSERT(mRU!=0); return mSpecies; } ///< pointer to the tree species of the tree. |
187 | iland | 27 | const ResourceUnit *ru() const { Q_ASSERT(mRU!=0); return mRU; } ///< pointer to the ressource unit the tree belongs to. |
158 | werner | 28 | |
234 | werner | 29 | // properties |
30 | float dbh() const { return mDbh; } ///< dimater at breast height in cm |
||
31 | float height() const { return mHeight; } ///< tree height in m |
||
32 | float lightResourceIndex() const { return mLRI; } ///< LRI of the tree (updated during readStamp()) |
||
33 | float leafArea() const { return mLeafArea; } ///< leaf area (m2) of the tree |
||
158 | werner | 34 | double volume() const; ///< volume (m3) of stem volume based on geometry and density calculated on the fly. |
180 | werner | 35 | double basalArea() const; ///< basal area of the tree at breast height in m2 |
158 | werner | 36 | bool isDead() const { return flag(Tree::TreeDead); } ///< returns true if the tree is already dead. |
37 | // actions |
||
38 | void die() { setFlag(Tree::TreeDead, true); } ///< kills the tree. |
||
39 | void enableDebugging(const bool enable=true) {setFlag(Tree::TreeDebugging, enable); } |
||
40 | |||
41 | // setters for initialization |
||
42 | void setNewId() { mId = m_nextId++; } ///< force a new id for this object (after copying trees) |
||
247 | werner | 43 | void setId(const int id) { mId = id; } ///< set a spcific ID (if provided in stand init file). |
156 | werner | 44 | void setPosition(const QPointF pos) { Q_ASSERT(mGrid!=0); mPositionIndex = mGrid->indexAt(pos); } |
106 | Werner | 45 | void setDbh(const float dbh) { mDbh=dbh; } |
46 | void setHeight(const float height) { mHeight=height; } |
||
47 | void setSpecies(Species *ts) { mSpecies=ts; } |
||
187 | iland | 48 | void setRU(ResourceUnit *ru) { mRU = ru; } |
170 | werner | 49 | void setAge(const int age) { mAge = age; } |
158 | werner | 50 | |
107 | Werner | 51 | // grid based light-concurrency functions |
158 | werner | 52 | void applyLIP(); ///< apply LightInfluencePattern onto the global grid |
187 | iland | 53 | void readLIF(); ///< calculate the lightResourceIndex with multiplicative approach |
107 | Werner | 54 | void heightGrid(); ///< calculate the height grid |
39 | Werner | 55 | |
158 | werner | 56 | void applyLIP_torus(); ///< apply LightInfluencePattern on a closed 1ha area |
57 | void readLIF_torus(); ///< calculate LRI from a closed 1ha area |
||
58 | void heightGrid_torus(); ///< calculate the height grid |
||
155 | werner | 59 | |
251 | werner | 60 | void calcLightResponse(); ///< calculate light response |
107 | Werner | 61 | // growth, etc. |
158 | werner | 62 | void grow(); ///< main growth function to update the tree state. |
107 | Werner | 63 | |
64 | // static functions |
||
151 | iland | 65 | static void setGrid(FloatGrid* gridToStamp, Grid<HeightGridValue> *dominanceGrid); |
40 | Werner | 66 | // statistics |
67 | static void resetStatistics(); |
||
145 | Werner | 68 | static int statPrints() { return m_statPrint; } |
69 | static int statCreated() { return m_statCreated; } |
||
40 | Werner | 70 | |
135 | Werner | 71 | QString dump(); |
145 | Werner | 72 | void dumpList(QList<QVariant> &rTargetList); |
135 | Werner | 73 | |
3 | Werner | 74 | private: |
110 | Werner | 75 | // helping functions |
159 | werner | 76 | void partitioning(TreeGrowthData &d); ///< split NPP into various plant pools. |
158 | werner | 77 | double relative_height_growth(); ///< estimate height growth based on light status. |
159 | werner | 78 | void grow_diameter(TreeGrowthData &d); ///< actual growth of the tree's stem. |
79 | void mortality(TreeGrowthData &d); ///< main function that checks whether trees is to die |
||
80 | |||
107 | Werner | 81 | // state variables |
169 | werner | 82 | int mId; ///< unique ID of tree |
83 | int mAge; ///< age of tree in years |
||
125 | Werner | 84 | float mDbh; ///< diameter at breast height [cm] |
85 | float mHeight; ///< tree height [m] |
||
156 | werner | 86 | QPoint mPositionIndex; ///< index of the trees position on the basic LIF grid |
107 | Werner | 87 | // biomass compartements |
149 | werner | 88 | float mLeafArea; ///< m2 leaf area |
89 | float mOpacity; ///< multiplier on LIP weights, depending on leaf area status (opacity of the crown) |
||
136 | Werner | 90 | float mFoliageMass; // kg |
91 | float mWoodyMass; // kg |
||
107 | Werner | 92 | float mRootMass; // kg |
116 | Werner | 93 | // production relevant |
94 | float mNPPReserve; // kg |
||
187 | iland | 95 | float mLRI; ///< resulting lightResourceIndex |
212 | werner | 96 | float mLightResponse; ///< light response used for distribution of biomass on RU level |
159 | werner | 97 | // auxiliary |
125 | Werner | 98 | float mDbhDelta; ///< diameter growth [cm] |
159 | werner | 99 | float mStressIndex; ///< stress index (used for mortality) |
100 | |||
187 | iland | 101 | // Stamp, Species, Resource Unit |
106 | Werner | 102 | const Stamp *mStamp; |
103 | Species *mSpecies; |
||
187 | iland | 104 | ResourceUnit *mRU; |
107 | Werner | 105 | |
157 | werner | 106 | // various flags |
107 | int mFlags; |
||
108 | enum Flags { TreeDead=1, TreeDebugging=2 }; |
||
109 | void setFlag(const Tree::Flags flag, const bool value) { if (value) mFlags |= flag; else mFlags &= (flag ^ 0xffffff );} |
||
110 | bool flag(const Tree::Flags flag) const { return mFlags & flag; } |
||
139 | Werner | 111 | |
117 | Werner | 112 | // special functions |
157 | werner | 113 | bool isDebugging() { return flag(Tree::TreeDebugging); } |
135 | Werner | 114 | |
107 | Werner | 115 | // static data |
106 | Werner | 116 | static FloatGrid *mGrid; |
151 | iland | 117 | static Grid<HeightGridValue> *mHeightGrid; |
53 | Werner | 118 | |
40 | Werner | 119 | // statistics |
120 | static int m_statPrint; |
||
48 | Werner | 121 | static int m_statAboveZ; |
105 | Werner | 122 | static int m_statCreated; |
40 | Werner | 123 | static int m_nextId; |
148 | iland | 124 | |
125 | // friends |
||
126 | friend class TreeWrapper; |
||
180 | werner | 127 | friend class StandStatistics; |
3 | Werner | 128 | }; |
129 | |||
257 | werner | 130 | /// internal data structure which is passed between function and to statistics |
131 | struct TreeGrowthData |
||
132 | { |
||
261 | werner | 133 | double NPP; ///< total NPP (kg) |
134 | double NPP_above; ///< NPP aboveground (kg) (NPP - fraction roots), no consideration of tree senescence |
||
257 | werner | 135 | double NPP_stem; ///< NPP used for growth of stem (dbh,h) |
136 | double stress_index; ///< stress index used for mortality calculation |
||
137 | }; |
||
3 | Werner | 138 | #endif // TREE_H |