Subversion Repositories public iLand

Rev

Rev 1113 | Rev 1117 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1
 
1111 werner 2
#ifndef SAPLINGS_H
3
#define SAPLINGS_H
4
 
5
#include "grid.h"
1113 werner 6
#include "snag.h"
1111 werner 7
 
1113 werner 8
 
1111 werner 9
struct SaplingTree {
1113 werner 10
    SaplingTree() { clear(); }
1111 werner 11
    short unsigned int age;  // number of consectuive years the sapling suffers from dire conditions
12
    short unsigned int species_index; // index of the species within the resource-unit-species container
13
    unsigned char stress_years; // (upper 16bits) + age of sapling (lower 16 bits)
14
    unsigned char flags;
15
    float height; // height of the sapling in meter
16
    bool is_occupied() const { return height>0.f; }
1113 werner 17
    void clear()  {  age=0; species_index=0; stress_years=0; flags=0; height=0.f;  }
1112 werner 18
    void setSapling(const float h_m, const int age_yrs, const int species_idx) { height=h_m; age=static_cast<short unsigned int>(age_yrs); stress_years=0; species_index=static_cast<short unsigned int>(species_idx); }
1111 werner 19
};
20
#define NSAPCELLS 5
21
struct SaplingCell {
22
    enum ECellState { CellInvalid=0, CellFree=1, CellFull=2};
23
    SaplingCell() {
24
        state=CellInvalid;
25
    }
26
    ECellState state;
27
    SaplingTree saplings[NSAPCELLS];
28
    void checkState() { if (state==CellInvalid) return;
1112 werner 29
                        bool free = false;
1111 werner 30
                        for (int i=0;i<NSAPCELLS;++i) {
31
                            // locked for all species, if a sapling of one species >1.3m
1112 werner 32
                            if (saplings[i].height>1.3f) {state = CellFull; return; }
1111 werner 33
                            // locked, if all slots are occupied.
34
                            if (!saplings[i].is_occupied())
35
                                free=true;
36
                        }
37
                        state = free? CellFree : CellFull;
38
                      }
39
};
40
class ResourceUnit;
1113 werner 41
class Saplings;
1111 werner 42
 
1113 werner 43
class SaplingStat
44
{
45
public:
1115 werner 46
    SaplingStat() { clearStatistics(); }
1113 werner 47
    void clearStatistics();
48
    // actions
49
    void addCarbonOfDeadSapling(float dbh) { mDied++; mSumDbhDied+=dbh; }
1111 werner 50
 
1113 werner 51
    // access to statistics
52
    int newSaplings() const { return mAdded; }
53
    int diedSaplings() const { return mDied; }
54
    int livingSaplings() const { return mLiving; } ///< get the number
55
    int recruitedSaplings() const { return mRecruited; }
56
    ///  returns the *represented* (Reineke's Law) number of trees (N/ha) and the mean dbh/height (cm/m)
57
    double livingStemNumber(double &rAvgDbh, double &rAvgHeight, double &rAvgAge) const;
58
 
59
    double averageHeight() const { return mAvgHeight; }
60
    double averageAge() const { return mAvgAge; }
61
    double averageDeltaHPot() const { return mAvgDeltaHPot; }
62
    double averageDeltaHRealized() const { return mAvgHRealized; }
63
    /// return the number of trees represented by one sapling of the current species and given 'height'
64
    double representedStemNumber(float height) const;
65
    // carbon and nitrogen
66
    const CNPair &carbonLiving() const { return mCarbonLiving; } ///< state of the living
67
    const CNPair &carbonGain() const { return mCarbonGain; } ///< state of the living
68
 
69
private:
70
    int mAdded; ///< number of trees added
71
    int mRecruited; ///< number recruited (i.e. grown out of regeneration layer)
72
    int mDied; ///< number of trees died
73
    double mSumDbhDied; ///< running sum of dbh of died trees (used to calculate detritus)
74
    int mLiving; ///< number of trees (cohorts!!!) currently in the regeneration layer
75
    double mAvgHeight; ///< average height of saplings (m)
76
    double mAvgAge; ///< average age of saplings (years)
77
    double mAvgDeltaHPot; ///< average height increment potential (m)
78
    double mAvgHRealized; ///< average realized height increment
79
    CNPair mCarbonLiving;
80
    CNPair mCarbonGain; ///< net growth (kg / ru) of saplings
81
 
82
    friend class Saplings;
83
 
84
};
85
 
1111 werner 86
class Saplings
87
{
88
public:
89
    Saplings();
90
    void setup();
91
    // main functions
92
    void establishment(const ResourceUnit *ru);
1113 werner 93
    void saplingGrowth(const ResourceUnit *ru);
94
 
95
 
1111 werner 96
    void clearStats() { mAdded=0; mTested=0;}
97
    int saplingsAdded() const { return mAdded; }
98
    int pixelTested() const { return mTested; }
99
 
1113 werner 100
    static void setRecruitmentVariation(const double variation) { mRecruitmentVariation = variation; }
101
    static void updateBrowsingPressure();
102
 
1111 werner 103
private:
1115 werner 104
    bool growSapling(const ResourceUnit *ru, SaplingTree &tree, int isc, float dom_height, float lif_value);
1111 werner 105
    Grid<SaplingCell> mGrid;
106
    int mAdded;
107
    int mTested;
1113 werner 108
    static double mRecruitmentVariation;
109
    static double mBrowsingPressure;
1111 werner 110
};
111
 
112
#endif // SAPLINGS_H