Subversion Repositories public iLand

Rev

Rev 1221 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
671 werner 1
/********************************************************************************************
2
**    iLand - an individual based forest landscape and disturbance model
3
**    http://iland.boku.ac.at
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
 
3 Werner 20
#ifndef TREE_H
21
#define TREE_H
22
#include <QPointF>
23
 
83 Werner 24
#include "grid.h"
1071 werner 25
 
26
 
27
// mortality workshop 2015 / COST Action with H. Bugmann
1102 werner 28
//#define ALT_TREE_MORTALITY
1071 werner 29
 
30
 
158 werner 31
// forwards
90 Werner 32
class Species;
38 Werner 33
class Stamp;
187 iland 34
class ResourceUnit;
151 iland 35
struct HeightGridValue;
159 werner 36
struct TreeGrowthData;
264 werner 37
class TreeOut;
1102 werner 38
class TreeRemovedOut;
1114 werner 39
class LandscapeRemovedOut;
3 Werner 40
 
41
class Tree
42
{
43
public:
141 Werner 44
    // lifecycle
3 Werner 45
    Tree();
885 werner 46
    void setup(); ///< calculates initial values for biomass pools etc. after dimensions are set.
141 Werner 47
 
48
    // access to properties
885 werner 49
    int id() const { return mId; } ///< numerical unique ID of the tree
50
    int age() const { return mAge; } ///< the tree age (years)
156 werner 51
    /// @property position The tree does not store the floating point coordinates but only the index of pixel on the LIF grid
52
    const QPointF position() const { Q_ASSERT(mGrid!=0); return mGrid->cellCenterPoint(mPositionIndex); }
544 werner 53
    const QPoint positionIndex() const { return mPositionIndex; }
158 werner 54
    const Species* species() const { Q_ASSERT(mRU!=0); return mSpecies; } ///< pointer to the tree species of the tree.
187 iland 55
    const ResourceUnit *ru() const { Q_ASSERT(mRU!=0); return mRU; } ///< pointer to the ressource unit the tree belongs to.
158 werner 56
 
234 werner 57
    // properties
58
    float dbh() const { return mDbh; } ///< dimater at breast height in cm
59
    float height() const { return mHeight; } ///< tree height in m
60
    float lightResourceIndex() const { return mLRI; } ///< LRI of the tree (updated during readStamp())
61
    float leafArea() const { return mLeafArea; } ///< leaf area (m2) of the tree
158 werner 62
    double volume() const; ///< volume (m3) of stem volume based on geometry and density calculated on the fly.
180 werner 63
    double basalArea() const; ///< basal area of the tree at breast height in m2
158 werner 64
    bool isDead() const { return flag(Tree::TreeDead); } ///< returns true if the tree is already dead.
407 werner 65
    float crownRadius() const; ///< fetch crown radius (m) from the attached stamp
449 werner 66
    // biomass properties
67
    float biomassFoliage() const { return mFoliageMass; } ///< mass (kg) of foliage
476 werner 68
    float biomassBranch() const;  ///< mass (kg) of branches
449 werner 69
    float biomassFineRoot() const { return mFineRootMass; } ///< mass (kg) of fine roots
70
    float biomassCoarseRoot() const { return mCoarseRootMass; } ///< mass (kg) of coarse roots
71
    float biomassStem() const { return mWoodyMass; } ///< mass (kg) of stem
667 werner 72
    double barkThickness() const; ///< thickness of the bark (cm)
1010 werner 73
    float stressIndex() const { return mStressIndex; } ///< the scalar stress rating (0..1)
449 werner 74
 
158 werner 75
    // actions
1157 werner 76
    enum TreeRemovalType { TreeDeath=0, TreeHarvest=1, TreeDisturbance=2, TreeSalavaged=3, TreeKilled=4, TreeCutDown=5};
713 werner 77
    /// the tree dies (is killed)
78
    void die(TreeGrowthData *d=0);
564 werner 79
    /// remove the tree (management). removalFractions for tree compartments: if 0: all biomass stays in the system, 1: all is "removed"
80
    /// default values: all biomass remains in the forest (i.e.: kill()).
81
    void remove(double removeFoliage=0., double removeBranch=0., double removeStem=0. );
713 werner 82
    /// remove the tree due to an special event (disturbance)
83
    /// the part of the biomass that goes not to soil/snags is removed (e.g. fire)
84
    /// @param stem_to_soil_fraction (0..1) of stem biomass that is routed to the soil
85
    /// @param stem_to_snag_fraction (0..1) of the stem biomass continues as standing dead
86
    /// @param branch_to_soil_fraction (0..1) of branch biomass that is routed to the soil
87
    /// @param branch_to_snag_fraction (0..1) of the branch biomass continues as standing dead
88
    /// @param foliage_to_soil_fraciton (0..1) fraction of biomass that goes directly to the soil. The rest (1.-fraction) is removed.
89
    void removeDisturbance(const double stem_to_soil_fraction, const double stem_to_snag_fraction,
90
                           const double branch_to_soil_fraction, const double branch_to_snag_fraction,
91
                           const double foliage_to_soil_fraction);
92
 
158 werner 93
    void enableDebugging(const bool enable=true) {setFlag(Tree::TreeDebugging, enable); }
668 werner 94
    /// removes fractions (0..1) for foliage, branches, stem from a tree, e.g. due to a fire.
95
    /// values of "0" remove nothing, "1" removes the full compartent.
903 werner 96
    void removeBiomassOfTree(const double removeFoliageFraction, const double removeBranchFraction, const double removeStemFraction);
158 werner 97
 
98
    // setters for initialization
99
    void setNewId() { mId = m_nextId++; } ///< force a new id for this object (after copying trees)
247 werner 100
    void setId(const int id) { mId = id; } ///< set a spcific ID (if provided in stand init file).
156 werner 101
    void setPosition(const QPointF pos) { Q_ASSERT(mGrid!=0); mPositionIndex = mGrid->indexAt(pos); }
287 werner 102
    void setPosition(const QPoint posIndex) { mPositionIndex = posIndex; }
106 Werner 103
    void setDbh(const float dbh) { mDbh=dbh; }
975 werner 104
    void setHeight(const float height);
106 Werner 105
    void setSpecies(Species *ts) { mSpecies=ts; }
187 iland 106
    void setRU(ResourceUnit *ru) { mRU = ru; }
388 werner 107
    void setAge(const int age, const float treeheight);
158 werner 108
 
885 werner 109
    // management flags (used by ABE management system)
110
    void markForHarvest(bool do_mark) { setFlag(Tree::MarkForHarvest, do_mark);}
111
    bool isMarkedForHarvest() const { return flag(Tree::MarkForHarvest);}
112
    void markForCut(bool do_mark) { setFlag(Tree::MarkForCut, do_mark);}
113
    bool isMarkedForCut() const { return flag(Tree::MarkForCut);}
114
    void markCropTree(bool do_mark) { setFlag(Tree::MarkCropTree, do_mark);}
115
    bool isMarkedAsCropTree() const { return flag(Tree::MarkCropTree);}
951 werner 116
    void markCropCompetitor(bool do_mark) { setFlag(Tree::MarkCropCompetitor, do_mark);}
117
    bool isMarkedAsCropCompetitor() const { return flag(Tree::MarkCropCompetitor);}
1044 werner 118
    // death reasons
119
    void setDeathReasonWind()  { setFlag(Tree::TreeDeadWind, true); }
120
    void setDeathReasonBarkBeetle()  { setFlag(Tree::TreeDeadBarkBeetle, true); }
121
    void setDeathReasonFire()  { setFlag(Tree::TreeDeadFire, true); }
122
    void setDeathCutdown()  { setFlag(Tree::TreeDeadKillAndDrop, true); }
1050 werner 123
    void setIsHarvested()  { setFlag(Tree::TreeHarvested, true); }
124
 
1044 werner 125
    bool isDeadWind() const { return flag(Tree::TreeDeadWind);}
126
    bool isDeadBarkBeetle() const { return flag(Tree::TreeDeadBarkBeetle);}
127
    bool isDeadFire() const { return flag(Tree::TreeDeadFire);}
128
    bool isCutdown() const { return flag(Tree::TreeDeadKillAndDrop);}
1050 werner 129
    bool isHarvested() const { return flag(Tree::TreeHarvested);}
885 werner 130
 
107 Werner 131
    // grid based light-concurrency functions
158 werner 132
    void applyLIP(); ///< apply LightInfluencePattern onto the global grid
187 iland 133
    void readLIF(); ///< calculate the lightResourceIndex with multiplicative approach
107 Werner 134
    void heightGrid(); ///< calculate the height grid
39 Werner 135
 
158 werner 136
    void applyLIP_torus(); ///< apply LightInfluencePattern on a closed 1ha area
137
    void readLIF_torus(); ///< calculate LRI from a closed 1ha area
138
    void heightGrid_torus(); ///< calculate the height grid
155 werner 139
 
251 werner 140
    void calcLightResponse(); ///< calculate light response
107 Werner 141
    // growth, etc.
158 werner 142
    void grow(); ///< main growth function to update the tree state.
107 Werner 143
 
144
    // static functions
151 iland 145
    static void setGrid(FloatGrid* gridToStamp, Grid<HeightGridValue> *dominanceGrid);
40 Werner 146
    // statistics
147
    static void resetStatistics();
145 Werner 148
    static int statPrints() { return m_statPrint; }
149
    static int statCreated() { return m_statCreated; }
1071 werner 150
#ifdef ALT_TREE_MORTALITY
151
    static void mortalityParams(double dbh_inc_threshold, int stress_years, double stress_mort_prob);
152
#endif
40 Werner 153
 
135 Werner 154
    QString dump();
145 Werner 155
    void dumpList(QList<QVariant> &rTargetList);
733 werner 156
    const Stamp *stamp() const { return mStamp; } ///< TODO: only for debugging purposes
135 Werner 157
 
3 Werner 158
private:
110 Werner 159
    // helping functions
159 werner 160
    void partitioning(TreeGrowthData &d); ///< split NPP into various plant pools.
158 werner 161
    double relative_height_growth(); ///< estimate height growth based on light status.
159 werner 162
    void grow_diameter(TreeGrowthData &d); ///< actual growth of the tree's stem.
163
    void mortality(TreeGrowthData &d); ///< main function that checks whether trees is to die
1071 werner 164
#ifdef ALT_TREE_MORTALITY
165
    void altMortality(TreeGrowthData &d); ///< alternative version of the mortality sub module
166
#endif
1064 werner 167
    void notifyTreeRemoved(TreeRemovalType reason); ///< record the removed volume in the height grid
159 werner 168
 
107 Werner 169
    // state variables
169 werner 170
    int mId; ///< unique ID of tree
171
    int mAge; ///< age of tree in years
125 Werner 172
    float mDbh; ///< diameter at breast height [cm]
173
    float mHeight; ///< tree height [m]
156 werner 174
    QPoint mPositionIndex; ///< index of the trees position on the basic LIF grid
107 Werner 175
    // biomass compartements
149 werner 176
    float mLeafArea; ///< m2 leaf area
177
    float mOpacity; ///< multiplier on LIP weights, depending on leaf area status (opacity of the crown)
885 werner 178
    float mFoliageMass; ///< kg of foliage (dry)
179
    float mWoodyMass; ///< kg biomass of aboveground stem biomass
180
    float mFineRootMass; ///< kg biomass of fine roots (linked to foliage mass)
181
    float mCoarseRootMass; ///< kg biomass of coarse roots (allometric equation)
116 Werner 182
    // production relevant
885 werner 183
    float mNPPReserve; ///< NPP reserve pool [kg] - stores a part of assimilates for use in less favorable years
187 iland 184
    float mLRI; ///< resulting lightResourceIndex
212 werner 185
    float mLightResponse; ///< light response used for distribution of biomass on RU level
159 werner 186
    // auxiliary
125 Werner 187
    float mDbhDelta; ///< diameter growth [cm]
159 werner 188
    float mStressIndex; ///< stress index (used for mortality)
189
 
187 iland 190
    // Stamp, Species, Resource Unit
106 Werner 191
    const Stamp *mStamp;
192
    Species *mSpecies;
187 iland 193
    ResourceUnit *mRU;
107 Werner 194
 
157 werner 195
    // various flags
196
    int mFlags;
885 werner 197
    /// (binary coded) tree flags
198
    enum Flags { TreeDead=1, TreeDebugging=2,
1050 werner 199
                 TreeDeadBarkBeetle=16, TreeDeadWind=32, TreeDeadFire=64, TreeDeadKillAndDrop=128, TreeHarvested=256,
200
                 MarkForCut=512, // mark tree for being cut down
201
                 MarkForHarvest=1024, // mark tree for being harvested
202
                 MarkCropTree=2048, // mark as crop tree
203
                 MarkCropCompetitor=4096 // mark as competitor for a crop tree
885 werner 204
               };
205
    /// set a Flag 'flag' to the value 'value'.
157 werner 206
    void setFlag(const Tree::Flags flag, const bool value) { if (value) mFlags |= flag; else mFlags &= (flag ^ 0xffffff );}
885 werner 207
    /// set a number of flags (need to be constructed by or'ing flags together) at the same time to the Boolean value 'value'.
208
    void setFlag(const int flag, const bool value) { if (value) mFlags |= flag; else mFlags &= (flag ^ 0xffffff );}
209
    /// retrieve the value of the flag 'flag'.
157 werner 210
    bool flag(const Tree::Flags flag) const { return mFlags & flag; }
139 Werner 211
 
117 Werner 212
    // special functions
157 werner 213
    bool isDebugging() { return flag(Tree::TreeDebugging); }
135 Werner 214
 
107 Werner 215
    // static data
106 Werner 216
    static FloatGrid *mGrid;
151 iland 217
    static Grid<HeightGridValue> *mHeightGrid;
1102 werner 218
    static TreeRemovedOut *mRemovalOutput;
219
    static void setTreeRemovalOutput(TreeRemovedOut *rout) { mRemovalOutput=rout; }
1114 werner 220
    static LandscapeRemovedOut *mLSRemovalOutput;
221
    static void setLandscapeRemovalOutput(LandscapeRemovedOut *rout) { mLSRemovalOutput=rout; }
53 Werner 222
 
40 Werner 223
    // statistics
224
    static int m_statPrint;
48 Werner 225
    static int m_statAboveZ;
105 Werner 226
    static int m_statCreated;
40 Werner 227
    static int m_nextId;
148 iland 228
 
229
    // friends
230
    friend class TreeWrapper;
180 werner 231
    friend class StandStatistics;
264 werner 232
    friend class TreeOut;
1102 werner 233
    friend class TreeRemovedOut;
1114 werner 234
    friend class LandscapeRemovedOut;
675 werner 235
    friend class Snapshot;
3 Werner 236
};
237
 
257 werner 238
/// internal data structure which is passed between function and to statistics
239
struct TreeGrowthData
240
{
261 werner 241
    double NPP; ///< total NPP (kg)
242
    double NPP_above; ///< NPP aboveground (kg) (NPP - fraction roots), no consideration of tree senescence
257 werner 243
    double NPP_stem;  ///< NPP used for growth of stem (dbh,h)
244
    double stress_index; ///< stress index used for mortality calculation
262 werner 245
    TreeGrowthData(): NPP(0.), NPP_above(0.), NPP_stem(0.) {}
257 werner 246
};
3 Werner 247
#endif // TREE_H