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