/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/plume/plume_scan.c

Go to the documentation of this file.
00001 #include <glib.h>
00002 #include <utils/utils.h>
00003 #include <sed/sed_sedflux.h>
00004 #include "plume_local.h"
00005 #include "plume_types.h"
00006 #include "plumeinput.h"
00007 
00008 GQuark
00009 plume_error_quark( void )
00010 {
00011    return g_quark_from_static_string( "plume-error-quark" );
00012 }
00013 
00014 static Plume_param_st _p;
00015 
00016 static Eh_key_file_entry template[] =
00017 {
00018  { "Bulk density"                                    , EH_ARG_DARRAY , &_p.bulk_density    , &_p.n_grains } ,
00019  { "Removal rate constant"                           , EH_ARG_DARRAY , &_p.lambda          , &_p.n_grains } ,
00020  { "Coast normal"                                    , EH_ARG_DBL    , &_p.r_dir           } ,
00021  { "River angle wrt coast normal"                    , EH_ARG_DBL    , &_p.r_angle         } ,
00022  { "Latitude"                                        , EH_ARG_DBL    , &_p.latitude        } ,
00023  { "Ocean sediment concentration"                    , EH_ARG_DBL    , &_p.ocean_conc      } ,
00024  { "Normalized with of coastal current"              , EH_ARG_DBL    , &_p.coastal_current_width      } ,
00025  { "Number of grid nodes within river mouth"         , EH_ARG_INT    , &_p.river_mouth_nodes      } ,
00026  { "Ratio of cross- to along-shore grid spacing"     , EH_ARG_DBL    , &_p.aspect_ratio      } ,
00027 // { "Position of left fjord wall"                     , EH_ARG_DBL    , &p.fjord_wall_left   } ,
00028 // { "Position of right fjord wall"                    , EH_ARG_DBL    , &p.fjord_wall_right  } ,
00029  { "Basin width"                                     , EH_ARG_DBL    , &_p.basin_width  } ,
00030  { "Basin length"                                    , EH_ARG_DBL    , &_p.basin_len  } ,
00031  { "Cross-shore output resolution"                   , EH_ARG_DBL    , &_p.dx  } ,
00032  { NULL }
00033 };
00034 
00035 Plume_param_st*
00036 plume_scan_parameter_file( const gchar* file , GError** error )
00037 {
00038    Plume_param_st* p_new     = NULL;
00039    GError*         tmp_error = NULL;
00040 
00041    eh_return_val_if_fail( error==NULL || *error==NULL , NULL );
00042 
00043    eh_require( file );
00044 
00045    eh_key_file_scan_from_template( file , "PLUME" , template , &tmp_error );
00046 
00047    if ( !tmp_error )
00048    {
00049       p_new = eh_new( Plume_param_st , 1 );
00050 
00051       *p_new = _p;
00052 
00053       plume_check_params( p_new , &tmp_error );
00054    }
00055 
00056    if ( tmp_error )
00057    {
00058       eh_free( p_new );
00059       p_new = NULL;
00060       g_propagate_error( error , tmp_error );
00061    }
00062 
00063    return p_new;
00064 }
00065 
00066 Plume_param_st*
00067 plume_check_params( Plume_param_st* p , GError** error )
00068 {
00069    eh_require( p );
00070    eh_return_val_if_fail( error==NULL || *error==NULL , NULL );
00071 
00072    if ( p )
00073    {
00074       gchar** err_s = NULL;
00075 
00076       eh_check_to_s( p->latitude<= 90. , "Latitude must be between -90 and 90" , &err_s );
00077       eh_check_to_s( p->latitude>=-90. , "Latitude must be between -90 and 90" , &err_s );
00078    }
00079 
00080    return p;
00081 }
00082 
00083 gint
00084 plume_print_data( const gchar* file , double** deposit , gint len , gint n_grains )
00085 {
00086    gint n = 0;
00087 
00088    eh_require( deposit && *deposit );
00089    eh_require( len>0 )
00090    eh_require( n_grains>0 );
00091 
00092    if ( file && deposit )
00093    {
00094       gint  i, j;
00095       FILE* fp = eh_open_file( file , "a" );
00096 
00097       for ( j=0 ; j<n_grains ; j++ )
00098       {
00099          n += fprintf( fp , "%f" , deposit[0][j] );
00100          for ( i=1 ; i<len ; i++ )
00101             n += fprintf( fp , "; %f" , deposit[i][j] );
00102          n += fprintf( fp , "\n" );
00103       }
00104 
00105       fclose( fp );
00106    }
00107 
00108    return n;
00109 }
00110 
00111 double**
00112 plume_wrapper( Sed_hydro r , Plume_param_st* p , gint* len , gint* n_grains )
00113 {
00114    double** deposit = NULL;
00115 
00116    eh_require( p );
00117 
00118    if ( r )
00119    {
00120       Plume_enviro  env;
00121       Plume_grid    grid;
00122       Plume_options opt;
00123 
00124       { /* Set Plume_enviro structure */
00125          gint       n;
00126 
00127          *n_grains = sed_hydro_size( r );
00128 
00129          env.lat = p->latitude;
00130 
00131          env.n_grains = *n_grains;
00132          env.sed = eh_new( Plume_sediment , env.n_grains );
00133          for ( n=0 ; n<*n_grains ; n++ )
00134          {
00135             env.sed[n].rho    = p->bulk_density[n];
00136             env.sed[n].lambda = p->lambda[n]*S_DAYS_PER_SECOND;
00137          }
00138 
00139          env.river             = eh_new( Plume_river , 1 );
00140          env.river->Q          = sed_hydro_water_flux        ( r );
00141          env.river->u0         = sed_hydro_velocity          ( r );
00142          env.river->b0         = sed_hydro_width             ( r );
00143          env.river->d0         = sed_hydro_depth             ( r );
00144          env.river->Cs         = sed_hydro_copy_concentration( NULL , r );
00145          env.river->rdirection = p->r_dir;
00146          env.river->rma        = p->r_angle;
00147 
00148          env.ocean             = eh_new( Plume_ocean , 1 );
00149          env.ocean->Cw         = p->ocean_conc;
00150          env.ocean->vo         = p->coastal_current;
00151          env.ocean->vdirection = p->coastal_current_dir;
00152          env.ocean->cc         = p->coastal_current_width;
00153          env.ocean->So         = p->river_tracer;
00154          env.ocean->Sw         = p->ocean_tracer;
00155       }
00156 
00157       { /* Set Plume_grid structure */
00158          grid.ndy   =  p->river_mouth_nodes;
00159          grid.ndx   =  p->aspect_ratio;
00160          grid.ymin  = -p->basin_width*.5;
00161          grid.ymax  =  p->basin_width*.5;
00162          grid.max_len = p->basin_len;
00163          grid.x_len = 0;
00164          grid.y_len = 0;
00165       }
00166 
00167       { /* Set Plume_opt structure */
00168          opt.fjrd = 1;
00169          opt.kwf  = 0;
00170 
00171          opt.o1   = 1;
00172          opt.o2   = 0;
00173          opt.o3   = 0;
00174       }
00175 /*
00176    double *Cs;        // River Concentration (kg/m^3) [0.001:100]
00177    double Q;          // discharge (m^3/s) [1:1e6]
00178    double u0;         // velocity (m/s) [0.01:10]
00179    double rdirection; // river mouth direction (degN) [0:360]
00180    double b0;         // river mouth width (m) [1.0:1e5]
00181    double d0;         // river depth (m) [calculated]
00182    double rma;        // River mouth angle (degrees), + is in plus y dir.
00183 
00184    double Cw;         // ocean sediment concentration (kg/m^3) [0:min(Cs)]
00185    double vo;         // alongshore current magnitude (m/s) [-3:3]
00186    double vdirection; // alongshore current direction (degN) [0:360]
00187    double cc;         // Coastal Current width = cc*inertial length scale [0.1:1]
00188    double So;         // Conservative Tracer Property, River concentration
00189    double Sw;         // Conservative Tracer Property, Ocean concentration
00190 */
00191 
00192       if ( FALSE )
00193       {
00194          gint n;
00195       for ( n=0 ; n<env.n_grains ; n++ )
00196          eh_watch_dbl( env.river->Cs[n] );
00197       eh_watch_dbl( env.river->Q );
00198       eh_watch_dbl( env.river->u0 );
00199       eh_watch_dbl( env.river->rdirection );
00200       eh_watch_dbl( env.river->b0 );
00201       eh_watch_dbl( env.river->d0 );
00202       eh_watch_dbl( env.river->rma );
00203 
00204       eh_watch_dbl( env.ocean->Cw );
00205       eh_watch_dbl( env.ocean->vo );
00206       eh_watch_dbl( env.ocean->vdirection );
00207       eh_watch_dbl( env.ocean->cc );
00208       eh_watch_dbl( env.ocean->So );
00209       eh_watch_dbl( env.ocean->Sw );
00210 
00211       for ( n=0 ; n<env.n_grains ; n++ )
00212       {
00213          eh_watch_dbl( env.sed[n].rho    );
00214          eh_watch_dbl( env.sed[n].lambda );
00215          eh_watch_dbl( env.sed[n].lambda*S_SECONDS_PER_DAY );
00216       }
00217       }
00218       plume( &env , &grid , &opt );
00219 
00220       *len = p->basin_len / p->dx;
00221 
00222       deposit = eh_new_2( double , *len , *n_grains );
00223 
00224       plumeout2( &env , &grid , p->dx , deposit , *len , *n_grains , p->basin_width );
00225    }
00226 
00227    return deposit;
00228 }
00229 

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