Subversion Repositories public iLand

Rev

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

Rev Author Line No. Line
1
 
1033 werner 2
/********************************************************************************************
3
**    iLand - an individual based forest landscape and disturbance model
4
**    http://iland.boku.ac.at
5
**    Copyright (C) 2009-  Werner Rammer, Rupert Seidl
6
**
7
**    This program is free software: you can redistribute it and/or modify
8
**    it under the terms of the GNU General Public License as published by
9
**    the Free Software Foundation, either version 3 of the License, or
10
**    (at your option) any later version.
11
**
12
**    This program is distributed in the hope that it will be useful,
13
**    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
**    GNU General Public License for more details.
16
**
17
**    You should have received a copy of the GNU General Public License
18
**    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
********************************************************************************************/
20
 
21
 
111 Werner 22
#include "global.h"
189 iland 23
#include "resourceunitspecies.h"
111 Werner 24
 
25
#include "species.h"
189 iland 26
#include "resourceunit.h"
468 werner 27
#include "model.h"
496 werner 28
#include "watercycle.h"
808 werner 29
#include "debugtimer.h"
376 werner 30
 
458 werner 31
/** @class ResourceUnitSpecies
697 werner 32
  @ingroup core
458 werner 33
    The class contains data available at ResourceUnit x Species scale.
34
    Data stored is either statistical (i.e. number of trees per species) or used
468 werner 35
    within the model (e.g. fraction of utilizable Radiation).
36
    Important submodules are:
37
    * 3PG production (Production3PG)
38
    * Establishment
39
    * Growth and Recruitment of Saplings
40
    * Snag dynamics
458 werner 41
  */
468 werner 42
ResourceUnitSpecies::~ResourceUnitSpecies()
43
{
44
}
440 werner 45
 
376 werner 46
double ResourceUnitSpecies::leafArea() const
47
{
48
    // Leaf area of the species:
49
    // total leaf area on the RU * fraction of leafarea
50
    return mLAIfactor * ru()->leafAreaIndex();
51
}
52
 
235 werner 53
void ResourceUnitSpecies::setup(Species *species, ResourceUnit *ru)
54
{
55
    mSpecies = species;
56
    mRU = ru;
57
    mResponse.setup(this);
58
    m3PG.setResponse(&mResponse);
440 werner 59
    mEstablishment.setup(ru->climate(), this);
452 werner 60
    mSapling.setup(this);
235 werner 61
    mStatistics.setResourceUnitSpecies(this);
277 werner 62
    mStatisticsDead.setResourceUnitSpecies(this);
278 werner 63
    mStatisticsMgmt.setResourceUnitSpecies(this);
440 werner 64
 
277 werner 65
    mRemovedGrowth = 0.;
438 werner 66
    mLastYear = -1;
468 werner 67
 
1157 werner 68
    DBGMODE( if(mSpecies->index()>1000 || mSpecies->index()<0)
69
             qDebug() << "suspicious species?? in RUS::setup()";
70
                );
71
 
235 werner 72
}
111 Werner 73
 
74
 
440 werner 75
void ResourceUnitSpecies::calculate(const bool fromEstablishment)
226 werner 76
{
936 werner 77
 
78
    // if *not* called from establishment, clear the species-level-stats
518 werner 79
    if (!fromEstablishment)
80
        statistics().clear();
513 werner 81
 
1157 werner 82
    // if already processed in this year, do not repeat
83
    if (mLastYear == GlobalSettings::instance()->currentYear())
84
        return;
85
 
936 werner 86
    if (mLAIfactor>0. || fromEstablishment==true) {
496 werner 87
        // execute the water calculation...
88
        if (fromEstablishment)
89
            const_cast<WaterCycle*>(mRU->waterCycle())->run(); // run the water sub model (only if this has not be done already)
626 werner 90
        DebugTimer rst("response+3pg");
496 werner 91
        mResponse.calculate();// calculate environmental responses per species (vpd, temperature, ...)
92
        m3PG.calculate();// production of NPP
513 werner 93
        mLastYear = GlobalSettings::instance()->currentYear(); // mark this year as processed
369 werner 94
    } else {
95
        // if no LAI is present, then just clear the respones.
96
        mResponse.clear();
97
        m3PG.clear();
98
    }
226 werner 99
}
277 werner 100
 
101
 
102
void ResourceUnitSpecies::updateGWL()
103
{
104
    // removed growth is the running sum of all removed
105
    // tree volume. the current "GWL" therefore is current volume (standing) + mRemovedGrowth.
936 werner 106
    // important: statisticsDead() and statisticsMgmt() need to calculate() before -> volume() is already scaled to ha
278 werner 107
    mRemovedGrowth+=statisticsDead().volume() + statisticsMgmt().volume();
277 werner 108
}
440 werner 109
 
863 werner 110
void ResourceUnitSpecies::calculateEstablishment()
440 werner 111
{
1005 werner 112
    //DebugTimer t("to remove");
440 werner 113
    mEstablishment.calculate();
1005 werner 114
    //qDebug() << species()->id() << t.elapsed() << mEstablishment.avgSeedDensity() << mEstablishment.numberEstablished()<< "new";
442 werner 115
    //DBGMODE(
116
        if (GlobalSettings::instance()->isDebugEnabled(GlobalSettings::dEstablishment)) {
117
            DebugList &out = GlobalSettings::instance()->debugList(ru()->index(), GlobalSettings::dEstablishment);
118
            // establishment details
605 werner 119
            out << mSpecies->id() << ru()->index() << ru()->id();
442 werner 120
            out << mEstablishment.avgSeedDensity();
121
            out << mEstablishment.TACAminTemp() << mEstablishment.TACAchill() << mEstablishment.TACAfrostFree() << mEstablishment.TACgdd();
122
            out << mEstablishment.TACAfrostDaysAfterBudBirst() << mEstablishment.abioticEnvironment();
123
            out << m3PG.fEnvYear() << mEstablishment.avgLIFValue() << mEstablishment.numberEstablished();
466 werner 124
            out << mSapling.livingSaplings() << mSapling.averageHeight() << mSapling.averageAge() << mSapling.averageDeltaHPot() << mSapling.averageDeltaHRealized();
471 werner 125
            out << mSapling.newSaplings() << mSapling.diedSaplings() << mSapling.recruitedSaplings() << mSpecies->saplingGrowthParameters().referenceRatio;
442 werner 126
        }
127
    //); // DBGMODE()
440 werner 128
 
442 werner 129
 
440 werner 130
    if ( logLevelDebug() )
131
        qDebug() << "establishment of RU" << mRU->index() << "species" << species()->id()
132
        << "seeds density:" << mEstablishment.avgSeedDensity()
133
        << "abiotic environment:" << mEstablishment.abioticEnvironment()
134
        << "f_env,yr:" << m3PG.fEnvYear()
135
        << "N(established):" << mEstablishment.numberEstablished();
136
 
137
}
450 werner 138
 
139
void ResourceUnitSpecies::calclulateSaplingGrowth()
140
{
141
    mSapling.calculateGrowth();
142
}
453 werner 143
 
144
void ResourceUnitSpecies::visualGrid(Grid<float> &grid) const
145
{
564 werner 146
    mSapling.fillMaxHeightGrid(grid);
453 werner 147
}
462 werner 148
 
475 werner 149