/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/flow/flow_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 <math.h>
00023 
00024 #include <glib.h>
00025 #include <utils/utils.h>
00026 #include "flow.h"
00027 
00028 //BOP
00029 //
00030 // !ROUTINE: flow - solve the 1d consolidation equation.
00031 //
00032 // !INTERFACE:
00033 //
00034 // hw4 [file]
00035 //
00036 // !INPUT PARAMETERS:
00037 //
00038 // file        if a file name is given the input parameters will be read
00039 //             from that file.  otherwise the user will be propmpted for
00040 //             each of the parameters individually.
00041 //
00042 // !DESCRIPTION:
00043 //
00044 // solve the non-linear 1d unsaturated flow problem in a heterogeneous medium.
00045 // the governing equation is,
00046 //   $$ {\partial \over \partial z} \left( K(\theta) \left( {\partial \psi \over \partial z} + 1 \right) \right) = C(\psi){\partial \psi \over \partial t} \eqno{(1)}$$
00047 // the dirichlet boundary condition at the base is,
00048 // $$ \psi(0,t) = 0 $$
00049 // and the neuman boundary condition at the surface is,
00050 // $$ \psi_z(l,t) = {R \over K(\theta) } - 1 $$
00051 // as equation (1) is non-linear, that is the coefficients, $K$ and $C$ are
00052 // themselves a function of the quantity that we are trying to find, we must
00053 // iterate to that solution for each time step.  we do this by guessing at
00054 // a solution, $\tilde{\psi}$, calculating $K$ and $C$ for this $\tilde{\psi}$,
00055 // and then solving for $\psi$ using these $K$ and $C$.  if $\psi$ and
00056 // $\tilde{\psi}$ compare, then we have found an acceptable solution and can
00057 // move to the next time step.  if the predicted solution does not match the
00058 // calculated solution, then we make a new guess and carry out this precedure
00059 // again.
00060 // 
00061 // we predict the solution at the next iteration, $i+1$, as,
00062 // $$ \{ \tilde{\psi} \}_{i+1} = \{ \tilde{\psi} \}_i + \lambda ( \{\psi\}_i - \{ \tilde{\psi} \}_i ) $$
00063 // where $\lambda=.05$.  after we find a solution, we guess at the solution
00064 // for the next time step, $k+1$ as,
00065 // $$ \{ \psi \}^{k+1} = {3\over 2} \{ \psi \}^k - {1\over 2}\{ \psi \}^{k-1} $$
00066 //
00067 // !REVISION HISTORY:
00068 // feb 2002 eric hutton initial version.
00069 //
00070 //EOP
00071 //BOC
00072 
00073 #define SED_RATE_DEFAULT (.005)
00074 #define DEPTH_DEFAULT    (1500.)
00075 #define PSI_BASE_DEFAULT (80.)
00076 #define DZ_DEFAULT       (25.)
00077 #define DT_DEFAULT       (48000.)
00078 #define END_TIME_DEFAULT (1280000.)
00079 #define PSI_MIN_DEFAULT  (10.)
00080 #define N_DEFAULT        (10)
00081 #define VERBOSE_DEFAULT  (FALSE)
00082 
00083 void print_profile( double t , double *psi , int n );
00084 
00085 static char *help_msg[] = {
00086 " flow - sovle the 1d consolidation equation.                         ",
00087 "                                                                     ",
00088 " options:                                                            ",
00089 "   r       : sedimentation rate (m/s)                                ",
00090 "   d       : initial depth of the sediment (m)                       ",
00091 "   u0      : excess porewater pressure at the base of the model      ",
00092 "   umin    : excess porewater pressure of surface sediment           ",
00093 "   dz      : vertical resolution of the model (m)                    ",
00094 "   dt      : time resolution of the model (s)                        ",
00095 "   end     : length of the model (s)                                 ",
00096 "                                                                     ",
00097 NULL };
00098 
00099 
00100 int main( int argc , char *argv[] )
00101 {
00102    double sed_rate;
00103    double depth;
00104    double psi_base;
00105    double psi_min;
00106    double dz;
00107    double dt;
00108    double dt_init;
00109    double end_time;
00110    gboolean verbose;
00111    int i, n;
00112    double t=0;
00113    double *psi;
00114    double *k, *c;
00115    Eh_args *args;
00116 
00117    args = eh_opts_init( argc , argv );
00118    if ( eh_check_opts( args , NULL , NULL , help_msg )!=0 )
00119       eh_exit(-1);
00120 
00121    sed_rate = eh_get_opt_dbl ( args , "r"    , SED_RATE_DEFAULT );
00122    depth    = eh_get_opt_dbl ( args , "d"    , DEPTH_DEFAULT    );
00123    psi_base = eh_get_opt_dbl ( args , "u0"   , PSI_BASE_DEFAULT );
00124    psi_min  = eh_get_opt_dbl ( args , "umin" , PSI_MIN_DEFAULT  );
00125    dz       = eh_get_opt_dbl ( args , "dz"   , DZ_DEFAULT       );
00126    dt_init  = eh_get_opt_dbl ( args , "dt"   , DT_DEFAULT       );
00127    end_time = eh_get_opt_dbl ( args , "end"  , END_TIME_DEFAULT );
00128    n        = eh_get_opt_int ( args , "n"    , N_DEFAULT        );
00129    verbose  = eh_get_opt_bool( args , "v"    , VERBOSE_DEFAULT  );
00130 
00131    if ( verbose )
00132    {
00133       eh_print_opt( args , "r"    );
00134       eh_print_opt( args , "d"    );
00135       eh_print_opt( args , "u0"   );
00136       eh_print_opt( args , "umin" );
00137       eh_print_opt( args , "dz"   );
00138       eh_print_opt( args , "dt"   );
00139       eh_print_opt( args , "end"  );
00140       eh_print_opt( args , "n"    );
00141    }
00142 
00143    // the number of nodes.
00144    n = pow(2,n)+1;
00145 
00146    dz = depth/(n-1);
00147 
00148    // allocate memory.
00149    psi = eh_linspace( psi_base , psi_min , n );
00150    k   = eh_new( double , n );
00151    c   = eh_new( double , n );
00152 
00153    for ( i=0 ; i<n ; i++ )
00154    {
00155       psi[i] = 1;
00156       k[i]   = 1.;
00157       c[i]   = 1.;
00158 
00159       if ( i>n/4 && i<n/2 )
00160          k[i] = .1;
00161 
00162    }
00163    psi[n-1] = psi_min;
00164 
00165    // write out the initial conditions.
00166    print_profile( t , psi , n );
00167 
00168    for ( t=0 ; t<end_time ; t+=dt)
00169    {
00170 //      if ( t>end_time/2 )
00171 //         sed_rate = -fabs(sed_rate);
00172 //         sed_rate = 0;
00173 
00174 //      if ( fabs(sed_rate)>0 )
00175 //         dt = dz/fabs(sed_rate);
00176 //      else
00177          dt = dt_init;
00178 
00179       solve_excess_pore_pressure( psi , k , c , n , dz , dt , psi_min , sed_rate );
00180 
00181       // write out the solution for this time step.
00182       print_profile( t+dt , psi , n );
00183 
00184 /*
00185       if ( sed_rate>0 )
00186       {
00187          n++;
00188          psi = g_renew( double , psi , n );
00189          k   = g_renew( double , k   , n );
00190          c   = g_renew( double , c   , n );
00191          psi[n-1] = psi_min;
00192          k[n-1]   = k[n-2];
00193          c[n-1]   = c[n-2];
00194       }
00195       else if ( sed_rate<0 )
00196          n--;
00197 */
00198    }
00199 //      print_profile( t+dt , psi , n );
00200 
00201    eh_free( k );
00202    eh_free( c );
00203 
00204    return 0;
00205 }
00206 //EOC
00207 
00208 void print_profile( double t , double *psi , int n )
00209 {
00210    int i;
00211    fprintf( stdout , "%f ", t );
00212    for ( i=0 ; i<n ; i++ )
00213       fprintf( stdout , ", %f ", psi[i] );
00214    fprintf( stdout , "\n" );
00215 }
00216 

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