00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #define SED_DEBRIS_FLOW_PROC_NAME "debris flow"
00022 #define EH_LOG_DOMAIN SED_DEBRIS_FLOW_PROC_NAME
00023
00024 #include <stdio.h>
00025 #include <stdlib.h>
00026 #include <utils/utils.h>
00027 #include <sed/sed_sedflux.h>
00028
00029 #include "bing.h"
00030
00031 #include "my_processes.h"
00032
00033 #define MAX_TRIES (1)
00034
00035 #define BING_LOCAL_MODEL
00036 #undef BING_OLD_LOCAL_MODEL
00037
00038 Sed_process_info
00039 run_debris_flow( Sed_process proc , Sed_cube p )
00040 {
00041 Debris_flow_t* data = sed_process_user_data(proc);
00042 Sed_process_info info = SED_EMPTY_INFO;
00043 Sed_cell c, flow_cell;
00044 int i;
00045 int i_start, i_end;
00046 int tries=0, max_tries=MAX_TRIES;
00047 double flow_rho, flow_age, flow_load;
00048 double head_start;
00049 pos_t *bathy, *flow;
00050 double *deposit;
00051 Sed_cube fail;
00052 bing_t bing_const;
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 fail = sed_process_use( proc , FAILURE_PROFILE_DATA );
00075
00076
00077 deposit = eh_new( double , sed_cube_n_y(p) );
00078
00079
00080 bathy = createPosVec(sed_cube_n_y(p));
00081 for (i=0;i<sed_cube_n_y(p);i++)
00082 {
00083
00084
00085 bathy->x[i] = sed_cube_col_y( p,i );
00086 bathy->y[i] = sed_cube_water_depth(p,0,i);
00087 }
00088
00089
00090
00091 flow = createPosVec(sed_cube_n_y(fail)-2);
00092 for (i=0;i<flow->size;i++)
00093 {
00094 flow->x[i] = sed_cube_col_y ( fail,i+1 );
00095 flow->y[i] = sed_cube_thickness( fail,0,i+1 );
00096 }
00097 head_start = flow->x[flow->size-1];
00098
00099
00100
00101 eh_dbl_array_set( flow->y ,
00102 flow->size ,
00103 eh_dbl_array_mean( flow->y , flow->size ) );
00104
00105
00106 flow_cell = sed_cell_new_env();
00107 c = sed_cell_new_env();
00108 for (i=0;i<sed_cube_n_y(fail);i++)
00109 {
00110 sed_column_top( sed_cube_col(fail,i) , sed_cube_thickness(fail,0,i) , c );
00111 sed_cell_add( flow_cell , c );
00112 }
00113 flow_rho = sed_cell_density( flow_cell );
00114 flow_age = sed_cell_age ( flow_cell );
00115 flow_load = sed_cell_load ( flow_cell ) / sed_cube_n_y(fail);
00116
00117
00118 bing_const.numericalViscosity = data->numerical_viscosity;
00119 bing_const.dt = data->dt;
00120 bing_const.maxTime = data->max_time;
00121 bing_const.flowDensity = flow_rho;
00122
00123 #ifdef BING_LOCAL_MODEL // the (new) local model.
00124
00125 bing_const.yieldStrength = sed_cell_bulk_yield_strength ( flow_cell );
00126 bing_const.viscosity = sed_cell_bulk_dynamic_viscosity( flow_cell );
00127
00128 #else // the global model.
00129
00130 bing_const.yieldStrength = data->yield_strength;
00131 bing_const.viscosity = data->viscosity;
00132
00133 #endif
00134
00135 #ifdef BING_OLD_LOCAL_MODEL
00136
00137 bing_const.yieldStrength = sed_cell_shear_strength( flow_cell , flow_load/2. )
00138 / 5.;
00139 bing_const.viscosity = sed_cell_viscosity( flow_cell )/1.;
00140
00141 #endif
00142
00143
00144
00145
00146 while ( !bing(bathy,flow,bing_const,deposit) && (++tries)<max_tries )
00147 bing_const.numericalViscosity += .1;
00148
00149 eh_message( "time : %f" , sed_cube_age_in_years(p) );
00150 eh_message( "mass : %f" , sed_cube_mass(fail) );
00151 eh_message( "viscosity : %f" , bing_const.viscosity );
00152 eh_message( "yield strength : %f" , bing_const.yieldStrength );
00153
00154 if ( tries<max_tries )
00155 {
00156
00157 sed_cell_set_facies( flow_cell , S_FACIES_DEBRIS_FLOW );
00158 sed_cell_set_age( flow_cell , flow_age );
00159 sed_cell_set_age( flow_cell , sed_cube_age_in_years(p) );
00160 sed_cell_set_pressure( flow_cell , 0. );
00161
00162 for ( i=0 ; i<sed_cube_n_y(p) ; i++ )
00163 if ( deposit[i] > 0 )
00164 {
00165 sed_cell_resize( flow_cell , deposit[i] );
00166 sed_column_add_cell( sed_cube_col(p,i) , flow_cell );
00167 }
00168
00169
00170 for ( i_start=0 ; i_start<sed_cube_n_y(p) && deposit[i_start] <= 0. ; i_start++ );
00171 for ( i_end=sed_cube_n_y(p)-1 ; i_end>=0 && deposit[i_end] <= 0. ; i_end-- );
00172
00173 if ( i_start == sed_cube_n_y(p) )
00174 {
00175 i_start = sed_cube_n_y(p)-1;
00176 eh_require_not_reached( );
00177 }
00178 if ( i_end == -1 )
00179 {
00180 i_end = 0;
00181 eh_require_not_reached( );
00182 }
00183
00184 eh_message( "runout length : %f" ,
00185 i_end*sed_cube_y_res(p)-head_start );
00186 eh_message( "head start : %f" , head_start );
00187 eh_message( "drop : %f" ,
00188 sed_cube_water_depth(p,0,i_end)
00189 - sed_cube_water_depth(p,0,i_start) );
00190
00191 }
00192 else
00193 {
00194 eh_message( "runout length : -999" );
00195 eh_message( "head start : -999" );
00196 eh_message( "drop : -999" );
00197 sed_cube_add(p,fail);
00198 }
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 sed_cell_destroy( c );
00209 sed_cell_destroy( flow_cell );
00210
00211 destroyPosVec( bathy );
00212 destroyPosVec( flow );
00213 eh_free( deposit );
00214
00215
00216 return info;
00217 }
00218
00219 #define S_KEY_YIELD_STRENGTH "yield strength"
00220 #define S_KEY_VISCOSITY "kinematic viscosity"
00221 #define S_KEY_NUM_VISCOSITY "artificial viscosity"
00222 #define S_KEY_DT "time step"
00223 #define S_KEY_MAX_TIME "maximum run time"
00224
00225 gboolean
00226 init_debris_flow( Sed_process p , Eh_symbol_table tab , GError** error )
00227 {
00228 Debris_flow_t* data = sed_process_new_user_data( p , Debris_flow_t );
00229 GError* tmp_err = NULL;
00230 gchar** err_s = NULL;
00231 gboolean is_ok = TRUE;
00232
00233 eh_return_val_if_fail( error==NULL || *error==NULL , FALSE );
00234
00235 data->yield_strength = eh_symbol_table_dbl_value( tab , S_KEY_YIELD_STRENGTH );
00236 data->viscosity = eh_symbol_table_dbl_value( tab , S_KEY_VISCOSITY );
00237 data->numerical_viscosity = eh_symbol_table_dbl_value( tab , S_KEY_NUM_VISCOSITY );
00238 data->dt = eh_symbol_table_dbl_value( tab , S_KEY_DT );
00239 data->max_time = eh_symbol_table_dbl_value( tab , S_KEY_MAX_TIME );
00240
00241 eh_check_to_s( data->yield_strength>=0 , "Yield strength positive" , &err_s );
00242 eh_check_to_s( data->viscosity>=0 , "Viscosity positive" , &err_s );
00243 eh_check_to_s( data->numerical_viscosity>=0 , "Numerical viscosity positive" , &err_s );
00244 eh_check_to_s( data->dt>0 , "Time step positive" , &err_s );
00245 eh_check_to_s( data->max_time>0 , "Maximum run time positive" , &err_s );
00246
00247
00248 data->failure = NULL;
00249
00250 if ( !tmp_err && err_s )
00251 eh_set_error_strv( &tmp_err , SEDFLUX_ERROR , SEDFLUX_ERROR_BAD_PARAM , err_s );
00252
00253 if ( tmp_err )
00254 {
00255 g_propagate_error( error , tmp_err );
00256 is_ok = FALSE;
00257 }
00258
00259 return is_ok;
00260 }
00261
00262 gboolean
00263 destroy_debris_flow( Sed_process p )
00264 {
00265 if ( p )
00266 {
00267 Debris_flow_t* data = sed_process_user_data( p );
00268
00269 if ( data )
00270 eh_free( data );
00271 }
00272
00273 return TRUE;
00274 }
00275
00276 gboolean dump_debris_flow_data( gpointer ptr , FILE *fp )
00277 {
00278 Debris_flow_t *data = (Debris_flow_t*)ptr;
00279
00280 fwrite( data , sizeof(Debris_flow_t) , 1 , fp );
00281 sed_cube_write( fp , data->failure );
00282
00283 return TRUE;
00284 }
00285
00286 gboolean load_debris_flow_data( gpointer ptr , FILE *fp )
00287 {
00288 Debris_flow_t *data = (Debris_flow_t*)ptr;
00289
00290 fread( data , sizeof(Debris_flow_t*) , 1 , fp );
00291 data->failure = sed_cube_read( fp );
00292
00293 return TRUE;
00294 }
00295
00296