00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <stdio.h>
00029 #include <stdlib.h>
00030 #include <math.h>
00031 #include <string.h>
00032
00033 #include "nvector_serial.h"
00034 #include "sundials_types.h"
00035 #include "ihm.h"
00036 #include "calib.h"
00037 #include "et_is.h"
00038
00039 #define EPSILON 0.05
00040
00041 realtype is_CALIB;
00042 realtype et0_CALIB;
00043 realtype mf_CALIB;
00044 realtype tf_CALIB;
00045
00046
00047
00048
00049
00050
00051
00052 realtype Interpolation(TSD *Data, realtype t);
00053
00054 void calIS(realtype t, realtype stepsize, void *DS,N_Vector VY)
00055 {
00056 int i;
00057 realtype totEvap;
00058 realtype Delta, Gamma;
00059 realtype Rn, G, T, Vel, RH, VP,P,LAI,zero_dh,cnpy_h,rl,r_a;
00060 realtype isval=0,etval=0;
00061 realtype fracSnow,snowRate,MeltRate,MF,Ts=-3.0,Tr=1.0,To=0.0,massMelt=0,ret;
00062
00063 is_CALIB = setis_CALIB();
00064 et0_CALIB = setet0_CALIB();
00065 mf_CALIB=setmf_CALIB();
00066 tf_CALIB = settf_CALIB();
00067
00068
00069 Model_Data MD;
00070
00071 MD = (Model_Data)DS;
00072
00073
00074 stepsize=stepsize/(24.0*60.0);
00075 for(i=0; i<MD->NumEle; i++)
00076 {
00077 MD->ElePrep[i] = Interpolation(&MD->TSD_Prep[MD->Ele[i].prep-1], t);
00078 Rn = Interpolation(&MD->TSD_Rn[MD->Ele[i].Rn-1], t);
00079
00080 T = Interpolation(&MD->TSD_Temp[MD->Ele[i].temp-1], t);
00081 Vel = Interpolation(&MD->TSD_WindVel[MD->Ele[i].WindVel-1], t);
00082 RH = Interpolation(&MD->TSD_Humidity[MD->Ele[i].humidity-1], t);
00083 VP = Interpolation(&MD->TSD_Pressure[MD->Ele[i].pressure-1], t);
00084 P = 101.325*pow(10,3)*pow((293-0.0065*MD->Ele[i].zmax)/293,5.26);
00085 LAI = Interpolation(&MD->TSD_LAI[MD->Ele[i].LC-1], t);
00086 MF = Interpolation(&MD->TSD_MeltF[0], t);
00087 MF=mf_CALIB*MF;
00088
00089
00090 fracSnow = T<Ts?1.0:T>Tr?0:(Tr-T)/(Tr-Ts);
00091 snowRate = fracSnow*MD->ElePrep[i];
00092 MD->EleSnow[i]=MD->EleSnow[i]+snowRate*stepsize;
00093 MeltRate=(T>To?(T-To)*MF:0);
00094
00095
00096 if(MD->EleSnow[i]>MeltRate*stepsize)
00097 {
00098 MD->EleSnow[i]=MD->EleSnow[i]-MeltRate*stepsize;
00099
00100 }
00101 else
00102 {
00103 MeltRate=MD->EleSnow[i]/stepsize;
00104 MD->EleSnow[i]=0;
00105 }
00106
00107
00108
00109
00110
00111 MD->EleISmax[i] = MD->SIFactor[MD->Ele[i].LC-1]*Interpolation(&MD->TSD_LAI[MD->Ele[i].LC-1], t);
00112
00114 MD->EleISmax[i] = is_CALIB*MD->EleISmax[i];
00115 if(LAI>0.0)
00116 {
00117 Delta = 2503*pow(10,3)*exp(17.27*T/(T+237.3))/(pow(237.3 + T, 2));
00118 Gamma = P*1.0035*0.92/(0.622*2441);
00119 zero_dh=Interpolation(&MD->TSD_DH[MD->Ele[i].LC-1], t);
00120
00121 cnpy_h = zero_dh/(1.1*(0.0000001+log(1+pow(0.007*LAI,0.25))));
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 rl=Interpolation(&MD->TSD_DH[MD->Ele[i].LC-1], t);
00132 r_a = log(MD->Ele[i].windH/rl)*log(10*MD->Ele[i].windH/rl)/(Vel*0.16);
00133
00134
00135
00136 MD->EleET[i][0] = (LAI/MD->Ele[i].LAImax)*(pow((MD->EleIS[i]<0?0:MD->EleIS[i])/MD->EleISmax[i],2.0/3.0))*(Rn*(1-MD->Ele[i].Albedo)*Delta+(1.2*1003.5*((VP/RH)-VP)/r_a))/(1000*2441000.0*(Delta+Gamma));
00137 MD->EleTF[i]=tf_CALIB*5.65*pow(10,-2)*MD->EleISmax[i]*exp(3.89*(MD->EleIS[i]<0?0:MD->EleIS[i])/MD->EleISmax[i]);
00138
00139
00140 }
00141 else
00142 {
00143 MD->EleET[i][0]=0.0;
00144 MD->EleTF[i]=0.0;
00145 }
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 MD->EleET[i][0]=et0_CALIB*MD->EleET[i][0];
00158
00159
00160 if(MD->EleIS[i] >= MD->EleISmax[i])
00161 {
00162 if((1-fracSnow)*MD->ElePrep[i]>=MD->EleET[i][0]+MD->EleTF[i])
00163 {
00164 MD->Ele2IS[i] = MD->EleET[i][0];
00165 ret = MD->EleTF[i];
00166 }
00167 else if(((1-fracSnow)*MD->ElePrep[i]<MD->EleET[i][0]+MD->EleTF[i])&&(MD->EleIS[i]+stepsize*((1-fracSnow)*MD->ElePrep[i]-MD->EleET[i][0]-MD->EleTF[i])<=0))
00168 {
00169 MD->Ele2IS[i] =(1-fracSnow)*MD->ElePrep[i];
00170 MD->EleET[i][0]=(MD->EleET[i][0]/(MD->EleET[i][0]+MD->EleTF[i]))*(MD->EleIS[i]/stepsize+(1-fracSnow)*MD->ElePrep[i]);
00171 MD->EleIS[i] = 0;
00172 ret =(MD->EleTF[i]/(MD->EleET[i][0]+MD->EleTF[i]))*(MD->EleIS[i]/stepsize+(1-fracSnow)*MD->ElePrep[i]);
00173 }
00174 else
00175 {
00176 MD->Ele2IS[i] =(1-fracSnow)*MD->ElePrep[i];
00177 MD->EleIS[i] = MD->EleIS[i]+stepsize*((1-fracSnow)*MD->ElePrep[i]-MD->EleET[i][0]-MD->EleTF[i]);
00178 ret = MD->EleTF[i];
00179 }
00180
00181
00182
00183
00184
00185
00186
00187
00188 }
00189 else if(((MD->EleIS[i] + ((1-fracSnow)*MD->ElePrep[i]-MD->EleET[i][0]-MD->EleTF[i])*stepsize) >= MD->EleISmax[i]))
00190 {
00191 MD->Ele2IS[i] = (MD->EleISmax[i]/stepsize - (MD->EleIS[i]/stepsize-MD->EleET[i][0]-MD->EleTF[i]));
00192 MD->EleIS[i] = MD->EleISmax[i];
00193 ret = MD->EleTF[i];
00194
00195 }
00196 else if(((MD->EleIS[i] + ((1-fracSnow)*MD->ElePrep[i]-MD->EleET[i][0]-MD->EleTF[i])*stepsize) <=0))
00197 {
00198 MD->Ele2IS[i] = (1-fracSnow)*MD->ElePrep[i];
00199 if((MD->EleET[i][0]>0)||(MD->EleTF[i]>0))
00200 {
00201 MD->EleET[i][0] = (MD->EleET[i][0]/(MD->EleET[i][0]+MD->EleTF[i]))*(MD->EleIS[i]/stepsize+(1-fracSnow)*MD->ElePrep[i]);
00202 ret =(MD->EleTF[i]/(MD->EleET[i][0]+MD->EleTF[i]))*(MD->EleIS[i]/stepsize+(1-fracSnow)*MD->ElePrep[i]);
00203 }
00204 else
00205 {
00206 MD->EleET[i][0] = 0;
00207 ret = 0;
00208 }
00209 MD->EleIS[i] = 0;
00210
00211 }
00212 else
00213 {
00214 MD->Ele2IS[i] = (1-fracSnow)*MD->ElePrep[i];
00215 MD->EleIS[i] = MD->EleIS[i] + ((1-fracSnow)*MD->ElePrep[i]-MD->EleET[i][0]-MD->EleTF[i])*stepsize;
00216 ret = MD->EleTF[i];
00217
00218 }
00219 massMelt=massMelt+MeltRate*stepsize;
00220 MD->EleNetPrep[i] = (1-MD->Ele[i].VegFrac)*(1-fracSnow)*MD->ElePrep[i] + ((1-fracSnow)*MD->ElePrep[i]+ret - MD->Ele2IS[i])*MD->Ele[i].VegFrac+MeltRate;
00221 MD->EleTF[i] = ret;
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 }
00237
00238
00239 }
00240
00241 void calET(realtype t, realtype stepsize, N_Vector VY, void *DS)
00242 {
00243 int i;
00244
00245
00246
00247
00248
00249 }