Subversion Repositories public iLand

Rev

Rev 1221 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1211 werner 1
/********************************************************************************************
2
**    iLand - an individual based forest landscape and disturbance model
3
**    http://iland.boku.ac.at
4
**    Copyright (C) 2009-  Werner Rammer, Rupert Seidl
5
**
6
**    This program is free software: you can redistribute it and/or modify
7
**    it under the terms of the GNU General Public License as published by
8
**    the Free Software Foundation, either version 3 of the License, or
9
**    (at your option) any later version.
10
**
11
**    This program is distributed in the hope that it will be useful,
12
**    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
**    GNU General Public License for more details.
15
**
16
**    You should have received a copy of the GNU General Public License
17
**    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
********************************************************************************************/
1124 werner 19
#include "waterout.h"
20
#include "output.h"
21
#include "model.h"
22
#include "watercycle.h"
23
#include "resourceunit.h"
24
#include "climate.h"
25
 
26
WaterOut::WaterOut()
27
{
28
    setName("Water output", "water");
29
    setDescription("Annual water cycle output on resource unit/landscape unit.\n" \
30
                   "The output includes annual averages of precipitation, evapotranspiration, water excess, " \
31
                   "snow cover, and radiation input. The spatial resolution is landscape averages and/or resource unit level (i.e. 100m pixels). " \
32
                   "Landscape level averages are indicated by -1 for the 'ru' and 'index' columns.\n\n" \
33
                   "You can specify a 'condition' to limit output execution to specific years (variable 'year'). " \
34
                   "The 'conditionRU' can be used to suppress resource-unit-level details; eg. specifying 'in(year,100,200,300)' limits output on reosurce unit level to the years 100,200,300 " \
35
                   "(leaving 'conditionRU' blank enables details per default).");
36
    columns() << OutputColumn::year() << OutputColumn::ru() << OutputColumn::id()
1141 werner 37
              << OutputColumn("stocked_area", "area (ha/ha) which is stocked (covered by crowns, absorbing radiation)", OutDouble)
38
              << OutputColumn("stockable_area", "area (ha/ha) which is stockable (and within the project area)", OutDouble)
1124 werner 39
              << OutputColumn("precipitation_mm", "Annual precipitation sum (mm)", OutDouble)
40
              << OutputColumn("et_mm", "Evapotranspiration (mm)", OutDouble)
41
              << OutputColumn("excess_mm", "annual sum of water loss due to lateral outflow/groundwater flow (mm)", OutDouble)
42
              << OutputColumn("snowcover_days", "days with snowcover >0mm", OutInteger)
43
              << OutputColumn("total_radiation", "total incoming radiation over the year (MJ/m2), sum of data in climate input)", OutDouble)
44
              << OutputColumn("radiation_snowcover", "sum of radiation input (MJ/m2) for days with snow cover", OutInteger);
45
 
46
 
47
}
48
 
49
void WaterOut::exec()
50
{
51
    Model *m = GlobalSettings::instance()->model();
52
 
53
    // global condition
54
    if (!mCondition.isEmpty() && mCondition.calculate(GlobalSettings::instance()->currentYear())==0.)
55
        return;
56
 
57
    bool ru_level = true;
58
    // switch off details if this is indicated in the conditionRU option
59
    if (!mConditionDetails.isEmpty() && mConditionDetails.calculate(GlobalSettings::instance()->currentYear())==0.)
60
        ru_level = false;
61
 
62
 
63
    double ru_count = 0.;
64
    int snow_days = 0;
65
    double et=0., excess=0., rad=0., snow_rad=0., p=0.;
66
    double stockable=0., stocked=0.;
67
    foreach(ResourceUnit *ru, m->ruList()) {
68
        if (ru->id()==-1)
69
            continue; // do not include if out of project area
70
 
71
        const WaterCycle *wc = ru->waterCycle();
72
        if (ru_level) {
73
            *this << currentYear() << ru->index() << ru->id();
1143 werner 74
            *this << ru->stockedArea()/cRUArea << ru->stockableArea()/cRUArea;
1124 werner 75
            *this << ru->climate()->annualPrecipitation();
76
            *this << wc->mTotalET << wc->mTotalExcess;
77
            *this << wc->mSnowDays;
78
            *this << ru->climate()->totalRadiation() << wc->mSnowRad;
79
            writeRow();
80
        }
81
        ++ru_count;
82
        stockable+=ru->stockableArea(); stocked+=ru->stockedArea();
83
        p+=ru->climate()->annualPrecipitation();
84
        et+=wc->mTotalET; excess+=wc->mTotalExcess; snow_days+=wc->mSnowDays;
85
        rad+=ru->climate()->totalRadiation();
86
        snow_rad+=wc->mSnowRad;
87
 
88
    }
89
    // write landscape sums
90
    if (ru_count==0.)
91
        return;
92
    *this << currentYear() << -1 << -1; // codes -1/-1 for landscape level
1143 werner 93
    *this << stocked/ru_count/cRUArea << stockable/ru_count/cRUArea;
1124 werner 94
    *this << p / ru_count; // mean precip
95
    *this << et / ru_count;
96
    *this << excess / ru_count;
97
    *this << snow_days / ru_count;
98
    *this << rad / ru_count << snow_rad / ru_count;
99
    writeRow();
100
 
101
 
102
}
103
 
104
void WaterOut::setup()
105
{
106
    // use a condition for to control execuation for the current year
107
    QString condition = settings().value(".condition", "");
108
    mCondition.setExpression(condition);
1138 werner 109
 
1124 werner 110
    condition = settings().value(".conditionRU", "");
111
    mConditionDetails.setExpression(condition);
112
 
113
 
114
}