Rev 1221 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
671 | werner | 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 | |||
187 | iland | 20 | #ifndef RESOURCEUNIT_H |
21 | #define RESOURCEUNIT_H |
||
92 | Werner | 22 | |
23 | #include "tree.h" |
||
189 | iland | 24 | #include "resourceunitspecies.h" |
180 | werner | 25 | #include "standstatistics.h" |
293 | werner | 26 | #include <QtCore/QVector> |
27 | #include <QtCore/QRectF> |
||
92 | Werner | 28 | class SpeciesSet; |
208 | werner | 29 | class Climate; |
241 | werner | 30 | class WaterCycle; |
521 | werner | 31 | class Snag; |
526 | werner | 32 | class Soil; |
1159 | werner | 33 | struct SaplingCell; |
444 | werner | 34 | |
281 | werner | 35 | struct ResourceUnitVariables |
36 | { |
||
1157 | werner | 37 | ResourceUnitVariables(): nitrogenAvailable(0.), cumCarbonUptake(0.), cumCarbonToAtm(0.), cumNEP(0.), carbonUptake(0.), carbonToAtm(0.), NEP(0.) {} |
281 | werner | 38 | double nitrogenAvailable; ///< nitrogen content (kg/m2/year) |
1157 | werner | 39 | double cumCarbonUptake; ///< NPP (kg C/ha) |
40 | double cumCarbonToAtm; ///< total flux of carbon to atmosphere (kg C/ha) |
||
41 | double cumNEP; ///< cumulative ecosystem productivity (kg C/ha), i.e. cumulative(NPP-losses(atm,harvest) |
||
42 | double carbonUptake, carbonToAtm, NEP; ///< values of the current year (NPP, flux to atmosphere, net ecosystem prod., all values in kgC/ha) |
||
281 | werner | 43 | }; |
92 | Werner | 44 | |
187 | iland | 45 | class ResourceUnit |
92 | Werner | 46 | { |
47 | public: |
||
187 | iland | 48 | ResourceUnit(const int index); |
241 | werner | 49 | ~ResourceUnit(); |
449 | werner | 50 | // setup/maintenance |
51 | void setup(); ///< setup operations after the creation of the model space. |
||
52 | void setSpeciesSet(SpeciesSet *set); |
||
53 | void setClimate(Climate* climate) { mClimate = climate; } |
||
451 | werner | 54 | void setBoundingBox(const QRectF &bb); |
569 | werner | 55 | void setID(const int id) { mID = id; } |
255 | werner | 56 | |
234 | werner | 57 | // access to elements |
255 | werner | 58 | const Climate *climate() const { return mClimate; } ///< link to the climate on this resource unit |
449 | werner | 59 | SpeciesSet *speciesSet() const { return mSpeciesSet; } ///< get SpeciesSet this RU links to. |
255 | werner | 60 | const WaterCycle *waterCycle() const { return mWater; } ///< water model of the unit |
521 | werner | 61 | Snag *snag() const { return mSnag; } ///< access the snag object |
526 | werner | 62 | Soil *soil() const { return mSoil; } ///< access the soil model |
1159 | werner | 63 | SaplingCell *saplingCellArray() const { return mSaplings; } ///< access the array of sapling-cells |
1203 | werner | 64 | SaplingCell *saplingCell(const QPoint &lifCoords) const; ///< return a pointer to the 2x2m SaplingCell located at 'lif' |
526 | werner | 65 | |
255 | werner | 66 | ResourceUnitSpecies &resourceUnitSpecies(const Species *species); ///< get RU-Species-container of @p species from the RU |
1040 | werner | 67 | const ResourceUnitSpecies *constResourceUnitSpecies(const Species *species) const; ///< get RU-Species-container of @p species from the RU |
1162 | werner | 68 | ResourceUnitSpecies *resourceUnitSpecies(const int species_index) const { return mRUSpecies[species_index]; } ///< get RU-Species-container with index 'species_index' from the RU |
720 | werner | 69 | const QList<ResourceUnitSpecies*> &ruSpecies() const { return mRUSpecies; } |
105 | Werner | 70 | QVector<Tree> &trees() { return mTrees; } ///< reference to the tree list. |
449 | werner | 71 | const QVector<Tree> &constTrees() const { return mTrees; } ///< reference to the (const) tree list. |
294 | werner | 72 | Tree *tree(const int index) { return &(mTrees[index]);} ///< get pointer to a tree |
281 | werner | 73 | const ResourceUnitVariables &resouceUnitVariables() const { return mUnitVariables; } ///< access to variables that are specific to resourceUnit (e.g. nitrogenAvailable) |
367 | werner | 74 | const StandStatistics &statistics() const {return mStatistics; } |
255 | werner | 75 | |
234 | werner | 76 | // properties |
255 | werner | 77 | int index() const { return mIndex; } |
569 | werner | 78 | int id() const { return mID; } |
255 | werner | 79 | const QRectF &boundingBox() const { return mBoundingBox; } |
1118 | werner | 80 | const QPoint &cornerPointOffset() const { return mCornerOffset; } ///< coordinates on the LIF grid of the upper left corner of the RU |
1017 | werner | 81 | double area() const { return mPixelCount*100; } ///< get the resource unit area in m2 |
234 | werner | 82 | double stockedArea() const { return mStockedArea; } ///< get the stocked area in m2 |
574 | werner | 83 | double stockableArea() const { return mStockableArea; } ///< total stockable area in m2 |
280 | werner | 84 | double productiveArea() const { return mEffectiveArea; } ///< TotalArea - Unstocked Area - loss due to BeerLambert (m2) |
575 | werner | 85 | double leafAreaIndex() const { return stockableArea()?mAggregatedLA / stockableArea():0.; } ///< Total Leaf Area Index |
376 | werner | 86 | double leafArea() const { return mAggregatedLA; } ///< total leaf area of resource unit (m2) |
449 | werner | 87 | double interceptedArea(const double LA, const double LightResponse) { return mEffectiveArea_perWLA * LA * LightResponse; } |
88 | const double &LRImodifier() const { return mLRI_modification; } |
||
89 | double averageAging() const { return mAverageAging; } ///< leaf area weighted average aging |
||
255 | werner | 90 | |
107 | Werner | 91 | // actions |
287 | werner | 92 | Tree &newTree(); ///< returns a modifiable reference to a free space inside the tree-vector. should be used for tree-init. |
93 | int newTreeIndex(); ///< returns the index of a newly inserted tree |
||
449 | werner | 94 | void cleanTreeList(); ///< remove dead trees from the tree storage. |
664 | werner | 95 | void treeDied() { mHasDeadTrees = true; } ///< sets the flag that indicates that the resource unit contains dead trees |
720 | werner | 96 | bool hasDiedTrees() const { return mHasDeadTrees; } ///< if true, the resource unit has dead trees and needs maybe some cleanup |
111 | Werner | 97 | /// addWLA() is called by each tree to aggregate the total weighted leaf area on a unit |
212 | werner | 98 | void addWLA(const float LA, const float LRI) { mAggregatedWLA += LA*LRI; mAggregatedLA += LA; } |
251 | werner | 99 | void addLR(const float LA, const float LightResponse) { mAggregatedLR += LA*LightResponse; } |
230 | werner | 100 | /// function that distributes effective interception area according to the weight of Light response and LeafArea of the indivudal (@sa production()) |
376 | werner | 101 | void calculateInterceptedArea(); |
102 | void addTreeAging(const double leaf_area, const double aging_factor) { mAverageAging += leaf_area*aging_factor; } ///< aggregate the tree aging values (weighted by leaf area) |
||
482 | werner | 103 | void addTreeAgingForAllTrees(); ///< calculate average tree aging for all trees of a RU. Used directly after stand initialization. |
449 | werner | 104 | // stocked area calculation |
105 | void countStockedPixel(bool pixelIsStocked) { mPixelCount++; if (pixelIsStocked) mStockedPixelCount++; } |
||
720 | werner | 106 | void createStandStatistics(); ///< helping function to create an initial state for stand statistics |
1157 | werner | 107 | void recreateStandStatistics(bool recalculate_stats); ///< re-build stand statistics after some change happened to the resource unit |
574 | werner | 108 | void setStockableArea(const double area) { mStockableArea = area; } ///< set stockable area (m2) |
1113 | werner | 109 | |
521 | werner | 110 | // snag / snag dynamics |
111 | // snag dynamics, soil carbon and nitrogen cycle |
||
112 | void snagNewYear() { if (snag()) snag()->newYear(); } ///< clean transfer pools |
||
526 | werner | 113 | void calculateCarbonCycle(); ///< calculate snag dynamics at the end of a year |
111 | Werner | 114 | // model flow |
107 | Werner | 115 | void newYear(); ///< reset values for a new simulation year |
376 | werner | 116 | // LIP/LIF-cylcle -> Model |
117 | void production(); ///< called after the LIP/LIF calc, before growth of individual trees. Production (3PG), Water-cycle |
||
118 | void beforeGrow(); ///< called before growth of individuals |
||
119 | // the growth of individuals -> Model |
||
120 | void afterGrow(); ///< called after the growth of individuals |
||
121 | void yearEnd(); ///< called at the end of a year (after regeneration??) |
||
107 | Werner | 122 | |
92 | Werner | 123 | private: |
569 | werner | 124 | int mIndex; ///< internal index |
125 | int mID; ///< ID provided by external stand grid |
||
664 | werner | 126 | bool mHasDeadTrees; ///< flag that indicates if currently dead trees are in the tree list |
208 | werner | 127 | Climate *mClimate; ///< pointer to the climate object of this RU |
92 | Werner | 128 | SpeciesSet *mSpeciesSet; ///< pointer to the species set for this RU |
241 | werner | 129 | WaterCycle *mWater; ///< link to the Soil water calculation engine |
521 | werner | 130 | Snag *mSnag; ///< ptr to snag storage / dynamics |
526 | werner | 131 | Soil *mSoil; ///< ptr to CN dynamics soil submodel |
455 | werner | 132 | QList<ResourceUnitSpecies*> mRUSpecies; ///< data for this ressource unit per species |
92 | Werner | 133 | QVector<Tree> mTrees; ///< storage container for tree individuals |
1159 | werner | 134 | SaplingCell *mSaplings; ///< pointer to the array of Sapling-cells for the resource unit |
105 | Werner | 135 | QRectF mBoundingBox; ///< bounding box (metric) of the RU |
1118 | werner | 136 | QPoint mCornerOffset; ///< coordinates on the LIF grid of the upper left corner of the RU |
251 | werner | 137 | double mAggregatedLA; ///< sum of leafArea |
138 | double mAggregatedWLA; ///< sum of lightResponse * LeafArea for all trees |
||
139 | double mAggregatedLR; ///< sum of lightresponse*LA of the current unit |
||
140 | double mEffectiveArea; ///< total "effective" area per resource unit, i.e. area of RU - non-stocked - beerLambert-loss |
||
230 | werner | 141 | double mEffectiveArea_perWLA; ///< |
251 | werner | 142 | double mLRI_modification; |
376 | werner | 143 | double mAverageAging; ///< leaf-area weighted average aging f this species on this RU. |
451 | werner | 144 | float *mSaplingHeightMap; ///< pointer to array that holds max-height for each 2x2m pixel. Note: this information is not persistent |
230 | werner | 145 | |
151 | iland | 146 | int mPixelCount; ///< count of (Heightgrid) pixels thare are inside the RU |
147 | int mStockedPixelCount; ///< count of pixels that are stocked with trees |
||
234 | werner | 148 | double mStockedArea; ///< size of stocked area |
574 | werner | 149 | double mStockableArea; ///< area of stockable area (defined by project setup) |
180 | werner | 150 | StandStatistics mStatistics; ///< aggregate values on stand value |
281 | werner | 151 | ResourceUnitVariables mUnitVariables; |
92 | Werner | 152 | |
183 | werner | 153 | friend class RUWrapper; |
92 | Werner | 154 | }; |
155 | |||
863 | werner | 156 | |
200 | werner | 157 | #endif // RESOURCEUNIT_H |