Rev 779 | Rev 863 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | |||
671 | werner | 2 | /******************************************************************************************** |
3 | ** iLand - an individual based forest landscape and disturbance model |
||
4 | ** http://iland.boku.ac.at |
||
5 | ** Copyright (C) 2009- Werner Rammer, Rupert Seidl |
||
6 | ** |
||
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 |
||
9 | ** the Free Software Foundation, either version 3 of the License, or |
||
10 | ** (at your option) any later version. |
||
11 | ** |
||
12 | ** This program is distributed in the hope that it will be useful, |
||
13 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
14 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
15 | ** GNU General Public License for more details. |
||
16 | ** |
||
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/>. |
||
19 | ********************************************************************************************/ |
||
20 | |||
187 | iland | 21 | #ifndef RESOURCEUNIT_H |
22 | #define RESOURCEUNIT_H |
||
92 | Werner | 23 | |
24 | #include "tree.h" |
||
189 | iland | 25 | #include "resourceunitspecies.h" |
180 | werner | 26 | #include "standstatistics.h" |
293 | werner | 27 | #include <QtCore/QVector> |
28 | #include <QtCore/QRectF> |
||
92 | Werner | 29 | class SpeciesSet; |
208 | werner | 30 | class Climate; |
241 | werner | 31 | class WaterCycle; |
521 | werner | 32 | class Snag; |
526 | werner | 33 | class Soil; |
444 | werner | 34 | |
281 | werner | 35 | struct ResourceUnitVariables |
36 | { |
||
37 | double nitrogenAvailable; ///< nitrogen content (kg/m2/year) |
||
38 | }; |
||
92 | Werner | 39 | |
187 | iland | 40 | class ResourceUnit |
92 | Werner | 41 | { |
42 | public: |
||
187 | iland | 43 | ResourceUnit(const int index); |
241 | werner | 44 | ~ResourceUnit(); |
449 | werner | 45 | // setup/maintenance |
46 | void setup(); ///< setup operations after the creation of the model space. |
||
47 | void setSpeciesSet(SpeciesSet *set); |
||
48 | void setClimate(Climate* climate) { mClimate = climate; } |
||
451 | werner | 49 | void setBoundingBox(const QRectF &bb); |
569 | werner | 50 | void setID(const int id) { mID = id; } |
255 | werner | 51 | |
234 | werner | 52 | // access to elements |
255 | werner | 53 | const Climate *climate() const { return mClimate; } ///< link to the climate on this resource unit |
449 | werner | 54 | SpeciesSet *speciesSet() const { return mSpeciesSet; } ///< get SpeciesSet this RU links to. |
255 | werner | 55 | const WaterCycle *waterCycle() const { return mWater; } ///< water model of the unit |
521 | werner | 56 | Snag *snag() const { return mSnag; } ///< access the snag object |
526 | werner | 57 | Soil *soil() const { return mSoil; } ///< access the soil model |
58 | |||
255 | werner | 59 | ResourceUnitSpecies &resourceUnitSpecies(const Species *species); ///< get RU-Species-container of @p species from the RU |
720 | werner | 60 | const QList<ResourceUnitSpecies*> &ruSpecies() const { return mRUSpecies; } |
105 | Werner | 61 | QVector<Tree> &trees() { return mTrees; } ///< reference to the tree list. |
449 | werner | 62 | const QVector<Tree> &constTrees() const { return mTrees; } ///< reference to the (const) tree list. |
294 | werner | 63 | Tree *tree(const int index) { return &(mTrees[index]);} ///< get pointer to a tree |
281 | werner | 64 | const ResourceUnitVariables &resouceUnitVariables() const { return mUnitVariables; } ///< access to variables that are specific to resourceUnit (e.g. nitrogenAvailable) |
367 | werner | 65 | const StandStatistics &statistics() const {return mStatistics; } |
255 | werner | 66 | |
234 | werner | 67 | // properties |
255 | werner | 68 | int index() const { return mIndex; } |
569 | werner | 69 | int id() const { return mID; } |
255 | werner | 70 | const QRectF &boundingBox() const { return mBoundingBox; } |
487 | werner | 71 | const QPoint &cornerPointOffset() const { return mCornerCoord; } |
234 | werner | 72 | double area() const { return mPixelCount*100; } ///< get the resuorce unit area in m2 |
73 | double stockedArea() const { return mStockedArea; } ///< get the stocked area in m2 |
||
574 | werner | 74 | double stockableArea() const { return mStockableArea; } ///< total stockable area in m2 |
280 | werner | 75 | double productiveArea() const { return mEffectiveArea; } ///< TotalArea - Unstocked Area - loss due to BeerLambert (m2) |
575 | werner | 76 | double leafAreaIndex() const { return stockableArea()?mAggregatedLA / stockableArea():0.; } ///< Total Leaf Area Index |
376 | werner | 77 | double leafArea() const { return mAggregatedLA; } ///< total leaf area of resource unit (m2) |
449 | werner | 78 | double interceptedArea(const double LA, const double LightResponse) { return mEffectiveArea_perWLA * LA * LightResponse; } |
79 | const double &LRImodifier() const { return mLRI_modification; } |
||
80 | double averageAging() const { return mAverageAging; } ///< leaf area weighted average aging |
||
255 | werner | 81 | |
107 | Werner | 82 | // actions |
287 | werner | 83 | Tree &newTree(); ///< returns a modifiable reference to a free space inside the tree-vector. should be used for tree-init. |
84 | int newTreeIndex(); ///< returns the index of a newly inserted tree |
||
449 | werner | 85 | void cleanTreeList(); ///< remove dead trees from the tree storage. |
664 | werner | 86 | void treeDied() { mHasDeadTrees = true; } ///< sets the flag that indicates that the resource unit contains dead trees |
720 | werner | 87 | bool hasDiedTrees() const { return mHasDeadTrees; } ///< if true, the resource unit has dead trees and needs maybe some cleanup |
111 | Werner | 88 | /// addWLA() is called by each tree to aggregate the total weighted leaf area on a unit |
212 | werner | 89 | void addWLA(const float LA, const float LRI) { mAggregatedWLA += LA*LRI; mAggregatedLA += LA; } |
251 | werner | 90 | void addLR(const float LA, const float LightResponse) { mAggregatedLR += LA*LightResponse; } |
230 | werner | 91 | /// function that distributes effective interception area according to the weight of Light response and LeafArea of the indivudal (@sa production()) |
376 | werner | 92 | void calculateInterceptedArea(); |
93 | 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 | 94 | void addTreeAgingForAllTrees(); ///< calculate average tree aging for all trees of a RU. Used directly after stand initialization. |
449 | werner | 95 | // stocked area calculation |
96 | void countStockedPixel(bool pixelIsStocked) { mPixelCount++; if (pixelIsStocked) mStockedPixelCount++; } |
||
720 | werner | 97 | void createStandStatistics(); ///< helping function to create an initial state for stand statistics |
98 | void recreateStandStatistics(); ///< re-build stand statistics after some change happened to the resource unit |
||
574 | werner | 99 | void setStockableArea(const double area) { mStockableArea = area; } ///< set stockable area (m2) |
454 | werner | 100 | // sapling growth: the height map is per resource unit and holds the maximum height of saplings for each LIF-pixel and all species |
101 | // the map itself is a local variable and only filled temporarily. |
||
824 | werner | 102 | void setSaplingHeightMap(float *map_pointer); ///< set (temporal) storage for sapling-height-map |
600 | werner | 103 | /// returns maximum sapling height at point given by point-index (LIF-index). |
104 | /// you must call setSaplingHeightMap() with a valid map before. |
||
451 | werner | 105 | float saplingHeightAt(const QPoint &position) const { Q_ASSERT(mSaplingHeightMap); int pixel_index = cPxPerRU*(position.x()-mCornerCoord.x())+(position.y()-mCornerCoord.y()); return mSaplingHeightMap[pixel_index];} |
600 | werner | 106 | /// return maximum sapling height at point 'position' (LIF-index). This call is slower but works witout a prior call |
107 | /// to setSaplingHeightMap(). |
||
108 | float saplingHeightForInit(const QPoint &position) const; |
||
461 | werner | 109 | /// set the height of the sapling map to the maximum of current value and 'height'. |
110 | void setMaxSaplingHeightAt(const QPoint &position, const float height); |
||
111 | /// clear all saplings of all species on a given position (after recruitment) |
||
112 | void clearSaplings(const QPoint &position); |
||
662 | werner | 113 | /// kill all saplings within a given rect |
114 | void clearSaplings(const QRectF pixel_rect, const bool remove_from_soil); |
||
521 | werner | 115 | // snag / snag dynamics |
116 | // snag dynamics, soil carbon and nitrogen cycle |
||
117 | void snagNewYear() { if (snag()) snag()->newYear(); } ///< clean transfer pools |
||
526 | werner | 118 | void calculateCarbonCycle(); ///< calculate snag dynamics at the end of a year |
111 | Werner | 119 | // model flow |
107 | Werner | 120 | void newYear(); ///< reset values for a new simulation year |
376 | werner | 121 | // LIP/LIF-cylcle -> Model |
122 | void production(); ///< called after the LIP/LIF calc, before growth of individual trees. Production (3PG), Water-cycle |
||
123 | void beforeGrow(); ///< called before growth of individuals |
||
124 | // the growth of individuals -> Model |
||
125 | void afterGrow(); ///< called after the growth of individuals |
||
126 | void yearEnd(); ///< called at the end of a year (after regeneration??) |
||
107 | Werner | 127 | |
92 | Werner | 128 | private: |
569 | werner | 129 | int mIndex; ///< internal index |
130 | int mID; ///< ID provided by external stand grid |
||
664 | werner | 131 | bool mHasDeadTrees; ///< flag that indicates if currently dead trees are in the tree list |
208 | werner | 132 | Climate *mClimate; ///< pointer to the climate object of this RU |
92 | Werner | 133 | SpeciesSet *mSpeciesSet; ///< pointer to the species set for this RU |
241 | werner | 134 | WaterCycle *mWater; ///< link to the Soil water calculation engine |
521 | werner | 135 | Snag *mSnag; ///< ptr to snag storage / dynamics |
526 | werner | 136 | Soil *mSoil; ///< ptr to CN dynamics soil submodel |
455 | werner | 137 | QList<ResourceUnitSpecies*> mRUSpecies; ///< data for this ressource unit per species |
92 | Werner | 138 | QVector<Tree> mTrees; ///< storage container for tree individuals |
105 | Werner | 139 | QRectF mBoundingBox; ///< bounding box (metric) of the RU |
451 | werner | 140 | QPoint mCornerCoord; ///< coordinates on the LIF grid of the upper left corner of the RU |
251 | werner | 141 | double mAggregatedLA; ///< sum of leafArea |
142 | double mAggregatedWLA; ///< sum of lightResponse * LeafArea for all trees |
||
143 | double mAggregatedLR; ///< sum of lightresponse*LA of the current unit |
||
144 | double mEffectiveArea; ///< total "effective" area per resource unit, i.e. area of RU - non-stocked - beerLambert-loss |
||
230 | werner | 145 | double mEffectiveArea_perWLA; ///< |
251 | werner | 146 | double mLRI_modification; |
376 | werner | 147 | double mAverageAging; ///< leaf-area weighted average aging f this species on this RU. |
451 | werner | 148 | float *mSaplingHeightMap; ///< pointer to array that holds max-height for each 2x2m pixel. Note: this information is not persistent |
230 | werner | 149 | |
151 | iland | 150 | int mPixelCount; ///< count of (Heightgrid) pixels thare are inside the RU |
151 | int mStockedPixelCount; ///< count of pixels that are stocked with trees |
||
234 | werner | 152 | double mStockedArea; ///< size of stocked area |
574 | werner | 153 | double mStockableArea; ///< area of stockable area (defined by project setup) |
180 | werner | 154 | StandStatistics mStatistics; ///< aggregate values on stand value |
281 | werner | 155 | ResourceUnitVariables mUnitVariables; |
92 | Werner | 156 | |
183 | werner | 157 | friend class RUWrapper; |
92 | Werner | 158 | }; |
159 | |||
200 | werner | 160 | #endif // RESOURCEUNIT_H |