Example #1
0
void test_trace_edge( const ecl_grid_type * grid) {
  const int k = 1;
  fault_block_layer_type * layer = fault_block_layer_alloc( grid , k );
  double_vector_type * x_list = double_vector_alloc( 0,0);
  double_vector_type * y_list = double_vector_alloc( 0,0);
  fault_block_type * block = fault_block_layer_safe_get_block( layer , 99);
  int_vector_type * cell_list = int_vector_alloc(0,0);
    
  test_assert_false( fault_block_trace_edge( block , x_list , y_list , cell_list));
  fault_block_add_cell( block , 0,0);
  test_assert_true( fault_block_trace_edge( block , x_list , y_list , cell_list));
  test_assert_int_equal( 4 , double_vector_size( x_list ));
  test_assert_int_equal( 4 , double_vector_size( y_list ));
  
  test_assert_double_equal( 0 , double_vector_iget( x_list , 0 ));
  test_assert_double_equal( 1 , double_vector_iget( x_list , 1 ));
  test_assert_double_equal( 1 , double_vector_iget( x_list , 2 ));
  test_assert_double_equal( 0 , double_vector_iget( x_list , 3 ));
  
  test_assert_double_equal( 0 , double_vector_iget( y_list , 0 ));
  test_assert_double_equal( 0 , double_vector_iget( y_list , 1 ));
  test_assert_double_equal( 1 , double_vector_iget( y_list , 2 ));
  test_assert_double_equal( 1 , double_vector_iget( y_list , 3 ));

  test_assert_int_equal( 1 , int_vector_size( cell_list ));
  test_assert_int_equal( 0 , int_vector_iget( cell_list , 0));

  int_vector_free( cell_list );
  double_vector_free( x_list );
  double_vector_free( y_list );
}
Example #2
0
static geo_polygon_type * geo_polygon_fload_alloc_xyz( const char * filename , bool irap_format) {
  bool stop_on_999 = irap_format;
  bool skip_last_point = irap_format;

  geo_polygon_type * polygon = geo_polygon_alloc( filename );
  {
    FILE * stream = util_fopen( filename , "r");
    double x , y , z;
    while (true) {
      if (fscanf(stream , "%lg %lg %lg" , &x, &y , &z) == 3) {
        if (stop_on_999 && (x == 999) && (y == 999) && (z == 999))
          break;

        geo_polygon_add_point( polygon , x , y );
      } else
        break;
    }

    fclose( stream );

    if ((double_vector_size( polygon->xcoord ) > 1) && (skip_last_point)) {
      if ((double_vector_get_last(polygon->xcoord) == double_vector_get_first(polygon->xcoord)) &&
          (double_vector_get_last(polygon->ycoord) == double_vector_get_first(polygon->ycoord))) {

        double_vector_pop( polygon->xcoord );
        double_vector_pop( polygon->ycoord );
      }
    }
  }
  return polygon;
}
Example #3
0
bool summary_has_data( const summary_type * summary , int report_step , state_enum state) {
  if (summary->vector_storage) {
    double_vector_type * storage_vector = SELECT_VECTOR( summary , state );
    return (double_vector_size( storage_vector ) > report_step) ? true : false;
  } else 
    return true; 
}
Example #4
0
static void text_fprintf2(plot_driver_type * driver , const char * label , const double_vector_type * d1 , const double_vector_type * d2) {
  FILE * stream = text_fopen( driver , label );

  for (int i=0; i < double_vector_size( d1 ); i++) 
    fprintf(stream , "%12.7f  %12.7f  \n",double_vector_iget(d1 , i) , double_vector_iget(d2 , i));
  
  fclose( stream );
}
Example #5
0
bool double_vector_approx_equal( const double_vector_type * v1 , const double_vector_type * v2 , double epsilon) {
  bool equal = true;
  if (double_vector_size( v1 ) == double_vector_size( v2 )) {
    int i;
    
    for (i=0; i < double_vector_size( v1 ); i++) {
      double d1 = double_vector_iget( v1 , i );
      double d2 = double_vector_iget( v2 , i );

      if (!util_double_approx_equal__(d1 , d2 , epsilon))
        equal = false;
    }
  } else
    equal = false;
  
  return equal;
}
Example #6
0
File: ecl_sum.c Project: flikka/ert
void ecl_sum_resample_from_sim_days( const ecl_sum_type * ecl_sum , const double_vector_type * sim_days , double_vector_type * value , const char * gen_key) {
  const smspec_node_type * node = ecl_smspec_get_general_var_node( ecl_sum->smspec , gen_key);
  double_vector_reset( value );
  {
    int i;
    for (i=0; i < double_vector_size( sim_days ); i++)
      double_vector_iset( value , i , ecl_sum_data_get_from_sim_days( ecl_sum->data , double_vector_iget( sim_days , i ) , node));
  }
}
Example #7
0
double statistics_mean( const double_vector_type * data_vector ) {
  const double * data = double_vector_get_const_ptr( data_vector );
  int size = double_vector_size( data_vector );
  double sum = 0;
  int i;
  for (i=0; i < size; i++)
    sum += data[i];

  return sum / size;
}
void test_range_fill_double() {
  double_vector_type * double_vector = double_vector_alloc(0,0);
  double_vector_range_fill( double_vector , 1,2,10 ); /* 1 , 3 , 5 , 7 , 9 */
  
  test_assert_double_equal( double_vector_size( double_vector ), 5);
  test_assert_double_equal( double_vector_iget( double_vector , 0 ) , 1 );
  test_assert_double_equal( double_vector_iget( double_vector , 1 ) , 3 );
  test_assert_double_equal( double_vector_iget( double_vector , 2 ) , 5 );
  test_assert_double_equal( double_vector_iget( double_vector , 3 ) , 7 );
  test_assert_double_equal( double_vector_iget( double_vector , 4 ) , 9 );
  
  double_vector_range_fill( double_vector , 3,3,9 ); /* 3,6,9 */
  test_assert_double_equal( double_vector_size( double_vector ), 3);
  test_assert_double_equal( double_vector_iget( double_vector , 0 ) , 3 );
  test_assert_double_equal( double_vector_iget( double_vector , 1 ) , 6 );
  test_assert_double_equal( double_vector_iget( double_vector , 2 ) , 9 );

  double_vector_free( double_vector );
}
Example #9
0
double geo_polygon_get_length( geo_polygon_type * polygon ) {
  if (double_vector_size( polygon->xcoord) == 1)
    return 0;
  else {
    double length = 0;
    double x0 = double_vector_iget( polygon->xcoord , 0 );
    double y0 = double_vector_iget( polygon->ycoord , 0 );
    int i;

    for (i = 1; i < double_vector_size( polygon->xcoord ); i++) {
      double x1 = double_vector_iget( polygon->xcoord , i );
      double y1 = double_vector_iget( polygon->ycoord , i );

      length += sqrt( (x1 - x0)*(x1 - x0) + (y1 - y0)*(y1 - y0));
      x0 = x1;
      y0 = y1;
    }
    return length;
  }
}
Example #10
0
double statistics_std( const double_vector_type * data_vector ) {
  const double * data = double_vector_get_const_ptr( data_vector );
  double std = 0;
  double mean = statistics_mean( data_vector );
  int size = double_vector_size( data_vector );
  int i;

  for (i=0; i < size; i++) {
    double d = (data[i] - mean);
    std += d*d;
  }
  
  return sqrt(std / size);
}
Example #11
0
void plplot_plot_hist( plot_driver_type * driver, const char * label , double_vector_type * x , line_attribute_type line_attr) {
  int size = double_vector_size( x );
  plplot_setup_linestyle( line_attr );
  {
    int    bins = (int) sqrt( size );
    double xmin = double_vector_get_min( x );
    double xmax = double_vector_get_max( x );
    {
      /*
        Could for some fuxxxing reason not get the plhist() function
          to work, and had to resort to the low level plbin function.
      */
      double * limits  = util_calloc(bins + 1 , sizeof * limits );
      double * x_      = util_calloc(bins     , sizeof * x_     ); 
      double * y_      = util_calloc(bins     , sizeof * y_     );
      int i;
      double delta = (xmax - xmin) / bins;
      
      for (i= 0; i <= bins; i++)
        limits[i] = xmin + i*delta;
      
      for (i=0; i < bins; i++) {
        y_[i] = 0;
        x_[i] = 0.50 * (limits[i] + limits[i + 1]);
      }
      
      
      for (i=0; i < size; i++) {
        double value = double_vector_iget(x , i);
        int j;
        for (j = 1; j <= bins; j++)
          if (value < limits[j]) {
            y_[j-1]++;
            break;
          }
      }
      
      /*
        for (i = 0; i < bins; i++)
        printf("x[%d] = %g    y[%d] = %g\n",i,x_[i],i,y_[i]);
      */
      
      plbin(bins , x_ , y_ , PL_BIN_CENTRED + PL_BIN_NOEXPAND);
      free(x_);
      free(y_);
      free(limits);
    }
    //plhist(size , double_vector_get_ptr(d->x) , xmin , xmax , bins , 0 /* PL_HIST_DEFAULT */);
  }
}
Example #12
0
File: ecl_sum.c Project: flikka/ert
time_t_vector_type * ecl_sum_alloc_time_solution( const ecl_sum_type * ecl_sum , const char * gen_key , double cmp_value , bool rates_clamp_lower) {
  time_t_vector_type * solution = time_t_vector_alloc( 0 , 0);
  {
    double_vector_type * seconds = ecl_sum_alloc_seconds_solution( ecl_sum , gen_key , cmp_value , rates_clamp_lower );
    time_t start_time = ecl_sum_get_start_time(ecl_sum);
    for (int i=0; i < double_vector_size( seconds ); i++) {
      time_t t = start_time;
      util_inplace_forward_seconds( &t , double_vector_iget( seconds , i ));
      time_t_vector_append( solution , t );
    }
    double_vector_free( seconds );
  }
  return solution;
}
Example #13
0
void plplot_plot_x1x2y(plot_driver_type * driver      , 
                       const char * label             , 
                       double_vector_type * x1  , 
                       double_vector_type * x2  , 
                       double_vector_type * y   , 
                       line_attribute_type line_attr) {
  
  int size = double_vector_size( x1 );
  
  plplot_logtransform_x( driver , x1 );
  plplot_logtransform_x( driver , x2 );
  plplot_logtransform_y( driver , y );

  plplot_setup_linestyle( line_attr );
  plerrx(size , double_vector_get_ptr(x1) , double_vector_get_ptr(x2) , double_vector_get_ptr(y));
}
Example #14
0
void plplot_plot_xy1y2(plot_driver_type * driver     , 
                       const char * label , 
                       double_vector_type * x  , 
                       double_vector_type * y1  , 
                       double_vector_type * y2  , 
                       line_attribute_type line_attr) {

  int size = double_vector_size( x );
  
  plplot_logtransform_x( driver , x );
  plplot_logtransform_x( driver , y1 );
  plplot_logtransform_x( driver , y2 );
  
  plplot_setup_linestyle( line_attr );
  plerry(size , double_vector_get_ptr(x) , double_vector_get_ptr(y1) , double_vector_get_ptr(y2));
}
Example #15
0
void misfit_ranking_display( const misfit_ranking_type * misfit_ranking , FILE * stream) {
  const int ens_size                  = double_vector_size( misfit_ranking->total );
  const int * permutations            = misfit_ranking->sort_permutation;
  hash_type * obs_hash = NULL;
  {
    // The ensemble vector can contain invalid nodes with NULL.
    int index = 0;
    while ((obs_hash == NULL) && (index < vector_get_size( misfit_ranking->ensemble))) {
      obs_hash = vector_iget( misfit_ranking->ensemble , index );
      index++;
    }
    if (obs_hash == NULL) {
      fprintf(stderr,"Sorry: no valid results loaded for this misfit_ranking - returning\n");
      return;
    }
  }
  
  {
    int i;
    double summed_up = 0.0;
    stringlist_type * obs_keys          = hash_alloc_stringlist( obs_hash );
    int num_obs                         = stringlist_get_size( obs_keys );
    int num_obs_total                   = num_obs * ens_size;  // SHould not count failed/missing members ...
    
    fprintf(stream,"\n\n");
    fprintf(stream,"  #    Realization    Normalized misfit    Total misfit\n");
    fprintf(stream,"-------------------------------------------------------\n");
    for (i = 0; i < ens_size; i++) {
      int    iens         = permutations[i];
      double total_misfit = double_vector_iget( misfit_ranking->total , iens );
      double normalized_misfit = sqrt(total_misfit / num_obs_total);
      summed_up = summed_up+total_misfit;
      fprintf(stream,"%3d    %3d                   %10.3f      %10.3f  \n",i,iens,normalized_misfit,total_misfit);
    }
    
    {
      double normalized_summed_up = sqrt(summed_up / (num_obs_total * ens_size));
      fprintf(stream,"        All                  %10.3f      %10.3f  \n",normalized_summed_up,summed_up);
    }
    fprintf(stream,"-------------------------------------------------------\n");
  }
  
}
Example #16
0
void plplot_plot_xy(plot_driver_type * driver     , 
                    const char * label , 
                    double_vector_type * x  , 
                    double_vector_type * y  , 
                    plot_style_type style         , 
                    line_attribute_type line_attr , 
                    point_attribute_type point_attr) {

  int size = double_vector_size( x );

  plplot_logtransform_x( driver , x );
  plplot_logtransform_y( driver , y );
  
  /* 
     Special case: 
     -------------
     If only one single point AND plot_style == LINE, we
     effectively change the plot_style to POINTS (and use the
     line_color) - otherwise the single point will not be visible.
  */
  
  if ((style == LINE) && (size == 1)) {
    style                  = POINTS;
    point_attr.point_color = line_attr.line_color;
  }
  
  if (style & LINE) {
    plplot_setup_linestyle( line_attr );
    plline(size , double_vector_get_ptr(x) , double_vector_get_ptr(y));
  }

  if (style & POINTS) {
    plplot_setup_pointstyle( point_attr );
    plpoin(size , double_vector_get_ptr(x) , double_vector_get_ptr(y) , point_attr.symbol_type);
  }
}
Example #17
0
void output_run_line( const output_type * output , ensemble_type * ensemble) {

  const int    data_columns = vector_get_size( output->keys );
  const int    data_rows    = time_t_vector_size( ensemble->interp_time );
  double     ** data;
  int row_nr, column_nr;

  data = util_calloc( data_rows , sizeof * data );
  /*
    time-direction, i.e. the row index is the first index and the
    column number (i.e. the different keys) is the second index.
  */
  for (row_nr=0; row_nr < data_rows; row_nr++)
    data[row_nr] = util_calloc( data_columns , sizeof * data[row_nr] );

  printf("Creating output file: %s \n",output->file );


  /*
     Go through all the cases and check that they have this key;
     exit if missing. Could also ignore the missing keys and just
     continue; and even defer the checking to the inner loop.
  */
  for (column_nr = 0; column_nr < vector_get_size( output->keys ); column_nr++) {
    const quant_key_type * qkey = vector_iget( output->keys , column_nr );
    {
      bool OK = true;

      for (int iens = 0; iens < vector_get_size( ensemble->data ); iens++) {
        const sum_case_type * sum_case = vector_iget_const( ensemble->data , iens );

        if (!ecl_sum_has_general_var(sum_case->ecl_sum , qkey->sum_key)) {
          OK = false;
          fprintf(stderr,"** Sorry: the case:%s does not have the summary key:%s \n", ecl_sum_get_case( sum_case->ecl_sum ), qkey->sum_key);
        }
      }

      if (!OK)
        util_exit("Exiting due to missing summary vector(s).\n");
    }
  }


  /* The main loop - outer loop is running over time. */
  {
    /**
       In the quite typical case that we are asking for several
       quantiles of the quantity, i.e.

       WWCT:OP_1:0.10  WWCT:OP_1:0.50  WWCT:OP_1:0.90

       the interp_data_cache construction will ensure that the
       underlying ecl_sum object is only queried once; and also the
       sorting will be performed once.
    */

    hash_type * interp_data_cache = hash_alloc();

    for (row_nr = 0; row_nr < data_rows; row_nr++) {
      time_t interp_time = time_t_vector_iget( ensemble->interp_time , row_nr);
      for (column_nr = 0; column_nr < vector_get_size( output->keys ); column_nr++) {
        const quant_key_type * qkey = vector_iget( output->keys , column_nr );
        double_vector_type * interp_data;

        /* Check if we have the vector in the cache table - if not create it. */
        if (!hash_has_key( interp_data_cache , qkey->sum_key)) {
          interp_data = double_vector_alloc(0 , 0);
          hash_insert_hash_owned_ref( interp_data_cache , qkey->sum_key , interp_data , double_vector_free__);
        }
        interp_data = hash_get( interp_data_cache , qkey->sum_key );

        /* Check if the vector has data - if not initialize it. */
        if (double_vector_size( interp_data ) == 0) {
          for (int iens = 0; iens < vector_get_size( ensemble->data ); iens++) {
            const sum_case_type * sum_case = vector_iget_const( ensemble->data , iens );

            if ((interp_time >= sum_case->start_time) && (interp_time <= sum_case->end_time))  /* We allow the different simulations to have differing length */
              double_vector_append( interp_data , ecl_sum_get_general_var_from_sim_time( sum_case->ecl_sum , interp_time , qkey->sum_key)) ;

            double_vector_sort( interp_data );
          }
        }
        data[row_nr][column_nr] = statistics_empirical_quantile__( interp_data , qkey->quantile );
      }
      hash_apply( interp_data_cache , double_vector_reset__ );
    }
    hash_free( interp_data_cache );
  }

  output_save( output , ensemble , (const double **) data);
  for (row_nr=0; row_nr < data_rows; row_nr++)
    free( data[row_nr] );
  free( data );
}
Example #18
0
int well_rate_get_length( const well_rate_type * well_rate ) {
  return double_vector_size( well_rate->base_value );
}
Example #19
0
bool geo_polygon_contains_point__( const geo_polygon_type * polygon , double x , double y, bool force_edge_inside) {
  return geo_util_inside_polygon__( double_vector_get_const_ptr( polygon->xcoord ) ,
                                    double_vector_get_const_ptr( polygon->ycoord ) ,
                                    double_vector_size( polygon->xcoord ) ,
                                    x , y , force_edge_inside);
}
Example #20
0
double statistics_empirical_quantile__( const double_vector_type * data , double quantile ) {
  if ((quantile < 0) || (quantile > 1.0))
    util_abort("%s: quantile must be in [0,1] \n",__func__);

  {
    const int size = (double_vector_size( data ) - 1);
    if (double_vector_iget( data , 0) == double_vector_iget( data , size))
      /* 
         All elements are equal - and it is impossible to find a meaingful quantile,
         we just return "the value".
      */
      return double_vector_iget( data, 0 );    
    else {
      double value;
      double lower_value;
      double upper_value;
      double real_index;
      double upper_quantile;
      double lower_quantile;
      
      int    lower_index;
      int    upper_index;
      
      
      real_index  = quantile * size;
      lower_index = floor( real_index );
      upper_index = ceil( real_index );
      
      upper_value    = double_vector_iget( data , upper_index );
      lower_value    = double_vector_iget( data , lower_index );

      /* 
         Will iterate in this loop until we have found upper_value !=
         lower_value. As long as we know that now all elements are
         equal (the first test), this is guaranteed to succeed, but of
         course the estimate will not be very meaningful if the sample
         consist of a significant number of equal values.
      */
      while (true) {

        /*1: Try to shift the upper index up. */
        if (upper_value == lower_value) {
          upper_index = util_int_min( size , upper_index + 1);
          upper_value = double_vector_iget( data , upper_index );
        } else 
          break;

        /*2: Try to shift the lower index down. */
        if (upper_value == lower_value) {
          lower_index = util_int_max( 0 , lower_index - 1);
          lower_value = double_vector_iget( data , lower_index );
        } else 
          break;
        
      }
      
      upper_quantile = upper_index * 1.0 / size;
      lower_quantile = lower_index * 1.0 / size;
      /* Linear interpolation: */
      {
        double a = (upper_value - lower_value) / (upper_quantile - lower_quantile);
        
        value = lower_value + a*(quantile - lower_quantile);
        return value;
      }
    }
  }
}
Example #21
0
void geo_polygon_fprintf(const geo_polygon_type * polygon , FILE * stream) {
  int i;
  for (i=0; i < double_vector_size( polygon->xcoord ); i++)
    fprintf(stream , "%10.3f  %10.3f \n", double_vector_iget( polygon->xcoord , i ) , double_vector_iget( polygon->ycoord , i));
}
Example #22
0
int geo_polygon_get_size(const geo_polygon_type * polygon ) {
  return double_vector_size( polygon->xcoord );
}
Example #23
0
void plot_range_update_vector_x( plot_range_type * range , const double_vector_type * x ) {
  int i;
  const double * x_data = double_vector_get_const_ptr( x );
  for (i=0; i < double_vector_size( x ); i++)
    plot_range_update_x( range , x_data[i] );
}
Example #24
0
void plot_range_update_vector_y( plot_range_type * range , const double_vector_type * y ) {
  int i;
  const double * y_data = double_vector_get_const_ptr( y );
  for (i=0; i < double_vector_size( y ); i++)
    plot_range_update_y( range , y_data[i] );
}
Example #25
0
bool geo_polygon_contains_point( const geo_polygon_type * polygon , double x , double y) {
  return geo_util_inside_polygon( double_vector_get_const_ptr( polygon->xcoord ) , 
                                  double_vector_get_const_ptr( polygon->ycoord ) ,
                                  double_vector_size( polygon->xcoord ) , 
                                  x , y );
}