/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/bing/bing_main.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 <stdio.h>
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include <math.h>
00025 
00026 #include <sed/sed_sedflux.h>
00027 
00028 /*** Self Documentation ***/
00029 char *help_msg[] =
00030 {
00031 "                                                                             ",
00032 " bing [options] [parameters]  [filein]                                       ",
00033 "  run a bingham plastic debris flow.                                         ",
00034 "                                                                             ",
00035 " Options                                                                     ",
00036 "  -o outfile  - send output to outfile instead of stdout. [stdout]           ",
00037 "  -v          - be verbose. [off]                                            ",
00038 "  -h          - print this help message.                                     ",
00039 "                                                                             ",
00040 " Parameters                                                                  ",
00041 "  -pdt=value  - Use a time step of value seconds. [ .01 ]                    ",
00042 "  -pnu=value  - Use a viscosity value of value m^2/s for the flow. [ .00083 ]",
00043 "  -pnuart=value - Use a numerical viscosity value of value m^2/s for the     ",
00044 "                  flow. [ .01 ]                                              ",
00045 "  -pyield=value - Use a yield strength of value N/m^2. [ 100. ]              ",
00046 "  -prho=value - Use a flow density of value kg/m^3. [ 1500. ]                ",
00047 "  -pend=value - Stop the simulation after value minutes. [ 60. ]             ",
00048 "  -pint=value - Write to output file every value seconds [ 120 ]             ",
00049 "                                                                             ",
00050 " Files                                                                       ",
00051 "  Input File                                                                 ",
00052 "   filein      -- Read bathymetry data from filein. [ stdin ]                ",
00053 "    Bathymetry is defined by x-y pairs with each point given on a new line.  ",
00054 "    Values are in meters from an arbitrary origin.  Comment lines are allowed",
00055 "    and are defined as any lines not beginning with a number.                ",
00056 "                                                                             ",
00057 "  Output File:                                                               ",
00058 "    Output is binary and gives flow characteristics for each node of the flow",
00059 "    at regular time intervals.  A header is written, then the data.          ",
00060 "    --The header--                                                           ",
00061 "    The number of points defining the profile - 4 byte int                   ",
00062 "    X-coordinates of profile nodes            - 8 byte doubles               ",
00063 "    Y-coordinates of profile nodes            - 8 byte doubles               ",
00064 "    The number of nodes defining the flow     - 4 byte int                   ",
00065 "    --The body--                                                             ",
00066 "    Flag indicating that there is more data   - 8 byte double                ",
00067 "    X-coordinate of each node                 - 8 byte doubles               ",
00068 "    Thickness of flow at each node            - 8 byte doubles               ",
00069 "    Velocity of flow at each node             - 8 byte doubles               ",
00070 "    Y-coordinate of base of flow at each node - 8 byte doubles               ",
00071 "                                                                             ",
00072 NULL
00073 };
00074 
00075 #include <utils/utils.h>
00076 #include "bing.h"
00077 
00078 /* int ReadFloor(FILE *,double **,double **); */
00079 /*
00080 int bing(double[],int,int,double,double*,double*,double,double,
00081    double,double,double,double,int,double[]);
00082 */
00083 
00084 #ifndef EPS
00085 # define EPS 1e-5
00086 #endif
00087 
00088 #define NNODES                  7     /* number of nodes defining flow */
00089 #define nxpts                   1000    /* array lengths */
00090 
00091 #define D_MAX                   4.0
00092 #define INIT_LEN                1000.0 /* inital length of debris flow (m) */
00093 #define FLOW_START              10     /* index to node of tail of flow */
00094 
00095 /* Default values */
00096 #define DEFAULT_VERBOSE             0
00097 #define DEFAULT_IN_FILE             stdin
00098 #define DEFAULT_OUT_FILE            stdout
00099 #define DEFAULT_IN_FILE_NAME        "stdin"
00100 #define DEFAULT_OUT_FILE_NAME       "stdout"
00101 #define DEFAULT_WRITE_INTERVAL      120
00102 #define DEFAULT_END_TIME            60.0
00103 #define DEFAULT_SLOPE               2.0
00104 #define DEFAULT_VISCOSITY           0.00083
00105 #define DEFAULT_NUMERICAL_VISCOSITY 0.01
00106 #define DEFAULT_YIELD_STRENGTH      100.0
00107 #define DEFAULT_TIME_STEP           .01
00108 #define DEFAULT_FLOW_DENSITY        1500.0
00109 
00110 #define FLOOR_LENGTH 100000.
00111 
00112 int main(int argc, char *argv[]) 
00113 {
00114    Eh_args *args;
00115    int write_interval;
00116    double p_mud, tau_y, nu, nu_ar;
00117    double end_time, dt;
00118    FILE *fpin, *fpout;
00119    char *infile, *outfile;
00120    gboolean verbose;
00121    double dx;
00122    int i;
00123    double Sj;
00124    double *deposit;
00125    int const nodes=NNODES-1;
00126    bing_t bing_const;
00127    pos_t *bathy, *flow;
00128    
00129    args = eh_opts_init( argc , argv );
00130    if ( eh_check_opts( args , NULL , NULL , help_msg )!=0 )
00131       eh_exit( -1 );
00132 
00133    write_interval = eh_get_opt_int ( args , "int"   , DEFAULT_WRITE_INTERVAL );
00134    end_time       = eh_get_opt_dbl ( args , "end"   , DEFAULT_END_TIME       );
00135    p_mud          = eh_get_opt_dbl ( args , "rho"   , DEFAULT_FLOW_DENSITY   );
00136    tau_y          = eh_get_opt_dbl ( args , "yield" , DEFAULT_YIELD_STRENGTH );
00137    nu             = eh_get_opt_dbl ( args , "nu"    , DEFAULT_VISCOSITY      );
00138    nu_ar          = eh_get_opt_dbl ( args , "nuart" , DEFAULT_NUMERICAL_VISCOSITY );
00139    dt             = eh_get_opt_dbl ( args , "dt"    , DEFAULT_TIME_STEP      );
00140    verbose        = eh_get_opt_bool( args , "v"     , DEFAULT_VERBOSE        );
00141    infile         = eh_get_opt_str ( args , "in"    , DEFAULT_IN_FILE_NAME   );
00142    outfile        = eh_get_opt_str ( args , "out"   , DEFAULT_OUT_FILE_NAME  );
00143 
00144    if ( strcmp( infile , "stdin" )==0 )
00145       fpin = stdin;
00146    else
00147       fpin = eh_fopen( infile , "r" );
00148    if ( strcmp( outfile , "stdout" )==0 )
00149       fpout = stdout;
00150    else
00151       fpout = eh_fopen( outfile , "w" );
00152 
00153    /* convert output interval to iterations.
00154    */
00155    write_interval = (int) (write_interval / dt);
00156    
00157    if ( verbose )
00158    {
00159       fprintf(stderr,"\nBingham Plastic Debris Flow Model.\n\n");
00160       fprintf(stderr,"\tType 'bing help' for help.\n\n");
00161    
00162       fprintf(stderr,"Bing is go ...\n");
00163       fprintf(stderr,"\tSlope          = reading from %s\n",infile);
00164       fprintf(stderr,"\tTime step      = %.5f seconds\n",dt);
00165       fprintf(stderr,"\tViscosity      = %.5f m^2/s\n",nu);
00166       fprintf(stderr,"\tYield Strength = %.5f N/m^2\n",tau_y);
00167       fprintf(stderr,"\tDensity        = %.5f kg/m^3\n",p_mud);
00168       fprintf(stderr,"\tEnd Time       = %.5f minutes\n",end_time);
00169       fprintf(stderr,"\tPrinting every = %.5f minutes\n",write_interval*dt/60.);
00170    }
00171 
00172    Sj = tan(Sj*PI/180.);
00173 
00177 /*   len=ReadFloor(fpin,&x,&h); */
00178    if ( verbose ) fprintf( stderr , "reading bathymetry...\n" );
00179 
00180    dx = 10;
00181    bathy = createPosVec((int)(FLOOR_LENGTH/dx));
00182    for (i=0;i<bathy->size;i++)
00183       bathy->x[i] = i*dx;
00184 //   ReadFloor(fpin,bathy->x,bathy->size,bathy->y);
00185    sed_get_floor_vec(infile,bathy->x,bathy->size,bathy->y , NULL );
00186    for (i=0;i<bathy->size;i++)
00187       bathy->y[i] *= -1.;
00188 
00189 /* Write header to output file */
00190    if ( verbose ) fprintf( stderr , "writing output header...\n" );
00191 
00192    fwrite(&bathy->size,sizeof(bathy->size),1,fpout);
00193    fwrite(bathy->x,sizeof(double),bathy->size,fpout);
00194    fwrite(bathy->y,sizeof(double),bathy->size,fpout);
00195    fwrite(&nodes,sizeof(int),1,fpout);
00196 
00200    flow = createPosVec(NNODES);
00201    for (i=0;i<NNODES;i++) 
00202    {
00203       float DX = INIT_LEN/(NNODES-1);
00204       float width = DX*(NNODES-1)/2.;
00205       
00209       flow->y[i] = (DX*(i-(NNODES-1)/2.+.5)-width)*(DX*(i-(NNODES-1)/2.+.5)+width)/(-width*width)*D_MAX;
00210       flow->x[i] = bathy->x[FLOW_START] + DX*i;
00211    }
00212 
00213    deposit = eh_new( double , bathy->size );
00214    
00215    bing_const.yieldStrength = tau_y;
00216    bing_const.viscosity = nu;
00217    bing_const.numericalViscosity = nu_ar;
00218    bing_const.flowDensity = p_mud;
00219    bing_const.dt = dt;
00220    bing_const.maxTime = end_time;
00221    bing_const.MC = write_interval;
00222 
00223    if ( verbose ) fprintf( stderr , "running the debris flow...\n" );
00224    bing(bathy,flow,bing_const,deposit);
00225 /*
00226    bing(h,len,NNODES,dx,nodeX,nodeH,tau_y,nu,nu_ar,p_mud,dt,end_time,write_interval,deposit);
00227 */
00228 
00229    if ( verbose ) fprintf( stderr , "writing output...\n" );
00230    fwrite(deposit,bathy->size,sizeof(double),fpout);
00231 
00232    fclose(fpin);
00233    fclose(fpout);
00234 
00235    destroyPosVec(flow);
00236    destroyPosVec(bathy);
00237    eh_free(deposit);
00238    
00239    return 0;
00240 
00241 }
00242 

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