iLand
barkbeetlemodule.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 BARKBEETLEMODULE_H
20#define BARKBEETLEMODULE_H
21
22#include "grid.h"
23#include "layeredgrid.h"
24#include "random.h"
25#include "expression.h"
26
27#include "bbgenerations.h"
28
29
30
37{
38public:
42 void reset() {clear(); dbh=0.f; tree_stress=0.f; outbreakYear=0.f; n_events=0; sum_volume_killed=0.f; }
43 bool isHost() const { return dbh>0.f; }
44 bool isPotentialHost() const {return dbh>0.f && killedYear==0 && infested==false; }
46 void setInfested(bool is_infested) { infested=is_infested; if (infested) { total_infested++; killedYear=0; n=0;} }
48 void finishedSpread(int iteration) { infested=false; killedYear=iteration; killed=true; max_iteration=qMax(max_iteration, iteration); ++n_events; }
50
51 bool infested; // true for cells that are currently occupied by beetles
52 bool killed; // true for cells that are killed in the current year
53 float dbh; // the dbh of the biggest spruce on the pixel
54 float tree_stress; // the stress rating of this tree (SI)
55 float p_colonize; // the highest probability (0..1) that a pixel is killed
56 int n; // number of cohorts that landed on the pixel in each iteration
57 int n_total; // number of cohorts that landed on a pixel (total)
58 int killedYear; // year (iteration) at which pixel was killed ??
59 float outbreakYear; // year in which the outbreak started (this information is preserved by spreading beatles)
60 float packageOutbreakYear; // outbreak year of packages landing on a cell
61 int n_events; // total number of events on the pixel since the start of the simulation
62 float sum_volume_killed; // total killed volume (since start of the simulation) on a pixel (m3)
66 bool isNeutralized() const { return deadtrees!=NoDeadTrees; }
67
69 static int total_infested;
70 static int max_iteration;
71
72};
73
80{
81public:
85 infested(0.) {}
88 bool scanned;
89 double generations; // filial generations + 0.5 if full sisterbrood develops for last filial generation
91 int cold_days; // number of days in the winter season with t_min below a given threshold (-15 degree Celsius)
96 int infested; // number of pixels that are currently infested
97
98};
99
103class BarkBeetleLayers: public LayeredGrid<BarkBeetleCell> {
104 public:
105 void setGrid(const Grid<BarkBeetleCell> &grid) { mGrid = &grid; }
106 double value(const BarkBeetleCell& data, const int index) const;
107 const QVector<LayeredGridBase::LayerElement> &names();
108 bool onClick(const QPointF &world_coord) const;
109private:
110 QVector<LayeredGridBase::LayerElement> mNames;
111};
112
113class BarkBeetleRULayers: public LayeredGrid<BarkBeetleRUCell> {
114 public:
115 void setGrid(const Grid<BarkBeetleRUCell> &grid) { mGrid = &grid; }
116 double value(const BarkBeetleRUCell& data, const int index) const;
117 const QVector<LayeredGridBase::LayerElement> &names();
118 bool onClick(const QPointF &world_coord) const;
119private:
120 QVector<LayeredGridBase::LayerElement> mNames;
121};
122
123
124
125class ResourceUnit; // forward
126class Tree; // forward
127class BarkBeetleOut; // forward
128class Climate; // forward
135{
136public:
139 static double cellsize() { return 10.; }
140
141 void setup();
142 void setup(const ResourceUnit *ru);
143 void loadParameters(bool do_reset=true);
144 void clearGrids();
145 void loadAllVegetation();
146
148 void run(int iteration=0);
149
151 void treeDeath(const Tree *tree);
152
153 void yearBegin();
155 int manualYearBegin() { int y=mYear; yearBegin(); mYear = y + 1; return mYear; }
156 int internalYear() const { return mYear; }
157 // properties
158 void setSimulate(bool do_simulate) { mSimulate = do_simulate; }
159 bool simulate() const {return mSimulate; }
160
161 void setEnabled(bool do_set_enabled) { mEnabled = do_set_enabled; }
162 bool enabled() const { return mEnabled; }
163private:
164 void calculateGenerations();
165 void calculateOutbreakFactor();
166 void startSpread();
167 int clumpedBackgroundActivation(QPoint start_idx);
168 void prepareInteractions(bool update_interaction=false);
169 void barkbeetleSpread();
170 void barkbeetleKill();
171 void scanResourceUnitTrees(const QPointF &position);
172 bool sanitationTreatment(QPointF coord) const;
173 //void calculateMeanDamage(); ///< calculate the mean damage percentage (fraction of killed pixels to host pixels)
174 int mIteration;
175 QString mAfterExecEvent;
176 struct SBBParams {
177 SBBParams(): minDbh(10.f), cohortsPerGeneration(30), cohortsPerSisterbrood(50),
178 spreadKernelMaxDistance(100.), backgroundInfestationProbability(0.0001), initialInfestationProbability(0.),
179 stormInfestationProbability(1.), winterMortalityBaseLevel(0.),
180 outbreakDurationMin(0.), outbreakDurationMax(0.), deadTreeSelectivity(1.), sanitationTreatmentProb(0.) {}
181 float minDbh;
182 int cohortsPerGeneration;
183 int cohortsPerSisterbrood;
184 QString spreadKernelFormula;
185 double spreadKernelMaxDistance;
186 double backgroundInfestationProbability;
187 double initialInfestationProbability;
188 double stormInfestationProbability;
189 double winterMortalityBaseLevel;
190 double outbreakDurationMin;
191 double outbreakDurationMax;
192 double deadTreeSelectivity;
193 double sanitationTreatmentProb;
194
195 } params;
196 struct SBBStats {
197 void clear() { infestedStart=0;infestedBackground=0; infestedStorm=0; maxGenerations=0;NCohortsLanded=0;NPixelsLanded=0;NCohortsSpread=0;NInfested=0;NWinterMortality=0;NAreaKilled=0;NTreesKilled=0;BasalAreaKilled=0.; VolumeKilled=0.;}
198 int infestedStart; // # of pixels that are infested at the beginning of an iteration
199 int infestedBackground; // # of pixels that are getting active
200 int infestedStorm; // # of pixels that are activated due to storm damage
201 int maxGenerations; // maxium number of generations found this year
202 int NCohortsLanded; // number of cohorts that landed on new potential host pixels
203 int NPixelsLanded; // number of potential host pixels that received at least one cohort
204 int NCohortsSpread; // number of pixels that are spread from infested cells
205 int NInfested; // number of newly infested pixels (a subset of those who 'landed')
206 int NWinterMortality; // number of (infested) pixels that died off during winter
207 int NAreaKilled; // number of pixels on which trees were killed
208 int NTreesKilled; // number of spruce trees killed
209 double BasalAreaKilled; // sum of basal area of killed trees
210 double VolumeKilled; // sum of killed tree volumes (m3)
211 } stats;
212
213
214 bool mSimulate;
215 bool mEnabled;
216 int mYear;
217 BBGenerations mGenerations;
218 RandomCustomPDF mKernelPDF;
219 Expression mColonizeProbability;
220 Expression mWinterMortalityFormula;
223 Expression mOutbreakClimateSensitivityFormula;
224 Expression mOutbreakDurationFormula;
227 BarkBeetleLayers mLayers;
228 BarkBeetleRULayers mRULayers;
229 // reference climate
230 QVector<double> mRefClimateAverages;
231 double *mClimateVariables[8]; // pointer to the variables
232 const Climate *mRefClimate;
233 double mRc;
234
235 friend class BarkBeetleScript;
236 friend class BarkBeetleOut;
237
238};
239
240
241
242#endif // BARKBEETLEMODULE_H
BBGenerations calculates potential bark beetle generations based on climate data (including bark temp...
Definition: bbgenerations.h:28
The BarkBeetleCell is the basic unit (10m pixels) of the bark beetle module.
Definition: barkbeetlemodule.h:37
void setInfested(bool is_infested)
sets the 'infested' state (true: the cell is newly infested, false: the cell stops being infested,...
Definition: barkbeetlemodule.h:46
float sum_volume_killed
Definition: barkbeetlemodule.h:62
int killedYear
Definition: barkbeetlemodule.h:58
int n_total
Definition: barkbeetlemodule.h:57
static int total_infested
Definition: barkbeetlemodule.h:69
DeadTrees deadtrees
Definition: barkbeetlemodule.h:64
bool isHost() const
Definition: barkbeetlemodule.h:43
float outbreakYear
Definition: barkbeetlemodule.h:59
bool infested
Definition: barkbeetlemodule.h:51
bool killed
Definition: barkbeetlemodule.h:52
BarkBeetleCell()
Definition: barkbeetlemodule.h:39
static int max_iteration
Definition: barkbeetlemodule.h:70
float dbh
Definition: barkbeetlemodule.h:53
bool isPotentialHost() const
Definition: barkbeetlemodule.h:44
float tree_stress
Definition: barkbeetlemodule.h:54
void finishedSpread(int iteration)
called after beetles spread out from the cell. The cell is marked as 'killed', and trees will be kill...
Definition: barkbeetlemodule.h:48
int n_events
Definition: barkbeetlemodule.h:61
static void resetCounters()
Definition: barkbeetlemodule.h:68
float backgroundInfestationProbability
background prob. of infestation per 10m cell
Definition: barkbeetlemodule.h:49
DeadTrees
Definition: barkbeetlemodule.h:63
@ BeetleTrapTree
Definition: barkbeetlemodule.h:63
@ SinkInVicinity
Definition: barkbeetlemodule.h:63
@ StormDamage
Definition: barkbeetlemodule.h:63
@ NoDeadTrees
Definition: barkbeetlemodule.h:63
void clear()
Definition: barkbeetlemodule.h:40
bool isNeutralized() const
return true if either storm damaged trees or trap trees are on the pixel or in the Moore neighborhood...
Definition: barkbeetlemodule.h:66
int n
Definition: barkbeetlemodule.h:56
void reset()
full reset of the pixel
Definition: barkbeetlemodule.h:42
float packageOutbreakYear
Definition: barkbeetlemodule.h:60
float p_colonize
Definition: barkbeetlemodule.h:55
Helper class manage and visualize data layers related to the barkbeetle module.
Definition: barkbeetlemodule.h:103
const QVector< LayeredGridBase::LayerElement > & names()
list of stored layers
Definition: barkbeetlemodule.cpp:767
bool onClick(const QPointF &world_coord) const
Definition: barkbeetlemodule.cpp:787
double value(const BarkBeetleCell &data, const int index) const
Definition: barkbeetlemodule.cpp:741
void setGrid(const Grid< BarkBeetleCell > &grid)
Definition: barkbeetlemodule.h:105
The BarkBeetleModule class is the main class of the bark beetle module.
Definition: barkbeetlemodule.h:135
void clearGrids()
reset the state of the internal grids (used for javascript based tests)
Definition: barkbeetlemodule.cpp:191
static double cellsize()
Definition: barkbeetlemodule.h:139
bool enabled() const
Definition: barkbeetlemodule.h:162
void run(int iteration=0)
main function to execute the bark beetle module (iteration can be non-0 when called from Javascript)
Definition: barkbeetlemodule.cpp:222
~BarkBeetleModule()
Definition: barkbeetlemodule.cpp:65
void setSimulate(bool do_simulate)
Definition: barkbeetlemodule.h:158
void setup()
general setup
Definition: barkbeetlemodule.cpp:69
void loadAllVegetation()
scan the state of the vegetation of the full landscape
Definition: barkbeetlemodule.cpp:206
void yearBegin()
called automatically
Definition: barkbeetlemodule.cpp:362
void setEnabled(bool do_set_enabled)
Definition: barkbeetlemodule.h:161
BarkBeetleModule()
Definition: barkbeetlemodule.cpp:55
bool simulate() const
Definition: barkbeetlemodule.h:159
int internalYear() const
Definition: barkbeetlemodule.h:156
int manualYearBegin()
call from script (from script)
Definition: barkbeetlemodule.h:155
void treeDeath(const Tree *tree)
function that is called whenever a tree dies somewhere in iLand
Definition: barkbeetlemodule.cpp:265
void loadParameters(bool do_reset=true)
load params from XML
Definition: barkbeetlemodule.cpp:106
BarkBeetleOut handles the database output of the bark beetle module.
Definition: barkbeetleout.h:28
The BarkBeetleRUCell class collects information on resource unit (100m pixel) level.
Definition: barkbeetlemodule.h:80
int host_pixels
Definition: barkbeetlemodule.h:95
int killed_pixels
Definition: barkbeetlemodule.h:94
double currentDamageFraction()
relative damage: fraction of host pixels that died in the current or the last year
Definition: barkbeetlemodule.h:87
BarkBeetleRUCell()
Definition: barkbeetlemodule.h:82
double generations
Definition: barkbeetlemodule.h:89
bool add_sister
Definition: barkbeetlemodule.h:90
int infested
Definition: barkbeetlemodule.h:96
int cold_days_late
Definition: barkbeetlemodule.h:92
int cold_days
Definition: barkbeetlemodule.h:91
bool scanned
Definition: barkbeetlemodule.h:88
bool killed_trees
Definition: barkbeetlemodule.h:93
Definition: barkbeetlemodule.h:113
const QVector< LayeredGridBase::LayerElement > & names()
list of stored layers
Definition: barkbeetlemodule.cpp:803
double value(const BarkBeetleRUCell &data, const int index) const
Definition: barkbeetlemodule.cpp:794
void setGrid(const Grid< BarkBeetleRUCell > &grid)
Definition: barkbeetlemodule.h:115
bool onClick(const QPointF &world_coord) const
Definition: barkbeetlemodule.cpp:811
BarkBeetleScript is the scripting shell for the bark beetle module.
Definition: barkbeetlescript.h:31
Climate handles climate input data and performs some basic related calculations on that data.
Definition: climate.h:66
An expression engine for mathematical expressions provided as strings.
Definition: expression.h:29
Grid class (template).
Definition: grid.h:44
This is the base class for multi-layer grids in iLand.
Definition: layeredgrid.h:95
const Grid< BarkBeetleCell > * mGrid
Definition: layeredgrid.h:130
numbers with a user defined probaility density function.
Definition: random.h:62
ResourceUnit is the spatial unit that encapsulates a forest stand and links to several environmental ...
Definition: resourceunit.h:49
A tree is the basic simulation entity of iLand and represents a single tree.
Definition: tree.h:44