iLand
climate.h
Go to the documentation of this file.
1/********************************************************************************************
2** iLand - an individual based forest landscape and disturbance model
3** http://iland-model.org
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********************************************************************************************/
19
20#ifndef CLIMATE_H
21#define CLIMATE_H
22
23#include <QtSql>
24#include "phenology.h"
28{
29 int year; // year
30 int month; // month (1..12)
31 int dayOfMonth; // day of the month (1..31)
32 double temperature; // average day degree C (of the light hours)
33 double min_temperature; // minimum temperature of the day
34 double max_temperature; // maximum temperature of the day
35 double mean_temp() const { return (min_temperature + max_temperature) / 2.; } // mean temperature
36 double temp_delayed; // temperature delayed (after Maekela, 2008) for response calculations
37 double preciptitation; // sum of day [mm]
38 double radiation; // sum of day (MJ/m2)
39 double vpd; // average of day [kPa] = [0.1 mbar] (1 bar = 100kPa)
40 static double co2; // ambient CO2 content in ppm
41 QString toString() const { return QString("%1.%2.%3").arg(dayOfMonth).arg(month).arg(year); }
42 bool isValid() const { return (year>=0); }
43 int id() const { return year*10000 + month*100 + dayOfMonth; }
44};
45
47class Sun
48{
49public:
50 void setup(const double latitude_rad);
51 QString dump();
52 const double &daylength(const int day) const { return mDaylength_h[day]; }
53 int longestDay() const { return mDayWithMaxLength; }
54 bool northernHemishere() const { return mDayWithMaxLength<300; }
55 int dayShorter10_5hrs() const { return mDayWith10_5hrs; }
56 int dayShorter14_5hrs() const { return mDayWith14_5hrs; }
57private:
58 double mLatitude;
59 int mDayWithMaxLength;
60 double mDaylength_h[366];
61 int mDayWith10_5hrs; // last day of year with a day length > 10.5 hours (see Establishment)
62 int mDayWith14_5hrs; // last doy with at least 14.5 hours of day length
63};
64
66{
67public:
68 Climate();
69 void setup();
70 bool isSetup() const { return mIsSetup; }
71 const QString &name() const { return mName; }
72 // activity
73 void nextYear();
74 // access to climate data
75 const ClimateDay *dayOfYear(const int dayofyear) const { return mBegin + dayofyear;}
76 const ClimateDay *day(const int month, const int day) const;
77 int whichDayOfYear(const ClimateDay *climate) const {return climate-mBegin; }
79 void monthRange(const int month, const ClimateDay **rBegin, const ClimateDay **rEnd) const;
80 double days(const int month) const;
81 int daysOfYear() const;
82 const ClimateDay *begin() const { return mBegin; }
83 const ClimateDay *end() const { return mEnd; }
84 void toDate(const int yearday, int *rDay=0, int *rMonth=0, int *rYear=0) const;
85 //
86 double totalRadiation() const { return mAnnualRadiation; }
87 const double* precipitationMonth() const { return mPrecipitationMonth; }
89 double meanAnnualTemperature() const { return mMeanAnnualTemperature; }
91 double annualPrecipitation() const { double r=0.; for (int i=0;i<12;++i) r+=mPrecipitationMonth[i]; return r;}
93 const double *temperatureMonth() const { return mTemperatureMonth; }
95 int climateDataYear() const { return mBegin->year; }
96 // access to other subsystems
97 int phenologyGroupCount() const { return mPhenology.count(); }
98 const Phenology &phenology(const int phenologyGroup) const;
99 const Sun &sun() const { return mSun; }
100 double daylength_h(const int doy) const { return sun().daylength(doy); }
101
102private:
103 bool mIsSetup;
104 bool mDoRandomSampling;
105 bool mTMaxAvailable;
106 QString mName;
107 Sun mSun;
108 void load();
109 void setupPhenology();
110 void climateCalculations(const ClimateDay &lastDay);
111 ClimateDay mInvalidDay;
112 int mLoadYears; // count of years to load ahead
113 int mCurrentYear; // current year (relative)
114 int mMinYear; // lowest year in store (relative)
115 int mMaxYear; // highest year in store (relative)
116 double mTemperatureShift; // add this to daily temp
117 double mPrecipitationShift; // multiply prec with that
118 ClimateDay *mBegin; // pointer to the first day of the current year
119 ClimateDay *mEnd; // pointer to the last day of the current year (+1)
120 QVector<ClimateDay> mStore;
121 QVector<int> mDayIndices;
122 QSqlQuery mClimateQuery;
123 QList<Phenology> mPhenology;
124 QVector<int> mRandomYearList;
125 int mRandomListIndex;
126 double mAnnualRadiation;
127 double mPrecipitationMonth[12];
128 double mTemperatureMonth[12];
129 double mMeanAnnualTemperature;
130 static QVector<int> sampled_years;
131};
132
133#endif // CLIMATE_H
Climate handles climate input data and performs some basic related calculations on that data.
Definition: climate.h:66
const ClimateDay * day(const int month, const int day) const
gets pointer to climate structure of given day (0-based indices, i.e. month=11=december!...
Definition: climate.cpp:87
const QString & name() const
table name of this climate
Definition: climate.h:71
void monthRange(const int month, const ClimateDay **rBegin, const ClimateDay **rEnd) const
returns two pointer (arguments!!!) to the begin and one after end of the given month (month: 0....
Definition: climate.cpp:93
void toDate(const int yearday, int *rDay=0, int *rMonth=0, int *rYear=0) const
decode "yearday" to the actual year, month, day if provided
Definition: climate.cpp:111
double days(const int month) const
returns number of days of given month (0..11)
Definition: climate.cpp:100
double daylength_h(const int doy) const
length of the day in hours
Definition: climate.h:100
Climate()
Definition: climate.cpp:76
void setup()
setup routine that opens database connection
Definition: climate.cpp:119
double annualPrecipitation() const
annual precipitation sum (mm)
Definition: climate.h:91
void nextYear()
Definition: climate.cpp:303
double totalRadiation() const
return radiation sum (MJ) of the whole year
Definition: climate.h:86
const double * temperatureMonth() const
get a array with mean temperatures per month (deg C)
Definition: climate.h:93
int phenologyGroupCount() const
Definition: climate.h:97
const Sun & sun() const
solar radiation class
Definition: climate.h:99
bool isSetup() const
Definition: climate.h:70
const double * precipitationMonth() const
Definition: climate.h:87
const ClimateDay * dayOfYear(const int dayofyear) const
get pointer to climate structure by day of year (0-based-index)
Definition: climate.h:75
double meanAnnualTemperature() const
the mean annual temperature of the current year (degree C)
Definition: climate.h:89
const ClimateDay * begin() const
STL-like (pointer)-iterator to the first day of the current year.
Definition: climate.h:82
const Phenology & phenology(const int phenologyGroup) const
phenology class of given type
Definition: climate.cpp:416
int whichDayOfYear(const ClimateDay *climate) const
get the 0-based index of the climate given by 'climate' within the current year
Definition: climate.h:77
const ClimateDay * end() const
STL-like pointer iterator to the day after last day of the current year.
Definition: climate.h:83
int daysOfYear() const
returns number of days of current year.
Definition: climate.cpp:104
int climateDataYear() const
retrieve the year provided in the climate table
Definition: climate.h:95
Definition: phenology.h:25
Sun handles calculations of day lengths, etc.
Definition: climate.h:48
int dayShorter10_5hrs() const
Definition: climate.h:55
bool northernHemishere() const
Definition: climate.h:54
int dayShorter14_5hrs() const
Definition: climate.h:56
int longestDay() const
Definition: climate.h:53
QString dump()
Definition: climate.cpp:68
void setup(const double latitude_rad)
Definition: climate.cpp:36
const double & daylength(const int day) const
Definition: climate.h:52
current climate variables of a day.
Definition: climate.h:28
double mean_temp() const
Definition: climate.h:35
double min_temperature
Definition: climate.h:33
double vpd
Definition: climate.h:39
static double co2
Definition: climate.h:40
double preciptitation
Definition: climate.h:37
int id() const
Definition: climate.h:43
int month
Definition: climate.h:30
bool isValid() const
Definition: climate.h:42
double temp_delayed
Definition: climate.h:36
int dayOfMonth
Definition: climate.h:31
QString toString() const
Definition: climate.h:41
double temperature
Definition: climate.h:32
double max_temperature
Definition: climate.h:34
double radiation
Definition: climate.h:38
int year
Definition: climate.h:29