Subversion Repositories public iLand

Rev

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