/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/sedflux/run_xshore.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 #define SED_XSHORE_PROC_NAME "xshore"
00022 #define EH_LOG_DOMAIN SED_XSHORE_PROC_NAME
00023 
00024 #include <stdio.h>
00025 #include <math.h>
00026 #include <string.h>
00027 #include <glib.h>
00028 #include <utils/utils.h>
00029 #include <sed/sed_sedflux.h>
00030 #include "my_processes.h"
00031 #include <xshore.h>
00032 
00033 gboolean is_worth_running( Sed_ocean_storm s );
00034 
00035 gboolean init_xshore_data( Sed_process proc , Sed_cube prof , GError** error );
00036 
00037 Sed_process_info
00038 run_xshore( Sed_process proc , Sed_cube prof )
00039 {
00040    Xshore_t*        data = sed_process_user_data(proc);
00041    Sed_process_info info = SED_EMPTY_INFO;
00042    double dt;
00043    double start_time, end_time, current_time;
00044    double xshore_current;
00045    double this_sea_level;
00046    double mass_before, mass_after, mass_added, mass_lost;
00047    Sed_cell *lost = NULL;
00048    Sed_cell along_shore_sediment;
00049    Sed_ocean_storm this_storm;
00050    GSList *this_link;
00051    Xshore_info x_info;
00052 
00053    if ( sed_process_run_count(proc)==0 )
00054       init_xshore_data( proc , prof , NULL );
00055 
00056    if ( sed_mode_is_3d() )
00057       return info;
00058    
00059    start_time      = data->last_time;
00060    end_time        = sed_cube_age_in_years( prof );
00061    dt              = end_time - start_time;
00062    data->last_time = sed_cube_age_in_years( prof );
00063 
00064    {
00065       double *along_shore_fraction = eh_new0( double , sed_sediment_env_n_types() );
00066 
00067       along_shore_fraction[data->sediment_type] = 1.;
00068 
00069       along_shore_sediment = sed_cell_new_env( );
00070       sed_cell_set_fraction( along_shore_sediment ,
00071                              along_shore_fraction );
00072 
00073       eh_free( along_shore_fraction );
00074    }
00075 
00076 //   dt = sed_cube_time_step( prof );
00077 
00078    current_time = start_time;
00079    sed_cube_set_age( prof , start_time );
00080 
00081    for ( this_link=sed_cube_storm_list( prof ) ;
00082          this_link ;
00083          this_link=this_link->next )
00084    {
00085       double storm_wave;
00086       double max_current = eh_input_val_eval( data->xshore_current ,
00087                                               current_time );
00088       mass_before = sed_cube_mass( prof );
00089 
00090       this_storm = this_link->data;
00091 
00092       storm_wave = sed_ocean_storm_wave_height( this_storm );
00093 
00094       xshore_current = max_current*0.5*storm_wave;
00095       eh_clamp( xshore_current , 0 , max_current );
00096 
00097       this_sea_level = sed_cube_sea_level( prof );
00098       sed_cube_adjust_sea_level( prof , storm_wave*.5 );
00099 
00100 //   if ( sed_cube_time_step_in_days( prof ) > 3. )
00101 //      sed_cube_set_time_step( prof , 3./S_DAYS_PER_YEAR );
00102 
00103 //   if ( sed_cube_wave_height( prof ) > .1 )
00104       if ( is_worth_running( this_storm ) )
00105       {
00106          x_info = xshore( prof                 ,
00107                           along_shore_sediment ,
00108                           xshore_current       ,
00109                           this_storm );
00110       }
00111       else
00112       {
00113          x_info.added = NULL;
00114          x_info.lost  = NULL;
00115          x_info.dt    = NULL;
00116       }
00117 
00118       sed_cube_set_sea_level( prof , this_sea_level );
00119 
00120       eh_message( "time                            : %f" , current_time );
00121 
00122       if ( TRUE )
00123       {
00124          if ( x_info.added )
00125          {
00126             mass_added = sed_cell_mass( x_info.added )
00127                        * sed_cube_x_res( prof )
00128                        * sed_cube_y_res( prof );
00129             mass_lost  = sed_cell_mass( x_info.lost )
00130                        * sed_cube_x_res( prof )
00131                        * sed_cube_y_res( prof );
00132 //            sed_cell_resize( info.added , sed_cell_thickness(info.added)*2 );
00133 //            sed_cell_add( sed_cube_to_remove(prof) , info.added );
00134          }
00135          else
00136          {
00137             mass_added       = 0;
00138             mass_lost        = 0;
00139             x_info.bruun_a   = 0;
00140             x_info.bruun_m   = 0;
00141             x_info.bruun_h_b = 0;
00142             x_info.bruun_y_0 = 0;
00143             x_info.bruun_y_b = 0;
00144             x_info.z_0       = 0;
00145          }
00146 
00147          info.mass_added = mass_added;
00148          info.mass_lost  = mass_lost;
00149          mass_after = sed_cube_mass( prof );
00150 
00151          eh_message( "time step (days)                : %f" , sed_ocean_storm_duration(this_storm) );
00152          eh_message( "cross shore current (m/s)       : %f" , xshore_current );
00153          eh_message( "incoming wave height (m)        : %f" , sed_ocean_storm_wave_height( this_storm ) );
00154          eh_message( "closure depth (m)               : %f" , x_info.z_0 );
00155          eh_message( "Bruun a (-)                     : %f" , x_info.bruun_a   );
00156          eh_message( "Bruun m (-)                     : %f" , x_info.bruun_m   );
00157          eh_message( "Bruun closure depth (m)         : %f" , x_info.bruun_h_b );
00158          eh_message( "Bruun start (m)                 : %f" , x_info.bruun_y_0 );
00159          eh_message( "Bruun end (m)                   : %f" , x_info.bruun_y_b );
00160 //         eh_message( "along shore sediment added (kg) : %f" , sed_cell_mass( info.added ) );
00161 //         eh_message( "sediment lost (kg)              : %f" , sed_cell_mass( info.lost  ) );
00162          eh_message( "mass before (kg)                : %f" , mass_before );
00163          eh_message( "mass after (kg)                 : %f" , mass_after  );
00164          eh_message( "mass added (kg)                 : %f" , mass_added  );
00165 
00166          eh_message( "mass balance (kg)               : %f" , (mass_after-mass_added)-mass_before );
00167 
00168          sed_cell_destroy( x_info.added );
00169          sed_cell_destroy( x_info.lost );
00170          eh_free( x_info.dt );
00171          lost = NULL;
00172       }
00173       else
00174       {
00175          eh_message( "time step (days)                : %f" , sed_ocean_storm_duration(this_storm) );
00176          eh_message( "cross shore current (m/s)       : %f" , xshore_current );
00177          eh_message( "incoming wave height (m)        : %f" , sed_ocean_storm_wave_height( this_storm ) );
00178          eh_message( "along shore sediment added (kg) : %f" , 0. );
00179          eh_message( "total sediment moved (kg)       : %f" , 0. );
00180       }
00181 
00182       current_time += sed_ocean_storm_duration(this_storm)*S_YEARS_PER_DAY;
00183       sed_cube_set_age( prof , current_time );
00184 
00185    }
00186 
00187 //   sed_cube_set_time_step( prof , dt );
00188    sed_cube_set_age( prof , end_time );
00189 
00190    sed_cell_destroy( along_shore_sediment );
00191 
00192    return info;
00193 }
00194 
00195 gboolean
00196 is_worth_running( Sed_ocean_storm s )
00197 {
00198    return sed_ocean_storm_wave_height( s ) > .1;
00199 }
00200 
00201 #define S_KEY_ALONG_SHORE_SEDIMENT_NO "Grain type of along shore sediment"
00202 #define S_KEY_XSHORE_VEL              "Cross shore current"
00203 
00204 gboolean
00205 init_xshore( Sed_process p , Eh_symbol_table tab , GError** error )
00206 {
00207    Xshore_t* data    = sed_process_new_user_data( p , Xshore_t );
00208    GError*   tmp_err = NULL;
00209    gboolean  is_ok   = TRUE;
00210 
00211    eh_return_val_if_fail( error==NULL || *error==NULL , FALSE );
00212 
00213    data->last_time      = 0.;
00214 
00215    data->sediment_type  = eh_symbol_table_int_value  ( tab , S_KEY_ALONG_SHORE_SEDIMENT_NO );
00216    data->xshore_current = eh_symbol_table_input_value( tab , S_KEY_XSHORE_VEL , &tmp_err);
00217 
00218    if ( tmp_err )
00219    {
00220       g_propagate_error( error , tmp_err );
00221       is_ok = FALSE;
00222    }
00223 
00224    return is_ok;
00225 }
00226 
00227 gboolean
00228 init_xshore_data( Sed_process proc , Sed_cube prof , GError** error )
00229 {
00230    Xshore_t* data = sed_process_user_data( proc );
00231 
00232    if ( data )
00233       data->last_time = sed_cube_age_in_years( prof );
00234 
00235    return TRUE;
00236 }
00237 
00238 gboolean
00239 destroy_xshore( Sed_process p )
00240 {
00241    if ( p )
00242    {
00243       Xshore_t* data = sed_process_user_data( p );
00244       
00245       if ( data )
00246       {
00247          eh_input_val_destroy( data->xshore_current );
00248          eh_free             ( data                 );
00249       }
00250    }
00251 
00252    return TRUE;
00253 }
00254 

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