00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00028 #include "inflow.h"
00029 #include <sed/sed_sedflux.h>
00030 #include <utils/utils.h>
00031
00032
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
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
00116 I = eh_new( double , n_nodes );
00117
00118
00119 for (i=0;i<n_nodes;i++)
00120 x[i] /= b0;
00121 lambda *= (b0/u0);
00122
00123
00124 pseudoplume(x,n_nodes,lambda,I);
00125
00126
00127 for (i=0;i<n_nodes;i++)
00128 {
00129 x[i] *= b0;
00130 I[i] *= inv0;
00131 }
00132
00133
00134 for (i=0;i<n_nodes;i++)
00135 y[i] += I[i];
00136
00137
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
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
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