/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/flow/flow_2d_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 DX_DEFAULT       (25.)
00078 #define DT_DEFAULT       (48000.)
00079 #define END_TIME_DEFAULT (1280000.)
00080 #define PSI_MIN_DEFAULT  (10.)
00081 #define N_DEFAULT        (5)
00082 #define VERBOSE_DEFAULT  (FALSE)
00083 
00084 void print_profile_2d( double t , double **psi , int n );
00085 
00086 static char *help_msg[] = {
00087 " flow - sovle the 1d consolidation equation.                         ",
00088 "                                                                     ",
00089 " options:                                                            ",
00090 "   r       : sedimentation rate (m/s)                                ",
00091 "   d       : initial depth of the sediment (m)                       ",
00092 "   u0      : excess porewater pressure at the bsae of the model      ",
00093 "   umin    : excess porewater pressure of surface sediment           ",
00094 "   dz      : vertical resolution of the model (m)                    ",
00095 "   dt      : time resolution of the model (s)                        ",
00096 "   end     : length of the model (s)                                 ",
00097 "                                                                     ",
00098 NULL };
00099 
00100 #include <stdlib.h>
00101 
00102 int main( int argc , char *argv[] )
00103 {
00104    double *sed_rate_vec;
00105    double sed_rate;
00106    double depth;
00107    double psi_base;
00108    double psi_min;
00109    double dx;
00110    double dz;
00111    double dt;
00112    double dt_init;
00113    double end_time;
00114    gboolean verbose;
00115    int i, j, n;
00116    double t;
00117    double **psi;
00118    double **kx, **kz, **c;
00119    Eh_args *args;
00120 
00121    args = eh_opts_init( argc , argv );
00122    if ( eh_check_opts( args , NULL , NULL , help_msg )!=0 )
00123       eh_exit(-1);
00124 
00125    sed_rate = eh_get_opt_dbl ( args , "r"    , SED_RATE_DEFAULT );
00126    depth    = eh_get_opt_dbl ( args , "d"    , DEPTH_DEFAULT    );
00127    psi_base = eh_get_opt_dbl ( args , "u0"   , PSI_BASE_DEFAULT );
00128    psi_min  = eh_get_opt_dbl ( args , "umin" , PSI_MIN_DEFAULT  );
00129    dz       = eh_get_opt_dbl ( args , "dz"   , DZ_DEFAULT       );
00130    n        = eh_get_opt_int ( args , "n"    , N_DEFAULT        );
00131    dx       = eh_get_opt_dbl ( args , "dx"   , DZ_DEFAULT       );
00132    dt_init  = eh_get_opt_dbl ( args , "dt"   , DT_DEFAULT       );
00133    end_time = eh_get_opt_dbl ( args , "end"  , END_TIME_DEFAULT );
00134    verbose  = eh_get_opt_bool( args , "v"    , VERBOSE_DEFAULT  );
00135 
00136    if ( verbose )
00137    {
00138       eh_print_opt( args , "r" );
00139       eh_print_opt( args , "d" );
00140       eh_print_opt( args , "u0" );
00141       eh_print_opt( args , "umin" );
00142       eh_print_opt( args , "dz" );
00143       eh_print_opt( args , "dt" );
00144       eh_print_opt( args , "end" );
00145       eh_print_opt( args , "n" );
00146    }
00147 
00148    // the number of nodes.
00149    n = pow(2,n)+1;
00150 
00151    dz = depth/(n-1);
00152 
00153    // allocate memory.
00154    psi = allocate_2d( n );
00155    kx  = allocate_2d( n );
00156    kz  = allocate_2d( n );
00157    c   = allocate_2d( n );
00158 
00159    for ( i=0 ; i<n ; i++ )
00160    {
00161       for ( j=0 ; j<n ; j++ )
00162       {
00163          psi[i][j] = 1;
00164          kx[i][j]  = 1;
00165          kz[i][j]  = 1;
00166          c[i][j]   = 1.;
00167          if ( j>n/4 && j<n/2 ) //&& ( i>n/3 && i<2*n/3 ) )
00168          {
00169             kx[i][j] = .1;
00170             kz[i][j] = .1;
00171          }
00172       }
00173    }
00174 
00175    sed_rate_vec = eh_linspace( 0 , sed_rate , n );
00176 
00177    for ( j=0 ; j<n ; j++ )
00178    {
00179       psi[j][n-1] = psi_min;
00180       sed_rate_vec[j] = 0;
00181    }
00182 
00183 //   sed_rate_vec[(n-1)/2] = sed_rate*dz;
00184 
00185    // write out the initial conditions.
00186    print_profile_2d( t , psi , n );
00187 
00188    for ( t=0 ; t<end_time ; t+=dt)
00189    {
00190 
00191       dt = dt_init;
00192 
00193       solve_excess_pore_pressure_mg_2d( psi , kx , kz , c , n , dx , dz , dt , sed_rate_vec );
00194 
00195       // write out the solution for this time step.
00196       print_profile_2d( t+dt , psi , n );
00197 
00198    }
00199 
00200 //   print_profile_2d( t+dt , psi , n );
00201 
00202    return 0;
00203 }
00204 //EOC
00205 
00206 void print_profile_2d( double t , double **psi , int n )
00207 {
00208    int i, j;
00209    fprintf( stdout , "%f ", t );
00210    for ( i=0 ; i<n ; i++ )
00211       for ( j=0 ; j<n ; j++ )
00212          fprintf( stdout , ", %f ", psi[i][j] );
00213    fprintf( stdout , "\n" );
00214 }
00215 

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