Subversion Repositories public iLand

Rev

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