Subversion Repositories public iLand

Rev

Rev 513 | Rev 521 | 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"
8
#include "snag.h"
496 werner 9
#include "watercycle.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
    if (mSnag)
24
        delete mSnag;
25
    mSnag = 0;
26
}
440 werner 27
 
376 werner 28
double ResourceUnitSpecies::leafArea() const
29
{
30
    // Leaf area of the species:
31
    // total leaf area on the RU * fraction of leafarea
32
    return mLAIfactor * ru()->leafAreaIndex();
33
}
34
 
235 werner 35
void ResourceUnitSpecies::setup(Species *species, ResourceUnit *ru)
36
{
37
    mSpecies = species;
38
    mRU = ru;
39
    mResponse.setup(this);
40
    m3PG.setResponse(&mResponse);
440 werner 41
    mEstablishment.setup(ru->climate(), this);
452 werner 42
    mSapling.setup(this);
235 werner 43
    mStatistics.setResourceUnitSpecies(this);
277 werner 44
    mStatisticsDead.setResourceUnitSpecies(this);
278 werner 45
    mStatisticsMgmt.setResourceUnitSpecies(this);
468 werner 46
    if (mSnag)
47
        delete mSnag;
48
    mSnag=0;
49
    if (Model::settings().carbonCycleEnabled) {
50
       mSnag = new Snag;
490 werner 51
       mSnag->setup(mRU);
468 werner 52
    }
440 werner 53
 
277 werner 54
    mRemovedGrowth = 0.;
438 werner 55
    mLastYear = -1;
468 werner 56
 
235 werner 57
}
111 Werner 58
 
59
 
440 werner 60
void ResourceUnitSpecies::calculate(const bool fromEstablishment)
226 werner 61
{
438 werner 62
    if (mLastYear == GlobalSettings::instance()->currentYear())
63
        return;
64
 
518 werner 65
    // the call *not* from establishment
66
    if (!fromEstablishment)
67
        statistics().clear();
513 werner 68
 
440 werner 69
    if (mLAIfactor>0 || fromEstablishment==true) {
496 werner 70
        // execute the water calculation...
71
        if (fromEstablishment)
72
            const_cast<WaterCycle*>(mRU->waterCycle())->run(); // run the water sub model (only if this has not be done already)
73
        mResponse.calculate();// calculate environmental responses per species (vpd, temperature, ...)
74
        m3PG.calculate();// production of NPP
513 werner 75
        mLastYear = GlobalSettings::instance()->currentYear(); // mark this year as processed
369 werner 76
    } else {
77
        // if no LAI is present, then just clear the respones.
78
        mResponse.clear();
79
        m3PG.clear();
80
    }
226 werner 81
}
277 werner 82
 
83
 
84
void ResourceUnitSpecies::updateGWL()
85
{
86
    // removed growth is the running sum of all removed
87
    // tree volume. the current "GWL" therefore is current volume (standing) + mRemovedGrowth.
278 werner 88
    mRemovedGrowth+=statisticsDead().volume() + statisticsMgmt().volume();
277 werner 89
}
440 werner 90
 
91
void ResourceUnitSpecies::calclulateEstablishment()
92
{
93
    mEstablishment.calculate();
442 werner 94
    //DBGMODE(
95
        if (GlobalSettings::instance()->isDebugEnabled(GlobalSettings::dEstablishment)) {
96
            DebugList &out = GlobalSettings::instance()->debugList(ru()->index(), GlobalSettings::dEstablishment);
97
            // establishment details
98
            out << mSpecies->id() << ru()->index();
99
            out << mEstablishment.avgSeedDensity();
100
            out << mEstablishment.TACAminTemp() << mEstablishment.TACAchill() << mEstablishment.TACAfrostFree() << mEstablishment.TACgdd();
101
            out << mEstablishment.TACAfrostDaysAfterBudBirst() << mEstablishment.abioticEnvironment();
102
            out << m3PG.fEnvYear() << mEstablishment.avgLIFValue() << mEstablishment.numberEstablished();
466 werner 103
            out << mSapling.livingSaplings() << mSapling.averageHeight() << mSapling.averageAge() << mSapling.averageDeltaHPot() << mSapling.averageDeltaHRealized();
471 werner 104
            out << mSapling.newSaplings() << mSapling.diedSaplings() << mSapling.recruitedSaplings() << mSpecies->saplingGrowthParameters().referenceRatio;
442 werner 105
        }
106
    //); // DBGMODE()
440 werner 107
 
442 werner 108
 
440 werner 109
    if ( logLevelDebug() )
110
        qDebug() << "establishment of RU" << mRU->index() << "species" << species()->id()
111
        << "seeds density:" << mEstablishment.avgSeedDensity()
112
        << "abiotic environment:" << mEstablishment.abioticEnvironment()
113
        << "f_env,yr:" << m3PG.fEnvYear()
114
        << "N(established):" << mEstablishment.numberEstablished();
115
 
116
}
450 werner 117
 
118
void ResourceUnitSpecies::calclulateSaplingGrowth()
119
{
120
    mSapling.calculateGrowth();
121
}
453 werner 122
 
123
void ResourceUnitSpecies::visualGrid(Grid<float> &grid) const
124
{
125
    mSapling.fillHeightGrid(grid);
126
}
462 werner 127
 
475 werner 128
void ResourceUnitSpecies::calculateSnagDynamics()
129
{
130
    if (!snag())
131
        return;
132
 
133
    snag()->processYear();
477 werner 134
    if (GlobalSettings::instance()->isDebugEnabled(GlobalSettings::dSnagDynamics) && !snag()->isEmpty()) {
475 werner 135
        DebugList &out = GlobalSettings::instance()->debugList(ru()->index(), GlobalSettings::dSnagDynamics);
477 werner 136
        out << mSpecies->id() << ru()->index() << snag()->debugList(); // use private variables...
475 werner 137
    }
138
 
139
}