Rev 1221 | 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 | |||
248 | werner | 21 | /** @class StandStatistics |
697 | werner | 22 | @ingroup tools |
248 | werner | 23 | Collects information on stand level for each tree species. |
180 | werner | 24 | Call clear() to clear the statistics, then call add() for each tree and finally calculate(). |
25 | To aggregate on a higher level, use add() for each StandStatistics object to include, and then |
||
26 | calculate() on the higher level. |
||
234 | werner | 27 | Todo-List for new items: |
28 | - add a member variable and a getter |
||
29 | - add to "add(Tree)" and "calculate()" |
||
30 | - add to "add(StandStatistics)" as well! |
||
180 | werner | 31 | */ |
32 | #include "standstatistics.h" |
||
33 | #include "tree.h" |
||
234 | werner | 34 | #include "resourceunit.h" |
35 | #include "resourceunitspecies.h" |
||
1163 | werner | 36 | //#include "sapling.h" |
1158 | werner | 37 | #include "saplings.h" |
587 | werner | 38 | #include "species.h" |
180 | werner | 39 | |
40 | void StandStatistics::clear() |
||
41 | { |
||
42 | // reset all values |
||
43 | mCount = 0; |
||
44 | mSumDbh=mSumHeight = mAverageDbh=mAverageHeight =0.; |
||
277 | werner | 45 | mSumBasalArea = mSumVolume = mGWL = 0.; |
240 | werner | 46 | mLeafAreaIndex = 0.; |
261 | werner | 47 | mNPP = mNPPabove = 0.; |
1157 | werner | 48 | mNPPsaplings = 0.; |
453 | werner | 49 | mCohortCount = mSaplingCount = 0; |
454 | werner | 50 | mAverageSaplingAge = 0.; |
51 | mSumSaplingAge = 0.; |
||
587 | werner | 52 | mCStem=0., mCFoliage=0., mCBranch=0., mCCoarseRoot=0., mCFineRoot=0.; |
53 | mNStem=0., mNFoliage=0., mNBranch=0., mNCoarseRoot=0., mNFineRoot=0.; |
||
54 | mCRegeneration=0., mNRegeneration=0.; |
||
55 | |||
180 | werner | 56 | } |
57 | |||
1202 | werner | 58 | void StandStatistics::clearOnlyTrees() |
59 | { |
||
60 | // reset only those values that are directly accumulated from trees |
||
61 | mCount = 0; |
||
62 | mSumDbh=mSumHeight = mAverageDbh=mAverageHeight =0.; |
||
63 | mSumBasalArea = mSumVolume = mGWL = 0.; |
||
64 | mLeafAreaIndex = 0.; |
||
65 | /*mNPP = mNPPabove = 0.; |
||
66 | mNPPsaplings = 0.; |
||
67 | mCohortCount = mSaplingCount = 0; |
||
68 | mAverageSaplingAge = 0.; |
||
69 | mSumSaplingAge = 0.;*/ |
||
70 | mCStem=0., mCFoliage=0., mCBranch=0., mCCoarseRoot=0., mCFineRoot=0.; |
||
71 | mNStem=0., mNFoliage=0., mNBranch=0., mNCoarseRoot=0., mNFineRoot=0.; |
||
72 | /*mCRegeneration=0., mNRegeneration=0.;*/ |
||
73 | |||
74 | } |
||
75 | |||
587 | werner | 76 | void StandStatistics::addBiomass(const double biomass, const double CNRatio, double *C, double *N) |
77 | { |
||
78 | *C+=biomass*biomassCFraction; |
||
79 | *N+=biomass*biomassCFraction/CNRatio; |
||
80 | } |
||
81 | |||
257 | werner | 82 | void StandStatistics::add(const Tree *tree, const TreeGrowthData *tgd) |
180 | werner | 83 | { |
84 | mCount++; |
||
85 | mSumDbh+=tree->dbh(); |
||
86 | mSumHeight+=tree->height(); |
||
87 | mSumBasalArea+=tree->basalArea(); |
||
88 | mSumVolume += tree->volume(); |
||
234 | werner | 89 | mLeafAreaIndex += tree->leafArea(); // warning: sum of leafarea! |
257 | werner | 90 | if (tgd) { |
91 | mNPP += tgd->NPP; |
||
261 | werner | 92 | mNPPabove += tgd->NPP_above; |
257 | werner | 93 | } |
587 | werner | 94 | // carbon and nitrogen pools |
95 | addBiomass(tree->biomassStem(), tree->species()->cnWood(), &mCStem, &mNStem); |
||
96 | addBiomass(tree->biomassBranch(), tree->species()->cnWood(), &mCBranch, &mNBranch); |
||
97 | addBiomass(tree->biomassFoliage(), tree->species()->cnFoliage(), &mCFoliage, &mNFoliage); |
||
98 | addBiomass(tree->biomassFineRoot(), tree->species()->cnFineroot(), &mCFineRoot, &mNFineRoot); |
||
99 | addBiomass(tree->biomassCoarseRoot(), tree->species()->cnWood(), &mCCoarseRoot, &mNCoarseRoot); |
||
180 | werner | 100 | } |
101 | |||
277 | werner | 102 | // note: mRUS = 0 for aggregated statistics |
180 | werner | 103 | void StandStatistics::calculate() |
104 | { |
||
1102 | werner | 105 | if (mCount>0.) { |
106 | mAverageDbh = mSumDbh / mCount; |
||
107 | mAverageHeight = mSumHeight / mCount; |
||
575 | werner | 108 | if (mRUS && mRUS->ru()->stockableArea()>0.) |
109 | mLeafAreaIndex /= mRUS->ru()->stockableArea(); // convert from leafarea to LAI |
||
180 | werner | 110 | } |
454 | werner | 111 | if (mCohortCount) |
112 | mAverageSaplingAge = mSumSaplingAge / double(mCohortCount); |
||
113 | |||
277 | werner | 114 | // scale values to per hectare if resource unit <> 1ha |
1157 | werner | 115 | // note: do this only on species-level (avoid double scaling) |
277 | werner | 116 | if (mRUS) { |
1157 | werner | 117 | double area_factor = cRUArea / mRUS->ru()->stockableArea(); |
277 | werner | 118 | if (area_factor!=1.) { |
855 | werner | 119 | mCount = mCount * area_factor; |
277 | werner | 120 | mSumBasalArea *= area_factor; |
121 | mSumVolume *= area_factor; |
||
1157 | werner | 122 | mSumDbh *= area_factor; |
277 | werner | 123 | mNPP *= area_factor; |
124 | mNPPabove *= area_factor; |
||
1157 | werner | 125 | mNPPsaplings *= area_factor; |
936 | werner | 126 | //mGWL *= area_factor; |
453 | werner | 127 | mCohortCount *= area_factor; |
128 | mSaplingCount *= area_factor; |
||
1157 | werner | 129 | //double mCStem, mCFoliage, mCBranch, mCCoarseRoot, mCFineRoot; |
130 | //double mNStem, mNFoliage, mNBranch, mNCoarseRoot, mNFineRoot; |
||
131 | //double mCRegeneration, mNRegeneration; |
||
132 | mCStem *= area_factor; mNStem *= area_factor; |
||
133 | mCFoliage *= area_factor; mNFoliage *= area_factor; |
||
134 | mCBranch *= area_factor; mNBranch *= area_factor; |
||
135 | mCCoarseRoot *= area_factor; mNCoarseRoot *= area_factor; |
||
136 | mCFineRoot *= area_factor; mNFineRoot *= area_factor; |
||
137 | mCRegeneration *= area_factor; mNRegeneration *= area_factor; |
||
138 | |||
277 | werner | 139 | } |
936 | werner | 140 | mGWL = mSumVolume + mRUS->removedVolume(); // removedVolume: per ha, SumVolume now too |
277 | werner | 141 | } |
180 | werner | 142 | } |
143 | |||
144 | void StandStatistics::add(const StandStatistics &stat) |
||
145 | { |
||
146 | mCount+=stat.mCount; |
||
147 | mSumBasalArea+=stat.mSumBasalArea; |
||
148 | mSumDbh+=stat.mSumDbh; |
||
149 | mSumHeight+=stat.mSumHeight; |
||
150 | mSumVolume+=stat.mSumVolume; |
||
234 | werner | 151 | mLeafAreaIndex += stat.mLeafAreaIndex; |
257 | werner | 152 | mNPP += stat.mNPP; |
261 | werner | 153 | mNPPabove += stat.mNPPabove; |
1157 | werner | 154 | mNPPsaplings += stat.mNPPsaplings; |
277 | werner | 155 | mGWL+=stat.mGWL; |
466 | werner | 156 | // regeneration |
453 | werner | 157 | mCohortCount += stat.mCohortCount; |
158 | mSaplingCount += stat.mSaplingCount; |
||
454 | werner | 159 | mSumSaplingAge += stat.mSumSaplingAge; |
587 | werner | 160 | // carbon/nitrogen pools |
161 | mCStem += stat.mCStem; mNStem += stat.mNStem; |
||
162 | mCBranch += stat.mCBranch; mNBranch += stat.mNBranch; |
||
163 | mCFoliage += stat.mCFoliage; mNFoliage += stat.mNFoliage; |
||
164 | mCFineRoot += stat.mCFineRoot; mNFineRoot += stat.mNFineRoot; |
||
165 | mCCoarseRoot += stat.mCCoarseRoot; mNCoarseRoot += stat.mNCoarseRoot; |
||
166 | mCRegeneration += stat.mCRegeneration; mNRegeneration += stat.mNRegeneration; |
||
466 | werner | 167 | |
180 | werner | 168 | } |
453 | werner | 169 | |
837 | werner | 170 | void StandStatistics::addAreaWeighted(const StandStatistics &stat, const double weight) |
171 | { |
||
1157 | werner | 172 | // aggregates that are not scaled to hectares |
837 | werner | 173 | mCount+=stat.mCount * weight; |
174 | mSumBasalArea+=stat.mSumBasalArea * weight; |
||
175 | mSumDbh+=stat.mSumDbh * weight; |
||
176 | mSumHeight+=stat.mSumHeight * weight; |
||
177 | mSumVolume+=stat.mSumVolume * weight; |
||
1157 | werner | 178 | // averages that are scaled to per hectare need to be scaled |
855 | werner | 179 | mAverageDbh+=stat.mAverageDbh * weight; |
180 | mAverageHeight+=stat.mAverageHeight * weight; |
||
181 | mAverageSaplingAge+=stat.mAverageSaplingAge * weight; |
||
837 | werner | 182 | mLeafAreaIndex += stat.mLeafAreaIndex * weight; |
1157 | werner | 183 | |
837 | werner | 184 | mNPP += stat.mNPP * weight; |
185 | mNPPabove += stat.mNPPabove * weight; |
||
1157 | werner | 186 | mNPPsaplings += stat.mNPPsaplings * weight; |
837 | werner | 187 | mGWL+=stat.mGWL * weight; |
188 | // regeneration |
||
189 | mCohortCount += stat.mCohortCount * weight; |
||
190 | mSaplingCount += stat.mSaplingCount * weight; |
||
191 | mSumSaplingAge += stat.mSumSaplingAge * weight; |
||
192 | // carbon/nitrogen pools |
||
193 | mCStem += stat.mCStem * weight; mNStem += stat.mNStem * weight; |
||
194 | mCBranch += stat.mCBranch * weight; mNBranch += stat.mNBranch * weight; |
||
195 | mCFoliage += stat.mCFoliage * weight; mNFoliage += stat.mNFoliage * weight; |
||
196 | mCFineRoot += stat.mCFineRoot * weight; mNFineRoot += stat.mNFineRoot * weight; |
||
197 | mCCoarseRoot += stat.mCCoarseRoot * weight; mNCoarseRoot += stat.mNCoarseRoot * weight; |
||
198 | mCRegeneration += stat.mCRegeneration * weight; mNRegeneration += stat.mNRegeneration * weight; |
||
199 | |||
200 | } |
||
201 | |||
504 | werner | 202 | |
587 | werner | 203 | |
1158 | werner | 204 | void StandStatistics::add(const SaplingStat *sapling) |
205 | { |
||
1177 | werner | 206 | mCohortCount += sapling->livingCohorts(); |
207 | mSaplingCount += sapling->livingSaplings(); // saplings with height >1.3m |
||
1158 | werner | 208 | |
1177 | werner | 209 | mSumSaplingAge += sapling->averageAge() * sapling->livingCohorts(); |
1158 | werner | 210 | |
211 | mCRegeneration += sapling->carbonLiving().C; |
||
212 | mNRegeneration += sapling->carbonLiving().N; |
||
213 | |||
214 | mNPPsaplings += sapling->carbonGain().C / biomassCFraction; |
||
215 | |||
216 | } |
||
217 | |||
615 | werner | 218 | void SystemStatistics::writeOutput() |
219 | { |
||
220 | if (GlobalSettings::instance()->isDebugEnabled(GlobalSettings::dPerformance)) { |
||
221 | DebugList &out = GlobalSettings::instance()->debugList(0, GlobalSettings::dPerformance); |
||
222 | out << treeCount << saplingCount << newSaplings << tManagement |
||
223 | << tApplyPattern << tReadPattern << tTreeGrowth |
||
1158 | werner | 224 | << tSeedDistribution << tEstablishment << tSapling |
615 | werner | 225 | << tCarbonCycle << tWriteOutput << tTotalYear; |
226 | } |
||
227 | } |
||
228 | |||
229 |