iLand
saplings.h
Go to the documentation of this file.
1/********************************************************************************************
2** iLand - an individual based forest landscape and disturbance model
3** http://iland-model.org
4** Copyright (C) 2009- Werner Rammer, Rupert Seidl
5**
6** This program is free software: you can redistribute it and/or modify
7** it under the terms of the GNU General Public License as published by
8** the Free Software Foundation, either version 3 of the License, or
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
16** You should have received a copy of the GNU General Public License
17** along with this program. If not, see <http://www.gnu.org/licenses/>.
18********************************************************************************************/
19#ifndef SAPLINGS_H
20#define SAPLINGS_H
21
22#include "grid.h"
23#include "snag.h"
24#include "model.h"
25#include <QRectF>
26class ResourceUnitSpecies; // forward
27class ResourceUnit; // forward
28
31 short unsigned int age; // age of the cohort in years
32 short signed int species_index; // index of the species within the resource-unit-species container
33 unsigned char stress_years; // number of consecutive years that a sapling suffers from stress
34 unsigned char flags; // flags, e.g. whether sapling stems from sprouting
35 float height; // height of the sapling in meter
36 bool is_occupied() const { return height>0.f; }
37 void clear() { age=0; species_index=-1; stress_years=0; flags=0; height=0.f; }
38 void setSapling(const float h_m, const int age_yrs, const int species_idx) { height=h_m;
39 age=static_cast<short unsigned int>(age_yrs);
41 species_index=static_cast<short signed int>(species_idx); }
42 // flags
43 // sprouting - bit 1
44 bool is_sprout() const { return flags & 1; }
45 void set_sprout(const bool sprout) {if (sprout) flags |= 1; else flags &= (1 ^ 0xffffff ); }
46 // browsing - bit 2
47 bool is_browsed() const { return flags & 2; }
48 void set_browsed(const bool browse) {if (browse) flags |= 2; else flags &= (2 ^ 0xffffff ); }
49 // get resource unit species of the sapling tree
51};
52#define NSAPCELLS 5
61 ru=nullptr;
62 }
67 bool hasFreeSlots() const {return state>CellInvalid && state<CellFull; }
68 void checkState() { if (state==CellInvalid) return;
69 bool free = false;
70 bool occupied=false;
71 for (int i=0;i<NSAPCELLS;++i) {
72 // locked for all species, if a sapling of one species >1.3m
73 if (saplings[i].height>1.3f) {state = CellFull; return; }
74 occupied |= saplings[i].is_occupied();
75 // locked, if all slots are occupied.
76 if (!saplings[i].is_occupied())
77 free=true;
78 }
79 state = free? (occupied? CellEmpty: CellFree) : CellFull;
80 }
82 int free_index() {
83 for (int i=0;i<NSAPCELLS;++i)
84 if (!saplings[i].is_occupied())
85 return i;
86 return -1;
87 }
89 int n_occupied() {
90 int n=0;
91 for (int i=0;i<NSAPCELLS;++i)
92 n+=saplings[i].is_occupied();
93 return n;
94 }
95
97 SaplingTree *addSapling(const float h_m, const int age_yrs, const int species_idx) {
98 int idx = free_index();
99 if (idx==-1)
100 return nullptr;
101 saplings[idx].setSapling(h_m, age_yrs, species_idx);
102 return &saplings[idx];
103 }
105 float max_height() { if (state==CellInvalid) return 0.f;
106 float h_max = 0.f;
107 for (int i=0;i<NSAPCELLS;++i)
108 h_max = std::max(saplings[i].height, h_max);
109 return h_max;
110 }
111 bool has_new_saplings() { if (state==CellInvalid) return 0.f;
112 for (int i=0;i<NSAPCELLS;++i)
113 if (saplings[i].is_occupied() && saplings[i].age<2)
114 return true;
115 return false;
116 }
118 SaplingTree *saplingOfSpecies(int species_index) {
119 if (state==CellInvalid) return nullptr;
120 for (int i=0;i<NSAPCELLS;++i)
121 if (saplings[i].species_index == species_index)
122 return &saplings[i];
123 return nullptr;
124 }
125};
126class ResourceUnit;
127class Saplings;
128
132{
133public:
135 void clearStatistics();
137 void calculate(const Species *species, ResourceUnit *ru);
138 // actions
139 void addCarbonOfDeadSapling(float dbh) { mDied++; mSumDbhDied+=dbh; }
140
141 // access to statistics
142 int newSaplings() const { return mAdded; }
143 int newSaplingsVegetative() const { return mAddedVegetative; }
144 int diedSaplings() const { return mDied; }
145 int livingCohorts() const { return mLiving; }
146 double livingSaplings() const { return mLivingSaplings; }
147 double livingSaplingsSmall() const { return mLivingSmallSaplings; }
148 int recruitedSaplings() const { return mRecruited; }
150 double livingStemNumber(const Species *species, double &rAvgDbh, double &rAvgHeight, double &rAvgAge) const;
151
152 double averageHeight() const { return mAvgHeight; }
153 double averageAge() const { return mAvgAge; }
154 double averageDeltaHPot() const { return mAvgDeltaHPot; }
155 double averageDeltaHRealized() const { return mAvgHRealized; }
156 float leafArea() const { return mLeafArea; }
157 void setLeafArea(float leaf_area){ mLeafArea = leaf_area; }
158 double leafAreaIndex() const {return mLeafAreaIndex; }
159 double basalArea() const { return mBasalArea; }
160 // carbon and nitrogen
161 const CNPair &carbonLiving() const { return mCarbonLiving; }
162 const CNPair &carbonGain() const { return mCarbonGain; }
163
164private:
165 short int mAdded;
166 short int mAddedVegetative;
167 short int mRecruited;
168 short int mDied;
169 float mSumDbhDied;
170 short int mLiving;
171 short int mCohortsWithDbh;
172 float mLivingSaplings;
173 float mLivingSmallSaplings;
174 float mAvgHeight;
175 float mAvgAge;
176 float mAvgDeltaHPot;
177 float mAvgHRealized;
178 float mLeafArea;
179 float mLeafAreaIndex;
180 float mBasalArea;
181 CNPair mCarbonLiving;
182 CNPair mCarbonGain;
183 float mCarbonOfRecruitedTrees;
184
185 friend class Saplings;
186
187};
192{
193public:
194 Saplings();
195 void setup();
197 // main functions
198 void establishment(const ResourceUnit *ru);
199 void saplingGrowth(const ResourceUnit *ru);
200
202 void simplifiedGrassCover(const ResourceUnit *ru);
203
205 double topHeight(const ResourceUnit *ru) const;
206
207 // access
211 SaplingCell *cell(QPoint lif_coords, bool only_valid=true, ResourceUnit **rRUPtr=nullptr);
212
215 QPointF coordOfCell(ResourceUnit *ru, int cell_index);
216
219 void clearSaplings(const QRectF &rectangle, const bool remove_biomass, bool resprout);
221 void clearSaplings(SaplingCell *s, ResourceUnit *ru, const bool remove_biomass, bool resprout);
223 void clearAllSaplings();
224
226 int addSaplings(const QRectF &rectangle, QString species, double height, int age);
227
229 int addSprout(const Tree *t, bool tree_is_removed);
230
231 static void setRecruitmentVariation(const double variation) { mRecruitmentVariation = variation; }
232 static void updateBrowsingPressure();
233
234private:
235 bool growSapling(const ResourceUnit *ru, SaplingCell &scell, SaplingTree &tree, int isc, HeightGridValue &hgv, float lif_value, int cohorts_on_px);
236 void vegetativeSprouting(const Species *species, SaplingCell &scell, QPoint tree_pos);
237 //Grid<SaplingCell> mGrid;
238 static double mRecruitmentVariation;
239 static double mBrowsingPressure;
240};
241
242
246class MapGrid; // forward
248{
249public:
250 SaplingCellRunner(const int stand_id, const MapGrid *stand_grid=nullptr);
252 SaplingCell *next();
253 ResourceUnit *ru() const { return mRU; }
254 QPointF currentCoord() const;
255private:
256 GridRunner<float> *mRunner;
257 ResourceUnit *mRU;
258 const MapGrid *mStandGrid;
259 int mStandId;
260};
261
262#endif // SAPLINGS_H
CNPair stores a duple of carbon and nitrogen (kg/ha) use addBiomass(biomass, cnratio) to add biomass;...
Definition: snag.h:31
helper class to iterate over a rectangular fraction of a grid
Definition: grid.h:200
Definition: mapgrid.h:32
ResourceUnit is the spatial unit that encapsulates a forest stand and links to several environmental ...
Definition: resourceunit.h:49
The class contains data available at ResourceUnit x Species scale.
Definition: resourceunitspecies.h:34
Definition: saplings.h:248
SaplingCellRunner(const int stand_id, const MapGrid *stand_grid=nullptr)
Definition: saplings.cpp:842
SaplingCell * next()
Definition: saplings.cpp:859
QPointF currentCoord() const
Definition: saplings.cpp:880
ResourceUnit * ru() const
Definition: saplings.h:253
~SaplingCellRunner()
Definition: saplings.cpp:853
The SaplingStat class stores statistics on the resource unit x species level.
Definition: saplings.h:132
double basalArea() const
Definition: saplings.h:159
int newSaplingsVegetative() const
Definition: saplings.h:143
float leafArea() const
Definition: saplings.h:156
const CNPair & carbonGain() const
state of the living
Definition: saplings.h:162
void setLeafArea(float leaf_area)
Definition: saplings.h:157
double averageAge() const
Definition: saplings.h:153
SaplingStat()
Definition: saplings.h:134
double averageHeight() const
Definition: saplings.h:152
double livingStemNumber(const Species *species, double &rAvgDbh, double &rAvgHeight, double &rAvgAge) const
returns the represented (Reineke's Law) number of trees (N/ha) and the mean dbh/height (cm/m)
Definition: saplings.cpp:800
void calculate(const Species *species, ResourceUnit *ru)
calculate statistics (and carbon flows) for the saplings of species 'species' on 'ru'.
Definition: saplings.cpp:689
int diedSaplings() const
Definition: saplings.h:144
double livingSaplingsSmall() const
Definition: saplings.h:147
const CNPair & carbonLiving() const
state of the living
Definition: saplings.h:161
double leafAreaIndex() const
Definition: saplings.h:158
double livingSaplings() const
number of individual trees in the regen layer (using Reinekes R), with h>1.3m
Definition: saplings.h:146
void addCarbonOfDeadSapling(float dbh)
Definition: saplings.h:139
double averageDeltaHRealized() const
Definition: saplings.h:155
int livingCohorts() const
get the number of cohorts
Definition: saplings.h:145
void clearStatistics()
Definition: saplings.cpp:674
double averageDeltaHPot() const
Definition: saplings.h:154
int recruitedSaplings() const
Definition: saplings.h:148
int newSaplings() const
Definition: saplings.h:142
The Saplings class the container for the establishment and sapling growth in iLand.
Definition: saplings.h:192
QPointF coordOfCell(ResourceUnit *ru, int cell_index)
return the metric coordinates of a given cell at resource unit ru and at the internal index cell_inde...
Definition: saplings.cpp:320
void saplingGrowth(const ResourceUnit *ru)
Definition: saplings.cpp:199
SaplingCell * cell(QPoint lif_coords, bool only_valid=true, ResourceUnit **rRUPtr=nullptr)
return the SaplingCell (i.e.
Definition: saplings.cpp:297
int addSprout(const Tree *t, bool tree_is_removed)
generate vegetative offspring from the tree 't' (sprouts)
Definition: saplings.cpp:408
void clearSaplings(const QRectF &rectangle, const bool remove_biomass, bool resprout)
clear/kill all saplings within the rectangle given by 'rectangle'.
Definition: saplings.cpp:328
void establishment(const ResourceUnit *ru)
establishment of saplings from seeds see http://iland-model.org/seed+kernel+and+seed+distribution and...
Definition: saplings.cpp:95
Saplings()
Definition: saplings.cpp:36
static void updateBrowsingPressure()
Definition: saplings.cpp:459
int addSaplings(const QRectF &rectangle, QString species, double height, int age)
add saplings by plantings within the (metric) rectangle. Fill cells with trees of given species/heigh...
Definition: saplings.cpp:388
void clearAllSaplings()
clear all saplings, biomass is removed (not routed to the soil layer)
Definition: saplings.cpp:376
static void setRecruitmentVariation(const double variation)
Definition: saplings.h:231
void simplifiedGrassCover(const ResourceUnit *ru)
run the simplified grass cover for a RU
Definition: saplings.cpp:259
void setup()
Definition: saplings.cpp:41
void calculateInitialStatistics(const ResourceUnit *ru)
Definition: saplings.cpp:60
double topHeight(const ResourceUnit *ru) const
calculate the top height of the sapling layer
Definition: saplings.cpp:282
The behavior and general properties of tree species.
Definition: species.h:75
A tree is the basic simulation entity of iLand and represents a single tree.
Definition: tree.h:44
#define NSAPCELLS
Definition: saplings.h:52
Definition: model.h:51
Definition: saplings.h:53
SaplingCell()
Definition: saplings.h:59
ECellState
Definition: saplings.h:54
@ CellGrass
the cell is empty and has grass cover (see grass module)
Definition: saplings.h:56
@ CellEmpty
the cell has no slots occupied (no saplings on the cell)
Definition: saplings.h:55
@ CellInvalid
not stockable (outside project area)
Definition: saplings.h:54
@ CellFull
Definition: saplings.h:58
@ CellFree
seedlings may establish on the cell (at least one slot occupied)
Definition: saplings.h:57
SaplingTree saplings[NSAPCELLS]
Definition: saplings.h:64
int n_occupied()
count the number of occupied slots on the pixel
Definition: saplings.h:89
SaplingTree * saplingOfSpecies(int species_index)
return the sapling tree of the requested species, or 0
Definition: saplings.h:118
SaplingTree * addSapling(const float h_m, const int age_yrs, const int species_idx)
add a sapling to this cell, return a pointer to the tree on success, or 0 otherwise
Definition: saplings.h:97
void checkState()
Definition: saplings.h:68
bool hasFreeSlots() const
returns true if establishment is allowed for the cell
Definition: saplings.h:67
int free_index()
get an index to an open slot in the cell, or -1 if all slots are occupied
Definition: saplings.h:82
bool has_new_saplings()
Definition: saplings.h:111
float max_height()
return the maximum height on the pixel
Definition: saplings.h:105
ResourceUnit * ru
Definition: saplings.h:65
ECellState state
Definition: saplings.h:63
Definition: saplings.h:29
ResourceUnitSpecies * resourceUnitSpecies(const ResourceUnit *ru) const
Definition: saplings.cpp:834
bool is_browsed() const
Definition: saplings.h:47
float height
Definition: saplings.h:35
bool is_occupied() const
Definition: saplings.h:36
void clear()
Definition: saplings.h:37
short unsigned int age
Definition: saplings.h:31
unsigned char stress_years
Definition: saplings.h:33
bool is_sprout() const
Definition: saplings.h:44
short signed int species_index
Definition: saplings.h:32
unsigned char flags
Definition: saplings.h:34
void set_browsed(const bool browse)
Definition: saplings.h:48
void setSapling(const float h_m, const int age_yrs, const int species_idx)
Definition: saplings.h:38
void set_sprout(const bool sprout)
Definition: saplings.h:45
SaplingTree()
Definition: saplings.h:30