Rev 1165 | Rev 1175 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1165 | Rev 1174 | ||
---|---|---|---|
1 | Redirecting to URL 'https://iland.boku.ac.at/svn/iland/tags/release_1.0/src/core/saplings.h': |
1 | Redirecting to URL 'https://iland.boku.ac.at/svn/iland/tags/release_1.0/src/core/saplings.h': |
2 | #ifndef SAPLINGS_H
|
2 | #ifndef SAPLINGS_H
|
3 | #define SAPLINGS_H
|
3 | #define SAPLINGS_H
|
4 | 4 | ||
5 | #include "grid.h"
|
5 | #include "grid.h"
|
6 | #include "snag.h"
|
6 | #include "snag.h"
|
7 | #include <QRectF>
|
7 | #include <QRectF>
|
8 | - | ||
- | 8 | class ResourceUnitSpecies; // forward |
|
- | 9 | class ResourceUnit; // forward |
|
9 | 10 | ||
10 | struct SaplingTree { |
11 | struct SaplingTree { |
11 | SaplingTree() { clear(); } |
12 | SaplingTree() { clear(); } |
12 | short unsigned int age; // number of consectuive years the sapling suffers from dire conditions |
13 | short unsigned int age; // number of consectuive years the sapling suffers from dire conditions |
13 | short signed int species_index; // index of the species within the resource-unit-species container |
14 | short signed int species_index; // index of the species within the resource-unit-species container |
14 | unsigned char stress_years; // (upper 16bits) + age of sapling (lower 16 bits) |
15 | unsigned char stress_years; // (upper 16bits) + age of sapling (lower 16 bits) |
15 | unsigned char flags; // flags, e.g. whether sapling stems from sprouting |
16 | unsigned char flags; // flags, e.g. whether sapling stems from sprouting |
16 | float height; // height of the sapling in meter |
17 | float height; // height of the sapling in meter |
17 | bool is_occupied() const { return height>0.f; } |
18 | bool is_occupied() const { return height>0.f; } |
18 | void clear() { age=0; species_index=-1; stress_years=0; flags=0; height=0.f; } |
19 | void clear() { age=0; species_index=-1; stress_years=0; flags=0; height=0.f; } |
19 | 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 signed int>(species_idx); } |
20 | 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 signed int>(species_idx); } |
20 | // flags
|
21 | // flags
|
21 | bool is_sprout() const { return flags & 1; } |
22 | bool is_sprout() const { return flags & 1; } |
22 | void set_sprout(const bool sprout) {if (sprout) flags |= 1; else flags &= (1 ^ 0xffffff ); } |
23 | void set_sprout(const bool sprout) {if (sprout) flags |= 1; else flags &= (1 ^ 0xffffff ); } |
- | 24 | // get resource unit species of the sapling tree
|
|
- | 25 | ResourceUnitSpecies *resourceUnitSpecies(const ResourceUnit *ru); |
|
23 | }; |
26 | }; |
24 | #define NSAPCELLS 5
|
27 | #define NSAPCELLS 5
|
25 | struct SaplingCell { |
28 | struct SaplingCell { |
26 | enum ECellState { CellInvalid=0, CellFree=1, CellFull=2}; |
29 | enum ECellState { CellInvalid=0, CellFree=1, CellFull=2}; |
27 | SaplingCell() { |
30 | SaplingCell() { |
28 | state=CellInvalid; |
31 | state=CellInvalid; |
29 | }
|
32 | }
|
30 | ECellState state;
|
33 | ECellState state;
|
31 | SaplingTree saplings[NSAPCELLS]; |
34 | SaplingTree saplings[NSAPCELLS]; |
32 | void checkState() { if (state==CellInvalid) return; |
35 | void checkState() { if (state==CellInvalid) return; |
33 | bool free = false; |
36 | bool free = false; |
34 | for (int i=0;i<NSAPCELLS;++i) { |
37 | for (int i=0;i<NSAPCELLS;++i) { |
35 | // locked for all species, if a sapling of one species >1.3m
|
38 | // locked for all species, if a sapling of one species >1.3m
|
36 | if (saplings[i].height>1.3f) {state = CellFull; return; } |
39 | if (saplings[i].height>1.3f) {state = CellFull; return; } |
37 | // locked, if all slots are occupied.
|
40 | // locked, if all slots are occupied.
|
38 | if (!saplings[i].is_occupied()) |
41 | if (!saplings[i].is_occupied()) |
39 | free=true; |
42 | free=true; |
40 | }
|
43 | }
|
41 | state = free? CellFree : CellFull; |
44 | state = free? CellFree : CellFull; |
42 | }
|
45 | }
|
43 | /// get an index to an open slot in the cell, or -1 if all slots are occupied
|
46 | /// get an index to an open slot in the cell, or -1 if all slots are occupied
|
44 | int free_index() { |
47 | int free_index() { |
45 | for (int i=0;i<NSAPCELLS;++i) |
48 | for (int i=0;i<NSAPCELLS;++i) |
46 | if (!saplings[i].is_occupied()) |
49 | if (!saplings[i].is_occupied()) |
47 | return i; |
50 | return i; |
48 | return -1; |
51 | return -1; |
49 | }
|
52 | }
|
50 | /// add a sapling to this cell, return a pointer to the tree on success, or 0 otherwise
|
53 | /// add a sapling to this cell, return a pointer to the tree on success, or 0 otherwise
|
51 | SaplingTree *addSapling(const float h_m, const int age_yrs, const int species_idx) { |
54 | SaplingTree *addSapling(const float h_m, const int age_yrs, const int species_idx) { |
52 | int idx = free_index(); |
55 | int idx = free_index(); |
53 | if (idx==-1) |
56 | if (idx==-1) |
54 | return 0; |
57 | return 0; |
55 | saplings[idx].setSapling(h_m, age_yrs, species_idx); |
58 | saplings[idx].setSapling(h_m, age_yrs, species_idx); |
56 | return &saplings[idx]; |
59 | return &saplings[idx]; |
57 | }
|
60 | }
|
58 | /// return the maximum height on the pixel
|
61 | /// return the maximum height on the pixel
|
59 | float max_height() { if (state==CellInvalid) return 0.f; |
62 | float max_height() { if (state==CellInvalid) return 0.f; |
60 | float h_max = 0.f; |
63 | float h_max = 0.f; |
61 | for (int i=0;i<NSAPCELLS;++i) |
64 | for (int i=0;i<NSAPCELLS;++i) |
62 | h_max = std::max(saplings[i].height, h_max); |
65 | h_max = std::max(saplings[i].height, h_max); |
63 | return h_max; |
66 | return h_max; |
64 | }
|
67 | }
|
65 | /// return the sapling tree of the requested species, or 0
|
68 | /// return the sapling tree of the requested species, or 0
|
66 | SaplingTree *sapling(int species_index) { |
69 | SaplingTree *sapling(int species_index) { |
67 | if (state==CellInvalid) return 0; |
70 | if (state==CellInvalid) return 0; |
68 | for (int i=0;i<NSAPCELLS;++i) |
71 | for (int i=0;i<NSAPCELLS;++i) |
69 | if (saplings[i].species_index == species_index) |
72 | if (saplings[i].species_index == species_index) |
70 | return &saplings[i]; |
73 | return &saplings[i]; |
71 | return 0; |
74 | return 0; |
72 | }
|
75 | }
|
73 | }; |
76 | }; |
74 | class ResourceUnit; |
77 | class ResourceUnit; |
75 | class Saplings; |
78 | class Saplings; |
76 | 79 | ||
77 | /** The SaplingStat class stores statistics on the resource unit x species level.
|
80 | /** The SaplingStat class stores statistics on the resource unit x species level.
|
78 | */
|
81 | */
|
79 | class SaplingStat
|
82 | class SaplingStat
|
80 | {
|
83 | {
|
81 | public: |
84 | public: |
82 | SaplingStat() { clearStatistics(); } |
85 | SaplingStat() { clearStatistics(); } |
83 | void clearStatistics(); |
86 | void clearStatistics(); |
84 | void calculate(const Species *species, ResourceUnit *ru); |
87 | void calculate(const Species *species, ResourceUnit *ru); |
85 | // actions
|
88 | // actions
|
86 | void addCarbonOfDeadSapling(float dbh) { mDied++; mSumDbhDied+=dbh; } |
89 | void addCarbonOfDeadSapling(float dbh) { mDied++; mSumDbhDied+=dbh; } |
87 | 90 | ||
88 | // access to statistics
|
91 | // access to statistics
|
89 | int newSaplings() const { return mAdded; } |
92 | int newSaplings() const { return mAdded; } |
90 | int diedSaplings() const { return mDied; } |
93 | int diedSaplings() const { return mDied; } |
91 | int livingSaplings() const { return mLiving; } ///< get the number |
94 | int livingSaplings() const { return mLiving; } ///< get the number |
92 | int recruitedSaplings() const { return mRecruited; } |
95 | int recruitedSaplings() const { return mRecruited; } |
93 | /// returns the *represented* (Reineke's Law) number of trees (N/ha) and the mean dbh/height (cm/m)
|
96 | /// returns the *represented* (Reineke's Law) number of trees (N/ha) and the mean dbh/height (cm/m)
|
94 | double livingStemNumber(const Species *species, double &rAvgDbh, double &rAvgHeight, double &rAvgAge) const; |
97 | double livingStemNumber(const Species *species, double &rAvgDbh, double &rAvgHeight, double &rAvgAge) const; |
95 | 98 | ||
96 | double averageHeight() const { return mAvgHeight; } |
99 | double averageHeight() const { return mAvgHeight; } |
97 | double averageAge() const { return mAvgAge; } |
100 | double averageAge() const { return mAvgAge; } |
98 | double averageDeltaHPot() const { return mAvgDeltaHPot; } |
101 | double averageDeltaHPot() const { return mAvgDeltaHPot; } |
99 | double averageDeltaHRealized() const { return mAvgHRealized; } |
102 | double averageDeltaHRealized() const { return mAvgHRealized; } |
100 | // carbon and nitrogen
|
103 | // carbon and nitrogen
|
101 | const CNPair &carbonLiving() const { return mCarbonLiving; } ///< state of the living |
104 | const CNPair &carbonLiving() const { return mCarbonLiving; } ///< state of the living |
102 | const CNPair &carbonGain() const { return mCarbonGain; } ///< state of the living |
105 | const CNPair &carbonGain() const { return mCarbonGain; } ///< state of the living |
103 | 106 | ||
104 | private: |
107 | private: |
105 | int mAdded; ///< number of trees added |
108 | int mAdded; ///< number of trees added |
106 | int mRecruited; ///< number recruited (i.e. grown out of regeneration layer) |
109 | int mRecruited; ///< number recruited (i.e. grown out of regeneration layer) |
107 | int mDied; ///< number of trees died |
110 | int mDied; ///< number of trees died |
108 | double mSumDbhDied; ///< running sum of dbh of died trees (used to calculate detritus) |
111 | double mSumDbhDied; ///< running sum of dbh of died trees (used to calculate detritus) |
109 | int mLiving; ///< number of trees (cohorts!!!) currently in the regeneration layer |
112 | int mLiving; ///< number of trees (cohorts!!!) currently in the regeneration layer |
110 | double mAvgHeight; ///< average height of saplings (m) |
113 | double mAvgHeight; ///< average height of saplings (m) |
111 | double mAvgAge; ///< average age of saplings (years) |
114 | double mAvgAge; ///< average age of saplings (years) |
112 | double mAvgDeltaHPot; ///< average height increment potential (m) |
115 | double mAvgDeltaHPot; ///< average height increment potential (m) |
113 | double mAvgHRealized; ///< average realized height increment |
116 | double mAvgHRealized; ///< average realized height increment |
114 | CNPair mCarbonLiving;
|
117 | CNPair mCarbonLiving;
|
115 | CNPair mCarbonGain; ///< net growth (kg / ru) of saplings |
118 | CNPair mCarbonGain; ///< net growth (kg / ru) of saplings |
116 | 119 | ||
117 | friend class Saplings; |
120 | friend class Saplings; |
118 | 121 | ||
119 | }; |
122 | }; |
120 | /** The Saplings class the container for the establishment and sapling growth in iLand.
|
123 | /** The Saplings class the container for the establishment and sapling growth in iLand.
|
121 | *
|
124 | *
|
122 | */
|
125 | */
|
123 | class Saplings
|
126 | class Saplings
|
124 | {
|
127 | {
|
125 | public: |
128 | public: |
126 | Saplings(); |
129 | Saplings(); |
127 | void setup(); |
130 | void setup(); |
128 | // main functions
|
131 | // main functions
|
129 | void establishment(const ResourceUnit *ru); |
132 | void establishment(const ResourceUnit *ru); |
130 | void saplingGrowth(const ResourceUnit *ru); |
133 | void saplingGrowth(const ResourceUnit *ru); |
131 | 134 | ||
132 | // access
|
135 | // access
|
133 | /// return the SaplingCell (i.e. container for the ind. saplings) for the given 2x2m coordinates
|
136 | /// return the SaplingCell (i.e. container for the ind. saplings) for the given 2x2m coordinates
|
134 | /// if 'only_valid' is true, then 0 is returned if no living saplings are on the cell
|
137 | /// if 'only_valid' is true, then 0 is returned if no living saplings are on the cell
|
135 | /// 'rRUPtr' is a pointer to a RU-ptr: if provided, a pointer to the resource unit is stored
|
138 | /// 'rRUPtr' is a pointer to a RU-ptr: if provided, a pointer to the resource unit is stored
|
136 | SaplingCell *cell(QPoint lif_coords, bool only_valid=true, ResourceUnit **rRUPtr=0); |
139 | SaplingCell *cell(QPoint lif_coords, bool only_valid=true, ResourceUnit **rRUPtr=0); |
137 | /// clear/kill all saplings within the rectangle given by 'rectangle'.
|
140 | /// clear/kill all saplings within the rectangle given by 'rectangle'.
|
138 | /// If 'remove_biomass' is true, then the biomass is extracted (e.g. burnt), otherwise they are moved to soil
|
141 | /// If 'remove_biomass' is true, then the biomass is extracted (e.g. burnt), otherwise they are moved to soil
|
139 | void clearSaplings(const QRectF &rectangle, const bool remove_biomass); |
142 | void clearSaplings(const QRectF &rectangle, const bool remove_biomass); |
140 | /// clear all saplings on a given cell 's' (if 'remove_biomass' is true: biomass removed from system (e.g. burnt))
|
143 | /// clear all saplings on a given cell 's' (if 'remove_biomass' is true: biomass removed from system (e.g. burnt))
|
141 | void clearSaplings(SaplingCell *s, ResourceUnit *ru, const bool remove_biomass); |
144 | void clearSaplings(SaplingCell *s, ResourceUnit *ru, const bool remove_biomass); |
142 | 145 | ||
143 | /// generate vegetative offspring from 't' (sprouts)
|
146 | /// generate vegetative offspring from 't' (sprouts)
|
144 | int addSprout(const Tree *t); |
147 | int addSprout(const Tree *t); |
145 | 148 | ||
146 | static void setRecruitmentVariation(const double variation) { mRecruitmentVariation = variation; } |
149 | static void setRecruitmentVariation(const double variation) { mRecruitmentVariation = variation; } |
147 | static void updateBrowsingPressure(); |
150 | static void updateBrowsingPressure(); |
148 | 151 | ||
149 | private: |
152 | private: |
150 | bool growSapling(const ResourceUnit *ru, SaplingCell &scell, SaplingTree &tree, int isc, float dom_height, float lif_value); |
153 | bool growSapling(const ResourceUnit *ru, SaplingCell &scell, SaplingTree &tree, int isc, float dom_height, float lif_value); |
151 | //Grid<SaplingCell> mGrid;
|
154 | //Grid<SaplingCell> mGrid;
|
152 | static double mRecruitmentVariation; |
155 | static double mRecruitmentVariation; |
153 | static double mBrowsingPressure; |
156 | static double mBrowsingPressure; |
154 | }; |
157 | }; |
155 | 158 | ||
156 | #endif // SAPLINGS_H
|
159 | #endif // SAPLINGS_H
|
157 | 160 |