/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/sedflux/run_flow.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 #define EH_LOG_DOMAIN FLOW_PROCESS_NAME_S
00022 
00023 #include <stdio.h>
00024 #include <sed/sed_sedflux.h>
00025 #include "my_processes.h"
00026 
00027 #include "sedflux.h"
00028 
00029 void run_exponential_flow( Sed_column c , double time_now_in_years );
00030 void run_terzaghi_flow( Sed_column c , double time_now_in_years );
00031 void run_darcy_flow( Sed_column c , double dt_in_years );
00032 
00033 Sed_process_info
00034 run_flow( Sed_process proc , Sed_cube p )
00035 {
00036    Flow_t*          data = sed_process_user_data(proc);
00037    Sed_process_info info = SED_EMPTY_INFO;
00038    double           dt_in_years;
00039    double           time_now;
00040    
00041    time_now    = sed_cube_age_in_years( p );
00042    dt_in_years = time_now - data->last_time;
00043 
00044    eh_message( "time : %f"       , time_now    );
00045    eh_message( "dt (years) : %f" , dt_in_years );
00046 
00047    switch ( data->method )
00048    {
00049       case FLOW_ALGORITHM_EXPONENTIAL: eh_message( "method : %s" , "EXPONENTIAL" ); break;
00050       case FLOW_ALGORITHM_TERZAGHI:    eh_message( "method : %s" , "TERZAGHI" );    break;
00051       case FLOW_ALGORITHM_DARCY:       eh_message( "method : %s" , "DARCY" );       break;
00052       default:                         eh_message( "method : %s" , "UNKNOWN" ); eh_require_not_reached();
00053    }
00054 
00055    {
00056       gssize i;
00057       gssize len = sed_cube_size(p);
00058       Sed_column this_col;
00059 
00060       for ( i=0 ; i<len ; i++ )
00061       {
00062          this_col = sed_cube_col(p,i);
00063 
00064          if ( sed_column_len( this_col )>3 )
00065          {
00066             switch ( data->method )
00067             {
00068                case FLOW_ALGORITHM_EXPONENTIAL:
00069                   run_exponential_flow( this_col , time_now );
00070                   break;
00071                case FLOW_ALGORITHM_TERZAGHI:
00072                   run_terzaghi_flow( this_col , time_now );
00073                   break;
00074                case FLOW_ALGORITHM_DARCY:
00075                   run_darcy_flow( this_col , dt_in_years );
00076                   break;
00077                default:
00078                   eh_require_not_reached();
00079             }
00080          }
00081       }
00082    }
00083 
00084    // the current time is now the old time.
00085    data->last_time = time_now;
00086    
00087    return info;
00088 }
00089 
00090 gboolean
00091 init_flow( Sed_process p , Eh_symbol_table tab , GError** error )
00092 {
00093    Flow_t*  data    = sed_process_new_user_data( p , Flow_t );
00094    GError*  tmp_err = NULL;
00095    gboolean is_ok   = TRUE;
00096    gchar*   key;
00097 
00098    data->last_time = 0;
00099 
00100    eh_return_val_if_fail( error==NULL || *error==NULL , FALSE );
00101 
00102    key = eh_symbol_table_lookup( tab , FLOW_KEY_METHOD );
00103 
00104    if      ( g_ascii_strcasecmp( key , "EXPONENTIAL" )==0 ) data->method = FLOW_ALGORITHM_EXPONENTIAL;
00105    else if ( g_ascii_strcasecmp( key , "DARCY"       )==0 ) data->method = FLOW_ALGORITHM_DARCY;
00106    else if ( g_ascii_strcasecmp( key , "TERZAGHI"    )==0 ) data->method = FLOW_ALGORITHM_TERZAGHI;
00107    else
00108       g_set_error( &tmp_err ,
00109                    SEDFLUX_ERROR ,
00110                    SEDFLUX_ERROR_BAD_ALGORITHM ,
00111                    "Invalid fluid flow algorithm (exponential, darcy, or terzaghi): %s" , key );
00112 
00113    if ( tmp_err )
00114    {
00115       g_propagate_error( error , tmp_err );
00116       is_ok = FALSE;
00117    }
00118 
00119    return is_ok;
00120 }
00121 
00122 gboolean
00123 destroy_flow( Sed_process p )
00124 {
00125    if ( p )
00126    {
00127       Flow_t* data = sed_process_user_data( p );
00128 
00129       if ( data ) eh_free( data );
00130    }
00131 
00132    return TRUE;
00133 }
00134 
00135 gboolean dump_flow_data( gpointer ptr , FILE *fp )
00136 {
00137    Flow_t *data = (Flow_t*)ptr;
00138 
00139    fwrite( data           , sizeof(Flow_t) , 1         , fp );
00140    fwrite( data->old_load , sizeof(double) , data->len , fp );
00141 
00142    return TRUE;
00143 }
00144 
00145 gboolean load_flow_data( gpointer ptr , FILE *fp )
00146 {
00147    Flow_t *data = (Flow_t*)ptr;
00148 
00149    fread( data           , sizeof(Flow_t) , 1         , fp );
00150    fread( data->old_load , sizeof(double) , data->len , fp );
00151 
00152    return TRUE;
00153 }
00154 
00155 void run_exponential_flow( Sed_column c , double time_now_in_years )
00156 {
00157    int j, n;
00158    double *k;
00159    double dt_in_secs, dt_in_years;
00160    Sed_cell this_cell;
00161 
00162    n = sed_column_len( c );
00163 
00164    k = eh_new( double , n );
00165 
00166    for ( j=0 ; j<n ; j++ )
00167       k[j] = sed_cell_cc( sed_column_nth_cell(c,j) );
00168 
00169    for ( j=0 ; j<n ; j++ )
00170    {
00171       this_cell = sed_column_nth_cell( c , j );
00172 
00173       dt_in_years = time_now_in_years
00174                   - sed_cell_age( this_cell );
00175       dt_in_secs  = dt_in_years * S_SECONDS_PER_YEAR;
00176 
00177       eh_lower_bound( dt_in_secs , 0 );
00178 
00179       sed_cell_set_pressure( this_cell ,
00180                                sed_cell_pressure( this_cell )
00181                              * exp( -dt_in_years/k[j] ) );
00182 
00183    }
00184 
00185    eh_free( k );
00186 
00187    return;
00188 }
00189 
00190 void run_terzaghi_flow( Sed_column c , double time_now_in_years )
00191 {
00192    int j, n;
00193    double *u, *c_v;
00194    double burial_depth;
00195    double dt_in_secs, dt_in_years;
00196    Sed_cell this_cell;
00197 
00198    n = sed_column_len( c );
00199 
00200    u   = eh_new( double , n );
00201    c_v = eh_new( double , n );
00202 
00203    for ( j=0 ; j<n ; j++ )
00204       c_v[j] = sed_cell_cv( sed_column_nth_cell(c,j) );
00205 
00206    burial_depth = sed_column_thickness( c );
00207 
00208    for ( j=0 ; j<n ; j++ )
00209    {
00210       this_cell = sed_column_nth_cell( c,j );
00211 
00212       dt_in_years = time_now_in_years
00213                   - sed_cell_age( this_cell );
00214       dt_in_secs  = dt_in_years * S_SECONDS_PER_YEAR;
00215 
00216       eh_lower_bound( dt_in_secs , 0 );
00217 
00218       u[j] = sed_calculate_consolidation( c_v[j]       ,
00219                                           burial_depth ,
00220                                           burial_depth ,
00221                                           dt_in_secs );
00222 
00223       burial_depth -= sed_cell_size( this_cell );
00224       sed_cell_set_pressure( this_cell ,
00225                                sed_cell_pressure( this_cell )
00226                              * (1-u[j]) );
00227 
00228    }
00229 
00230    eh_free( c_v      );
00231    eh_free( u        );
00232 
00233    return;
00234 }
00235 
00236 void run_darcy_flow( Sed_column col , double dt_in_years )
00237 {
00238    int j, n;
00239    double *load, *u, *k, *c;
00240    double hydro_static, dz, sed_rate;
00241    double max_k, mean_k, mean_c;
00242    double time, dt_in_secs;
00243    double *solve_excess_pore_pressure( double* , double* , double* , int ,
00244                                        double  , double  , double  , double );
00245    Sed_cell this_cell;
00246 
00247    dt_in_secs   = years_to_secs( dt_in_years );
00248 
00249    hydro_static = sed_column_water_pressure( col );
00250    dz           = sed_column_z_res( col );
00251    load         = sed_column_load( col , 0 , -1 , NULL );
00252 //   sed_rate     = ( load[0] - data->old_load[i] ) / dt_in_secs;
00253 
00254    n = sed_column_len( col );
00255 
00256    u = eh_new( double , n );
00257    k = eh_new( double , n );
00258    c = eh_new( double , n );
00259 
00260    for ( j=n-1 ; j>=0 ; j-- )
00261    {
00262       this_cell = sed_column_nth_cell( col , j );
00263 
00264       u[j] = sed_cell_pressure( this_cell ) - hydro_static;
00265 
00266       eh_lower_bound( u[j] , 1e-5 );
00267 
00268       k[j] = sed_cell_hydraulic_conductivity( this_cell );
00269       c[j] = sed_cell_compressibility       ( this_cell )
00270            * sed_rho_sea_water()*sed_gravity();
00271 
00272 
00273 //c[j] = 0;
00274 //k[j] = 0;
00275 //k[j] /= 1e6;
00276 //k[j] = 1e-9;
00277 //c[j] = 1e-4;
00278 //c[j] *= 1000000;
00279 
00280       eh_lower_bound( max_k , k[j]/c[j] );
00281 
00282    }
00283 
00284    mean_k = eh_dbl_array_mean( k , n );
00285    mean_c = eh_dbl_array_mean( c , n );
00286 
00287 mean_c = 1.;
00288 
00289    eh_dbl_array_set( k , n , mean_k );
00290    eh_dbl_array_set( c , n , mean_c );
00291 
00292 sed_rate = 0;
00293 
00294    // solve for the excess porewater pressure for this column.
00295    for ( time=0 ; time<dt_in_secs ; time+=dt_in_secs )
00296       solve_excess_pore_pressure( u  , k          , c  , n ,
00297                                   dz , dt_in_secs , 0. , sed_rate );
00298 
00299    // set_the new excess porewater pressures for this column.
00300    for ( j=0 ; j<n ; j++ )
00301       sed_cell_set_pressure( sed_column_nth_cell(col,j) ,
00302                              (u[j]<0)? (hydro_static):(u[j]+hydro_static) );
00303    
00304 //   data->old_load[i] = load[0];
00305 
00306    eh_free( load );
00307    eh_free( u    );
00308    eh_free( k    );
00309    eh_free( c    );
00310 
00311    return;
00312 }
00313 
00314 

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