Subversion Repositories public iLand

Rev

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