예제 #1
0
END_TEST

START_TEST ( test_approx_deposit_nd )
{
   gssize i;
   double* dep;
   gssize len = 1000;
   double* x = eh_new( double , len );

   for ( i=0 ; i<len ; i++ )
      x[i] = i/10.;

   dep = plume_centerline_deposit_nd( NULL , x , len , 1. );

   fail_if( dep==NULL , "Deposit array should be created" );

   for ( i=0 ; i<len ; i++ )
   {
      fail_unless( ~eh_isnan(dep[i]) , "Deposit thickness is non-NaN" );
      fail_unless( dep[i]>=0         , "Deposit thickness is positive" );
   }

   eh_free( dep );
   eh_free( x   );
}
예제 #2
0
void free_dmatrix( double **m )
{
   if ( m )
   {
      eh_free( m[0] );
      eh_free( m    );
   }
}
예제 #3
0
void free_d3tensor( double ***t )
{
   if ( t )
   {
      if ( t[0] )
      {
         eh_free( t[0][0] );
         eh_free( t[0] );
      }
      eh_free( t );
   }
}
예제 #4
0
/** Destroy an Eh_input_val

\param val An Eh_input_val that was created with eh_create_input_val.

\see eh_create_input_val.
*/
Eh_input_val
eh_input_val_destroy( Eh_input_val val )
{
   if (val)
   {
      eh_free (val->x);
      eh_free (val->y);
      eh_free (val->file);
      g_rand_free (val->rand);
      eh_free (val);
   }
   return NULL;
}
예제 #5
0
파일: csdms.c 프로젝트: SiccarPoint/sedflux
/** Destroy a CSDMSComp

\param[in,out]   c   A CSDMSComp

\return NULL
*/
CSDMSComp*
csdms_comp_destroy( CSDMSComp* c )
{
   if ( c ) eh_free( c );

   return NULL;
}
예제 #6
0
void destroy_plume_data( Plume_data *grid )
{
   if ( grid )
   {
      eh_free( grid->xval );
      eh_free( grid->yval );

      free_d3tensor( grid->ccnc  );
      free_d3tensor( grid->ncnc  );
      free_d3tensor( grid->deps  );
      free_d3tensor( grid->dist  );
      free_dmatrix ( grid->ualb  );
      free_dmatrix ( grid->pcent );

      eh_free( grid );
   }
}
예제 #7
0
END_TEST

START_TEST ( test_approx_from_file )
{
   gssize len = 1000;
   double* x   = eh_new( double , len );
   double* dep = eh_new( double , len );

   {
      Sed_type this_type;
      gssize n, i;
      gssize n_grains = sed_sediment_env_n_types();
      Sed_hydro_file f = sed_hydro_file_new( SED_HYDRO_TEST_FILE , SED_HYDRO_HYDROTREND , FALSE , TRUE , NULL );
      Sed_hydro river;
      double dt;
      double l;
      double* total = eh_new0( double , len );

      for ( n=1 ; n<n_grains ; n++ )
      {
         this_type = sed_sediment_type( NULL , n );
         for ( dt=0 ; dt<365 ; )
         {
            river = sed_hydro_file_read_record( f );

            l = plume_non_dim_lambda( sed_type_lambda(this_type) , river );
            for ( i=0 ; i<len ; i++ )
               x[i] = plume_non_dim_distance( i*100 , river );

            dt += sed_hydro_duration( river );
            if ( dt <= 365 )
               dep = plume_centerline_deposit_nd( dep , x , len , l );

            eh_dbl_array_add_each( total , len , dep );

            sed_hydro_destroy( river );
         }
      }

      sed_hydro_file_destroy( f );
      eh_free( total );
   }

   eh_free( x );
   eh_free( dep );
}
예제 #8
0
gboolean
parse_data_list( const gchar* name , const gchar* value , gpointer data , GError** error )
{
   gboolean    success = FALSE;
   Sakura_var* data_id = NULL;

   eh_return_val_if_fail( error==NULL || *error==NULL , FALSE );

   if ( name && value )
   {
      GError* tmp_err   = NULL;
      gchar** data_list = g_strsplit( value , "," , 0 );

      if ( !data_list )
      {
         g_set_error( &tmp_err ,
                      G_OPTION_ERROR ,
                      G_OPTION_ERROR_FAILED ,
                      "Failed to parse comma-separated list of data values to monitor" );
      }
      else
      {
         gchar**    key;
         Sakura_var id;
         gint       i;


         data_id = eh_new( Sakura_var , g_strv_length( data_list )+1 );

         for ( key=data_list,i=0 ; *key && !tmp_err ; key++,i++ )
         {
            id         = eh_strv_find( _DATA_VAL_KEYS , *key );
            data_id[i] = id;

            if ( id<0 )
               g_set_error( &tmp_err ,
                            G_OPTION_ERROR ,
                            G_OPTION_ERROR_FAILED ,
                            "Invalid data key (%s)" , *key );
         }
         data_id[i] = -1;
      }

      if ( tmp_err )
      {
         g_propagate_error( error , tmp_err );
         eh_free( data_id );
         data_id = NULL;
         success = FALSE;
      }
      else
         success = TRUE;
   }

   _data_id = data_id;

   return success;
}
예제 #9
0
END_TEST

START_TEST ( test_set_input_val )
{
   Eh_input_val v;

   {
      GError* err = NULL;

      v = eh_input_val_set( "-.5" , &err );

      if ( err!=NULL )
         fprintf( stderr , "%s" , err->message );

      fail_unless( eh_input_val_eval(v)==-.5 , "Scalar value set incorrectly" );
      v = eh_input_val_destroy( v );

      g_clear_error( &err );
   }

   {
      gssize n_evals = 100000;
      gssize i;
      double* vals = eh_new( double , n_evals );
      double mean, var;
      GError* err = NULL;

      v = eh_input_val_set( "normal=-.5,.1" , &err );

      if ( err!=NULL )
         fprintf( stderr , "%s" , err->message );

      for ( i=0 ; i<n_evals ; i++ )
         vals[i] = eh_input_val_eval( v );
      mean = eh_dbl_array_mean( vals , n_evals );
      var  = eh_dbl_array_var ( vals , n_evals );

      fail_unless( eh_compare_dbl(mean,-.5,.01)     , "Normal distribution mean set incorrectly" );
      fail_unless( eh_compare_dbl(sqrt(var),.1,.01) , "Normal distribution variance set incorrectly" );

      eh_free( vals );
      v = eh_input_val_destroy( v );

      g_clear_error( &err );
   }

/*
   {
      v = eh_input_val_set( "user=user_test.txt" );

      fail_if( v==NULL , "Could not read user file" );

      v = eh_input_val_destroy( v );
   }
*/
}
예제 #10
0
gboolean
destroy_erosion( Sed_process p )
{
   if ( p )
   {
      Erosion_t* data = (Erosion_t*)sed_process_user_data( p );

      if ( data ) eh_free( data );
   }

   return TRUE;
}
예제 #11
0
Sed_cell
erode_river_profile( Sed_cube p , Sed_riv r , double slope , gint method )
{
   Sed_cell eroded_sed = NULL;

   if ( p && r )
   {
      gint*  river_path = sed_cube_river_path_id( p , r , TRUE );

      eh_require( river_path );

      if ( river_path )
      {
         Sed_cube  river_profile = sed_cube_cols( p , river_path );
         Sed_hydro river_data    = sed_river_hydro( r );

         eh_require( river_data    );
         eh_require( river_profile );

         if ( sed_mode_is_3d() )
         {
            sed_cube_set_x_res( river_profile , 1. );
            sed_cube_set_y_res( river_profile , .5*(sed_cube_x_res(p)+sed_cube_y_res(p)) );
         }
         else
         {
            sed_cube_set_x_res( river_profile , sed_cube_x_res(p) );
            sed_cube_set_y_res( river_profile , sed_cube_y_res(p) );
         }
   
         switch ( method )
         {
            case EROSION_ALGORITHM_DIFFUSION:
               eroded_sed  = diffuse_profile( river_profile , river_data ); break;
            case EROSION_ALGORITHM_SLOPE:
               eroded_sed  = erode_profile  ( river_profile , slope      ); break;
            default:
               eh_require_not_reached();
         }

         sed_hydro_add_cell( river_data , eroded_sed );

         sed_river_set_hydro( r , river_data );

         sed_hydro_destroy( river_data );
         eh_free          ( river_path );
         sed_cube_free    ( river_profile , FALSE );
      }
   }

   return eroded_sed;
}
예제 #12
0
void
eh_set_error_strv( GError** error , GQuark domain , gint code , gchar** err_s )
{
   if ( err_s && *err_s )
   {
      gchar* str = g_strjoinv( "\n" , err_s );

      g_set_error( error , domain , code , "%s" , str );

      eh_free( str );
   }

   return;
}
예제 #13
0
gboolean
destroy_bioturbation( Sed_process p )
{
   if ( p )
   {
      Bioturbation_t* data = sed_process_user_data( p );

      if ( data )
      {
         eh_input_val_destroy( data->k     );
         eh_input_val_destroy( data->depth );
         eh_free             ( data        );
      }
   }
   return TRUE;
}
예제 #14
0
gboolean
destroy_xshore( Sed_process p )
{
   if ( p )
   {
      Xshore_t* data = (Xshore_t*)sed_process_user_data( p );
      
      if ( data )
      {
         eh_input_val_destroy( data->xshore_current );
         eh_free             ( data                 );
      }
   }

   return TRUE;
}
예제 #15
0
void
eh_print_on_error( GError* error , const gchar* format , ... )
{
   if ( error )
   {
      gchar* err_s;
      va_list ap;
      va_start( ap , format );

      err_s = g_strdup_vprintf( format , ap );
      eh_error( eh_render_error_str( error , err_s ) );

      va_end(ap);
      eh_free( err_s );
   }
}
예제 #16
0
void supla_client_clean(void *_suplaclient) {

	TSuplaClientData *suplaclient = (TSuplaClientData *)_suplaclient;

	if ( suplaclient ) {

		if ( suplaclient->eh ) {
			eh_free(suplaclient->eh);
			suplaclient->eh = NULL;
		}

		if ( suplaclient->srpc ) {
			srpc_free(suplaclient->srpc);
			suplaclient->srpc = NULL;
		}
	}
}
예제 #17
0
END_TEST

START_TEST ( test_compact_mixed )
{
   Sed_column c = sed_column_new( 5 );
   Sed_cell cell;

   {
      double* f = eh_new0( double , sed_sediment_env_n_types() );
      gssize n;

      for ( n=0 ; n<sed_sediment_env_n_types() ; n++ )
         f[n] = 1./(double)sed_sediment_env_n_types();
      cell = sed_cell_new_sized( sed_sediment_env_n_types() , 30000 , f );

      eh_free( f );
   }

   sed_column_set_sea_level  ( c , 10   );
   sed_column_set_base_height( c , -40000 );

   sed_column_add_cell( c , cell );

   {
      double mass_out;
      double mass_in = sed_column_sediment_mass(c);

      compact( c );

      mass_out = sed_column_sediment_mass(c);

      fail_unless( eh_compare_dbl( mass_in , mass_out , 1e-12 ) , "Mass balance error in compaction" );
   }

   {
      Sed_cell cell_0 = sed_column_nth_cell( c , 0 );
      double e_min  = sed_cell_void_ratio_min( cell_0 );
      double e      = sed_cell_void_ratio    ( cell_0 );

      fail_unless( eh_compare_dbl( e_min , e , 1e-5 )           , "Cell did not reach maximum compaction" );
   }

   sed_cell_destroy  ( cell );
   sed_column_destroy( c    );
}
예제 #18
0
void
my_hook( Sed_process_queue q )
{
   if ( q )
   {
      gssize i;
      Failure_proc_t** data;
      Sed_process d = sed_process_queue_find_nth_obj( q , "debris flow"       , 0 );
      Sed_process t = sed_process_queue_find_nth_obj( q , "turbidity current" , 0 );
      Sed_process s = sed_process_queue_find_nth_obj( q , "slump"             , 0 );

      data = (Failure_proc_t**)sed_process_queue_obj_data( q , "failure" );
      for ( i=0 ; data && data[i] ; i++ )
      {
         data[i]->debris_flow       = d;
         data[i]->turbidity_current = t;
         data[i]->slump             = s;
      }
      eh_free( data );
   }

   return;
}
예제 #19
0
Sed_cell
diffuse_profile( Sed_cube river_profile , Sed_hydro river_data )
{
   Sed_cell eroded_sed = NULL;

   eh_require( river_profile );

   if ( river_profile )
   {
      double    time_fraction = 1e-0;
      double    dt            = sed_cube_time_step_in_days( river_profile );
      double    width         = sed_cube_x_res( river_profile );
      Sed_cell* lost_cell     = NULL;
      double    k_land;
      
      k_land  = get_paola_diffusion( river_data , width , time_fraction , PAOLA_BRAIDED )
              * S_SECONDS_PER_DAY
              * sed_cube_storm( river_profile );
   //         k_land = 200;
   //         dt = 15;
/*
      eh_message( "diffusion coefficient : %.3e m^2/day" , k_land );
      eh_message( "time step : %.3e days"                , dt     );
*/
      lost_cell = diffuse_sediment( river_profile , k_land ,
                                    0             , dt     ,
                                    DIFFUSION_OPT_LAND|DIFFUSION_OPT_FILL );

      // convert time step to seconds.
   //         dt = sed_get_profile_time_step_in_seconds(p);
      if ( lost_cell )
      {
         double dx          = sed_cube_y_res ( river_profile );
         double river_width = sed_hydro_width( river_data    );
      
         /* The volume of sediment diffused through the right boundary.  This
            is the sediment that has made it to the ocean. */
//         volume_eroded = sed_cell_size(lost_cell[1])*dx*river_width;

         /* Bedload may have been added along the profile ([3]).  Remove this from the sediment
            that is diffused through the right boundary ([1]). */
         sed_cell_separate_cell( lost_cell[1] , lost_cell[3] );
      
//         dt *= S_SECONDS_PER_DAY;

         eroded_sed = sed_cell_new_env();

         sed_cell_add   ( eroded_sed , lost_cell[1] );
         sed_cell_add   ( eroded_sed , lost_cell[2] );
         sed_cell_resize( eroded_sed , sed_cell_size(eroded_sed)*dx*river_width );
/*
         // Add suspended sediment to the river
         sed_hydro_add_cell( river_data , lost_cell[2] , volume_eroded );

         // Add sediment diffused out of the right boundary to the river
         sed_hydro_add_cell( river_data , lost_cell[1] , volume_eroded );
*/
         sed_cell_destroy( lost_cell[0] );
         sed_cell_destroy( lost_cell[1] );
         sed_cell_destroy( lost_cell[2] );
         sed_cell_destroy( lost_cell[3] );

         eh_free( lost_cell );
      }
      
//      eh_message( "eroded sediment (m^3): %.3g" , volume_eroded );
   }

   return eroded_sed;
}
예제 #20
0
svr_ipcctrl::~svr_ipcctrl() {
	if ( sfd != -1 )
		close(sfd);

	eh_free(eh);
}
예제 #21
0
Sed_process_info
run_erosion( Sed_process proc , Sed_cube p )
{
   Erosion_t*       data = (Erosion_t*)sed_process_user_data(proc);
   Sed_process_info info = SED_EMPTY_INFO;
   Sed_riv* all;

//   for ( this_river=sed_cube_river_list(p) ; this_river ; this_river=this_river->next )
/*
   for ( n=0,this_river = sed_cube_nth_river(p,n) ;
         n<n_rivers ;
         n++,this_river = sed_cube_nth_river(p,n) )
*/

   all = sed_cube_all_leaves( p );

   if ( all )
   {
      Sed_riv* r;
      Sed_cell eroded_sed = NULL;

      for ( r=all ; *r ; r++ )
      {
         eh_message( "Eroding along river %s" , sed_river_name_loc( *r ) );

         eroded_sed = erode_river_profile( p , *r , data->slope , data->method );
         sed_cell_destroy( eroded_sed );
/*
         river_path = sed_cube_river_path_id( p , *r , TRUE );
      
         river_profile = sed_cube_cols( p , river_path );

         if ( sed_mode_is_3d() )
         {
            sed_cube_set_x_res( river_profile , 1. );
            sed_cube_set_y_res( river_profile , .5*(sed_cube_x_res(p)+sed_cube_y_res(p)) );
         }
         else
         {
            sed_cube_set_x_res( river_profile , sed_cube_x_res(p) );
            sed_cube_set_y_res( river_profile , sed_cube_y_res(p) );
         }
   
         eh_free( river_path );
      
   //      river_data    = ((Sed_river*)(this_river->data))->data;
         river_data = sed_river_hydro( *r );
   
         if ( data->method == EROSION_ALGORITHM_DIFFUSION )
            eroded_sed = diffuse_profile( river_profile , river_data );
         else
            eroded_sed = erode_profile( river_profile , river_data );

         sed_hydro_add_cell( river_data , eroded_sed );

         sed_river_set_hydro( *r , river_data );
         sed_hydro_destroy  ( river_data );
   
         sed_cube_free( river_profile , FALSE );
*/

/*
         if ( data->method == EROSION_ALGORITHM_DIFFUSION )
         {

            dt            = sed_cube_time_step_in_days( river_profile );
   //         time_fraction = 1e-1;
            time_fraction = 1e-0;
            if ( sed_mode_is_3d() )
               basin_width   = sed_cube_x_res( river_profile );
            else
               basin_width   = sed_cube_x_res( p );
      
            k_land  = get_paola_diffusion( river_data    , basin_width ,
                                           time_fraction , PAOLA_BRAIDED )
                    * S_SECONDS_PER_DAY;
            k_land *= sed_cube_storm( river_profile );
      
   //         k_land = 200;
   //         dt = 15;
   
            eh_message( "diffusion coefficient : %.3e m^2/day" , k_land );
            eh_message( "time step : %.3e days"                , dt     );
   
            lost_cell = diffuse_sediment( river_profile , k_land ,
                                          0             , dt     ,
                                          DIFFUSION_OPT_LAND|DIFFUSION_OPT_FILL );
             
            // convert time step to seconds.
   //         dt = sed_get_profile_time_step_in_seconds(p);
            if ( lost_cell )
            {
               dx    = sed_cube_y_res( river_profile );
               width = sed_hydro_width( river_data );
      
               // add the eroded sediment to the river discharge.
               volume_eroded = sed_cell_size(lost_cell[1])*dx*width;
      
               sed_cell_separate_cell( lost_cell[1] , lost_cell[3] );
      
               dt *= S_SECONDS_PER_DAY;

               sed_hydro_add_cell( river_data , lost_cell[2] , volume_eroded );
               sed_hydro_add_cell( river_data , lost_cell[1] , volume_eroded );
      
               sed_cell_destroy( lost_cell[0] );
               sed_cell_destroy( lost_cell[1] );
               sed_cell_destroy( lost_cell[2] );
               sed_cell_destroy( lost_cell[3] );
               eh_free( lost_cell );
            }
      
            eh_message( "eroded sediment (m^3): %.3g" , volume_eroded );
      
         }
         else
         {
            eroded_fraction = eh_new( double , n_grains );
         
            for (i=0;i<n_grains;i++)
               eroded_fraction[i] = 1.;
         
            total  = sed_cell_new( n_grains );
            eroded = sed_cell_new( n_grains );
         
            if ( sed_cube_river_mouth_1d( river_profile )<0 )
               return info;
         
            dx    = sed_cube_y_res( river_profile );
            width = sed_cube_x_res( river_profile );
         
            i_river = sed_cube_river_mouth_1d( river_profile ) - 1;
            if ( i_river < 0 )
               return info;
         
            river_height = sed_cube_top_height(river_profile,0,i_river);
   //         log_const = getLogConstants( OMEGA_DELTA         ,
   //                                      data->stream_relief ,
   //                                      data->stream_reach);
            linear_const = get_linear_constants(   data->stream_relief
                                                 / data->stream_reach );
      
            for (i=i_river-1;i>=0;i--)
            {
               x = (i-i_river)*dx;
   //            height = getLogHeight(x,log_const) + river_height;
               height = get_linear_height( x , linear_const ) + river_height;
         
               eroded_height = sed_cube_top_height(river_profile,0,i)-height;
               if ( eroded_height > 1e-12 )
               {
                  sed_column_extract_top( sed_cube_col(river_profile,i) ,
                                          eroded_height                 ,
                                          eroded);
                  sed_cell_add( total , eroded );
               }
            }
         
            if ( sed_cube_river_mouth_1d( river_profile )<0 )
               return info;
         
            // convert time step to seconds.
            dt = sed_cube_time_step_in_seconds( river_profile );
         
            // add the eroded sediment to the river discharge.
   //         river_data = sed_cube_river_data( river_profile );
         
            volume_eroded = sed_cell_size(total)*dx*width;
         
            sed_hydro_add_cell( river_data  , total , volume_eroded );
         
            eh_message( "eroded sediment (m^3): %.3g" , volume_eroded );
         
            sed_cell_destroy( eroded );
            sed_cell_destroy( total  );
            eh_free( eroded_fraction );
         }
   
         sed_river_set_hydro( *r , river_data );
         sed_hydro_destroy  ( river_data );
   
         sed_cube_free( river_profile , FALSE );
*/
      }

      eh_free( all );
   }

   return info;
}
예제 #22
0
gint
plumeout2( Plume_enviro* env         ,
           Plume_grid*   grid        ,
           double        dx          ,
           double**      deposit     ,
           int           deposit_len ,
           int           n_grains    ,
           double        basin_width )
{
   double *deposit_thickness, *deposit_int;
   double *deposit_x;
   double mass_in, mass_out;
   int   ii, jj, nn;
   Plume_river river = *(env->river);
   Plume_sediment *sedload = env->sed;

   deposit_thickness = eh_new( double , grid->lx );
   deposit_int       = eh_new( double , deposit_len );
   deposit_x         = eh_new( double , deposit_len );

   //---
   // initialize the x-coordinate for each deposit location.  this is where
   // where we want to calculate the sedimentation rates.  we will interpolate
   // plume's grid to this one.
   //---
   for ( ii=0 ; ii<deposit_len ; ii++ )
      deposit_x[ii] = ii*dx;
   
   //---
   // here we average the 2d plume grid row by row so that we obtain an
   // average sedimentation rate that we use as the centerline average.
   // we then interpolate this 1d array to the points that are specified
   // as input (a constant spacing of dx).
   //
   // we also calculate the sediment mass that was input (for each grain
   // size) and the mass the is output.  if there is a difference, we scale
   // the output mass to assure that mass is balanced.  we assume that any
   // discrepancy is a result of small numerical errors.
   //---
   for ( nn=0 ; nn<env->n_grains ; nn++ )
   {
      mass_in = river.Cs[nn]*river.Q*dTOs;

      // Determine the centerline average for each grain size
      for( ii=0 ; ii<grid->lx ; ii++ ) 
      {
         deposit_thickness[ii] = 0.0;
         for( jj=0 ; jj<grid->ly ; jj++ )
            deposit_thickness[ii] += grid->deps[ii][jj][nn];
         deposit_thickness[ii] /= grid->ly;
      }

      // Interpolate to the requested grid.
      interpolate( grid->xval ,
                   deposit_thickness ,
                   grid->lx ,
                   deposit_x ,
                   deposit_int ,
                   deposit_len );

      for( ii=0, mass_out=0 ; ii<deposit_len ; ii++ ) 
         if ( !isnan(deposit_int[ii]) )
            mass_out += deposit_int[ii]*sedload[nn].rho;
         else
            deposit_int[ii] = 0.;
      mass_out *= basin_width*dx;

      // Need to swap these arrays for sedflux.  While we are it, scale the
      // interpolated deposit for mass balance.
      if ( mass_out > 0 )
         for (ii=0;ii<deposit_len;ii++)
            deposit[ii][nn] = deposit_int[ii];
            //deposit[ii][nn] = deposit_int[ii]*(mass_in/mass_out);
      else
         eh_require_not_reached();

eh_watch_dbl( mass_in );
mass_out = 0;
         for (ii=0;ii<deposit_len;ii++)
            mass_out += deposit_int[ii]*dx*basin_width*sedload[nn].rho;
eh_watch_dbl( mass_out );
   }

   eh_free( deposit_x );
   eh_free( deposit_thickness );
   eh_free( deposit_int );

   return 0;
}   // end of PlumeOut2
예제 #23
0
END_TEST

/*
START_TEST ( test_plume_from_file )
{
   Plume_inputs plume_const;
   Plume_data plume_data;
   Eh_dbl_grid* deposit;

   plume_const.current_velocity    = 0.;
   plume_const.ocean_concentration = 0.;
   plume_const.plume_width         = 3000.;
   plume_const.ndx                 = 1;
   plume_const.ndy                 = 3;

   plume_data_init( &plume_data );

   {
      gssize n;
      deposit = eh_new( Eh_dbl_grid , 4 );
      for ( n=0 ; n<4 ; n++ )
      {
         deposit[n] = eh_grid_new( double , 2 , 800 );

         eh_grid_set_x_lin( deposit[n] , -30000 , 30000 );
         eh_grid_set_y_lin( deposit[n] , 0      , 100 );
      }
   }

   {
      Sed_hydro_file f = sed_hydro_file_new( SED_HYDRO_TEST_FILE , HYDRO_HYDROTREND , TRUE );
      Sed_hydro river;
      double dt;

      for ( dt=0 ; dt<365 ; )
      {
         river = sed_hydro_file_read_record( f );
         dt += sed_hydro_duration( river );
         if ( dt <= 365 )
            plume_3d( &plume_const , river , sed_sediment_env() , deposit , &plume_data );
         sed_hydro_destroy( river );
      }

      sed_hydro_file_destroy( f );
   }

}
END_TEST
*/

START_TEST ( test_i_bar )
{
   gssize n_x = 1000;
   double x_max = 40;
   double dy = x_max/n_x;
//   double dy = .1;
   double l  = .087;
   double** i_bar;
   double* x = eh_linspace( 0 , x_max , n_x );
   gssize n_y;

   i_bar = plume_i_bar( x , n_x , l , &n_y , dy);

   {
      gssize i, j;

      for ( i=0 ; i<n_x ; i++ )
      {
         for ( j=0 ; j<n_y ; j++ )
            fprintf( stderr , "%g, " , i_bar[i][j] );
         fprintf( stderr , "\n" );
      }
   }

   eh_free( x        );
   eh_free( i_bar[0] );
   eh_free( i_bar    );
}
예제 #24
0
Sed_process_info
run_xshore( Sed_process proc , Sed_cube prof )
{
   Xshore_t*        data = (Xshore_t*)sed_process_user_data(proc);
   Sed_process_info info = SED_EMPTY_INFO;
   double dt;
   double start_time, end_time, current_time;
   double xshore_current;
   double this_sea_level;
   double mass_before, mass_after, mass_added, mass_lost;
   Sed_cell *lost = NULL;
   Sed_cell along_shore_sediment;
   Sed_ocean_storm this_storm;
   GSList *this_link;
   Xshore_info x_info;

   if ( sed_process_run_count(proc)==0 )
      init_xshore_data( proc , prof , NULL );

   if ( sed_mode_is_3d() )
      return info;
   
   start_time      = data->last_time;
   end_time        = sed_cube_age_in_years( prof );
   dt              = end_time - start_time;
   data->last_time = sed_cube_age_in_years( prof );

   {
      double *along_shore_fraction = eh_new0( double , sed_sediment_env_n_types() );

      along_shore_fraction[data->sediment_type] = 1.;

      along_shore_sediment = sed_cell_new_env( );
      sed_cell_set_fraction( along_shore_sediment ,
                             along_shore_fraction );

      eh_free( along_shore_fraction );
   }

//   dt = sed_cube_time_step( prof );

   current_time = start_time;
   sed_cube_set_age( prof , start_time );

   for ( this_link=sed_cube_storm_list( prof ) ;
         this_link ;
         this_link=this_link->next )
   {
      double storm_wave;
      double max_current = eh_input_val_eval( data->xshore_current ,
                                              current_time );
      mass_before = sed_cube_mass( prof );

      this_storm = (Sed_ocean_storm)this_link->data;

      storm_wave = sed_ocean_storm_wave_height( this_storm );

      xshore_current = max_current*0.5*storm_wave;
      eh_clamp( xshore_current , 0 , max_current );

      this_sea_level = sed_cube_sea_level( prof );
      sed_cube_adjust_sea_level( prof , storm_wave*.5 );

//   if ( sed_cube_time_step_in_days( prof ) > 3. )
//      sed_cube_set_time_step( prof , 3./S_DAYS_PER_YEAR );

//   if ( sed_cube_wave_height( prof ) > .1 )
      if ( is_worth_running( this_storm ) )
      {
         x_info = xshore( prof                 ,
                          along_shore_sediment ,
                          xshore_current       ,
                          this_storm );
      }
      else
      {
         x_info.added = NULL;
         x_info.lost  = NULL;
         x_info.dt    = NULL;
      }

      sed_cube_set_sea_level( prof , this_sea_level );

      eh_message( "time                            : %f" , current_time );

      if ( TRUE )
      {
         if ( x_info.added )
         {
            mass_added = sed_cell_mass( x_info.added )
                       * sed_cube_x_res( prof )
                       * sed_cube_y_res( prof );
            mass_lost  = sed_cell_mass( x_info.lost )
                       * sed_cube_x_res( prof )
                       * sed_cube_y_res( prof );
//            sed_cell_resize( info.added , sed_cell_thickness(info.added)*2 );
//            sed_cell_add( sed_cube_to_remove(prof) , info.added );
         }
         else
         {
            mass_added       = 0;
            mass_lost        = 0;
            x_info.bruun_a   = 0;
            x_info.bruun_m   = 0;
            x_info.bruun_h_b = 0;
            x_info.bruun_y_0 = 0;
            x_info.bruun_y_b = 0;
            x_info.z_0       = 0;
         }

         info.mass_added = mass_added;
         info.mass_lost  = mass_lost;
         mass_after = sed_cube_mass( prof );

         eh_message( "time step (days)                : %f" , sed_ocean_storm_duration(this_storm) );
         eh_message( "cross shore current (m/s)       : %f" , xshore_current );
         eh_message( "incoming wave height (m)        : %f" , sed_ocean_storm_wave_height( this_storm ) );
         eh_message( "closure depth (m)               : %f" , x_info.z_0 );
         eh_message( "Bruun a (-)                     : %f" , x_info.bruun_a   );
         eh_message( "Bruun m (-)                     : %f" , x_info.bruun_m   );
         eh_message( "Bruun closure depth (m)         : %f" , x_info.bruun_h_b );
         eh_message( "Bruun start (m)                 : %f" , x_info.bruun_y_0 );
         eh_message( "Bruun end (m)                   : %f" , x_info.bruun_y_b );
//         eh_message( "along shore sediment added (kg) : %f" , sed_cell_mass( info.added ) );
//         eh_message( "sediment lost (kg)              : %f" , sed_cell_mass( info.lost  ) );
         eh_message( "mass before (kg)                : %f" , mass_before );
         eh_message( "mass after (kg)                 : %f" , mass_after  );
         eh_message( "mass added (kg)                 : %f" , mass_added  );

         eh_message( "mass balance (kg)               : %f" , (mass_after-mass_added)-mass_before );

         sed_cell_destroy( x_info.added );
         sed_cell_destroy( x_info.lost );
         eh_free( x_info.dt );
         lost = NULL;
      }
      else
      {
         eh_message( "time step (days)                : %f" , sed_ocean_storm_duration(this_storm) );
         eh_message( "cross shore current (m/s)       : %f" , xshore_current );
         eh_message( "incoming wave height (m)        : %f" , sed_ocean_storm_wave_height( this_storm ) );
         eh_message( "along shore sediment added (kg) : %f" , 0. );
         eh_message( "total sediment moved (kg)       : %f" , 0. );
      }

      current_time += sed_ocean_storm_duration(this_storm)*S_YEARS_PER_DAY;
      sed_cube_set_age( prof , current_time );

   }

//   sed_cube_set_time_step( prof , dt );
   sed_cube_set_age( prof , end_time );

   sed_cell_destroy( along_shore_sediment );

   return info;
}
예제 #25
0
Sed_wave sed_wave_destroy( Sed_wave w )
{
   if ( w )
      eh_free( w );
   return NULL;
}