Subversion Repositories public iLand

Rev

Rev 1112 | Rev 1115 | 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:
46
    void clearStatistics();
47
    // actions
48
    void addCarbonOfDeadSapling(float dbh) { mDied++; mSumDbhDied+=dbh; }
1111 werner 49
 
1113 werner 50
    // access to statistics
51
    int newSaplings() const { return mAdded; }
52
    int diedSaplings() const { return mDied; }
53
    int livingSaplings() const { return mLiving; } ///< get the number
54
    int recruitedSaplings() const { return mRecruited; }
55
    ///  returns the *represented* (Reineke's Law) number of trees (N/ha) and the mean dbh/height (cm/m)
56
    double livingStemNumber(double &rAvgDbh, double &rAvgHeight, double &rAvgAge) const;
57
 
58
    double averageHeight() const { return mAvgHeight; }
59
    double averageAge() const { return mAvgAge; }
60
    double averageDeltaHPot() const { return mAvgDeltaHPot; }
61
    double averageDeltaHRealized() const { return mAvgHRealized; }
62
    /// return the number of trees represented by one sapling of the current species and given 'height'
63
    double representedStemNumber(float height) const;
64
    // carbon and nitrogen
65
    const CNPair &carbonLiving() const { return mCarbonLiving; } ///< state of the living
66
    const CNPair &carbonGain() const { return mCarbonGain; } ///< state of the living
67
 
68
private:
69
    int mAdded; ///< number of trees added
70
    int mRecruited; ///< number recruited (i.e. grown out of regeneration layer)
71
    int mDied; ///< number of trees died
72
    double mSumDbhDied; ///< running sum of dbh of died trees (used to calculate detritus)
73
    int mLiving; ///< number of trees (cohorts!!!) currently in the regeneration layer
74
    double mAvgHeight; ///< average height of saplings (m)
75
    double mAvgAge; ///< average age of saplings (years)
76
    double mAvgDeltaHPot; ///< average height increment potential (m)
77
    double mAvgHRealized; ///< average realized height increment
78
    CNPair mCarbonLiving;
79
    CNPair mCarbonGain; ///< net growth (kg / ru) of saplings
80
 
81
    friend class Saplings;
82
 
83
};
84
 
1111 werner 85
class Saplings
86
{
87
public:
88
    Saplings();
89
    void setup();
90
    // main functions
91
    void establishment(const ResourceUnit *ru);
1113 werner 92
    void saplingGrowth(const ResourceUnit *ru);
93
 
94
 
1111 werner 95
    void clearStats() { mAdded=0; mTested=0;}
96
    int saplingsAdded() const { return mAdded; }
97
    int pixelTested() const { return mTested; }
98
 
1113 werner 99
    static void setRecruitmentVariation(const double variation) { mRecruitmentVariation = variation; }
100
    static void updateBrowsingPressure();
101
 
1111 werner 102
private:
1113 werner 103
    void growSapling(const ResourceUnit *ru, SaplingTree &tree, int isc, float dom_height, float lif_value);
1111 werner 104
    Grid<SaplingCell> mGrid;
105
    int mAdded;
106
    int mTested;
1113 werner 107
    static double mRecruitmentVariation;
108
    static double mBrowsingPressure;
1111 werner 109
};
110
 
111
#endif // SAPLINGS_H