iLand
sapling.h
Go to the documentation of this file.
1/********************************************************************************************
2** iLand - an individual based forest landscape and disturbance model
3** http://iland.boku.ac.at
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
20#ifndef SAPLING_H
21#define SAPLING_H
22#include <QtCore/QVector>
23#include <QtCore/QPoint>
24#include <bitset>
25#include "grid.h"
26#include "snag.h"
27#include "model.h"
30public:
31 SaplingTreeOld() { pixel=0; age.age=0; age.stress_years=0; height=0.05f; }
32 bool isValid() const {return pixel!=0; }
33 float *pixel; // pointer to the lifpixel the sapling lives on, set to 0 if sapling died/removed
34 QPoint coords() const { return GlobalSettings::instance()->model()->grid()->indexOf(pixel); }
35 struct { // packed two 16bit to a 32 bit integer
36 short unsigned int age; // number of consectuive years the sapling suffers from dire conditions
37 short unsigned int stress_years; // (upper 16bits) + age of sapling (lower 16 bits)
38 } age;
39 float height; // height of the sapling in meter
40private:
41};
42
43class ResourceUnitSpecies; // forward
44class Species;
45
48{
49public:
50 // maintenance
51 Sapling();
52 void setup(ResourceUnitSpecies *masterRUS) { mRUS = masterRUS; }
53 void cleanupStorage(); // maintenance operation - remove dead/recruited trees from vector
54 void clearStatistics();
56 void clear() { mSaplingTrees.clear(); mSapBitset.reset(); }
57 static void setRecruitmentVariation(const double variation) { mRecruitmentVariation = variation; }
58 static void updateBrowsingPressure();
59
60 // access
61 const QVector<SaplingTreeOld> &saplings() const {return mSaplingTrees; }
62 // actions
63 void calculateGrowth();
66 int addSapling(const QPoint &pos_lif, const float height=0.05f, const int age=1);
68 void clearSapling(SaplingTreeOld &tree, const bool remove);
69 void clearSapling(int index, const bool remove);
70 void clearSaplings(const QPoint &position);
71 void clearSaplings(const QRectF &rectangle, const bool remove_biomass);
72 bool hasSapling(const QPoint &position) const;
73 double heightAt(const QPoint &position) const;
74 // access to statistics
75 int newSaplings() const { return mAdded; }
76 int diedSaplings() const { return mDied; }
77 int livingSaplings() const { return mLiving; }
78 int recruitedSaplings() const { return mRecruited; }
79 double livingStemNumber(double &rAvgDbh, double &rAvgHeight, double &rAvgAge) const;
80 double averageHeight() const { return mAvgHeight; }
81 double averageAge() const { return mAvgAge; }
82 double averageDeltaHPot() const { return mAvgDeltaHPot; }
83 double averageDeltaHRealized() const { return mAvgHRealized; }
85 double representedStemNumber(float height) const;
86 // carbon and nitrogen
87 const CNPair &carbonLiving() const { return mCarbonLiving; }
88 const CNPair &carbonGain() const { return mCarbonGain; }
89 // output maps
90 void fillMaxHeightGrid(Grid<float> &grid) const;
91 const std::bitset<cPxPerRU*cPxPerRU> &presentPositions() const { return mSapBitset; }
92private:
93 bool growSapling(SaplingTreeOld &tree, const double f_env_yr, Species* species);
94 void setBit(const QPoint &pos_index, bool value);
96 QVector<SaplingTreeOld> mSaplingTrees;
97 std::bitset<cPxPerRU*cPxPerRU> mSapBitset;
98 int mAdded;
99 int mRecruited;
100 int mDied;
101 double mSumDbhDied;
102 int mLiving;
103 double mAvgHeight;
104 double mAvgAge;
105 double mAvgDeltaHPot;
106 double mAvgHRealized;
107 static double mRecruitmentVariation;
108 static double mBrowsingPressure;
109 CNPair mCarbonLiving;
110 CNPair mCarbonGain;
111
112
113 friend class Snapshot;
114};
115
116#endif // SAPLING_H
CNPair stores a duple of carbon and nitrogen (kg/ha) use addBiomass(biomass, cnratio) to add biomass;...
Definition: snag.h:31
Model * model() const
Definition: globalsettings.h:55
static GlobalSettings * instance()
Definition: globalsettings.h:51
QPoint indexOf(const int index) const
get index (x/y) of the (linear) index 'index' (0..count-1)
Definition: grid.h:127
FloatGrid * grid()
this is the global 'LIF'-grid (light patterns) (currently 2x2m)
Definition: model.h:124
The class contains data available at ResourceUnit x Species scale.
Definition: resourceunitspecies.h:34
saplings from 5cm to 4m
Definition: sapling.h:48
int addSapling(const QPoint &pos_lif, const float height=0.05f, const int age=1)
add a new sapling at 'pos_lif' (i.e.
Definition: sapling.cpp:180
int newSaplings() const
Definition: sapling.h:75
double representedStemNumber(float height) const
return the number of trees represented by one sapling of the current species and given 'height'
Definition: sapling.cpp:94
double heightAt(const QPoint &position) const
return the height at given position or 0 if position is not occupied
Definition: sapling.cpp:157
double livingStemNumber(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: sapling.cpp:66
static void setRecruitmentVariation(const double variation)
Definition: sapling.h:57
int recruitedSaplings() const
Definition: sapling.h:78
double averageDeltaHPot() const
Definition: sapling.h:82
bool hasSapling(const QPoint &position) const
return true if sapling is present at position
Definition: sapling.cpp:137
void setup(ResourceUnitSpecies *masterRUS)
Definition: sapling.h:52
static void updateBrowsingPressure()
Definition: sapling.cpp:57
double averageDeltaHRealized() const
Definition: sapling.h:83
const std::bitset< cPxPerRU *cPxPerRU > & presentPositions() const
Definition: sapling.h:91
void fillMaxHeightGrid(Grid< float > &grid) const
fill a grid with the maximum height of saplings per pixel (2x2m).
Definition: sapling.cpp:457
double averageAge() const
Definition: sapling.h:81
void cleanupStorage()
maintenance function to clear dead/recruited saplings from storage
Definition: sapling.cpp:103
Sapling()
Definition: sapling.cpp:39
void clearSaplings(const QPoint &position)
clear saplings on a given position (after recruitment)
Definition: sapling.cpp:195
double averageHeight() const
Definition: sapling.h:80
void calculateGrowth()
perform growth + mortality + recruitment of all saplings of this RU and species
Definition: sapling.cpp:352
void clear()
Definition: sapling.h:56
void clearSapling(SaplingTreeOld &tree, const bool remove)
clear (either remove or kill) a specific sapling
Definition: sapling.cpp:225
int livingSaplings() const
get the number
Definition: sapling.h:77
const CNPair & carbonGain() const
state of the living
Definition: sapling.h:88
const QVector< SaplingTreeOld > & saplings() const
Definition: sapling.h:61
int diedSaplings() const
Definition: sapling.h:76
void clearStatistics()
Definition: sapling.cpp:47
const CNPair & carbonLiving() const
state of the living
Definition: sapling.h:87
void newYear()
Definition: sapling.h:55
SaplingTreeOld holds information of a sapling (which represents N trees). Emphasis is on efficient st...
Definition: sapling.h:29
float * pixel
Definition: sapling.h:33
bool isValid() const
Definition: sapling.h:32
SaplingTreeOld()
Definition: sapling.h:31
float height
Definition: sapling.h:39
QPoint coords() const
Definition: sapling.h:34
short unsigned int stress_years
Definition: sapling.h:37
short unsigned int age
Definition: sapling.h:36
way to save/load the current state of the model to a database.
Definition: snapshot.h:35
The behavior and general properties of tree species.
Definition: species.h:75