00001
00002
00003
00004
00005
00006
00007
00008 #include "ReGen.h"
00009 #include <math.h>
00010
00012 RAINPARAMETERS::RAINPARAMETERS (int MAP, float dDMR)
00013 {
00014 calcParameters (MAP, dDMR);
00015 }
00016
00018 RAINPARAMETERS::RAINPARAMETERS (float A, float L, float W, float a, float l, float w, float dDMR)
00019 {
00020 lA=A; lL=L; lW=W; vA=a; vL=l; vW=w; d=dDMR;
00021 }
00022
00024 void RAINPARAMETERS::calcParameters (float MAP, float d)
00025 {
00026
00027
00028
00029 lA = 0.130034 + 0.000408 * MAP;
00030 lA = lA*(1-d +1.33*d*d-(0.61+1.57*lA)*d*d*d);
00031 lL = 5.735;
00032 lW = 1.704746 + 0.000242 * MAP;
00033
00034
00035 vA = -13.7178 + 4.0508301 * log(MAP);
00036 vA = vA * (1+d);
00037 vL = 5.586;
00038 vW = 11.336;
00039 }
00040
00041
00042
00043 ReGen::ReGen (RAINPARAMETERS* p_RainP)
00044 {
00045 pP = p_RainP;
00046 theAnnualRain = 0.0;
00047
00048 float days[days_in_year];
00049 for (int d = 0; d < days_in_year; days[d] = d++);
00050 valarray <float> localDays (days, days_in_year);
00051 theDays.resize(days_in_year);
00052 theDays = localDays;
00053
00054 rainProb.resize(days_in_year);
00055
00056 meanRainVolume.resize(days_in_year);
00057 meanRainVolume = calcGauss(pP->vA, pP->vL, pP->vW, 4);
00058
00059 rainyDay.resize(days_in_year);
00060
00061 rainVolume.resize(days_in_year);
00062 }
00063
00064
00065 void ReGen::drawYear (void)
00066 {
00067 calcRain();
00068 theAnnualRain = rainVolume.sum();
00069 }
00070
00071
00072 valarray <float> ReGen::calcGauss (float A, float L, float W, int s)
00073 {
00074
00075 valarray <float> G (days_in_year);
00076 G = theDays;
00077
00078 G *= (12.0F/365.0F);
00079 G += (6.0F - L);
00080 for (int i = 0; i < days_in_year; i++)
00081 G[i] = fmod(G[i],12.0F);
00082 G += (L - 6.0F);
00083
00084 G = A * exp(-pow(G - L, float(s))/float(2.0*W*W));
00085
00086 return G;
00087 }
00088
00089
00090 void ReGen::calcRain (void)
00091 {
00092
00093 rainProb = calcGauss(pP->lA, pP->lL, pP->lW);
00094
00095 rainyDay=0.0;
00096 for (int i = 0; i < days_in_year; i++)
00097 if (Zzg.rand_halfclosed01() < rainProb[i] && rainProb[i] > 0.05)
00098 rainyDay[i] = 1.0;
00099
00100
00101
00102 for (int i = 0; i < days_in_year; i++)
00103 rainVolume[i] = Zzg.rand_halfclosed01();
00104 rainVolume *= -1.0;
00105 rainVolume += 1.0;
00106 rainVolume = -log(rainVolume);
00107
00108 rainVolume *= meanRainVolume;
00109 rainVolume *= rainyDay;
00110 }
00111
00112
00113 float ReGen::getRain (int day) const
00114 {
00115 return rainVolume[day];
00116 }
00117
00118
00119 float ReGen::getAnnualRain (void) const
00120 {
00121 return theAnnualRain;
00122 }
00123
00124
00125
00126 float ReGen::getPeriodRain (int start, int end) const
00127 {
00128 float sum = 0.0;
00129 for (int day = start; day <= end; day++)
00130 sum+=rainVolume[day];
00131 return sum;
00132 }