Subversion Repositories public iLand

Rev

Rev 605 | Rev 639 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1
 
111 Werner 2
#include "global.h"
189 iland 3
#include "resourceunitspecies.h"
111 Werner 4
 
5
#include "species.h"
189 iland 6
#include "resourceunit.h"
468 werner 7
#include "model.h"
496 werner 8
#include "watercycle.h"
626 werner 9
#include "helper.h"
376 werner 10
 
458 werner 11
/** @class ResourceUnitSpecies
12
    The class contains data available at ResourceUnit x Species scale.
13
    Data stored is either statistical (i.e. number of trees per species) or used
468 werner 14
    within the model (e.g. fraction of utilizable Radiation).
15
    Important submodules are:
16
    * 3PG production (Production3PG)
17
    * Establishment
18
    * Growth and Recruitment of Saplings
19
    * Snag dynamics
458 werner 20
  */
468 werner 21
ResourceUnitSpecies::~ResourceUnitSpecies()
22
{
23
}
440 werner 24
 
376 werner 25
double ResourceUnitSpecies::leafArea() const
26
{
27
    // Leaf area of the species:
28
    // total leaf area on the RU * fraction of leafarea
29
    return mLAIfactor * ru()->leafAreaIndex();
30
}
31
 
235 werner 32
void ResourceUnitSpecies::setup(Species *species, ResourceUnit *ru)
33
{
34
    mSpecies = species;
35
    mRU = ru;
36
    mResponse.setup(this);
37
    m3PG.setResponse(&mResponse);
440 werner 38
    mEstablishment.setup(ru->climate(), this);
452 werner 39
    mSapling.setup(this);
235 werner 40
    mStatistics.setResourceUnitSpecies(this);
277 werner 41
    mStatisticsDead.setResourceUnitSpecies(this);
278 werner 42
    mStatisticsMgmt.setResourceUnitSpecies(this);
440 werner 43
 
277 werner 44
    mRemovedGrowth = 0.;
438 werner 45
    mLastYear = -1;
468 werner 46
 
235 werner 47
}
111 Werner 48
 
49
 
440 werner 50
void ResourceUnitSpecies::calculate(const bool fromEstablishment)
226 werner 51
{
438 werner 52
    if (mLastYear == GlobalSettings::instance()->currentYear())
53
        return;
54
 
518 werner 55
    // the call *not* from establishment
56
    if (!fromEstablishment)
57
        statistics().clear();
513 werner 58
 
440 werner 59
    if (mLAIfactor>0 || fromEstablishment==true) {
496 werner 60
        // execute the water calculation...
61
        if (fromEstablishment)
62
            const_cast<WaterCycle*>(mRU->waterCycle())->run(); // run the water sub model (only if this has not be done already)
626 werner 63
        DebugTimer rst("response+3pg");
496 werner 64
        mResponse.calculate();// calculate environmental responses per species (vpd, temperature, ...)
65
        m3PG.calculate();// production of NPP
513 werner 66
        mLastYear = GlobalSettings::instance()->currentYear(); // mark this year as processed
369 werner 67
    } else {
68
        // if no LAI is present, then just clear the respones.
69
        mResponse.clear();
70
        m3PG.clear();
71
    }
226 werner 72
}
277 werner 73
 
74
 
75
void ResourceUnitSpecies::updateGWL()
76
{
77
    // removed growth is the running sum of all removed
78
    // tree volume. the current "GWL" therefore is current volume (standing) + mRemovedGrowth.
278 werner 79
    mRemovedGrowth+=statisticsDead().volume() + statisticsMgmt().volume();
277 werner 80
}
440 werner 81
 
82
void ResourceUnitSpecies::calclulateEstablishment()
83
{
84
    mEstablishment.calculate();
442 werner 85
    //DBGMODE(
86
        if (GlobalSettings::instance()->isDebugEnabled(GlobalSettings::dEstablishment)) {
87
            DebugList &out = GlobalSettings::instance()->debugList(ru()->index(), GlobalSettings::dEstablishment);
88
            // establishment details
605 werner 89
            out << mSpecies->id() << ru()->index() << ru()->id();
442 werner 90
            out << mEstablishment.avgSeedDensity();
91
            out << mEstablishment.TACAminTemp() << mEstablishment.TACAchill() << mEstablishment.TACAfrostFree() << mEstablishment.TACgdd();
92
            out << mEstablishment.TACAfrostDaysAfterBudBirst() << mEstablishment.abioticEnvironment();
93
            out << m3PG.fEnvYear() << mEstablishment.avgLIFValue() << mEstablishment.numberEstablished();
466 werner 94
            out << mSapling.livingSaplings() << mSapling.averageHeight() << mSapling.averageAge() << mSapling.averageDeltaHPot() << mSapling.averageDeltaHRealized();
471 werner 95
            out << mSapling.newSaplings() << mSapling.diedSaplings() << mSapling.recruitedSaplings() << mSpecies->saplingGrowthParameters().referenceRatio;
442 werner 96
        }
97
    //); // DBGMODE()
440 werner 98
 
442 werner 99
 
440 werner 100
    if ( logLevelDebug() )
101
        qDebug() << "establishment of RU" << mRU->index() << "species" << species()->id()
102
        << "seeds density:" << mEstablishment.avgSeedDensity()
103
        << "abiotic environment:" << mEstablishment.abioticEnvironment()
104
        << "f_env,yr:" << m3PG.fEnvYear()
105
        << "N(established):" << mEstablishment.numberEstablished();
106
 
107
}
450 werner 108
 
109
void ResourceUnitSpecies::calclulateSaplingGrowth()
110
{
111
    mSapling.calculateGrowth();
112
}
453 werner 113
 
114
void ResourceUnitSpecies::visualGrid(Grid<float> &grid) const
115
{
564 werner 116
    mSapling.fillMaxHeightGrid(grid);
453 werner 117
}
462 werner 118
 
475 werner 119