00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdio.h>
00022 #include <sed/sed_sedflux.h>
00023 #include "diffusion.h"
00024
00025 static char *help_msg[] =
00026 {
00027 " ",
00028 " diffusion [options] [parameters] ",
00029 " diffuse a bathymetric profile. ",
00030 " ",
00031 " Options ",
00032 " v=yes : toggle verbose mode. [off] ",
00033 " help=yes : display this help message. [off] ",
00034 " ",
00035 " Parameters ",
00036 " k=k_val : use k_val as the diffusion coefficient at the surface of ",
00037 " the water. [1.0] ",
00038 " d=depth : use depth as the water depth that the diffusion coefficent",
00039 " will be 1% of its value at the surface. the diffusion ",
00040 " coefficient falls off exponentially with depth to simulate",
00041 " the attenuation of wave energy with depth. [100.0] ",
00042 " dt=time_step : use time_step as the time step for the model. [1.0] ",
00043 " sea=sea_level : use sea_level as the elevation of sea level. the ",
00044 " diffusion coefficient will fall off exponentially from ",
00045 " this elevation. [0.0] ",
00046 " dx=h_res : use h_res as the horizontal resolution for the model (in ",
00047 " meters). [1.0] ",
00048 " len=length : use length as the length (in km) of the basin that is ",
00049 " being being modeled. [100.] ",
00050 " t=thickness : use thickness to be the thickness (in meters) of the ",
00051 " sediment that already exists in the basin. [10.] ",
00052 " in=file : the input bathymetry file. this is the bathymetry that ",
00053 " will be diffused. ",
00054 " sed=file : file is used to describe the sediment that will be ",
00055 " diffused. ",
00056 " ",
00057 NULL
00058 };
00059
00060 #define DEFAULT_K (1.0)
00061 #define DEFAULT_SKIN_DEPTH (100.0)
00062 #define DEFAULT_TIME_STEP (1.)
00063 #define DEFAULT_SEA_LEVEL (0.)
00064 #define DEFAULT_HORIZ_RES (1.0)
00065 #define DEFAULT_BASIN_LENGTH (100.0)
00066 #define DEFAULT_SED_THICKNESS (10.0)
00067 #define DEFAULT_SEDIMENT_FILE_NAME "default.sediment"
00068
00069 int test_2d( void );
00070
00071 int main( int argc , char *argv[] )
00072 {
00073 gssize i, j;
00074 gssize n_grains;
00075 char *bathy_file, *sediment_file;
00076 GArray *x, *bathymetry;
00077 Sed_sediment sediment_type;
00078 char *req[] = { "in" , NULL };
00079 double basin_length, horiz_res, sed_thickness;
00080 double k, skin_depth, time_step, sea_level;
00081 gboolean verbose;
00082 char *next_file;
00083 Eh_file_list *file_name;
00084 double *grain_fractions;
00085 double val;
00086 Sed_cell cell;
00087 Sed_cube prof;
00088 Sed_property_file sed_fp;
00089 Eh_args *args;
00090 Sed_property grain_size = sed_property_new( "grain" );
00091 GError* error = NULL;
00092
00093 test_2d();
00094
00095 args = eh_opts_init( argc , argv );
00096 if ( eh_check_opts( args , req , NULL , help_msg )!=0 )
00097 eh_exit(-1);
00098
00099 k = eh_get_opt_dbl ( args , "k" , DEFAULT_K );
00100 skin_depth = eh_get_opt_dbl ( args , "d" , DEFAULT_SKIN_DEPTH );
00101 time_step = eh_get_opt_dbl ( args , "dt" , DEFAULT_TIME_STEP );
00102 sea_level = eh_get_opt_dbl ( args , "sea" , DEFAULT_SEA_LEVEL );
00103 horiz_res = eh_get_opt_dbl ( args , "dx" , DEFAULT_HORIZ_RES );
00104 basin_length = eh_get_opt_dbl ( args , "len" , DEFAULT_BASIN_LENGTH );
00105 sed_thickness = eh_get_opt_dbl ( args , "t" , DEFAULT_SED_THICKNESS );
00106 bathy_file = eh_get_opt_str ( args , "in" , NULL );
00107 sediment_file = eh_get_opt_str ( args , "sed" , DEFAULT_SEDIMENT_FILE_NAME );
00108 verbose = eh_get_opt_bool( args , "v" , FALSE );
00109
00110 x = g_array_new( FALSE , FALSE , sizeof(double) );
00111
00112
00113 for ( val=0 ; val<basin_length ; val+=horiz_res )
00114 g_array_append_val(x,val);
00115
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 sediment_type = sed_sediment_scan( sediment_file , &error );
00123 if ( !sediment_type )
00124 eh_error( "%s: Unable to read sediment file: %s" , sediment_file , error->message);
00125 else
00126 sed_sediment_set_env( sediment_type );
00127
00128 n_grains = sed_sediment_n_types( sediment_type );
00129
00130
00131 prof = sed_cube_new( 1 , x->len );
00132 for (i=0;i<x->len;i++)
00133 {
00134 sed_column_set_base_height( sed_cube_col(prof,i) ,
00135 g_array_index( bathymetry , double , i )
00136 - sed_thickness );
00137 sed_column_set_y_position( sed_cube_col(prof,i) ,
00138 g_array_index( x , double , i ) );
00139 }
00140 sed_cube_set_y_res ( prof , horiz_res );
00141 sed_cube_set_z_res ( prof , sed_thickness/10 );
00142 sed_cube_set_sea_level( prof , sea_level );
00143
00144
00145 grain_fractions = eh_new( double , n_grains );
00146 for ( i=0 ; i<n_grains ; i++ )
00147 grain_fractions[i] = 1./n_grains*sed_thickness;
00148 cell = sed_cell_new( n_grains );
00149 sed_cell_add_amount( cell , grain_fractions );
00150 for ( i=0 ; i<sed_cube_n_y(prof) ; i++ )
00151 sed_column_add_cell( sed_cube_col(prof,i) , cell );
00152 sed_cell_destroy( cell );
00153 eh_free( grain_fractions );
00154
00155 file_name = eh_create_file_list( "output#.grain" );
00156
00157 for ( j=0 ; j<50 ; j++ )
00158 {
00159
00160 diffuse_sediment( prof , k , skin_depth , time_step , DIFFUSION_OPT_WATER );
00161
00162
00163 for (i=0;i<sed_cube_n_y(prof);i++)
00164 fprintf( stdout , "%f , %f\n" ,
00165 sed_cube_col_y( prof , i ) ,
00166 sed_cube_water_depth( prof , 0 , i ) );
00167
00168 next_file = eh_get_next_file( file_name );
00169
00170
00171 sed_fp=sed_property_file_new( next_file , grain_size , NULL );
00172 sed_property_file_write( sed_fp , prof );
00173 sed_property_file_destroy( sed_fp );
00174 }
00175
00176 sed_property_destroy( grain_size );
00177 g_array_free( x , FALSE );
00178
00179 return 0;
00180 }
00181
00182 int test_2d( void )
00183 {
00184 gssize i, j;
00185 gssize n_grains;
00186 double *f;
00187 Sed_sediment sed;
00188 Sed_cell cell;
00189 Sed_cube cube;
00190 gssize n_x = 10;
00191 gssize n_y = 10;
00192 GError* error = NULL;
00193
00194 sed = sed_sediment_scan( NULL , &error );
00195 if ( !sed )
00196 eh_error( "(null): Unable to read sediment file: %s" , error->message);
00197
00198 n_grains = sed_sediment_n_types( sed );
00199 sed_sediment_set_env( sed );
00200
00201 f = eh_new( double , n_grains );
00202 cell = sed_cell_new( n_grains );
00203 cube = sed_cube_new( n_x , n_y );
00204
00205 sed_cell_set_equal_fraction( cell );
00206
00207 sed_cell_resize( cell , 50 );
00208
00209 sed_cube_set_x_res( cube , 100 );
00210 sed_cube_set_y_res( cube , 100 );
00211
00212 for ( i=0 ; i<n_x ; i++ )
00213 for ( j=0 ; j<n_y ; j++ )
00214 sed_cube_set_base_height( cube , i , j , -100 );
00215
00216 sed_column_add_cell( sed_cube_col_ij(cube,n_x/2,n_y/2) , cell );
00217
00218 diffuse_sediment_2( cube , 10 , 10 , 1000 , 365*50 , DIFFUSION_OPT_WATER );
00219
00220 for ( i=0 ; i<n_x ; i++ )
00221 {
00222 for ( j=0 ; j<n_y ; j++ )
00223 fprintf( stdout , "%f " , sed_cube_water_depth( cube , i , j ) );
00224 fprintf( stdout , "\n" );
00225 }
00226
00227 eh_free( f );
00228 sed_cell_destroy( cell );
00229 sed_sediment_destroy( sed );
00230 sed_sediment_unset_env( );
00231 sed_cube_destroy( cube );
00232
00233 return 0;
00234 }
00235