/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/compact/compact.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 #include <utils/utils.h>
00024 #include <sed/sed_sedflux.h>
00025 
00035 
00036 GQuark
00037 compact_error_quark( void )
00038 {
00039    return g_quark_from_static_string( "compact-error-quark" );
00040 }
00041 
00067 int compact( Sed_column s )
00068 {
00069    double *load_eff;
00070    double hydro_static;
00071    gssize n_grains = sed_sediment_env_n_types();
00072 
00073    // If there is only one (or no) bins, there is no
00074    // overlying load and so no compaction.
00075    if ( sed_column_len(s) < 2 )
00076       return 0;
00077 
00078    load_eff     = eh_new0( double , sed_column_len(s) );
00079    hydro_static = sed_column_water_pressure( s );
00080 
00081    // Calculate the load of the overlying sediment.
00082    {
00083       gssize i;
00084       double p;
00085       double* load = sed_column_load( s , 0 , -1 , NULL );
00086 
00087       for (i=sed_column_len(s)-1; i>=0; --i) 
00088       {
00089          p = sed_cell_pressure( sed_column_nth_cell( s , i ) );
00090 
00091          load_eff[i] = load[i] - p;
00092 
00093          if ( load_eff[i] < 0 )
00094             load_eff[i] = 0.;
00095       }
00096 
00097       eh_free( load );
00098    }
00099 
00100    // Calculate the densities that the sediment should be.
00101    {
00102       gssize i, n;
00103       Sed_cell this_cell;
00104       double t_new;
00105       double* c         = sed_sediment_property( NULL , &sed_type_compressibility );
00106       double* rho_grain = sed_sediment_property( NULL , &sed_type_rho_grain       );
00107       double* rho_max   = sed_sediment_property( NULL , &sed_type_rho_max         );
00108       double* rho       = sed_sediment_property( NULL , &sed_type_rho_sat         );
00109       double rho_new;
00110       double t_0;
00111 
00112       for (i=sed_column_len(s)-1; i>=0 ; i--)
00113       {
00114          this_cell = sed_column_nth_cell( s , i );
00115          for ( n=0 , t_new=0. ; n<n_grains ; n++ )
00116          {
00117             t_0 = sed_cell_sediment_volume(this_cell)*sed_cell_fraction(this_cell,n);
00118             rho_new = rho_max[n] + (rho[n]-rho_max[n]) / exp(c[n]*load_eff[i]);
00119 
00120             t_new += t_0*(rho_grain[n]-sed_rho_sea_water())/(rho_new-sed_rho_sea_water());
00121 
00122             if ( t_new< 0 )
00123             {
00124                t_new = 0;
00125                eh_require_not_reached();
00126             }
00127 
00128          }
00129 
00130          // If the new thickness is greater than the current thickness, we
00131          // don't do anything.  In this case overlying sediment has been eroded.
00132          if ( t_new < sed_cell_size(this_cell) )
00133             sed_column_compact_cell(s,i,t_new);
00134       }
00135 
00136       eh_free( c         );
00137       eh_free( rho_max   );
00138       eh_free( rho_grain );
00139       eh_free( rho       );
00140    }
00141 
00142    eh_free(load_eff);
00143    
00144    return 0;
00145 }
00146 

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