/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/squall/squall_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 <squall.h>
00024 
00025 static char *help_msg[] =
00026 {
00027 "                                                                             ",
00028 " squall [options] [parameters]                                               ",
00029 "  simulate a storm hitting a shore.                                          ",
00030 "                                                                             ",
00031 " Options                                                                     ",
00032 "  v=yes          : toggle verbose mode. [off]                                ",
00033 "  help=yes       : display this help message. [off]                          ",
00034 "                                                                             ",
00035 " Parameters                                                                  ",
00036 "  sea=sea_level  : use sea_level as the elevation of sea level.              ",
00037 "  dx=h_res       : use h_res as the horizontal resolution for the model (in  ",
00038 "                   meters). [1.0]                                            ",
00039 "  t=thickness    : use thickness to be the thickness (in meters) of the      ",
00040 "                   sediment that already exists in the basin. [10.]          ",
00041 "  sed=file       : file is used to describe the sediment that will be        ",
00042 "                   diffused.                                                 ",
00043 "                                                                             ",
00044 NULL
00045 };
00046 
00047 #define DEFAULT_SEA_LEVEL     (0.)
00048 #define DEFAULT_HORIZ_RES     (1.)
00049 #define DEFAULT_VERT_RES      (1.)
00050 #define DEFAULT_DT            (1.)
00051 #define DEFAULT_TT            (1.)
00052 #define DEFAULT_WAVE_HEIGHT   (1.)
00053 #define DEFAULT_WAVE_LENGTH   (10.)
00054 #define DEFAULT_BASIN_LENGTH  (100.)
00055 #define DEFAULT_OUTPUT_INT    (G_MAXINT)
00056 #define DEFAULT_SED_THICKNESS (10.)
00057 #define DEFAULT_SED_FILE      ("default.sediment")
00058 #define DEFAULT_IN_FILE       ("default.bathy")
00059 
00060 
00061 int main( int argc , char *argv[] )
00062 {
00063    gssize i;
00064    gssize n_grains;
00065    char *bathy_file, *sed_file;
00066    GArray *x, *bathymetry;
00067    Sed_sediment sed;
00068    char *req[] = { "in" , NULL };
00069    double horiz_res, vert_res, dt, total_time;
00070    double basin_length, wave_height, wave_length;
00071    double sed_thickness, sea_level;
00072    int output_int;
00073    gboolean verbose;
00074    double t;
00075    Eh_file_list *file_name;
00076    double *grain_frac;
00077    double val;
00078    Sed_cell cell;
00079    Sed_cube p;
00080    Eh_args *args;
00081    GError* error = NULL;
00082 
00083    //---
00084    // parse the command line options.
00085    //---
00086    args = eh_opts_init( argc , argv );
00087    if ( eh_check_opts( args , req , NULL , help_msg )!=0 )
00088       eh_exit(-1);
00089 
00090    sea_level     = eh_get_opt_dbl ( args , "sea" , DEFAULT_SEA_LEVEL     );
00091    horiz_res     = eh_get_opt_dbl ( args , "dx"  , DEFAULT_HORIZ_RES     );
00092    vert_res      = eh_get_opt_dbl ( args , "dy"  , DEFAULT_VERT_RES      );
00093    dt            = eh_get_opt_dbl ( args , "dt"  , DEFAULT_DT            );
00094    total_time    = eh_get_opt_dbl ( args , "tt"  , DEFAULT_TT            );
00095    wave_height   = eh_get_opt_dbl ( args , "wh"  , DEFAULT_WAVE_HEIGHT   );
00096    wave_length   = eh_get_opt_dbl ( args , "wl"  , DEFAULT_WAVE_HEIGHT   );
00097    sed_thickness = eh_get_opt_dbl ( args , "t"   , DEFAULT_SED_THICKNESS );
00098    basin_length  = eh_get_opt_dbl ( args , "len" , DEFAULT_BASIN_LENGTH  );
00099    output_int    = eh_get_opt_int ( args , "oi"  , DEFAULT_OUTPUT_INT    );
00100    bathy_file    = eh_get_opt_str ( args , "in"  , DEFAULT_IN_FILE       );
00101    sed_file      = eh_get_opt_str ( args , "sed" , DEFAULT_SED_FILE      );
00102    verbose       = eh_get_opt_bool( args , "v"   , FALSE                 );
00103 
00104    if ( verbose )
00105       eh_print_all_opts( args , "squall" , stderr );
00106 
00107    //---
00108    // set the positions where the sediment columns will be located.
00109    //---
00110    x = g_array_new( FALSE , FALSE , sizeof(double) );
00111    for ( val=0 ; val<basin_length ; val+=horiz_res )
00112       g_array_append_val( x , val );
00113 
00114    //---
00115    // read in the bathymetry.
00116    //---
00117    bathymetry = sed_get_floor( bathy_file , x , &error );
00118    if ( !bathymetry )
00119       eh_error( "%s: Unable to read bathymetry file: %s" , bathy_file , error->message );
00120 
00121    //---
00122    // read in the sediment type from a file.
00123    //---
00124    sed = sed_sediment_scan( sed_file , &error );
00125    if ( !sed )
00126       eh_error( "%s: Unable to scan sediment file: %s" , sed_file , error->message );
00127    n_grains = sed_sediment_n_types( sed );
00128 
00129    //---
00130    // create a Sed_cube to hold the sediment.
00131    //---
00132    p = sed_cube_new( 1 , x->len );
00133 
00134    for ( i=0 ; i<x->len ; i++ )
00135    {
00136       sed_column_set_base_height( sed_cube_col(p,i) ,   g_array_index( bathymetry , double , i )
00137                                                       - sed_thickness );
00138       sed_column_set_y_position ( sed_cube_col(p,i) , g_array_index( x , double , i ) );
00139    }
00140    sed_cube_set_y_res( p , horiz_res );
00141    sed_cube_set_z_res( p , vert_res );
00142    sed_cube_set_x_res( p , 1 );
00143    sed_cube_set_sea_level( p , sea_level );
00144    sed_cube_set_wave_height( p , wave_height );
00145    sed_cube_set_wave_length( p , wave_length );
00146    sed_cube_set_time_step( p , dt );
00147 
00148    //---
00149    // add the existing sediment.
00150    //---
00151    grain_frac = eh_new( double , n_grains );
00152    for ( i=0 ; i<n_grains ; i++ )
00153       grain_frac[i] = 1./n_grains*sed_thickness;
00154    cell = sed_cell_new( n_grains );
00155    sed_cell_add_amount( cell , grain_frac );
00156    for ( i=0 ; i<sed_cube_n_y(p) ; i++ )
00157       sed_column_add_cell( sed_cube_col(p,i) , cell );
00158    sed_cell_destroy( cell );
00159    eh_free( grain_frac );
00160 
00161    file_name = eh_create_file_list( "output#.grain" );
00162 
00163    for ( t=0 , i=1 ; t<total_time ; t+=dt , i++ )
00164    {
00165       squall( p , dt );
00166 
00167       if ( i%output_int==0 )
00168          write_output_file( eh_get_next_file( file_name ) , p );
00169    }
00170 
00171    write_output_file( eh_get_next_file( file_name ) , p );
00172 
00173    g_array_free( x , FALSE );
00174 
00175    return 0;
00176 }
00177 
00178 void write_output_file( const char *file , Sed_cube p )
00179 {
00180    Sed_property grain_size_in_phi = sed_property_new( "grain" );
00181    Sed_property_file sed_fp = sed_property_file_new( file ,
00182                                                      grain_size_in_phi ,
00183                                                      NULL );
00184 
00185    sed_property_file_write( sed_fp , p );
00186    sed_property_file_destroy( sed_fp );
00187 
00188    sed_property_destroy( grain_size_in_phi );
00189 
00190    return;
00191 }
00192 

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