/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/inflow/pseudoplume.c

Go to the documentation of this file.
00001 //---
00002 //
00003 // This file is part of sedflux.
00004 //
00005 // sedflux is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 2 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // sedflux is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with sedflux; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //
00019 //---
00020 
00021 #include <stdlib.h>
00022 #include <stdio.h>
00023 #include <math.h>
00024 #include <limits.h>
00025 #include <unistd.h>
00026 #include <string.h>
00027 //#include <libgen.h>
00028 #include "inflow.h"
00029 #include <sed/sed_sedflux.h>
00030 #include <utils/utils.h>
00031 
00032 /*** Self Documentation ***/
00033 char *help_msg[] =
00034 {
00035 "                                                                             ",
00036 " pseudoplume [options] [parameters]  [filein]                                ",
00037 "  run a pseudo-plume.                                                        ",
00038 "                                                                             ",
00039 " Options                                                                     ",
00040 "  -o outfile  - send output to outfile instead of stdout. [stdout]           ",
00041 "  -v          - be verbose. [off]                                            ",
00042 "  -h          - print this help message.                                     ",
00043 "                                                                             ",
00044 " Parameters                                                                  ",
00045 "  -pday=value - set the length of a day to be value fraction of 24 hrs. [1]  ",
00046 "  -pb0=value  - width of the river mouth (m). [1]                            ",
00047 "  -pu0=value  - velocity at the river mouth (m/s). [1]                       ",
00048 "  -pI0=value  - sediment inventory at the river mouth (m/s). [1]             ",
00049 "  -plambda=value  - removal rate for the sediment (1/day). [10]              ",
00050 "                                                                             ",
00051 "  -fin        - input bathymetry file. [stdin]                               ",
00052 "  -fout       - output bathymetry file. [stdout]                             ",
00053 NULL
00054 };
00055 
00056 #ifndef M_PI
00057 # define M_PI           3.14159265358979323846
00058 #endif
00059 
00060 #define DEFAULT_DAY_LENGTH           1
00061 #define DEFAULT_VERBOSE              0
00062 #define DEFAULT_U0                   (1.)
00063 #define DEFAULT_B0                   (1.)
00064 #define DEFAULT_I0                   (1.)
00065 #define DEFAULT_LAMBDA               (10.)
00066 
00067 double *pseudoplume(double *x, int len_x, double lambda, double *I);
00068 
00069 int main(int argc,char *argv[])
00070 {
00071    FILE *fp_out;
00072    Eh_args *args;
00073    char *infile, *outfile;
00074    int i,  n_nodes;
00075    gboolean verbose;
00076    double day, u0, b0, inv0, lambda;
00077    double *x, *y, *z;
00078    double *I;
00079 
00080    args = eh_opts_init( argc , argv );
00081    if ( eh_check_opts( args , NULL , NULL , help_msg )!=0 )
00082       eh_exit(-1);
00083 
00084    verbose = eh_get_opt_bool( args , "v"      , FALSE              );
00085    day     = eh_get_opt_dbl ( args , "day"    , DEFAULT_DAY_LENGTH );
00086    b0      = eh_get_opt_dbl ( args , "b0"     , DEFAULT_B0         );
00087    u0      = eh_get_opt_dbl ( args , "u0"     , DEFAULT_U0         );
00088    inv0    = eh_get_opt_dbl ( args , "I0"     , DEFAULT_I0         );
00089    lambda  = eh_get_opt_dbl ( args , "lambda" , DEFAULT_LAMBDA     );
00090    infile  = eh_get_opt_str ( args , "in"     , NULL               );
00091    outfile = eh_get_opt_str ( args , "out"    , NULL               );
00092    
00093    lambda /= 86400.;
00094 
00095    if ( verbose )
00096    {
00097       fprintf(stderr,"pseudoplume : river width (m)      : %f\n",b0);
00098       fprintf(stderr,"pseudoplume : river velocity (m/s) : %f\n",u0);
00099       fprintf(stderr,"pseudoplume : removal rate (1/s)   : %f\n",lambda);
00100    }
00101 
00102 // Read input bathymetry.
00103    {
00104       Eh_data_record* all_records = eh_data_record_scan_file( infile , "," , EH_FAST_DIM_COL , FALSE , NULL );
00105 
00106       x = eh_data_record_dup_row( all_records[0] , 0 );
00107       y = eh_data_record_dup_row( all_records[0] , 1 );
00108       z = eh_data_record_dup_row( all_records[0] , 2 );
00109 
00110       for ( i=0 ; all_records[i] ; i++ )
00111          eh_data_record_destroy( all_records[i] );
00112       eh_free( all_records );
00113    }
00114 
00115 // Allocate space for the plume deposit.
00116    I = eh_new( double , n_nodes );
00117 
00118 // Non-dimesionalize x, and lambda.
00119    for (i=0;i<n_nodes;i++)
00120       x[i] /= b0;
00121    lambda *= (b0/u0);
00122 
00123 // Run the pseudoplume.
00124    pseudoplume(x,n_nodes,lambda,I);
00125 
00126 // Redimensionalize the output.
00127    for (i=0;i<n_nodes;i++)
00128    {
00129       x[i] *= b0;
00130       I[i] *= inv0;
00131    }
00132 
00133 // Add the pseudoplume deposit to the bathymetry.
00134    for (i=0;i<n_nodes;i++)
00135       y[i] += I[i];
00136 
00137 // Write out the new bathymetry.
00138    fp_out = eh_open_file( outfile , "w" );
00139    for (i=0;i<n_nodes;i++)
00140       fprintf(fp_out,"x, y, w : %f, %f, %f\n",x[i],I[i],z[i]);
00141    fclose( fp_out );
00142 
00143    eh_free(I);
00144    eh_free( x );
00145    eh_free( y );
00146    eh_free( z );
00147 
00148    return 0;
00149 }
00150 
00152 //
00153 // x      - non-dimensional distances from the river mouth.
00154 // len_x  - length of vector x.
00155 // lambda - non-dimensional removal rate.
00156 // I      - resulting non-dimentional inventory.
00157 //
00158 // The variables are non-dimensionalized as follows:
00159 //   x = x'/b0
00160 //   lambda = lambda' * b0 / u0
00161 //
00162 // where,
00163 //   x' = dimesional distance
00164 //   lambda' = dimensional removal rate
00165 //   b0 = dimensional river mouth width
00166 //   u0 = dimensional river mouth velocity
00167 //
00169 
00170 #define X_A (5.176)
00171 #define PSEUDOPLUME_A (0.126)
00172 #define PSEUDOPLUME_B (1.)
00173 
00174 double *pseudoplume(double *x, int len_x, double lambda, double *I)
00175 {
00176    int i;
00177    double x_a=X_A;
00178    double a=PSEUDOPLUME_A;
00179    double b=PSEUDOPLUME_B;
00180 
00181    for (i=0;i<len_x;i++)
00182    {
00183       if ( x[i] < x_a )
00184          I[i] = exp(-lambda*x[i]);
00185       else
00186          I[i] = exp(-lambda*x_a/3.*(1+2*pow(x[i]/x_a,1.5)))*(1./(1+a*pow(x[i]-x_a,b)));
00187    }
00188 
00189    return I;
00190 }
00191 

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