Subversion Repositories public iLand

Rev

Rev 496 | Rev 518 | 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
 
513 werner 65
 
438 werner 66
    statistics().clear();
440 werner 67
    if (mLAIfactor>0 || fromEstablishment==true) {
496 werner 68
        // execute the water calculation...
69
        if (fromEstablishment)
70
            const_cast<WaterCycle*>(mRU->waterCycle())->run(); // run the water sub model (only if this has not be done already)
71
        mResponse.calculate();// calculate environmental responses per species (vpd, temperature, ...)
72
        m3PG.calculate();// production of NPP
513 werner 73
        mLastYear = GlobalSettings::instance()->currentYear(); // mark this year as processed
369 werner 74
    } else {
75
        // if no LAI is present, then just clear the respones.
376 werner 76
        // note: subject to change when regeneration is added...
369 werner 77
        mResponse.clear();
78
        m3PG.clear();
79
    }
226 werner 80
}
277 werner 81
 
82
 
83
void ResourceUnitSpecies::updateGWL()
84
{
85
    // removed growth is the running sum of all removed
86
    // tree volume. the current "GWL" therefore is current volume (standing) + mRemovedGrowth.
278 werner 87
    mRemovedGrowth+=statisticsDead().volume() + statisticsMgmt().volume();
277 werner 88
}
440 werner 89
 
90
void ResourceUnitSpecies::calclulateEstablishment()
91
{
92
    mEstablishment.calculate();
442 werner 93
    //DBGMODE(
94
        if (GlobalSettings::instance()->isDebugEnabled(GlobalSettings::dEstablishment)) {
95
            DebugList &out = GlobalSettings::instance()->debugList(ru()->index(), GlobalSettings::dEstablishment);
96
            // establishment details
97
            out << mSpecies->id() << ru()->index();
98
            out << mEstablishment.avgSeedDensity();
99
            out << mEstablishment.TACAminTemp() << mEstablishment.TACAchill() << mEstablishment.TACAfrostFree() << mEstablishment.TACgdd();
100
            out << mEstablishment.TACAfrostDaysAfterBudBirst() << mEstablishment.abioticEnvironment();
101
            out << m3PG.fEnvYear() << mEstablishment.avgLIFValue() << mEstablishment.numberEstablished();
466 werner 102
            out << mSapling.livingSaplings() << mSapling.averageHeight() << mSapling.averageAge() << mSapling.averageDeltaHPot() << mSapling.averageDeltaHRealized();
471 werner 103
            out << mSapling.newSaplings() << mSapling.diedSaplings() << mSapling.recruitedSaplings() << mSpecies->saplingGrowthParameters().referenceRatio;
442 werner 104
        }
105
    //); // DBGMODE()
440 werner 106
 
442 werner 107
 
440 werner 108
    if ( logLevelDebug() )
109
        qDebug() << "establishment of RU" << mRU->index() << "species" << species()->id()
110
        << "seeds density:" << mEstablishment.avgSeedDensity()
111
        << "abiotic environment:" << mEstablishment.abioticEnvironment()
112
        << "f_env,yr:" << m3PG.fEnvYear()
113
        << "N(established):" << mEstablishment.numberEstablished();
114
 
115
}
450 werner 116
 
117
void ResourceUnitSpecies::calclulateSaplingGrowth()
118
{
119
    mSapling.calculateGrowth();
120
}
453 werner 121
 
122
void ResourceUnitSpecies::visualGrid(Grid<float> &grid) const
123
{
124
    mSapling.fillHeightGrid(grid);
125
}
462 werner 126
 
475 werner 127
void ResourceUnitSpecies::calculateSnagDynamics()
128
{
129
    if (!snag())
130
        return;
131
 
132
    snag()->processYear();
477 werner 133
    if (GlobalSettings::instance()->isDebugEnabled(GlobalSettings::dSnagDynamics) && !snag()->isEmpty()) {
475 werner 134
        DebugList &out = GlobalSettings::instance()->debugList(ru()->index(), GlobalSettings::dSnagDynamics);
477 werner 135
        out << mSpecies->id() << ru()->index() << snag()->debugList(); // use private variables...
475 werner 136
    }
137
 
138
}