Subversion Repositories public iLand

Rev

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