/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/muds/muds_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 <sed/sed_sedflux.h>
00023 #include "muds.h"
00024 
00025 static char *help_msg[] =
00026 {
00027 "                                                                             ",
00028 " mud [options] [parameters]                                                  ",
00029 "  move sediment in the bottom boundary layer.                                ",
00030 "                                                                             ",
00031 " Options                                                                     ",
00032 "  v=yes          : toggle verbose mode. [off]                                ",
00033 "  help=yes       : display this help message. [off]                          ",
00034 "                                                                             ",
00035 " Parameters                                                                  ",
00036 "  waveh=height   : use height as the height of the waves acting on the       ",
00037 "                   profile. [1]                                              ",
00038 "  wavet=period   : use period as the period of the waves acting on the       ",
00039 "                   profile. [15]                                             ",
00040 "  sea=sea_level  : use sea_level as the elevation of sea level.  the         ",
00041 "                   diffusion coefficient will fall off exponentially from    ",
00042 "                   this elevation. [0.0]                                     ",
00043 "  dx=h_res       : use h_res as the horizontal resolution for the model (in  ",
00044 "                   meters). [1.0]                                            ",
00045 "  len=length     : use length as the length (in m) of the basin that is      ",
00046 "                   being being modeled. [100000.]                            ",
00047 "  t=thickness    : use thickness to be the thickness (in meters) of the      ",
00048 "                   sediment that already exists in the basin. [10.]          ",
00049 "  in=file        : the input bathymetry file.  this is the bathymetry that   ",
00050 "                   will be diffused.                                         ",
00051 "  sed=file       : file is used to describe the sediment that will be        ",
00052 "                   diffused.                                                 ",
00053 "                                                                             ",
00054 NULL
00055 };
00056 
00057 #define DEFAULT_WAVE_HEIGHT   (1.)
00058 #define DEFAULT_WAVE_PERIOD   (15.)
00059 #define DEFAULT_WAVE_LENGTH   (350.)
00060 #define DEFAULT_SEA_LEVEL     (0.)
00061 #define DEFAULT_HORIZ_RES     (1.0)
00062 #define DEFAULT_BASIN_LENGTH  (100000.0)
00063 #define DEFAULT_SED_THICKNESS (10.0)
00064 #define DEFAULT_SED_FILE_NAME "default.sediment"
00065 
00066 int main( int argc , char *argv[] )
00067 {
00068    gssize i, j;
00069    gssize n_grains;
00070    gssize river_mouth;
00071    char *bathy_file, *sediment_file;
00072    GArray *x, *bathymetry;
00073    Sed_sediment sediment_type;
00074    char *req[] = { "in" , NULL };
00075    double basin_length, horiz_res, sed_thickness;
00076    double wave_height, wave_period, sea_level;
00077    double a, thickness;
00078    double mass_before, mass_after;
00079    gboolean verbose;
00080    double *grain_fractions, *wave;
00081    double val;
00082    Eh_file_list *file_name;
00083    char *next_file;
00084    Sed_cell cell;
00085    Sed_cell *deposit;
00086    Sed_cube prof;
00087    Sed_property_file sed_fp;
00088    Sed_property grain_size;
00089    Eh_args *args;
00090    GError* error = NULL;
00091 
00092    args = eh_opts_init( argc , argv );
00093    if ( eh_check_opts( args , req , NULL , help_msg )!=0 )
00094       eh_exit(-1);
00095 
00096    wave_height   = eh_get_opt_dbl ( args , "waveh" , DEFAULT_WAVE_HEIGHT   );
00097    wave_period   = eh_get_opt_dbl ( args , "wavet" , DEFAULT_WAVE_PERIOD   );
00098    sea_level     = eh_get_opt_dbl ( args , "sea"   , DEFAULT_SEA_LEVEL     );
00099    horiz_res     = eh_get_opt_dbl ( args , "dx"    , DEFAULT_HORIZ_RES     );
00100    basin_length  = eh_get_opt_dbl ( args , "len"   , DEFAULT_BASIN_LENGTH  );
00101    sed_thickness = eh_get_opt_dbl ( args , "t"     , DEFAULT_SED_THICKNESS );
00102    bathy_file    = eh_get_opt_str ( args , "in"    , NULL                  );
00103    sediment_file = eh_get_opt_str ( args , "sed"   , DEFAULT_SED_FILE_NAME );
00104    verbose       = eh_get_opt_bool( args , "v"     , FALSE                 );
00105 
00106    x = g_array_new( FALSE , FALSE , sizeof(double) );
00107 
00108    wave = eh_new( double , 3 );
00109    wave[0] = wave_height;
00110    wave[1] = wave_period;
00111    wave[2] = 5.*sed_gravity()*pow(wave_period*sinh(M_PI/10.)/M_PI,2.);
00112 
00113    if ( verbose )
00114    {
00115       fprintf( stderr , "wave height : %f\n" , wave[0] );
00116       fprintf( stderr , "wave period : %f\n" , wave[1] );
00117       fprintf( stderr , "wave length : %f\n" , wave[2] );
00118    }
00119 
00120    // set the positions where the sediment columns will be located.
00121    for ( val=0 ; val<basin_length ; val+=horiz_res )
00122       g_array_append_val(x,val);
00123 
00124    // read in the bathymetry.
00125    bathymetry = sed_get_floor( bathy_file , x , &error );
00126    if ( !bathymetry )
00127       eh_error( "%s: Unable to read bathymetry file: %s" , bathy_file , error->message );
00128 
00129    // read in the type of sediment.
00130    sediment_type = sed_sediment_scan( sediment_file , &error );
00131    if ( !sediment_type )
00132       eh_error( "%s: Unable to scan sediment file: %s" , sediment_file , error->message );
00133    n_grains = sed_sediment_n_types( sediment_type );
00134    sed_sediment_set_env( sediment_type );
00135 
00136    // initialize the sediment cube.
00137    prof = sed_cube_new( 1 , x->len );
00138    for (i=0;i<x->len;i++)
00139    {
00140       sed_column_set_base_height( sed_cube_col(prof,i) ,
00141                                     g_array_index( bathymetry , double , i )
00142                                   - sed_thickness );
00143       sed_column_set_y_position( sed_cube_col(prof,i) ,
00144                                  g_array_index( x , double , i ) );
00145    }
00146    sed_cube_set_x_res( prof , 1. );
00147    sed_cube_set_y_res( prof , horiz_res );
00148    sed_cube_set_z_res( prof , .1 );
00149    sed_cube_set_sea_level( prof , sea_level );
00150 
00151    file_name = eh_create_file_list( "output#.grain" );
00152    grain_size = sed_property_new( "grain" );
00153 
00154    for ( j=0 ; j<10 ; j++ )
00155    {
00156 if ( j<75 )
00157    wave[0] *= 1.02;
00158 else if ( j<150 )
00159    wave[0] *= .98;
00160 else if ( j<225 )
00161    wave[0] *= 1.02;
00162 else
00163    wave[0] *= .98;
00164 
00165 //wave[2] = eh_get_fuzzy_dbl_norm( 200 , 20 );
00166 
00167       // add the existing sediment.
00168       grain_fractions = eh_new( double , n_grains );
00169       for ( i=0 ; i<n_grains ; i++ )
00170          grain_fractions[i] = 1./n_grains*sed_thickness;
00171    
00172       deposit = sed_cell_list_new( sed_cube_n_y(prof) , n_grains );
00173    
00174       cell = sed_cell_new( n_grains );
00175       sed_cell_add_amount( cell , grain_fractions );
00176       mass_before = sed_cube_mass( prof );
00177       river_mouth = sed_cube_river_mouth_1d( prof );
00178       for (i=river_mouth;i<sed_cube_n_y(prof);i++)
00179       {
00180          a = .001;
00181          thickness = sed_thickness*exp(-a*(  sed_cube_col_y(prof,i)
00182                                            - sed_cube_col_y(prof,river_mouth) ) );
00183          sed_cell_resize( cell , thickness );
00184          sed_cell_copy( deposit[i] , cell );
00185          mass_before +=   sed_cell_mass( deposit[i] )
00186                         * sed_cube_y_res( prof )*sed_cube_x_res( prof );
00187       }
00188       sed_cell_destroy( cell );
00189       eh_free( grain_fractions );
00190 
00191       // diffuse the bathymetry.
00192       muddy( prof , deposit , wave , 86400. );
00193 
00194       mass_after = sed_cube_mass( prof );
00195 
00196 eh_watch_dbl( mass_before );
00197 eh_watch_dbl( mass_after );
00198 
00199       if ( fabs(mass_after-mass_before)/mass_after > 1e-6 )
00200       {
00201          fprintf( stderr , "error : mass balance error\n" );
00202       }
00203 
00204       sed_cell_list_destroy( deposit );
00205 
00206       if ( j%2 == 0 )
00207       {
00208          // write out the cube
00209          next_file = eh_get_next_file( file_name );
00210          sed_fp=sed_property_file_new( next_file , grain_size , NULL );
00211          sed_property_file_write( sed_fp , prof );
00212          sed_property_file_destroy( sed_fp );
00213       }
00214 
00215    }
00216 
00217    // write out the diffused bathymetry.
00218    for (i=0;i<sed_cube_n_y(prof);i++)
00219       fprintf( stdout , "%f , %f\n" ,
00220                sed_cube_col_y( prof,i ) ,
00221                sed_column_thickness( sed_cube_col(prof,i) ) );
00222 
00223    // write out the cube
00224    sed_fp=sed_property_file_new( "output.grain" , grain_size , NULL );
00225    sed_property_file_write( sed_fp , prof );
00226    sed_property_file_destroy( sed_fp );
00227 
00228    sed_property_destroy( grain_size );
00229 
00230    g_array_free( x , FALSE );
00231    eh_free( wave );
00232 
00233    return 0;
00234 }
00235 

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