Subversion Repositories public iLand

Rev

Rev 214 | Rev 234 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 214 Rev 226
1
Redirecting to URL 'https://iland.boku.ac.at/svn/iland/tags/release_1.0/src/core/climate.h':
1
Redirecting to URL 'https://iland.boku.ac.at/svn/iland/tags/release_1.0/src/core/climate.h':
2
#ifndef CLIMATE_H
2
#ifndef CLIMATE_H
3
#define CLIMATE_H
3
#define CLIMATE_H
4
4
5
#include <QtSql>
5
#include <QtSql>
6
#include "phenology.h"
6
#include "phenology.h"
7
/// current climate variables of a day. @sa Climate.
7
/// current climate variables of a day. @sa Climate.
8
struct ClimateDay
8
struct ClimateDay
9
{
9
{
10
    int year; // year
10
    int year; // year
11
    int month; // month
11
    int month; // month
12
    int day; // day of year
12
    int day; // day of year
13
    double temperature; // average day °C
13
    double temperature; // average day °C
14
    double temp_delayed; // temperature delayed (after Maekela, 2008) for response calculations
14
    double temp_delayed; // temperature delayed (after Maekela, 2008) for response calculations
15
    double preciptitation; // sum of day [mm]
15
    double preciptitation; // sum of day [mm]
16
    double radiation; // sum of day (MJ/m2)
16
    double radiation; // sum of day (MJ/m2)
17
    double vpd; // average of day [kPa]
17
    double vpd; // average of day [kPa]
-
 
18
    static double co2; // ambient CO2 content in ppm
18
    QString toString() const { return QString("%1.%2.%3").arg(day).arg(month).arg(year); }
19
    QString toString() const { return QString("%1.%2.%3").arg(day).arg(month).arg(year); }
19
    bool isValid() const  { return (year>=0); }
20
    bool isValid() const  { return (year>=0); }
20
};
21
};
21
22
22
/// Sun handles calculations of day lengths, etc.
23
/// Sun handles calculations of day lengths, etc.
23
class Sun
24
class Sun
24
{
25
{
25
public:
26
public:
26
    void setup(const double latitude_rad);
27
    void setup(const double latitude_rad);
27
    QString dump();
28
    QString dump();
28
    const double &daylength(const int day) const { return mDaylength_h[day]; }
29
    const double &daylength(const int day) const { return mDaylength_h[day]; }
29
    int longestDay() const { return mDayWithMaxLength; }
30
    int longestDay() const { return mDayWithMaxLength; }
30
    bool northernHemishere() const { return mDayWithMaxLength<300; }
31
    bool northernHemishere() const { return mDayWithMaxLength<300; }
31
private:
32
private:
32
    double mLatitude; ///< latitude in radians
33
    double mLatitude; ///< latitude in radians
33
    int mDayWithMaxLength; ///< day of year with maximum day length
34
    int mDayWithMaxLength; ///< day of year with maximum day length
34
    double mDaylength_h[366]; ///< daylength per day in hours
35
    double mDaylength_h[366]; ///< daylength per day in hours
35
};
36
};
36
37
37
class Climate
38
class Climate
38
{
39
{
39
public:
40
public:
40
    Climate();
41
    Climate();
41
    void setup(); ///< setup routine that opens database connection
42
    void setup(); ///< setup routine that opens database connection
42
    // activity
43
    // activity
43
    void nextYear();
44
    void nextYear();
44
    // access to climate data
45
    // access to climate data
45
    const ClimateDay *dayOfYear(const int dayofyear) { return mBegin + dayofyear;} ///< get pointer to climate structure by day of year (0-based-index)
46
    const ClimateDay *dayOfYear(const int dayofyear) { return mBegin + dayofyear;} ///< get pointer to climate structure by day of year (0-based-index)
46
    const ClimateDay *day(const int month, const int day); ///< gets pointer to climate structure of given day (0-based indices, i.e. month=11=december!)
47
    const ClimateDay *day(const int month, const int day); ///< gets pointer to climate structure of given day (0-based indices, i.e. month=11=december!)
47
    /// returns two pointer (arguments!!!) to the begin and one after end of the given month (month: 0..11)
48
    /// returns two pointer (arguments!!!) to the begin and one after end of the given month (month: 0..11)
48
    void monthRange(const int month, const ClimateDay **rBegin, const ClimateDay **rEnd);
49
    void monthRange(const int month, const ClimateDay **rBegin, const ClimateDay **rEnd);
49
    double days(const int month); ///< returns number of days of given month
50
    double days(const int month); ///< returns number of days of given month
50
    int daysOfYear(); ///< returns number of days of current year
51
    int daysOfYear(); ///< returns number of days of current year
51
    const ClimateDay *begin() { return mBegin; } ///< STL-like (pointer)-iterator
52
    const ClimateDay *begin() { return mBegin; } ///< STL-like (pointer)-iterator
52
    const ClimateDay *end() { return mEnd; } ///< STL-like pointer iterator
53
    const ClimateDay *end() { return mEnd; } ///< STL-like pointer iterator
53
    void toDate(const int yearday, int *rDay=0, int *rMonth=0, int *rYear=0); ///< decode "yearday" to the actual year, month, day if provided
54
    void toDate(const int yearday, int *rDay=0, int *rMonth=0, int *rYear=0); ///< decode "yearday" to the actual year, month, day if provided
54
    // access to other subsystems
55
    // access to other subsystems
55
    const Phenology &phenology(const int phenologyGroup); ///< phenology class of given type
56
    const Phenology &phenology(const int phenologyGroup); ///< phenology class of given type
56
    const Sun &sun() { return mSun; } ///< solar radiation class
57
    const Sun &sun() { return mSun; } ///< solar radiation class
57
58
58
private:
59
private:
59
    Sun mSun; ///< class doing solar radiation calculations
60
    Sun mSun; ///< class doing solar radiation calculations
60
    void load(); ///< load mLoadYears years from database
61
    void load(); ///< load mLoadYears years from database
61
    void setupPhenology(); ///< setup of phenology groups
62
    void setupPhenology(); ///< setup of phenology groups
62
    void climateCalculations(ClimateDay &lastDay); ///< more calculations done after loading of climate data
63
    void climateCalculations(ClimateDay &lastDay); ///< more calculations done after loading of climate data
63
    ClimateDay mInvalidDay;
64
    ClimateDay mInvalidDay;
64
    int mLoadYears; // count of years to load ahead
65
    int mLoadYears; // count of years to load ahead
65
    int mCurrentYear; // current year (relative)
66
    int mCurrentYear; // current year (relative)
66
    int mMinYear; // lowest year in store (relative)
67
    int mMinYear; // lowest year in store (relative)
67
    int mMaxYear;  // highest year in store (relative)
68
    int mMaxYear;  // highest year in store (relative)
68
    ClimateDay *mBegin; // pointer to the first day of the current year
69
    ClimateDay *mBegin; // pointer to the first day of the current year
69
    ClimateDay *mEnd; // pointer to the last day of the current year (+1)
70
    ClimateDay *mEnd; // pointer to the last day of the current year (+1)
70
    QVector<ClimateDay> mStore; ///< storage of climate data
71
    QVector<ClimateDay> mStore; ///< storage of climate data
71
    QVector<int> mDayIndices; ///< store indices for month / years within store
72
    QVector<int> mDayIndices; ///< store indices for month / years within store
72
    QSqlQuery mClimateQuery; ///< sql query for db access
73
    QSqlQuery mClimateQuery; ///< sql query for db access
73
    QList<Phenology> mPhenology; ///< phenology calculations
74
    QList<Phenology> mPhenology; ///< phenology calculations
74
};
75
};
75
76
76
#endif // CLIMATE_H
77
#endif // CLIMATE_H
77
 
78