/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/hydrotrend/hydrosedload.c

Go to the documentation of this file.
00001 /*
00002  *      HydroSedLoad.c
00003  *
00004  *              Author1:        S.D. Peckham    (September 2001)        (January 2002)
00005  *      Author2:        A.J. Kettner    (August - September 2002)(february 2003)
00006  *
00007  *      Calculates the sediment load (suspended and bedload) discharging
00008  *      from the river mouth for each day, using new formula from Morehead
00009  *      et al.(2001).  The formula is:
00010  *
00011  *      Qs(i) = Psi * Qsbar * (Q/Qbar)^C
00012  *
00013  *    Qsbar = long-term average of Qs (for an epoch)
00014  *    Qsbar = alpha3 * (1-TE) * pow(A,alpha4) * pow(H,alpha5) * exp(k * Tbar)
00015  * or:
00016  *    Qsbar = alpha6 * (1-TE) * pow(Qbar,alpha7) * pow(H,alpha8) * exp(k * Tbar)
00017  * 
00018  *    Qbar  = long-term average of Q  (for an epoch)
00019  *    Tbar  = Tmean - ((lapserate[ep] * maxalt[ep])/3.0);
00020  *    Tmean = (Tstart[ep] + (Tstart[ep] + (Tchange[ep]*nyears[ep])))/2;
00021  *
00022  *    Psi   = a random number from a lognormal distribution with
00023  *            mean 1 and sigma = 0.763 * (0.99995^Qbar)
00024  *    C     = a random number from a distribution with mean cbar
00025  *            and standard deviation s, where:
00026  *            cbar = (1.4 - (0.025*T) + (0.00013*H) + (0.145*ln(Qsbar))
00027  *            and s = 0.17 + (0.0000183 * Qbar)
00028  *
00029  *      i  = subscript for instantaneous or daily values
00030  *    A  = totalarea = basin area (km^2)
00031  *    H  = maxalt = basin relief (m)
00032  *    T  = Tbar = mean basin temp (C)
00033  *      Q  = daily discharge (m^3/s)
00034  *      Qs = daily sediment flux (kg/s)
00035  *      Cs = daily sediment concentration (kg sediment/ m^3 water)
00036  * 
00037  * If reservoir capacity is larger than 0.5km^3:
00038  * Trapping efficiency (TE) calculated, based on paper of:
00039  * Charles J. Vorosmarty, Michel Meybeck, Balazs Rekete & Keshav Sharma: 
00040  * The potential impact of neo-Castorization on sediment transport by the 
00041  * global network of rivers (1997) in Human Impact on erosion and 
00042  * Sedimentation (Proceedings of the Rabat Symposium April 1997).
00043  * Based on the Brune equation:
00044  *
00045  *    TE =  Is only effective as lakes of reservoirs are turned on in 
00046  *          the input file.
00047  *    TEbasin = 1.0 - (0.05 / exp(Rvol/RQbar)0.5
00048  *              Rvol = Volume of the reservoir
00049  *              RQbar= discharge at the basin mouth of the reservoir 
00050  * 
00051  * If reservoir capacity is smaller than 0.5km^3:
00052  * Trapping efficiency (TE) calculated, based on paper of:
00053  * Gert Verstraeten and Jean Poesen:
00054  * Estimating trap efficiency of small reservoirs and ponds: methods and 
00055  * implications for the assessment of sediment yield.
00056  * Progress in Physical Geography 24,2 (2000) pp.219-251
00057  * 
00058  * TEbasin = ( 1.0 - (1.0 / (1 + 0.00021 * ((Rvol[ep] * 1e9) / Rarea[ep]))))
00059  * 
00060  */
00061 
00062 #include <math.h>
00063 #include <stdlib.h>
00064 #include "hydroclimate.h"
00065 #include "hydroinout.h"
00066 #include "hydroparams.h"
00067 #include "hydrotimeser.h"
00068 #include "hydroreadclimate.h"
00069 #include "hydroalloc_mem.h"
00070 #include "hydrofree_mem.h"
00071 
00072 #ifdef DBG
00073 #include "hydroinout.h"
00074 #endif
00075 
00076 /*-------------------------
00077  *  Start of HydroSedLoad
00078  *-------------------------*/
00079 int hydrosedload ( gw_rainfall_etc* gw_rain )
00080 {
00081 
00082 /*-------------------
00083  *  Local Variables
00084  *-------------------*/
00085 #ifdef DBG
00086 FILE *fid;
00087 #endif
00088 
00089 int err, i,p,kk,y;
00090 long j;
00091 double A, H, RQbar[maxepoch];
00092 double Tbar, Tmean,Tend, Tdummy;
00093 double Psi[daysiy], mu, sigma;
00094 double cbar, s;
00095 double ratio;
00096 double unit_normal, normal;
00097 double unit_normal2, normal2;
00098 double trnfac;
00099 double test;
00100 double *Coutletannual, *cbaroutlet, *soutlet, **Coutlet, *sigmaoutlet;
00101 
00102 
00103 /*------------------------
00104  *  Initialize Variables
00105  *------------------------*/
00106 err  = 0;
00107 y       = 0;
00108 A    = (totalarea[ep] / 1e6);   /****  FORMULA USES AREA in km^2  ****/
00109 H    = maxalt[ep];
00110 
00111 /*-------------------------------------------------------
00112  *  Allocate memory for possible multiple outlet module
00113  *-------------------------------------------------------*/
00114         sigmaoutlet             = malloc1d( maxnoutlet, double );
00115         soutlet                 = malloc1d( maxnoutlet, double );
00116         Coutlet                 = malloc2d( daysiy, maxnoutlet, double );
00117         cbaroutlet              = malloc1d( maxnoutlet, double );
00118         Coutletannual   = malloc1d( maxnoutlet, double );
00119         Qsbartotoutlet  = malloc2d( maxepoch, maxnoutlet, double );
00120 
00121 /*-------------------------------------
00122  *  Calculate Tbar for drainage basin
00123  *-------------------------------------*/
00124 if ( raindatafile == 1 ){
00125         Tdummy=0.0;
00126         for (i=0; i<nyears[ep]; i++)
00127                 Tdummy +=gw_rain->Tperyear[i];
00128         Tmean=Tdummy/nyears[ep];
00129 }
00130 else{
00131         Tend = Tstart[ep] + (Tchange[ep]*nyears[ep]);
00132         Tmean=(Tstart[ep] + Tend)/2;
00133 }       
00134 Tbar = Tmean - ( (lapserate[ep] * maxalt[ep]) / 3.0 );
00135 
00136 /*-------------------------------------------------------
00137  *  Calculate trapping efficiency (TE) of the reservoir
00138  *-------------------------------------------------------*/
00139 if (setstartmeanQandQs == 3 && yr == syear[ep]){
00140         if ( Rvol[ep] != 0.0 ){
00141                 if ( Rarea[ep] == 0.0 )
00142                         for (kk=0; kk<nhypts[ep];kk++)
00143                                 if ( hypselev[ep][kk] == Ralt[ep] || hypselev[ep][kk] > Ralt[ep] ){
00144                                         Rarea[ep] = A - ( hypsarea[ep][kk] / 1e6 );
00145                                         kk = nhypts[ep];
00146                                 }
00147                         
00148                 if (Rvol[ep] < 0.5){
00149         /*-------------------------------------
00150          *  TE Calculated with Browns methode 
00151          *-------------------------------------*/                       
00152                         TEsubbasin[ep] = ( 1.0 - (1.0 / (1 + 0.00021 * ((Rvol[ep] * 1e9) / Rarea[ep]))));
00153                         TE[ep] = (Rarea[ep] / A) * TEsubbasin[ep];
00154                 }
00155                 
00156                 else if (Rvol[ep] >= 0.5) {
00157         /*----------------------------------------------------
00158          *  TE Calculated with Charles J. Vorosmarty methode 
00159          *----------------------------------------------------*/                                        
00160                 RQbar[ep] = Qbartotal[ep] * (Rarea[ep] / A);
00161                 RQbar[ep] *=0.031536;  /* FORMULA USES QBAR in KM3/YEAR */
00162                 TEsubbasin[ep] = 1.0 - (0.05 / pow(((Rvol[ep]/RQbar[ep])),0.5));
00163                 TE[ep] = (Rarea[ep] / A) * TEsubbasin[ep];
00164                 }
00165         }
00166         else if (Rvol[ep] == 0.0)
00167                 TE[ep] = 0.0;
00168 }
00169 
00170 /*--------------------------------
00171  *  Compute Qsbar for this epoch
00172  *--------------------------------*/
00173 if (Qsbarformulaflag[ep] == 1)
00174         if (setstartmeanQandQs == 3 && yr == syear[ep]){
00175                 Qsbartot[ep] = alpha3 * (1.0 - TE[ep]) * pow(A,alpha4) * pow(H,alpha5) * exp(k1*Tbar);
00176         }
00177 if (Qsbarformulaflag[ep] == 0){
00178         if (setstartmeanQandQs == 3 && yr == syear[ep])
00179                 Qsbartot[ep] = (alpha6  *(1.0 - TE[ep]) * pow(Qbartotal[ep],alpha7) * pow(H,alpha8) * exp(k2*Tbar));
00180 }
00181 if (setstartmeanQandQs == 2)
00182         Qsbartot[ep] = 1;
00183 /*-------------------------------------------
00184  *  Compute Qsbar per outlet for this epoch
00185  *-------------------------------------------*/
00186 if (outletmodelflag == 1 && setstartmeanQandQs > 2){
00187         Qsoutletdummy = 0.0;
00188         for (p=0; p<maxnoutlet; p++){
00189                 Qsbartotoutlet[ep][p]= pow(Qbar[ep][p][eventcounter-eventsperyear],alpha7) ;
00190                 Qsoutletdummy += Qsbartotoutlet[ep][p];
00191         }
00192 }
00193 
00194 /*--------------------------------------------
00195  *      Compute the bedload transport factor
00196  *--------------------------------------------*/
00197 trnfac = ( rhowater[ep] * rhosed[ep] * trneff ) /       \
00198         ( (rhosed[ep] - rhowater[ep]) * tan( anglerep*degTOr ));
00199 
00200 /*----------------------------------------------
00201  *  Get parameters for random numbers Psi & C.
00202  *  Qsum is passed in.
00203  *----------------------------------------------*/
00204 mu    = 0.0;
00205 s     = 0.17 + (0.0000183 * Qbartotal[ep]);
00206 sigma = 0.763 * pow(0.99995, Qbartotal[ep]);
00207 cbar  = 1.4 - (0.025 * Tbar) + (0.00013 * H) + (0.145 *log(Qsbartot[ep]));
00208 
00209 /*------------------------------------------
00210  *  Initialize the annual values to zero.
00211  *  The Cs[i], Qs[i], and Qb[i] arrays are
00212  *  initialized to zero in HydroTrend.c.
00213  *------------------------------------------*/
00214 Qsannual   = 0.0;
00215 Csannual   = 0.0;
00216 Qbedannual = 0.0;
00217 if (outletmodelflag == 1 && setstartmeanQandQs > 2)
00218         for (p=0; p<maxnoutlet; p++){
00219                 Qsannualoutlet[p]   = 0.0;
00220                 Csannualoutlet[p]       = 0.0;
00221                 Qbedannualoutlet[p] = 0.0;
00222                 Coutletannual[p]        = 0.0;
00223         }       
00224 if ( yr == syear[ep] ){
00225         Qsgrandtotal[ep] = 0.0;
00226         Csgrandtotal[ep] = 0.0;
00227         if ( outletmodelflag == 1 && setstartmeanQandQs > 2 )   
00228                 for (p=0; p<maxnoutlet; p++){
00229                         Qsgrandtotaloutlet[ep][p] = 0.0;
00230                         Csgrandtotaloutlet[ep][p] = 0.0;
00231                 }
00232 }
00233 
00234 /*--------------------------------------
00235  *  Loop through each day of year and
00236  *  calculate total sediment discharge.
00237  *  (daysiy defined in hydrotimeser.h)
00238  *--------------------------------------*/
00239 for (i=0; i < daysiy; i++) {
00240     /*-----------------------------------
00241      *  Generate the random number, Psi
00242      *-----------------------------------*/
00243         unit_normal = ranarray[i];
00244     normal = (sigma * unit_normal) + mu;
00245     Psi[i] = exp(normal);  
00246 }
00247     /*-----------------------------------
00248      *  Generate the random number, C
00249      *  (Can be normal or uniform.)
00250      *-----------------------------------*/
00251 if (setstartmeanQandQs == 2 && yr == syear[ep]){        
00252         C = malloc1d( nyears[ep], double );
00253         for (j=0; j < nyears[ep]; j++) {
00254         unit_normal2 = ((rand()/327680000.9));
00255 //      printf( "%f\n",unit_normal2);
00256             normal2 = (s * unit_normal2) + cbar;
00257         C[j] = normal2;
00258 //      printf("%f\n",C[j]);
00259         }
00260 //      exit(-1);
00261 }
00262 for (i=0; i < daysiy; i++) {    
00263 
00264     /*----------------------------------------------
00265      *  Compute daily sediment discharge, Qs.
00266      *  Save both ratio's in memory or if there is
00267      *  not enough memory, save it to temp file.
00268      *----------------------------------------------*/
00269     ratio = Qsumtot[i]/Qbartotal[ep];      
00270         if (setstartmeanQandQs < 4){            
00271             Qs[i] = Psi[i] * pow(ratio, C[yr-syear[ep]]);        
00272         }
00273         if (setstartmeanQandQs == 4){
00274                 Qs[i] = Psi[i] * Qsbarnew[ep] * pow(ratio, C[yr-syear[ep]]);
00275         
00276     /*-------------------------
00277      *  Check for NaNs in Qs
00278      *-------------------------*/
00279             if (isnan(Qs[i])) {
00280             fprintf( stderr,"\nHydroSedload ERROR: Qs = nan \n");
00281                 fprintf( stderr," yr = %d, day = %d \n", yr, i );
00282             fprintf( stderr,"   Qnival[i]    = %e \n", Qnival[i] );
00283                 fprintf( stderr,"   Qrain[i]     = %e \n", Qrain[i] );
00284                 fprintf( stderr,"   Qexceedgw[i] = %e \n", Qexceedgw[i] );
00285             fprintf( stderr,"   Qice[i]      = %e \n", Qice[i] );
00286                 fprintf( stderr,"   Qss[i]       = %e \n", Qss[i] );
00287                 fprintf( stderr,"   baseflow[ep] = %e \n", baseflowtot[ep] ); /*  variables below here should be deleted */
00288             fprintf( stderr,"   ratio        = %e \n", ratio );
00289                 fprintf( stderr,"       Qsum[i]          = %e \n", Qsumtot[i] );
00290                 fprintf( stderr,"       Qbar[ep]         = %e \n", Qbartotal[ep] );
00291             fprintf( stderr,"   Psi[i]       = %e \n", Psi[i] );
00292                 fprintf( stderr,"   Qsbarnew[ep] = %e \n", Qsbarnew[ep] );
00293                 fprintf( stderr,"   C[i]         = %e \n", C[yr-syear[ep]] );
00294             fprintf( stderr,"   ep           = %d \n", ep );
00295                 fprintf( stderr,"   cbar         = %e \n", cbar );
00296                 err = 1;
00297         }
00298         } //( end setstartmeanQandQs == 4 )
00299 
00300     /*---------------------------------
00301      *  Compute Qsannual and daily Cs
00302      *---------------------------------*/
00303     if (Qs[i] > 0.0) {
00304         Cs[i] = Qs[i] / Qsumtot[i];
00305         Qsannual += Qs[i] * dTOs;       
00306     } else
00307         Cs[i] = 0.0;
00308     Csannual += Cs[i]*dTOs;
00309 
00310     /*----------------------------
00311      *  Compute threshold (m3/s)
00312      *----------------------------*/
00313 //     threshbed[ep]=(Qbar[ep]/3);
00314 
00315     /*--------------------------------------------------------
00316      *  Compute bedload (kg/s), if above threshold flow rate
00317      *--------------------------------------------------------*/
00318 //     if (Qsum[i] > threshbed[ep]) {
00319            Qb[i] = trnfac * rslope[ep] * pow( Qsumtot[i], alphabed );
00320            Qbedannual += Qb[i] * dTOs;
00321 //     }
00322 
00323     /*-------------------------------
00324      *  Compute sediment per outlet
00325      *-------------------------------*/
00326         if (outletmodelflag == 1 && (setstartmeanQandQs > 2)){
00327         
00328         /*----------------------------------------------------------------
00329          *  If there is more than 1 event occuring during a single year,
00330          *  keep tracking on what they it is, to change the Qbar on that
00331          *  day.
00332          *----------------------------------------------------------------*/
00333                 if ( numberday[y] == i && eventsperyear > 0){
00334                         y++;
00335                         eventsperyear--;
00336                 }
00337                 
00338     /*-----------------------------------
00339      *  Generate the random number, Psi
00340      *  Generate the random number, C
00341      *  (Can be normal or uniform.)
00342      *-----------------------------------*/     
00343                 if (i == 0)
00344                 for (j=0; j < daysiy; j++) {
00345                         for (p=0; p<maxnoutlet; p++){
00346                                 if (outletpct[p][ep][eventcounter-eventsperyear] != 0.0){
00347                                         test = (Qsbartotoutlet[ep][p]/Qsoutletdummy)*Qsbartot[ep];
00348                                         if (test == 0.000 ){
00349                                                 printf("test=%f",test);
00350                                                 exit(-1);
00351                                         }
00352                                         cbaroutlet[p]   = (1.4 - (0.025 * Tbar) + (0.00013 * H) + (0.145 *log (test)));
00353                                         soutlet[p]              = (0.17 + (0.0000183 * Qbar[ep][p][eventcounter-eventsperyear]));
00354                                         unit_normal2 = ranarray[i + daysiy];
00355                                         normal2 = (soutlet[p] * unit_normal2) + cbaroutlet[p];
00356                                         Coutlet[j][p] = normal2;
00357                                         Coutletannual[p] +=Coutlet[j][p];
00358                                 }
00359                         }
00360                 }       
00361                 for (p=0; p<maxnoutlet; p++){
00362                         if (outletpct[p][ep][eventcounter-eventsperyear] != 0.0){       
00363     /*-------------------------
00364      *  Compute Qs per outlet
00365      *-------------------------*/                       
00366                                 ratio = Qsum[i][p]/Qbar[ep][p][eventcounter-eventsperyear];
00367                                 if (setstartmeanQandQs == 3){
00368                                         Qsoutlet[i][p] = Psi[i] * pow((Qsbartotoutlet[ep][p]/Qsoutletdummy), Coutlet[yr-syear[ep]][p]) * pow(ratio, Coutlet[yr-syear[ep]][p]);
00369                                 }
00370                                 if (setstartmeanQandQs == 4){
00371                                         Qsoutlet[i][p] = Psi[i] * pow((Qsbartotoutlet[ep][p]/Qsoutletdummy), Coutlet[yr-syear[ep]][p]) * Qsbarnew2[ep] * pow(ratio, Coutlet[yr-syear[ep]][p]);
00372                                 
00373     /*-------------------------
00374      *  Check for NaNs in Qs
00375      *-------------------------*/
00376                                         if (isnan(Qsoutlet[i][p])) {
00377                                         fprintf( stderr,"\nHydroSedload ERROR: Qsoutlet[day][nr] = nan \n");
00378                                                 fprintf( stderr," yr = %d, day = %d, outlet = %d \n", yr, i, p );
00379                                                 fprintf( stderr,"   Qnival[i]    = %e \n", Qnival[i] );
00380                                                 fprintf( stderr,"   Qrain[i]     = %e \n", Qrain[i] );
00381                                                 fprintf( stderr,"   Qexceedgw[i] = %e \n", Qexceedgw[i] );
00382                                                 fprintf( stderr,"   Qice[i]      = %e \n", Qice[i] );
00383                                                 fprintf( stderr,"   Qss[i]       = %e \n", Qss[i] );
00384                                                 fprintf( stderr,"   baseflow[ep] = %e \n", baseflowtot[ep] ); /*  variables below here should be deleted */
00385                                                 fprintf( stderr,"   ratio        = %e \n", ratio );
00386                                                 fprintf( stderr,"       Qsumoutlet       = %e \n", Qsum[i][p] );
00387                                                 fprintf( stderr,"       Qbar[ep]         = %e \n", Qbartotal[ep] );
00388                                                 fprintf( stderr,"   Psi[i]       = %e \n", Psi[i] );
00389                                                 fprintf( stderr,"   Qsbarnew2[ep]= %e \n", Qsbarnew2[ep] );
00390                                                 fprintf( stderr,"   Coutlet[i][p]= %e \n", Coutlet[i][p] );
00391                                                 fprintf( stderr,"   cbaroutlet[p]= %e \n", cbaroutlet[p] );
00392                                                 fprintf( stderr,"       soutlet[p]   = %e \n", soutlet[p] );
00393                                                 err = 1;
00394                                         }       
00395                                 }
00396                                 Qsannualoutlet[p] += Qsoutlet[i][p] * dTOs;
00397                         
00398     /*--------------------------------------------
00399      *  Compute Qsannual and daily Cs per outlet
00400      *--------------------------------------------*/
00401                                 if (Qsoutlet[i][p] > 0.0)
00402                                         Csoutlet[i][p] = Qsoutlet[i][p] / Qsum[i][p];
00403                                 else Csoutlet[i][p] = 0.0;                      
00404                                 Csannualoutlet[p] += Csoutlet[i][p] * dTOs;
00405     
00406     /*-------------------------------------
00407      *  Compute bedload (kg/s) per outlet
00408      *-------------------------------------*/                   
00409                                 Qboutlet[i][p] = trnfac * rslope[ep] * pow( Qsum[i][p], alphabed );
00410                                 Qbedannualoutlet[p] += Qboutlet[i][p] * dTOs;
00411                         }
00412                         else Qsoutlet[i][p] = 0.0;
00413                 } /* end for outlets*/
00414         }       
00415  }  /* end for loop over days */
00416  
00417 
00418 Qsgrandtotal[ep] += Qsannual;
00419 Csgrandtotal[ep] += Csannual;
00420 if ( outletmodelflag == 1 && setstartmeanQandQs > 2 )
00421         for (p=0; p<maxnoutlet; p++){ 
00422                 Qsgrandtotaloutlet[ep][p] += Qsannualoutlet[p];
00423                 Csgrandtotaloutlet[ep][p] += Csannualoutlet[p];
00424                 Coutlettotal[ep][p] +=Coutletannual[p];                                 
00425         }
00426 
00427 /*---------------
00428  *  Free memory
00429  *---------------*/     
00430         freematrix1D( (void*)sigmaoutlet);
00431         freematrix1D( (void*)soutlet);
00432         freematrix1D( (void*)cbaroutlet);
00433         freematrix1D( (void*)Coutletannual);
00434         freematrix2D( (void**)Coutlet, daysiy);
00435         freematrix2D( (void**)Qsbartotoutlet, maxepoch);
00436         
00437  return(err);
00438 }  /* end of HydroSedLoad */
00439 

Generated on Fri Jan 4 18:04:14 2008 for sedflux by  doxygen 1.5.2