00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #define SED_DIFFUSION_PROC_NAME "diffusion"
00022 #define EH_LOG_DOMAIN SED_DIFFUSION_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 <diffusion.h>
00031 #include "my_processes.h"
00032
00033 #include "sedflux.h"
00034
00035 Sed_process_info
00036 run_diffusion( Sed_process proc , Sed_cube prof )
00037 {
00038 Diffusion_t* data = sed_process_user_data(proc);
00039 Sed_process_info info = SED_EMPTY_INFO;
00040 double k_max;
00041 double skin_depth;
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 k_max = eh_input_val_eval( data->k_max ,
00054 sed_cube_age_in_years( prof ) )
00055 * sed_cube_storm(prof);
00056 skin_depth = data->skin_depth*sed_cube_storm(prof);
00057
00058 eh_require( k_max>0 )
00059 {
00060 Sed_cell *lost;
00061
00062 eh_message( "time : %f" ,
00063 sed_cube_age_in_years(prof) );
00064
00065 if ( sed_mode_is_3d() )
00066 lost = diffuse_sediment_2(
00067 prof , k_max , k_max ,
00068 skin_depth , sed_cube_time_step_in_days(prof) ,
00069 DIFFUSION_OPT_WATER );
00070 else
00071 lost = diffuse_sediment(
00072 prof , k_max ,
00073 skin_depth , sed_cube_time_step_in_days(prof) ,
00074 DIFFUSION_OPT_WATER );
00075
00076 if ( lost )
00077 {
00078 int i;
00079 for ( i=0 ; i<4 ; i++ )
00080 sed_cell_destroy( lost[i] );
00081 eh_free( lost );
00082 }
00083
00084
00085 eh_message( "time step (days) : %f" ,
00086 sed_cube_time_step_in_days(prof) );
00087 eh_message( "diffusion coeficient : %f" , k_max );
00088 }
00089
00090 return info;
00091 }
00092
00093 #define DIFFUSION_KEY_K_MAX "diffusion constant"
00094 #define DIFFUSION_KEY_SKIN_DEPTH "diffusion 1% depth"
00095 #define DIFFUSION_KEY_K_LONG_MAX "long-shore diffusion constant"
00096 #define DIFFUSION_KEY_K_CROSS_MAX "cross-shore diffusion constant"
00097
00098 static gchar* diffusion_req_labels[] =
00099 {
00100 DIFFUSION_KEY_K_MAX ,
00101 DIFFUSION_KEY_SKIN_DEPTH ,
00102 NULL
00103 };
00104
00105 gboolean
00106 init_diffusion( Sed_process p , Eh_symbol_table tab , GError** error )
00107 {
00108 Diffusion_t* data = sed_process_new_user_data( p , Diffusion_t );
00109 GError* tmp_err = NULL;
00110 gchar** err_s = NULL;
00111 gboolean is_ok = TRUE;
00112
00113 eh_return_val_if_fail( error==NULL || *error==NULL , FALSE );
00114
00115 eh_symbol_table_require_labels( tab , diffusion_req_labels , &tmp_err );
00116
00117 if ( !tmp_err )
00118 {
00119 data->k_max = eh_symbol_table_input_value( tab , DIFFUSION_KEY_K_MAX , &tmp_err );
00120 data->skin_depth = eh_symbol_table_dbl_value ( tab , DIFFUSION_KEY_SKIN_DEPTH );
00121
00122 eh_check_to_s( data->k_max>0 , "Diffusion coefficient positive" , &err_s );
00123 eh_check_to_s( data->skin_depth>0 , "Skin depth positive" , &err_s );
00124
00125 if ( !tmp_err && err_s )
00126 eh_set_error_strv( &tmp_err , SEDFLUX_ERROR , SEDFLUX_ERROR_BAD_PARAM , err_s );
00127 }
00128
00129 if ( tmp_err )
00130 {
00131 g_propagate_error( error , tmp_err );
00132 is_ok = FALSE;
00133 }
00134
00135 return is_ok;
00136 }
00137
00138 gboolean
00139 destroy_diffusion( Sed_process p )
00140 {
00141 if ( p )
00142 {
00143 Diffusion_t* data = sed_process_user_data( p );
00144
00145 if ( data )
00146 {
00147 eh_input_val_destroy( data->k_max );
00148 eh_free( data );
00149 }
00150 }
00151 return TRUE;
00152 }