/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/flow/flow_3d_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 N_DEFAULT        (5)
00078 #define DX_DEFAULT       (25.)
00079 #define DT_DEFAULT       (48000.)
00080 #define END_TIME_DEFAULT (1280000.)
00081 #define PSI_MIN_DEFAULT  (10.)
00082 #define VERBOSE_DEFAULT  (FALSE)
00083 
00084 void print_profile_3d( 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, k, 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_3d( n );
00155    psi = eh_new( double** , n );
00156    for ( i=0 ; i<n ; i++ )
00157    {
00158       psi[i] = eh_new( double* , n );
00159 //      for ( j=0 ; j<n ; j++ )
00160 //         psi[i][j] = eh_new( double , n );
00161    }
00162 
00163    kx  = allocate_3d( n );
00164    kz  = allocate_3d( n );
00165    c   = allocate_3d( n );
00166 
00167    for ( i=0 ; i<n ; i++ )
00168    {
00169       for ( j=0 ; j<n ; j++ )
00170       {
00171          psi[i][j] = eh_linspace( psi_base , psi_min , n );
00172          for ( k=0 ; k<n ; k++ )
00173          {
00174             psi[i][j][k] = 1.;
00175             kx[i][j][k]  = 1;
00176             kz[i][j][k]  = 1;
00177             c[i][j][k]   = 1.;
00178          }
00179       }
00180    }
00181 
00182    for ( i=0 ; i<n ; i++ )
00183    {
00184       for ( j=0 ; j<n ; j++ )
00185          for ( k=0 ; k<n ; k++ )
00186          {
00187 /*
00188             if ( i>n/4 && j>n/4  && (k>n/4 && k<n/2)  )
00189             {
00190                kx[i][j][k] /= 100;
00191                kz[i][j][k] /= 1000;
00192             }
00193 */
00194 /*
00195             if ( (k>n/2 && k<3*n/4)  )
00196             {
00197                kx[i][j][k] /= 50;
00198                kz[i][j][k] /= 1000;
00199             }
00200 */
00201          }
00202 
00203    }
00204 
00205    sed_rate_vec = allocate_2d( n );
00206 
00207    for ( i=0 ; i<n ; i++ )
00208       for ( j=0 ; j<n ; j++ )
00209       {
00210          psi[i][j][n-1]     = 0;
00211          sed_rate_vec[i][j] = 0;
00212 
00213 /*
00214          if ( (i>=(n-1)/2-1 && i<=(n-1)/2+1) && (j>=(n-1)/2-1 && j<=(n-1)/2+1) )
00215             sed_rate_vec[i][j] = sed_rate*10000;
00216 */
00217 
00218       }
00219 
00220 //   sed_rate_vec[(n-1)/2][(n-1)/2] = sed_rate*dz*dz;
00221 
00222    // write out the initial conditions.
00223    print_profile_3d( t , psi , n );
00224 
00225    for ( t=0 ; t<end_time ; t+=dt)
00226    {
00227 
00228 /*
00229       if ( t>end_time/2 )
00230          for ( i=0 ; i<n ; i++ )
00231             for ( j=0 ; j<n ; j++ )
00232                sed_rate_vec[i][j] = 0;
00233 */
00234 
00235       dt = dt_init;
00236 
00237       solve_excess_pore_pressure_mg_3d( psi , kx , kz , c , n , dx , dz , dt , sed_rate_vec );
00238 
00239       // write out the solution for this time step.
00240       print_profile_3d( t+dt , psi , n );
00241 
00242    }
00243 
00244    return 0;
00245 }
00246 //EOC
00247 
00248 void print_profile_3d( double t , double ***psi , int n )
00249 {
00250    int i, j, k;
00251 
00252    for ( k=0 ; k<n ; k++ )
00253       for ( j=0 ; j<n ; j++ )
00254          for ( i=0 ; i<n ; i++ )
00255             fwrite( &(psi[i][j][k]) , sizeof(double) , 1 , stdout );
00256 
00257 //   fwrite( psi[0][0] , sizeof(double) , n*n*n , stdout );
00258 fflush(stdout);
00259 }
00260 

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