Rev 1203 | Rev 1218 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1203 | Rev 1217 | ||
---|---|---|---|
1 | Redirecting to URL 'https://iland.boku.ac.at/svn/iland/tags/release_1.0/src/core/resourceunit.h': |
1 | Redirecting to URL 'https://iland.boku.ac.at/svn/iland/tags/release_1.0/src/core/resourceunit.h': |
2 | /********************************************************************************************
|
2 | /********************************************************************************************
|
3 | ** iLand - an individual based forest landscape and disturbance model
|
3 | ** iLand - an individual based forest landscape and disturbance model
|
4 | ** http://iland.boku.ac.at
|
4 | ** http://iland.boku.ac.at
|
5 | ** Copyright (C) 2009- Werner Rammer, Rupert Seidl
|
5 | ** Copyright (C) 2009- Werner Rammer, Rupert Seidl
|
6 | **
|
6 | **
|
7 | ** This program is free software: you can redistribute it and/or modify
|
7 | ** This program is free software: you can redistribute it and/or modify
|
8 | ** it under the terms of the GNU General Public License as published by
|
8 | ** it under the terms of the GNU General Public License as published by
|
9 | ** the Free Software Foundation, either version 3 of the License, or
|
9 | ** the Free Software Foundation, either version 3 of the License, or
|
10 | ** (at your option) any later version.
|
10 | ** (at your option) any later version.
|
11 | **
|
11 | **
|
12 | ** This program is distributed in the hope that it will be useful,
|
12 | ** This program is distributed in the hope that it will be useful,
|
13 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 | ** GNU General Public License for more details.
|
15 | ** GNU General Public License for more details.
|
16 | **
|
16 | **
|
17 | ** You should have received a copy of the GNU General Public License
|
17 | ** You should have received a copy of the GNU General Public License
|
18 | ** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18 | ** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19 | ********************************************************************************************/
|
19 | ********************************************************************************************/
|
20 | 20 | ||
21 | #ifndef RESOURCEUNIT_H
|
21 | #ifndef RESOURCEUNIT_H
|
22 | #define RESOURCEUNIT_H
|
22 | #define RESOURCEUNIT_H
|
23 | 23 | ||
24 | #include "tree.h"
|
24 | #include "tree.h"
|
25 | #include "resourceunitspecies.h"
|
25 | #include "resourceunitspecies.h"
|
26 | #include "standstatistics.h"
|
26 | #include "standstatistics.h"
|
27 | #include <QtCore/QVector>
|
27 | #include <QtCore/QVector>
|
28 | #include <QtCore/QRectF>
|
28 | #include <QtCore/QRectF>
|
29 | class SpeciesSet; |
29 | class SpeciesSet; |
30 | class Climate; |
30 | class Climate; |
31 | class WaterCycle; |
31 | class WaterCycle; |
32 | class Snag; |
32 | class Snag; |
33 | class Soil; |
33 | class Soil; |
34 | struct SaplingCell; |
34 | struct SaplingCell; |
35 | 35 | ||
36 | struct ResourceUnitVariables
|
36 | struct ResourceUnitVariables
|
37 | {
|
37 | {
|
38 | ResourceUnitVariables(): nitrogenAvailable(0.), cumCarbonUptake(0.), cumCarbonToAtm(0.), cumNEP(0.), carbonUptake(0.), carbonToAtm(0.), NEP(0.) {} |
38 | ResourceUnitVariables(): nitrogenAvailable(0.), cumCarbonUptake(0.), cumCarbonToAtm(0.), cumNEP(0.), carbonUptake(0.), carbonToAtm(0.), NEP(0.) {} |
39 | double nitrogenAvailable; ///< nitrogen content (kg/m2/year) |
39 | double nitrogenAvailable; ///< nitrogen content (kg/m2/year) |
40 | double cumCarbonUptake; ///< NPP (kg C/ha) |
40 | double cumCarbonUptake; ///< NPP (kg C/ha) |
41 | double cumCarbonToAtm; ///< total flux of carbon to atmosphere (kg C/ha) |
41 | double cumCarbonToAtm; ///< total flux of carbon to atmosphere (kg C/ha) |
42 | double cumNEP; ///< cumulative ecosystem productivity (kg C/ha), i.e. cumulative(NPP-losses(atm,harvest) |
42 | double cumNEP; ///< cumulative ecosystem productivity (kg C/ha), i.e. cumulative(NPP-losses(atm,harvest) |
43 | double carbonUptake, carbonToAtm, NEP; ///< values of the current year (NPP, flux to atmosphere, net ecosystem prod., all values in kgC/ha) |
43 | double carbonUptake, carbonToAtm, NEP; ///< values of the current year (NPP, flux to atmosphere, net ecosystem prod., all values in kgC/ha) |
44 | }; |
44 | }; |
45 | 45 | ||
46 | class ResourceUnit
|
46 | class ResourceUnit
|
47 | {
|
47 | {
|
48 | public: |
48 | public: |
49 | ResourceUnit(const int index); |
49 | ResourceUnit(const int index); |
50 | ~ResourceUnit(); |
50 | ~ResourceUnit(); |
51 | // setup/maintenance
|
51 | // setup/maintenance
|
52 | void setup(); ///< setup operations after the creation of the model space. |
52 | void setup(); ///< setup operations after the creation of the model space. |
53 | void setSpeciesSet(SpeciesSet *set); |
53 | void setSpeciesSet(SpeciesSet *set); |
54 | void setClimate(Climate* climate) { mClimate = climate; } |
54 | void setClimate(Climate* climate) { mClimate = climate; } |
55 | void setBoundingBox(const QRectF &bb); |
55 | void setBoundingBox(const QRectF &bb); |
56 | void setID(const int id) { mID = id; } |
56 | void setID(const int id) { mID = id; } |
57 | 57 | ||
58 | // access to elements
|
58 | // access to elements
|
59 | const Climate *climate() const { return mClimate; } ///< link to the climate on this resource unit |
59 | const Climate *climate() const { return mClimate; } ///< link to the climate on this resource unit |
60 | SpeciesSet *speciesSet() const { return mSpeciesSet; } ///< get SpeciesSet this RU links to. |
60 | SpeciesSet *speciesSet() const { return mSpeciesSet; } ///< get SpeciesSet this RU links to. |
61 | const WaterCycle *waterCycle() const { return mWater; } ///< water model of the unit |
61 | const WaterCycle *waterCycle() const { return mWater; } ///< water model of the unit |
62 | Snag *snag() const { return mSnag; } ///< access the snag object |
62 | Snag *snag() const { return mSnag; } ///< access the snag object |
63 | Soil *soil() const { return mSoil; } ///< access the soil model |
63 | Soil *soil() const { return mSoil; } ///< access the soil model |
64 | SaplingCell *saplingCellArray() const { return mSaplings; } ///< access the array of sapling-cells |
64 | SaplingCell *saplingCellArray() const { return mSaplings; } ///< access the array of sapling-cells |
65 | SaplingCell *saplingCell(const QPoint &lifCoords) const; ///< return a pointer to the 2x2m SaplingCell located at 'lif' |
65 | SaplingCell *saplingCell(const QPoint &lifCoords) const; ///< return a pointer to the 2x2m SaplingCell located at 'lif' |
66 | 66 | ||
67 | ResourceUnitSpecies &resourceUnitSpecies(const Species *species); ///< get RU-Species-container of @p species from the RU |
67 | ResourceUnitSpecies &resourceUnitSpecies(const Species *species); ///< get RU-Species-container of @p species from the RU |
68 | const ResourceUnitSpecies *constResourceUnitSpecies(const Species *species) const; ///< get RU-Species-container of @p species from the RU |
68 | const ResourceUnitSpecies *constResourceUnitSpecies(const Species *species) const; ///< get RU-Species-container of @p species from the RU |
69 | ResourceUnitSpecies *resourceUnitSpecies(const int species_index) const { return mRUSpecies[species_index]; } ///< get RU-Species-container with index 'species_index' from the RU |
69 | ResourceUnitSpecies *resourceUnitSpecies(const int species_index) const { return mRUSpecies[species_index]; } ///< get RU-Species-container with index 'species_index' from the RU |
70 | const QList<ResourceUnitSpecies*> &ruSpecies() const { return mRUSpecies; } |
70 | const QList<ResourceUnitSpecies*> &ruSpecies() const { return mRUSpecies; } |
71 | QVector<Tree> &trees() { return mTrees; } ///< reference to the tree list. |
71 | QVector<Tree> &trees() { return mTrees; } ///< reference to the tree list. |
72 | const QVector<Tree> &constTrees() const { return mTrees; } ///< reference to the (const) tree list. |
72 | const QVector<Tree> &constTrees() const { return mTrees; } ///< reference to the (const) tree list. |
73 | Tree *tree(const int index) { return &(mTrees[index]);} ///< get pointer to a tree |
73 | Tree *tree(const int index) { return &(mTrees[index]);} ///< get pointer to a tree |
74 | const ResourceUnitVariables &resouceUnitVariables() const { return mUnitVariables; } ///< access to variables that are specific to resourceUnit (e.g. nitrogenAvailable) |
74 | const ResourceUnitVariables &resouceUnitVariables() const { return mUnitVariables; } ///< access to variables that are specific to resourceUnit (e.g. nitrogenAvailable) |
75 | const StandStatistics &statistics() const {return mStatistics; } |
75 | const StandStatistics &statistics() const {return mStatistics; } |
76 | 76 | ||
77 | // properties
|
77 | // properties
|
78 | int index() const { return mIndex; } |
78 | int index() const { return mIndex; } |
79 | int id() const { return mID; } |
79 | int id() const { return mID; } |
80 | const QRectF &boundingBox() const { return mBoundingBox; } |
80 | const QRectF &boundingBox() const { return mBoundingBox; } |
81 | const QPoint &cornerPointOffset() const { return mCornerOffset; } ///< coordinates on the LIF grid of the upper left corner of the RU |
81 | const QPoint &cornerPointOffset() const { return mCornerOffset; } ///< coordinates on the LIF grid of the upper left corner of the RU |
82 | double area() const { return mPixelCount*100; } ///< get the resource unit area in m2 |
82 | double area() const { return mPixelCount*100; } ///< get the resource unit area in m2 |
83 | double stockedArea() const { return mStockedArea; } ///< get the stocked area in m2 |
83 | double stockedArea() const { return mStockedArea; } ///< get the stocked area in m2 |
84 | double stockableArea() const { return mStockableArea; } ///< total stockable area in m2 |
84 | double stockableArea() const { return mStockableArea; } ///< total stockable area in m2 |
85 | double productiveArea() const { return mEffectiveArea; } ///< TotalArea - Unstocked Area - loss due to BeerLambert (m2) |
85 | double productiveArea() const { return mEffectiveArea; } ///< TotalArea - Unstocked Area - loss due to BeerLambert (m2) |
86 | double leafAreaIndex() const { return stockableArea()?mAggregatedLA / stockableArea():0.; } ///< Total Leaf Area Index |
86 | double leafAreaIndex() const { return stockableArea()?mAggregatedLA / stockableArea():0.; } ///< Total Leaf Area Index |
87 | double leafArea() const { return mAggregatedLA; } ///< total leaf area of resource unit (m2) |
87 | double leafArea() const { return mAggregatedLA; } ///< total leaf area of resource unit (m2) |
88 | double interceptedArea(const double LA, const double LightResponse) { return mEffectiveArea_perWLA * LA * LightResponse; } |
88 | double interceptedArea(const double LA, const double LightResponse) { return mEffectiveArea_perWLA * LA * LightResponse; } |
89 | const double &LRImodifier() const { return mLRI_modification; } |
89 | const double &LRImodifier() const { return mLRI_modification; } |
90 | double averageAging() const { return mAverageAging; } ///< leaf area weighted average aging |
90 | double averageAging() const { return mAverageAging; } ///< leaf area weighted average aging |
91 | 91 | ||
92 | // actions
|
92 | // actions
|
93 | Tree &newTree(); ///< returns a modifiable reference to a free space inside the tree-vector. should be used for tree-init. |
93 | Tree &newTree(); ///< returns a modifiable reference to a free space inside the tree-vector. should be used for tree-init. |
94 | int newTreeIndex(); ///< returns the index of a newly inserted tree |
94 | int newTreeIndex(); ///< returns the index of a newly inserted tree |
95 | void cleanTreeList(); ///< remove dead trees from the tree storage. |
95 | void cleanTreeList(); ///< remove dead trees from the tree storage. |
96 | void treeDied() { mHasDeadTrees = true; } ///< sets the flag that indicates that the resource unit contains dead trees |
96 | void treeDied() { mHasDeadTrees = true; } ///< sets the flag that indicates that the resource unit contains dead trees |
97 | bool hasDiedTrees() const { return mHasDeadTrees; } ///< if true, the resource unit has dead trees and needs maybe some cleanup |
97 | bool hasDiedTrees() const { return mHasDeadTrees; } ///< if true, the resource unit has dead trees and needs maybe some cleanup |
98 | /// addWLA() is called by each tree to aggregate the total weighted leaf area on a unit
|
98 | /// addWLA() is called by each tree to aggregate the total weighted leaf area on a unit
|
99 | void addWLA(const float LA, const float LRI) { mAggregatedWLA += LA*LRI; mAggregatedLA += LA; } |
99 | void addWLA(const float LA, const float LRI) { mAggregatedWLA += LA*LRI; mAggregatedLA += LA; } |
100 | void addLR(const float LA, const float LightResponse) { mAggregatedLR += LA*LightResponse; } |
100 | void addLR(const float LA, const float LightResponse) { mAggregatedLR += LA*LightResponse; } |
101 | /// function that distributes effective interception area according to the weight of Light response and LeafArea of the indivudal (@sa production())
|
101 | /// function that distributes effective interception area according to the weight of Light response and LeafArea of the indivudal (@sa production())
|
102 | void calculateInterceptedArea(); |
102 | void calculateInterceptedArea(); |
103 | void addTreeAging(const double leaf_area, const double aging_factor) { mAverageAging += leaf_area*aging_factor; } ///< aggregate the tree aging values (weighted by leaf area) |
103 | void addTreeAging(const double leaf_area, const double aging_factor) { mAverageAging += leaf_area*aging_factor; } ///< aggregate the tree aging values (weighted by leaf area) |
104 | void addTreeAgingForAllTrees(); ///< calculate average tree aging for all trees of a RU. Used directly after stand initialization. |
104 | void addTreeAgingForAllTrees(); ///< calculate average tree aging for all trees of a RU. Used directly after stand initialization. |
105 | // stocked area calculation
|
105 | // stocked area calculation
|
106 | void countStockedPixel(bool pixelIsStocked) { mPixelCount++; if (pixelIsStocked) mStockedPixelCount++; } |
106 | void countStockedPixel(bool pixelIsStocked) { mPixelCount++; if (pixelIsStocked) mStockedPixelCount++; } |
107 | void createStandStatistics(); ///< helping function to create an initial state for stand statistics |
107 | void createStandStatistics(); ///< helping function to create an initial state for stand statistics |
108 | void recreateStandStatistics(bool recalculate_stats); ///< re-build stand statistics after some change happened to the resource unit |
108 | void recreateStandStatistics(bool recalculate_stats); ///< re-build stand statistics after some change happened to the resource unit |
109 | void setStockableArea(const double area) { mStockableArea = area; } ///< set stockable area (m2) |
109 | void setStockableArea(const double area) { mStockableArea = area; } ///< set stockable area (m2) |
110 | 110 | ||
111 | // snag / snag dynamics
|
111 | // snag / snag dynamics
|
112 | // snag dynamics, soil carbon and nitrogen cycle
|
112 | // snag dynamics, soil carbon and nitrogen cycle
|
113 | void snagNewYear() { if (snag()) snag()->newYear(); } ///< clean transfer pools |
113 | void snagNewYear() { if (snag()) snag()->newYear(); } ///< clean transfer pools |
114 | void calculateCarbonCycle(); ///< calculate snag dynamics at the end of a year |
114 | void calculateCarbonCycle(); ///< calculate snag dynamics at the end of a year |
115 | // model flow
|
115 | // model flow
|
116 | void newYear(); ///< reset values for a new simulation year |
116 | void newYear(); ///< reset values for a new simulation year |
117 | // LIP/LIF-cylcle -> Model
|
117 | // LIP/LIF-cylcle -> Model
|
118 | void production(); ///< called after the LIP/LIF calc, before growth of individual trees. Production (3PG), Water-cycle |
118 | void production(); ///< called after the LIP/LIF calc, before growth of individual trees. Production (3PG), Water-cycle |
119 | void beforeGrow(); ///< called before growth of individuals |
119 | void beforeGrow(); ///< called before growth of individuals |
120 | // the growth of individuals -> Model
|
120 | // the growth of individuals -> Model
|
121 | void afterGrow(); ///< called after the growth of individuals |
121 | void afterGrow(); ///< called after the growth of individuals |
122 | void yearEnd(); ///< called at the end of a year (after regeneration??) |
122 | void yearEnd(); ///< called at the end of a year (after regeneration??) |
123 | 123 | ||
124 | private: |
124 | private: |
125 | int mIndex; ///< internal index |
125 | int mIndex; ///< internal index |
126 | int mID; ///< ID provided by external stand grid |
126 | int mID; ///< ID provided by external stand grid |
127 | bool mHasDeadTrees; ///< flag that indicates if currently dead trees are in the tree list |
127 | bool mHasDeadTrees; ///< flag that indicates if currently dead trees are in the tree list |
128 | Climate *mClimate; ///< pointer to the climate object of this RU |
128 | Climate *mClimate; ///< pointer to the climate object of this RU |
129 | SpeciesSet *mSpeciesSet; ///< pointer to the species set for this RU |
129 | SpeciesSet *mSpeciesSet; ///< pointer to the species set for this RU |
130 | WaterCycle *mWater; ///< link to the Soil water calculation engine |
130 | WaterCycle *mWater; ///< link to the Soil water calculation engine |
131 | Snag *mSnag; ///< ptr to snag storage / dynamics |
131 | Snag *mSnag; ///< ptr to snag storage / dynamics |
132 | Soil *mSoil; ///< ptr to CN dynamics soil submodel |
132 | Soil *mSoil; ///< ptr to CN dynamics soil submodel |
133 | QList<ResourceUnitSpecies*> mRUSpecies; ///< data for this ressource unit per species |
133 | QList<ResourceUnitSpecies*> mRUSpecies; ///< data for this ressource unit per species |
134 | QVector<Tree> mTrees; ///< storage container for tree individuals |
134 | QVector<Tree> mTrees; ///< storage container for tree individuals |
135 | SaplingCell *mSaplings; ///< pointer to the array of Sapling-cells for the resource unit |
135 | SaplingCell *mSaplings; ///< pointer to the array of Sapling-cells for the resource unit |
136 | QRectF mBoundingBox; ///< bounding box (metric) of the RU |
136 | QRectF mBoundingBox; ///< bounding box (metric) of the RU |
137 | QPoint mCornerOffset; ///< coordinates on the LIF grid of the upper left corner of the RU |
137 | QPoint mCornerOffset; ///< coordinates on the LIF grid of the upper left corner of the RU |
138 | double mAggregatedLA; ///< sum of leafArea |
138 | double mAggregatedLA; ///< sum of leafArea |
139 | double mAggregatedWLA; ///< sum of lightResponse * LeafArea for all trees |
139 | double mAggregatedWLA; ///< sum of lightResponse * LeafArea for all trees |
140 | double mAggregatedLR; ///< sum of lightresponse*LA of the current unit |
140 | double mAggregatedLR; ///< sum of lightresponse*LA of the current unit |
141 | double mEffectiveArea; ///< total "effective" area per resource unit, i.e. area of RU - non-stocked - beerLambert-loss |
141 | double mEffectiveArea; ///< total "effective" area per resource unit, i.e. area of RU - non-stocked - beerLambert-loss |
142 | double mEffectiveArea_perWLA; ///< |
142 | double mEffectiveArea_perWLA; ///< |
143 | double mLRI_modification; |
143 | double mLRI_modification; |
144 | double mAverageAging; ///< leaf-area weighted average aging f this species on this RU. |
144 | double mAverageAging; ///< leaf-area weighted average aging f this species on this RU. |
145 | float *mSaplingHeightMap; ///< pointer to array that holds max-height for each 2x2m pixel. Note: this information is not persistent |
145 | float *mSaplingHeightMap; ///< pointer to array that holds max-height for each 2x2m pixel. Note: this information is not persistent |
146 | 146 | ||
147 | int mPixelCount; ///< count of (Heightgrid) pixels thare are inside the RU |
147 | int mPixelCount; ///< count of (Heightgrid) pixels thare are inside the RU |
148 | int mStockedPixelCount; ///< count of pixels that are stocked with trees |
148 | int mStockedPixelCount; ///< count of pixels that are stocked with trees |
149 | double mStockedArea; ///< size of stocked area |
149 | double mStockedArea; ///< size of stocked area |
150 | double mStockableArea; ///< area of stockable area (defined by project setup) |
150 | double mStockableArea; ///< area of stockable area (defined by project setup) |
151 | StandStatistics mStatistics; ///< aggregate values on stand value |
151 | StandStatistics mStatistics; ///< aggregate values on stand value |
152 | ResourceUnitVariables mUnitVariables;
|
152 | ResourceUnitVariables mUnitVariables;
|
153 | 153 | ||
154 | friend class RUWrapper; |
154 | friend class RUWrapper; |
155 | }; |
155 | }; |
156 | 156 | ||
157 | 157 | ||
158 | #endif // RESOURCEUNIT_H
|
158 | #endif // RESOURCEUNIT_H
|
159 | 159 |