Subversion Repositories public iLand

Rev

Rev 454 | Rev 461 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 454 Rev 455
Line 23... Line 23...
23
        delete mWater;
23
        delete mWater;
24
}
24
}
25
25
26
ResourceUnit::ResourceUnit(const int index)
26
ResourceUnit::ResourceUnit(const int index)
27
{
27
{
-
 
28
    qDeleteAll(mRUSpecies);
28
    mSpeciesSet = 0;
29
    mSpeciesSet = 0;
29
    mClimate = 0;
30
    mClimate = 0;
30
    mPixelCount=0;
31
    mPixelCount=0;
31
    mStockedArea = 0;
32
    mStockedArea = 0;
32
    mStockedPixelCount = 0;
33
    mStockedPixelCount = 0;
Line 53... Line 54...
53
54
54
/// set species and setup the species-per-RU-data
55
/// set species and setup the species-per-RU-data
55
void ResourceUnit::setSpeciesSet(SpeciesSet *set)
56
void ResourceUnit::setSpeciesSet(SpeciesSet *set)
56
{
57
{
57
    mSpeciesSet = set;
58
    mSpeciesSet = set;
58
    mRUSpecies.clear();
-
 
59
    mRUSpecies.resize(set->count()); // ensure that the vector space is not relocated
-
 
-
 
59
    qDeleteAll(mRUSpecies);
-
 
60
-
 
61
    //mRUSpecies.resize(set->count()); // ensure that the vector space is not relocated
60
    for (int i=0;i<set->count();i++) {
62
    for (int i=0;i<set->count();i++) {
61
        Species *s = const_cast<Species*>(mSpeciesSet->species(i));
63
        Species *s = const_cast<Species*>(mSpeciesSet->species(i));
62
        if (!s)
64
        if (!s)
63
            throw IException("ResourceUnit::setSpeciesSet: invalid index!");
65
            throw IException("ResourceUnit::setSpeciesSet: invalid index!");
64
66
-
 
67
        ResourceUnitSpecies *rus = new ResourceUnitSpecies();
-
 
68
        mRUSpecies.push_back(rus);
-
 
69
        rus->setup(s, this);
65
        /* be careful: setup() is called with a pointer somewhere to the content of the mRUSpecies container.
70
        /* be careful: setup() is called with a pointer somewhere to the content of the mRUSpecies container.
66
           If the container memory is relocated (QVector), the pointer gets invalid!!!
71
           If the container memory is relocated (QVector), the pointer gets invalid!!!
67
           Therefore, a resize() is called before the loop (no resize()-operations during the loop)! */
72
           Therefore, a resize() is called before the loop (no resize()-operations during the loop)! */
68
        mRUSpecies[i].setup(s,this); // setup this element
-
 
-
 
73
        //mRUSpecies[i].setup(s,this); // setup this element
69
74
70
    }
75
    }
71
}
76
}
72
77
73
ResourceUnitSpecies &ResourceUnit::resourceUnitSpecies(const Species *species)
78
ResourceUnitSpecies &ResourceUnit::resourceUnitSpecies(const Species *species)
74
{
79
{
75
    return mRUSpecies[species->index()];
-
 
-
 
80
    return *mRUSpecies[species->index()];
76
}
81
}
77
82
78
Tree &ResourceUnit::newTree()
83
Tree &ResourceUnit::newTree()
79
{
84
{
80
    // start simple: just append to the vector...
85
    // start simple: just append to the vector...
Line 130... Line 135...
130
    mAggregatedLA = 0.;
135
    mAggregatedLA = 0.;
131
    mAggregatedLR = 0.;
136
    mAggregatedLR = 0.;
132
    mEffectiveArea = 0.;
137
    mEffectiveArea = 0.;
133
    mPixelCount = mStockedPixelCount = 0;
138
    mPixelCount = mStockedPixelCount = 0;
134
    // clear statistics global and per species...
139
    // clear statistics global and per species...
135
    ResourceUnitSpecies *i;
-
 
136
    QVector<ResourceUnitSpecies>::iterator iend = mRUSpecies.end();
-
 
-
 
140
    QList<ResourceUnitSpecies*>::const_iterator i;
-
 
141
    QList<ResourceUnitSpecies*>::const_iterator iend = mRUSpecies.constEnd();
137
    mStatistics.clear();
142
    mStatistics.clear();
138
    for (i=mRUSpecies.begin(); i!=iend; ++i) {
-
 
139
        i->statisticsDead().clear();
-
 
140
        i->statisticsMgmt().clear();
-
 
-
 
143
    for (i=mRUSpecies.constBegin(); i!=iend; ++i) {
-
 
144
        (*i)->statisticsDead().clear();
-
 
145
        (*i)->statisticsMgmt().clear();
141
    }
146
    }
142
147
143
}
148
}
144
149
145
/** production() is the "stand-level" part of the biomass production (3PG).
150
/** production() is the "stand-level" part of the biomass production (3PG).
Line 178... Line 183...
178
            .arg(mLRI_modification)
183
            .arg(mLRI_modification)
179
            .arg(mStockedArea);
184
            .arg(mStockedArea);
180
    );
185
    );
181
186
182
    // calculate LAI fractions
187
    // calculate LAI fractions
183
    ResourceUnitSpecies *i;
-
 
184
    QVector<ResourceUnitSpecies>::iterator iend = mRUSpecies.end();
-
 
185
    for (i=mRUSpecies.begin(); i!=iend; ++i) {
-
 
186
         i->setLAIfactor(i->statistics().leafAreaIndex() / leafAreaIndex());
-
 
-
 
188
    QList<ResourceUnitSpecies*>::const_iterator i;
-
 
189
    QList<ResourceUnitSpecies*>::const_iterator iend = mRUSpecies.constEnd();
-
 
190
    for (i=mRUSpecies.constBegin(); i!=iend; ++i) {
-
 
191
         (*i)->setLAIfactor((*i)->statistics().leafAreaIndex() / leafAreaIndex());
187
    }
192
    }
188
193
189
    // soil water model - this determines soil water contents needed for response calculations
194
    // soil water model - this determines soil water contents needed for response calculations
190
    {
195
    {
191
    DebugTimer tw("water:run");
196
    DebugTimer tw("water:run");
192
    mWater->run();
197
    mWater->run();
193
    }
198
    }
194
199
195
    // invoke species specific calculation (3PG)
200
    // invoke species specific calculation (3PG)
196
    for (i=mRUSpecies.begin(); i!=iend; ++i) {
-
 
197
        i->calculate();
-
 
198
        if (logLevelInfo() &&  i->LAIfactor()>0)
-
 
199
            qDebug() << "ru" << mIndex << "species" << (*i).species()->id() << "LAIfraction" << i->LAIfactor() << "raw_gpp_m2"
-
 
200
                     << i->prod3PG().GPPperArea() << "area:" << productiveArea() << "gpp:"
-
 
201
                     << productiveArea()*i->prod3PG().GPPperArea()
-
 
202
                     << "aging(lastyear):" << averageAging() << "f_env,yr:" << i->prod3PG().fEnvYear();
-
 
-
 
201
    for (i=mRUSpecies.constBegin(); i!=iend; ++i) {
-
 
202
        (*i)->calculate();
-
 
203
        if (logLevelInfo() &&  (*i)->LAIfactor()>0)
-
 
204
            qDebug() << "ru" << mIndex << "species" << (*i)->species()->id() << "LAIfraction" << (*i)->LAIfactor() << "raw_gpp_m2"
-
 
205
                     << (*i)->prod3PG().GPPperArea() << "area:" << productiveArea() << "gpp:"
-
 
206
                     << productiveArea()*(*i)->prod3PG().GPPperArea()
-
 
207
                     << "aging(lastyear):" << averageAging() << "f_env,yr:" << (*i)->prod3PG().fEnvYear();
203
    }
208
    }
204
}
209
}
205
210
206
void ResourceUnit::calculateInterceptedArea()
211
void ResourceUnit::calculateInterceptedArea()
207
{
212
{
Line 231... Line 236...
231
void ResourceUnit::yearEnd()
236
void ResourceUnit::yearEnd()
232
{
237
{
233
    // calculate statistics for all tree species of the ressource unit
238
    // calculate statistics for all tree species of the ressource unit
234
    int c = mRUSpecies.count();
239
    int c = mRUSpecies.count();
235
    for (int i=0;i<c; i++) {
240
    for (int i=0;i<c; i++) {
236
        mRUSpecies[i].statisticsDead().calculate(); // calculate the dead trees
-
 
237
        mRUSpecies[i].statisticsMgmt().calculate(); // stats of removed trees
-
 
238
        mRUSpecies[i].updateGWL(); // get sum of dead trees (died + removed)
-
 
239
        mRUSpecies[i].statistics().calculate(); // calculate the living (and add removed volume to gwl)
-
 
240
        mStatistics.add(mRUSpecies[i].statistics());
-
 
-
 
241
        mRUSpecies[i]->statisticsDead().calculate(); // calculate the dead trees
-
 
242
        mRUSpecies[i]->statisticsMgmt().calculate(); // stats of removed trees
-
 
243
        mRUSpecies[i]->updateGWL(); // get sum of dead trees (died + removed)
-
 
244
        mRUSpecies[i]->statistics().calculate(); // calculate the living (and add removed volume to gwl)
-
 
245
        mStatistics.add(mRUSpecies[i]->statistics());
241
    }
246
    }
242
    mStatistics.calculate(); // aggreagte on stand level
247
    mStatistics.calculate(); // aggreagte on stand level
243
}
248
}
244
249
245
/// refresh of tree based statistics.
250
/// refresh of tree based statistics.
246
void ResourceUnit::createStandStatistics()
251
void ResourceUnit::createStandStatistics()
247
{
252
{
248
    // clear statistics (ru-level and ru-species level)
253
    // clear statistics (ru-level and ru-species level)
249
    mStatistics.clear();
254
    mStatistics.clear();
250
    for (int i=0;i<mRUSpecies.count();i++) {
255
    for (int i=0;i<mRUSpecies.count();i++) {
251
        mRUSpecies[i].statistics().clear();
-
 
252
        mRUSpecies[i].statisticsDead().clear();
-
 
253
        mRUSpecies[i].statisticsMgmt().clear();
-
 
-
 
256
        mRUSpecies[i]->statistics().clear();
-
 
257
        mRUSpecies[i]->statisticsDead().clear();
-
 
258
        mRUSpecies[i]->statisticsMgmt().clear();
254
    }
259
    }
255
260
256
    // add all trees to the statistics objects of the species
261
    // add all trees to the statistics objects of the species
257
    foreach(const Tree &t, mTrees) {
262
    foreach(const Tree &t, mTrees) {
258
        if (!t.isDead())
263
        if (!t.isDead())
259
            resourceUnitSpecies(t.species()).statistics().add(&t, 0);
264
            resourceUnitSpecies(t.species()).statistics().add(&t, 0);
260
    }
265
    }
261
    // summarize statistics for the whole resource unit
266
    // summarize statistics for the whole resource unit
262
    for (int i=0;i<mRUSpecies.count();i++) {
267
    for (int i=0;i<mRUSpecies.count();i++) {
263
        mRUSpecies[i].statistics().calculate();
-
 
264
        mStatistics.add(mRUSpecies[i].statistics());
-
 
-
 
268
        mRUSpecies[i]->statistics().calculate();
-
 
269
        mStatistics.add(mRUSpecies[i]->statistics());
265
    }
270
    }
266
    mStatistics.calculate();
271
    mStatistics.calculate();
267
    mAverageAging = mStatistics.leafAreaIndex()>0.?mAverageAging / (mStatistics.leafAreaIndex()*area()):0.;
272
    mAverageAging = mStatistics.leafAreaIndex()>0.?mAverageAging / (mStatistics.leafAreaIndex()*area()):0.;
268
}
273
}
269
274
Line 278... Line 283...
278
}
283
}
279
284
280
/// clear all saplings of all species on a given position (after recruitment)
285
/// clear all saplings of all species on a given position (after recruitment)
281
void ResourceUnit::clearSaplings(const QPoint &position)
286
void ResourceUnit::clearSaplings(const QPoint &position)
282
{
287
{
283
    for (QVector<ResourceUnitSpecies>::const_iterator i=mRUSpecies.constBegin(); i!=mRUSpecies.constEnd(); ++i)
-
 
284
        i->clearSaplings(position);
-
 
-
 
288
    foreach(ResourceUnitSpecies* rus, mRUSpecies)
-
 
289
        rus->clearSaplings(position);
285
290
286
}
291
}
287
292