iLand
fmstand.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 FMSTAND_H
20#define FMSTAND_H
21
22#include <QHash>
23#include <QJSValue>
24
25#include "activity.h"
26
27class Species; // forward (iLand species)
28class Tree; // forward (iLand tree)
29//enum TreeRemovalType; // forward
30
31namespace ABE {
32
33class FOMEWrapper; // forward
34class FMUnit; // forward
35
37{
40 double basalArea;
41 double relBasalArea;
42};
43
49{
50public:
52 FMStand(FMUnit *unit, const int id);
54 void setSTP(FMSTP *stp) {mSTP = stp; }
55 void initialize();
57 void reset(FMSTP *stp);
59 bool trace() const { return property(QStringLiteral("trace")).toBool(); }
60 const QString &context() const { return mContextStr; }
61
62 void checkArea();
63 void setArea(const double new_area_ha) { mArea = new_area_ha; } // area in ha
64
65 void reload(bool force=false); // fetch new data from the forest stand
66 // general properties
67 int id() const {return mId; }
68 const FMUnit *unit() const { return mUnit; }
69 Activity::Phase phase() const { return mPhase; }
70 int standType() const { return mStandType; }
71 FMSTP *stp() const {return mSTP; }
72 int lastUpdate() const { return mLastUpdate; }
73 int lastExecution() const { return mLastExecution; }
74 int initialStandId() const { return mInitialId; }
75 void setInitialId(int origin_id) { mInitialId = origin_id; }
76 // agent properties
78 double U() const { return mU; }
80 int thinningIntensity() const { return mThinningIntensityClass; }
82 int targetSpeciesIndex() const { return mSpeciesCompositionIndex; }
83
84 void setU(const double rotation_length) { mU = rotation_length; }
85 void setThinningIntensity(const int th_class) { mThinningIntensityClass = th_class; }
86 void setTargetSpeciesIndex(const int index) { mSpeciesCompositionIndex = index; }
87
88 // stand properties
90 double area() const { return mArea; }
92 double absoluteAge() const;
94 double basalArea() const {return mTotalBasalArea; }
96 double age() const {return mAge; }
98 double volume() const {return mVolume; }
100 double stems() const {return mStems; }
102 double dbh() const {return mDbh; }
104 double height() const {return mHeight; }
106 double topHeight() const {return mTopHeight; }
108 double scheduledHarvest() const {return mScheduledHarvest; }
110 double totalHarvest() const { return mFinalHarvested + mThinningHarvest + mSalvaged; }
112 double totalThinningHarvest() const { return mThinningHarvest; }
114 double disturbedTimber() const { return mDisturbed; }
116 double salvagedTimber() const { return mSalvaged; }
117
119 double meanAnnualIncrement() const { return mMAIdecade; }
121 double meanAnnualIncrementTotal() const { return mMAItotal; }
122
123 bool readyForFinalHarvest() {return absoluteAge()> 0.8*U(); } // { return currentActivity()?(currentFlags().isFinalHarvest() && currentFlags().isScheduled()):false; }
124
125 // specialized functions (invokable also from javascript)
126 double basalArea(const QString &species_id) const;
127 double relBasalArea(const QString &species_id) const;
128
129 int nspecies() const { return mSpeciesData.count(); }
131 SSpeciesStand &speciesData(const int index) {return mSpeciesData[index]; }
132 SSpeciesStand &speciesData(const Species *species);
133
134
135 // actions
137 bool execute();
138 bool executeActivity(Activity *act);
139 bool afterExecution(bool cancel = false);
140
142 void addScheduledHarvest(const double add_volume) {mScheduledHarvest += add_volume; }
144 void notifyTreeRemoval(Tree *tree, int reason);
146 bool notifyBarkBeetleAttack(double generations, int infested_px_per_ha);
147
149 void resetHarvestCounter() { mFinalHarvested = 0.; mThinningHarvest=0.; }
150 void resetDisturbanceSalvage() { mSalvaged=0.; mDisturbed=0.; }
151
154 void sleep(int years_to_sleep);
155 int sleepYears() const {return mYearsToWait; }
156
158 double calculateMAI();
159
161 void setAbsoluteAge(const double age);
162
166
167
168 // return stand-specific flags
169 ActivityFlags &flags(const int index) {return mStandFlags[index]; }
171 ActivityFlags &currentFlags() { return flags(mCurrentIndex); }
173 Activity *currentActivity() const { return mCurrentIndex>-1?mStandFlags[mCurrentIndex].activity():nullptr; }
174
176 Activity *lastExecutedActivity() const { return mLastExecutedIndex>-1?mStandFlags[mLastExecutedIndex].activity():nullptr; }
177
178 int lastExecutionAge() const { return absoluteAge()>0 ? static_cast<int>(absoluteAge()) : mLastRotationAge; }
179
180 // custom property storage
181 static void clearAllProperties() { mStandPropertyStorage.clear(); }
183 void setProperty(const QString &name, QJSValue value);
185 QJSValue property(const QString &name) const;
186
187 // retrieve current state of the object
188 QStringList info();
189 friend class FOMEWrapper;
190private:
191 int mId;
192 FMUnit *mUnit;
193 FMSTP *mSTP;
194 Activity::Phase mPhase;
195 int mInitialId;
196 int mStandType;
197 double mArea;
198 double mTotalBasalArea;
199 double mAge;
200 double mVolume;
201 double mStems;
202 double mDbh;
203 double mHeight;
204 double mTopHeight;
205 double mScheduledHarvest;
206 double mFinalHarvested;
207 double mThinningHarvest;
208 double mDisturbed;
209 double mSalvaged;
210
211 double mRemovedVolumeDecade;
212 double mRemovedVolumeTotal;
213
214 double mLastMAIVolume;
215 double mMAIdecade;
216 double mMAItotal;
217
218
219 int mRotationStartYear;
220 int mYearsToWait;
221 int mCurrentIndex;
222 int mLastUpdate;
223 int mLastExecution;
224 int mLastExecutedIndex;
225 int mLastRotationAge;
226
227 double mU;
228 int mSpeciesCompositionIndex;
229 int mThinningIntensityClass;
230
231 void newRotatation();
232
233 // storage for stand meta data (species level)
234 QVector<SSpeciesStand> mSpeciesData;
235 // storage for stand-specific management properties
236 QVector<ActivityFlags> mStandFlags;
237 // additional property values for each stand
238 QString mContextStr;
239 static QHash<const FMStand*, QHash<QString, QJSValue> > mStandPropertyStorage;
240
241 friend class StandObj;
242};
243
244
245} // namespace
246#endif // FMSTAND_H
Activity meta data (enabled, active, ...) that need to be stored per stand.
Definition: activity.h:110
Activity is the base class for management activities.
Definition: activity.h:162
Phase
Definition: activity.h:171
The FMSTP class encapsulates a stand treatment program, which is defined in Javascript.
Definition: fmstp.h:39
FMStand encapsulates a forest stand for the forest management engine.
Definition: fmstand.h:49
Activity * currentActivity() const
get a pointer to the current activity; returns 0 if no activity is set.
Definition: fmstand.h:173
void setTargetSpeciesIndex(const int index)
Definition: fmstand.h:86
int lastExecution() const
Definition: fmstand.h:73
void resetDisturbanceSalvage()
Definition: fmstand.h:150
bool trace() const
returns true if tracing is enabled for the stand
Definition: fmstand.h:59
int lastExecutionAge() const
Definition: fmstand.h:178
bool readyForFinalHarvest()
Definition: fmstand.h:123
ActivityFlags & flags(const int index)
Definition: fmstand.h:169
int id() const
Definition: fmstand.h:67
double volume() const
total standing volume (m3/ha) in the stand
Definition: fmstand.h:98
bool afterExecution(bool cancel=false)
Definition: fmstand.cpp:388
void setInitialId(int origin_id)
Definition: fmstand.h:75
void setThinningIntensity(const int th_class)
Definition: fmstand.h:85
double area() const
total area of the stand (ha)
Definition: fmstand.h:90
Activity::Phase phase() const
Definition: fmstand.h:69
int targetSpeciesIndex() const
species composition key
Definition: fmstand.h:82
void addScheduledHarvest(const double add_volume)
add a (simulated) harvest to the amount of planned harvest (used by the scheduling)
Definition: fmstand.h:142
static void clearAllProperties()
Definition: fmstand.h:181
double totalThinningHarvest() const
total realized thinning/tending harvests (m3 on the full stand area)
Definition: fmstand.h:112
double disturbedTimber() const
total disturbed timber volume, includes also disturbed trees not harvested, m3
Definition: fmstand.h:114
FMSTP * stp() const
Definition: fmstand.h:71
SSpeciesStand & speciesData(const int index)
retrieve species-specific meta data by index (0: largest basal area share, up to nspecies()-1)
Definition: fmstand.h:131
void checkArea()
Definition: fmstand.cpp:182
int initialStandId() const
Definition: fmstand.h:74
double scheduledHarvest() const
scheduled harvest (planned harvest by activities, m3)
Definition: fmstand.h:108
void notifyTreeRemoval(Tree *tree, int reason)
is called whenever a tree is removed (death, management, disturbance)
Definition: fmstand.cpp:457
void setArea(const double new_area_ha)
Definition: fmstand.h:63
int standType() const
Definition: fmstand.h:70
int thinningIntensity() const
thinning intensity (class); 1: low, 2: medium, 3: high
Definition: fmstand.h:80
void initialize()
Definition: fmstand.cpp:90
bool executeActivity(Activity *act)
execute activity given by "act".
Definition: fmstand.cpp:369
double stems() const
number of trees of the stand (stems/ha) (>4m)
Definition: fmstand.h:100
double meanAnnualIncrement() const
mean annual increment (MAI), m3 timber/ha for the last decade
Definition: fmstand.h:119
bool execute()
main function
Definition: fmstand.cpp:273
QJSValue property(const QString &name) const
retrieve the value of the property 'name'. Returns an empty QJSValue if the property is not defined.
Definition: fmstand.cpp:573
double age() const
(average) age of the stand (weighted with basal area)
Definition: fmstand.h:96
int setToLatestForcedActivity()
set active activity to the latest activity with forced=true (if a stand is outside the timeframe of a...
Definition: fmstand.cpp:547
void setProperty(const QString &name, QJSValue value)
set a property value for the current stand with the name 'name'
Definition: fmstand.cpp:567
double relBasalArea(const QString &species_id) const
Definition: fmstand.cpp:533
const QString & context() const
Definition: fmstand.h:60
double absoluteAge() const
absolute age: years since the rotation has started (years)
Definition: fmstand.cpp:267
double height() const
mean tree height (basal area weighted, of trees>4m), in m
Definition: fmstand.h:104
double meanAnnualIncrementTotal() const
mean annual increment (MAI), m3 timber/ha for the full rotation period
Definition: fmstand.h:121
Activity * lastExecutedActivity() const
get a pointer to the last executed activity; returns 0 if no activity has been executed before.
Definition: fmstand.h:176
double salvagedTimber() const
total amount of timber removed by salvage operation
Definition: fmstand.h:116
int sleepYears() const
Definition: fmstand.h:155
double basalArea() const
total basal area (m2/ha)
Definition: fmstand.h:94
double dbh() const
mean dbh (basal area weighted, of trees>4m) in cm
Definition: fmstand.h:102
void reload(bool force=false)
Definition: fmstand.cpp:192
double totalHarvest() const
total realized harvest (m3 on the full stand area)
Definition: fmstand.h:110
void resetHarvestCounter()
resets the harvest counters
Definition: fmstand.h:149
double calculateMAI()
calculate mean annual increment (m3/ha) and return total MAI.
Definition: fmstand.cpp:511
FMStand(FMUnit *unit, const int id)
c'tor: link stand to a forest management unit
Definition: fmstand.cpp:51
int lastUpdate() const
Definition: fmstand.h:72
void setAbsoluteAge(const double age)
set the absolute age of the stand
Definition: fmstand.cpp:541
void sleep(int years_to_sleep)
sleep() pauses the evaluation/execution of management activities for 'years_to_sleep'.
Definition: fmstand.cpp:505
bool notifyBarkBeetleAttack(double generations, int infested_px_per_ha)
is called when bark beetles are likely to attack: return ABE changed forest structure
Definition: fmstand.cpp:495
void setSTP(FMSTP *stp)
set the stand to be managed by a given 'stp'
Definition: fmstand.h:54
int nspecies() const
Definition: fmstand.h:129
double U() const
rotation period (years)
Definition: fmstand.h:78
void reset(FMSTP *stp)
sets the STP but nothing else (after disturbance related clearance)
Definition: fmstand.cpp:175
void setU(const double rotation_length)
Definition: fmstand.h:84
const FMUnit * unit() const
Definition: fmstand.h:68
QStringList info()
Definition: fmstand.cpp:584
ActivityFlags & currentFlags()
flags of currently active Activity
Definition: fmstand.h:171
double topHeight() const
top height (mean height of the 100 thickest trees/ha), in m
Definition: fmstand.h:106
The FMUnit represents a management unit, i.e.
Definition: fmunit.h:32
FOMEWrapper provides the context for the Forest Management Engine This wrapper blends activties,...
Definition: fomewrapper.h:33
StandObj is the bridge to stand variables from the Javascript world.
Definition: fomescript.h:161
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
Definition: abegrid.h:22
Definition: fmstand.h:37
SSpeciesStand()
Definition: fmstand.h:38
double relBasalArea
fraction [0..1] fraction of species based on basal area.
Definition: fmstand.h:41
double basalArea
basal area m2
Definition: fmstand.h:40
const Species * species
the ID of the species (ie a pointer)
Definition: fmstand.h:39