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 );
}
void test_approx_equal() {
  double_vector_type * d1 = double_vector_alloc(0,0);
  double_vector_type * d2 = double_vector_alloc(0,0);
  double_vector_type * d3 = double_vector_alloc(0,0);

  double_vector_append( d1 , 1.0 );
  double_vector_append( d1 , 2.0 );
  double_vector_append( d1 , 3.0 );


  double_vector_append( d2 , 1.0 );
  double_vector_append( d2 , 2.0 );

  test_assert_false( double_vector_approx_equal( d1 , d2 ,1e-6));

  double_vector_append( d2 , 3.0 );
  test_assert_true( double_vector_approx_equal( d1 , d2 ,1e-6));
  
  double_vector_append( d3 , 1.0 );
  double_vector_append( d3 , 2.0 );
  double_vector_append( d3 , 3.0 );

  double_vector_scale( d3 , 1 + 1e-6 );
  test_assert_true( double_vector_approx_equal( d1 , d3 ,1e-4));
  test_assert_false( double_vector_approx_equal( d1 , d3 ,1e-8));


  double_vector_free(d1);
  double_vector_free(d2);
  double_vector_free(d3);
}
Example #3
0
geo_polygon_type * geo_polygon_alloc(const char * name) {
  geo_polygon_type * polygon = (geo_polygon_type*)util_malloc( sizeof * polygon );

  UTIL_TYPE_ID_INIT( polygon , GEO_POLYGON_TYPE_ID );
  polygon->xcoord = double_vector_alloc( 0 , 0 );
  polygon->ycoord = double_vector_alloc( 0 , 0 );
  polygon->name   = util_alloc_string_copy( name );
  return polygon;
}
Example #4
0
geo_polygon_type * geo_polygon_alloc() {
  geo_polygon_type * polygon = util_malloc( sizeof * polygon );
  
  UTIL_TYPE_ID_INIT( polygon , GEO_POLYGON_TYPE_ID );
  polygon->xcoord = double_vector_alloc( 0 , 0 );
  polygon->ycoord = double_vector_alloc( 0 , 0 );

  return polygon;
}
Example #5
0
summary_type * summary_alloc(const summary_config_type * summary_config) {
  summary_type * summary   = util_malloc(sizeof *summary );
  summary->__type_id       = SUMMARY;
  summary->vector_storage  = summary_config_get_vector_storage( summary_config );
  summary->config          = (summary_config_type *) summary_config;
  summary->forecast_vector = double_vector_alloc(0 , SUMMARY_UNDEF_FORECAST);  
  summary->analyzed_vector = double_vector_alloc(0 , SUMMARY_UNDEF_ANALYZED);  
  {
    const int data_size = summary_config_get_data_size( summary_config );
    summary->data       = util_calloc( data_size , sizeof * summary->data );
  }
  return summary;
}
Example #6
0
void test_content() {
  rng_type * rng = rng_alloc(MZRAN , INIT_DEFAULT);
  matrix_type * PC = matrix_alloc( 3 , 10);
  matrix_type * PC_obs = matrix_alloc( 3 , 1 );
  double_vector_type * singular_values = double_vector_alloc(3 , 1);
  matrix_random_init( PC , rng );
  matrix_random_init( PC_obs , rng );
  {
    pca_plot_data_type * data = pca_plot_data_alloc("KEY" , PC , PC_obs, singular_values);
    for (int i=0; i < matrix_get_rows( PC ); i++) {
      const pca_plot_vector_type * vector = pca_plot_data_iget_vector( data , i );
      
      test_assert_double_equal( matrix_iget( PC_obs , i , 0) , 
                                pca_plot_vector_get_obs_value( vector ) );

      test_assert_double_equal( double_vector_iget( singular_values , i),
                                pca_plot_vector_get_singular_value( vector ) );

      for (int j=0; j < matrix_get_columns( PC ); j++) 
        test_assert_double_equal( matrix_iget( PC , i , j ) , pca_plot_vector_iget_sim_value( vector , j ));
      
      test_assert_int_equal( matrix_get_columns( PC ) , pca_plot_vector_get_size( vector ));

    }
    pca_plot_data_free( data );
  }

  double_vector_free( singular_values );
  matrix_free( PC );
  matrix_free( PC_obs );
}
Example #7
0
int ecl_sum_data_get_report_step_from_days(const ecl_sum_data_type * data , double sim_days) {
  if ((sim_days < data->days_start) || (sim_days > data->sim_length))
    return -1;
  else {
    int report_step = -1;

    double_vector_type * days_map = double_vector_alloc( 0 , 0 );
    int_vector_type    * report_map = int_vector_alloc( 0 , 0 );
    int i;

    for (i=1; i < int_vector_size( data->report_last_index ); i++) {
      int ministep_index = int_vector_iget( data->report_last_index , i );
      const ecl_sum_tstep_type * ministep = vector_iget_const( data->data , ministep_index );
      
      double_vector_iset( days_map , i , ecl_sum_tstep_get_sim_days( ministep ));
      int_vector_iset( report_map , i , ecl_sum_tstep_get_report( ministep ));
    }
    
    {
      /** Hmmmm - double == comparison ... */
      int index = double_vector_index_sorted( days_map , sim_days );
      
      if (index >= 0)
        report_step = int_vector_iget( report_map , index );
    }
    
    int_vector_free( report_map );
    double_vector_free( days_map );
    return report_step;
  }
}
Example #8
0
void test_diag_std() {
  const int N = 25;
  double_vector_type * data = double_vector_alloc( 0,0);
  rng_type * rng = rng_alloc(MZRAN , INIT_DEV_URANDOM ); 
  matrix_type * m = matrix_alloc( N , N );
  double sum1 = 0;
  double sum2 = 0;
  int i;

  for (i=0; i < N; i++) {
    double R = rng_get_double( rng ); 
    matrix_iset(m , i , i , R);
    double_vector_iset( data , i , R );
    
    sum1 += R;
    sum2 += R*R;
  }
  {
    double mean = sum1 / N;
    double std = sqrt( sum2 / N - mean * mean );

    test_assert_double_equal( std , matrix_diag_std( m , mean ));
    test_assert_double_equal( statistics_std( data ) , matrix_diag_std( m , mean ));
    test_assert_double_equal( statistics_mean( data ) , mean );
  }
  matrix_free( m );
  rng_free( rng );
}
Example #9
0
static misfit_ranking_type * misfit_ranking_alloc_empty( int ens_size ) {
  misfit_ranking_type * misfit_ranking = util_malloc( sizeof * misfit_ranking );
  UTIL_TYPE_ID_INIT( misfit_ranking , MISFIT_RANKING_TYPE_ID );
  misfit_ranking->sort_permutation = NULL;
  misfit_ranking->ensemble = vector_alloc_new();
  misfit_ranking->total    = double_vector_alloc( 0 , INVALID_RANKING_VALUE );
  misfit_ranking->ens_size = ens_size;
  return misfit_ranking;
}
Example #10
0
data_ranking_type * data_ranking_alloc( bool sort_increasing , int ens_size , const char * user_key , const char * key_index , enkf_fs_type * fs , const enkf_config_node_type * config_node , int step , state_enum state) {
    data_ranking_type * ranking = util_malloc( sizeof * ranking );
    UTIL_TYPE_ID_INIT( ranking , DATA_RANKING_TYPE_ID );
    ranking->ens_size = ens_size;
    ranking->sort_increasing = sort_increasing;

    if (ranking->sort_increasing)
        ranking->data_ensemble = double_vector_alloc( ens_size ,  INFINITY);  // To ensure it comes last when sorting
    else
        ranking->data_ensemble = double_vector_alloc( ens_size , -INFINITY);  // To ensure it comes last when sorting

    ranking->valid = bool_vector_alloc( ens_size , false );
    ranking->sort_permutation = NULL;
    ranking->user_key = util_alloc_string_copy( user_key );

    data_ranking_init( ranking , fs , config_node , key_index , step , state );
    return ranking;
}
void test_insert_double() {
  double_vector_type * vec = double_vector_alloc(0,0);
  double_vector_append( vec , 1 );
  double_vector_insert( vec , 0 , 0 );
  
  test_assert_double_equal( 0 , double_vector_iget( vec , 0 ));
  test_assert_double_equal( 1 , double_vector_iget( vec , 1 ));
  
  double_vector_free( vec );
}
Example #12
0
sum_case_type * sum_case_fread_alloc( const char * data_file , const time_t_vector_type * interp_time ) {
  sum_case_type * sum_case = util_malloc( sizeof * sum_case );

  sum_case->ecl_sum     = ecl_sum_fread_alloc_case( data_file , SUMMARY_JOIN );
  sum_case->interp_data = double_vector_alloc(0 , 0);
  sum_case->interp_time = interp_time;
  sum_case->start_time  = ecl_sum_get_start_time( sum_case->ecl_sum );
  sum_case->end_time    = ecl_sum_get_end_time( sum_case->ecl_sum );
  return sum_case;
}
Example #13
0
misfit_ts_type * misfit_ts_alloc(int history_length) {
  misfit_ts_type * misfit_ts = util_malloc( sizeof * misfit_ts );
  UTIL_TYPE_ID_INIT(misfit_ts , MISFIT_TS_TYPE_ID);

  if (history_length > 0)
    misfit_ts->data = double_vector_alloc( history_length + 1 , 0 );
  else
    misfit_ts->data = NULL;  /* Used by the xxx_fread_alloc() function below. */

  return misfit_ts;
}
Example #14
0
pca_plot_data_type * create_data() {
  matrix_type * PC = matrix_alloc( 3 , 10);
  matrix_type * PC_obs = matrix_alloc( 3 , 1 );
  double_vector_type * singular_values = double_vector_alloc(3 , 1);

  pca_plot_data_type * data = pca_plot_data_alloc("KEY" , PC , PC_obs , singular_values);

  double_vector_free( singular_values );
  matrix_free( PC );
  matrix_free( PC_obs );
  return data;
}
Example #15
0
void test_update_vector() {
  plot_range_type * range = plot_range_alloc();
  double_vector_type * xl = double_vector_alloc(0,0);
  double_vector_type * yl = double_vector_alloc(0,0);
  const int N = 100;
  int i;

  for (i=0; i < N; i++) {
    double x = 2*3.14159265 * i / (N - 1);
    
    double_vector_append( xl , sin(x));
    double_vector_append( yl , cos(x));
  }
  plot_range_update_vector( range , xl , yl );

  test_assert_double_equal( plot_range_get_current_xmin( range ) , -1 );
  test_assert_double_equal( plot_range_get_current_xmax( range ) ,  1 );
  test_assert_double_equal( plot_range_get_current_ymin( range ) , -1 );
  test_assert_double_equal( plot_range_get_current_ymax( range ) ,  1 );
  
  for (i=0; i < N; i++) {
    double x = 2*3.14159265 * i / (N - 1);
    
    double_vector_append( xl , 2*sin(x));
    double_vector_append( yl , 2*cos(x));
  }
  plot_range_update_vector_x( range , xl );
  plot_range_update_vector_y( range , yl );

  test_assert_double_equal( plot_range_get_current_xmin( range ) , -2 );
  test_assert_double_equal( plot_range_get_current_xmax( range ) ,  2 );
  test_assert_double_equal( plot_range_get_current_ymin( range ) , -2 );
  test_assert_double_equal( plot_range_get_current_ymax( range ) ,  2 );

  plot_range_free( range );
  double_vector_free( xl );
  double_vector_free( yl );
}
Example #16
0
group_rate_type * group_rate_alloc(const sched_history_type * sched_history , const time_t_vector_type * time_vector , const char * name , const char * phase , const char * type_string , const char * filename) {
  group_rate_type * group_rate = util_malloc( sizeof * group_rate , __func__);
  UTIL_TYPE_ID_INIT( group_rate , GROUP_RATE_ID );
  group_rate->name             = util_alloc_string_copy( name );
  group_rate->time_vector      = time_vector;
  group_rate->shift            = double_vector_alloc(0,0);
  group_rate->base_rate        = double_vector_alloc(0,0);
  group_rate->min_shift        = double_vector_alloc(0 , 0);
  group_rate->max_shift        = double_vector_alloc(0 , 0);
  group_rate->min_shift_string = stringlist_alloc_new();
  group_rate->max_shift_string = stringlist_alloc_new();
  group_rate->phase            = sched_phase_type_from_string( phase );  
  group_rate->sched_history    = sched_history;
  {
    if (strcmp( type_string , "INJECTOR") == 0)
      group_rate->producer = false;
    else if ( strcmp( type_string , "PRODUCER") == 0)
      group_rate->producer = true;
  }
  
  fscanf_2ts( time_vector , filename , group_rate->min_shift_string , group_rate->max_shift_string );
  group_rate->well_rates   = vector_alloc_new();
  return group_rate;
}
Example #17
0
void test_create_vector() {
  matrix_type * PC = matrix_alloc( 3 , 10);
  matrix_type * PC_obs = matrix_alloc( 3 , 1 );
  double_vector_type * singular_values = double_vector_alloc(3 , 1);
  
  {
    pca_plot_vector_type * vector = pca_plot_vector_alloc(0 , PC , PC_obs, singular_values);
    test_assert_true( pca_plot_vector_is_instance( vector ));
    pca_plot_vector_free( vector );
  }

  double_vector_free( singular_values );
  matrix_free( PC );
  matrix_free( PC_obs );
}
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 #19
0
void test_create_data() {
  matrix_type * PC = matrix_alloc( 3 , 10);
  matrix_type * PC_obs = matrix_alloc( 3 , 1 );
  double_vector_type * singular_values = double_vector_alloc(3 , 1);
  {
    pca_plot_data_type * data = pca_plot_data_alloc("KEY" , PC , PC_obs , singular_values);
    test_assert_true( pca_plot_data_is_instance( data ));
    test_assert_int_equal( 3 , pca_plot_data_get_size( data ));
    test_assert_int_equal( 10 , pca_plot_data_get_ens_size( data ));
    test_assert_string_equal( "KEY" , pca_plot_data_get_name( data ));
    pca_plot_data_free( data );
  }
  matrix_resize( PC , 4 , 10 , false);
  test_assert_NULL( pca_plot_data_alloc( "KEY" , PC , PC_obs , singular_values));

  matrix_resize( PC_obs , 3 , 2 , false);
  test_assert_NULL( pca_plot_data_alloc( "KEY" , PC , PC_obs , singular_values));

  double_vector_free( singular_values );
  matrix_free( PC );
  matrix_free( PC_obs );
}
Example #20
0
bool obs_vector_load_from_HISTORY_OBSERVATION(obs_vector_type * obs_vector , 
                                              const conf_instance_type * conf_instance , 
                                              const history_type * history , 
                                              ensemble_config_type * ensemble_config, 
                                              double std_cutoff ) {

  if(!conf_instance_is_of_class(conf_instance, "HISTORY_OBSERVATION"))
    util_abort("%s: internal error. expected \"HISTORY_OBSERVATION\" instance, got \"%s\".\n",__func__, conf_instance_get_class_name_ref(conf_instance) );
  
  {
    bool initOK = false;
    int          size , restart_nr;
    double_vector_type * value              = double_vector_alloc(0,0);
    double_vector_type * std                = double_vector_alloc(0,0);
    bool_vector_type   * valid              = bool_vector_alloc(0 , false); 
    
    /* The auto_corrf parameters can not be "segmentized" */
    double auto_corrf_param                 = -1;
    const char * auto_corrf_name            = NULL;
    
    
    double         error      = conf_instance_get_item_value_double(conf_instance, "ERROR"     );
    double         error_min  = conf_instance_get_item_value_double(conf_instance, "ERROR_MIN" );
    const char *   error_mode = conf_instance_get_item_value_ref(   conf_instance, "ERROR_MODE");
    const char *   sum_key    = conf_instance_get_name_ref(         conf_instance              );
    
    if(conf_instance_has_item(conf_instance, "AUTO_CORRF")) {
      auto_corrf_name  = conf_instance_get_item_value_ref( conf_instance , "AUTO_CORRF");
      auto_corrf_param = conf_instance_get_item_value_double(conf_instance, "AUTO_CORRF_PARAM");
      if(conf_instance_has_item(conf_instance, "AUTO_CORRF_PARAM")) 
        auto_corrf_param = conf_instance_get_item_value_double(conf_instance, "AUTO_CORRF_PARAM");
      else
        util_abort("%s: When specifying AUTO_CORRF you must also give a vlaue for AUTO_CORRF_PARAM",__func__);
    }
    
    
    // Get time series data from history object and allocate
    size = history_get_last_restart(history);
    if (history_init_ts( history , sum_key , value , valid )) {

      // Create  the standard deviation vector
      if(strcmp(error_mode, "ABS") == 0) {
        for( restart_nr = 0; restart_nr < size; restart_nr++)
          double_vector_iset( std , restart_nr , error );
      } else if(strcmp(error_mode, "REL") == 0) {
        for( restart_nr = 0; restart_nr < size; restart_nr++)
          double_vector_iset( std , restart_nr , error * abs( double_vector_iget( value , restart_nr )));
      } else if(strcmp(error_mode, "RELMIN") == 0) {
        for(restart_nr = 0; restart_nr < size; restart_nr++) {
          double tmp_std = util_double_max( error_min , error * abs( double_vector_iget( value , restart_nr )));
          double_vector_iset( std , restart_nr , tmp_std);
        }
      } else
        util_abort("%s: Internal error. Unknown error mode \"%s\"\n", __func__, error_mode);
      
      
      // Handle SEGMENTs which can be used to customize the observation error. */
      {
        stringlist_type * segment_keys = conf_instance_alloc_list_of_sub_instances_of_class_by_name(conf_instance, "SEGMENT");
        stringlist_sort( segment_keys , NULL );
        
        int num_segments = stringlist_get_size(segment_keys);
        
        for(int segment_nr = 0; segment_nr < num_segments; segment_nr++)
          {
            const char * segment_name = stringlist_iget(segment_keys, segment_nr);
            const conf_instance_type * segment_conf = conf_instance_get_sub_instance_ref(conf_instance, segment_name);
            
            int start                         = conf_instance_get_item_value_int(   segment_conf, "START"     );
            int stop                          = conf_instance_get_item_value_int(   segment_conf, "STOP"      );
            double         error_segment      = conf_instance_get_item_value_double(segment_conf, "ERROR"     );
            double         error_min_segment  = conf_instance_get_item_value_double(segment_conf, "ERROR_MIN" );
            const char *   error_mode_segment = conf_instance_get_item_value_ref(   segment_conf, "ERROR_MODE");
            
            if(start < 0)
              {
                printf("%s: WARNING - Segment out of bounds. Truncating start of segment to 0.\n", __func__);
                start = 0;
              }
            
            if(stop >= size)
              {
                printf("%s: WARNING - Segment out of bounds. Truncating end of segment to %d.\n", __func__, size - 1);
                stop = size -1;
              }
            
            if(start > stop)
              {
                printf("%s: WARNING - Segment start after stop. Truncating end of segment to %d.\n", __func__, start );
                stop = start;
              }
            
            // Create  the standard deviation vector
            if(strcmp(error_mode_segment, "ABS") == 0) {
              for( restart_nr = start; restart_nr <= stop; restart_nr++)
                double_vector_iset( std , restart_nr , error_segment) ;
            } else if(strcmp(error_mode_segment, "REL") == 0) {
              for( restart_nr = start; restart_nr <= stop; restart_nr++)
                double_vector_iset( std , restart_nr , error_segment * abs(double_vector_iget( value , restart_nr)));
            } else if(strcmp(error_mode_segment, "RELMIN") == 0) {
              for(restart_nr = start; restart_nr <= stop ; restart_nr++) {
                double tmp_std = util_double_max( error_min_segment , error_segment * abs( double_vector_iget( value , restart_nr )));
                double_vector_iset( std , restart_nr , tmp_std);
              }
            } else
              util_abort("%s: Internal error. Unknown error mode \"%s\"\n", __func__, error_mode);
          }
        stringlist_free(segment_keys);
      }
      
      
      /*
        This is where the summary observations are finally added.
      */
      for (restart_nr = 0; restart_nr < size; restart_nr++) {
        if (bool_vector_safe_iget( valid , restart_nr)) {
          if (double_vector_iget( std , restart_nr) > std_cutoff) {
            obs_vector_add_summary_obs( obs_vector , restart_nr , sum_key , sum_key , 
                                        double_vector_iget( value ,restart_nr) , double_vector_iget( std , restart_nr ) , 
                                        auto_corrf_name , auto_corrf_param);
          } else 
            fprintf(stderr,"** Warning: to small observation error in observation %s:%d - ignored. \n", sum_key , restart_nr);
        }
      } 
      initOK = true;
    }
    double_vector_free(std);
    double_vector_free(value);
    bool_vector_free(valid);
    return initOK;
  }
}
Example #21
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 #22
0
well_rate_type * well_rate_alloc(const sched_history_type * sched_history , const time_t_vector_type * time_vector , const char * name , double corr_length , const char * filename, sched_phase_enum phase, bool producer) {
  well_rate_type * well_rate = util_malloc( sizeof * well_rate , __func__);
  UTIL_TYPE_ID_INIT( well_rate , WELL_RATE_ID );
  well_rate->name         = util_alloc_string_copy( name );
  well_rate->time_vector  = time_vector;
  well_rate->corr_length  = corr_length;
  well_rate->shift        = double_vector_alloc(0,0);
  well_rate->mean_shift   = double_vector_alloc(0 , 0);
  well_rate->std_shift    = double_vector_alloc(0 , 0);
  well_rate->mean_shift_string   = stringlist_alloc_new();
  well_rate->std_shift_string    = stringlist_alloc_new();
  well_rate->base_value   = double_vector_alloc(0 , 0);
  well_rate->rate         = double_vector_alloc(0 , 0);
  well_rate->phase        = phase;
  well_rate->sched_history= sched_history; 
  well_rate->percent_std  = bool_vector_alloc( 0 , false );
  well_rate->producer     = producer;
  fscanf_2ts( time_vector , filename , well_rate->mean_shift_string , well_rate->std_shift_string);
  
  {
    char * key;
    if (well_rate->producer) {
      switch(well_rate->phase) {
      case (WATER):
        key = util_alloc_sprintf("WWPRH%s%s" , sched_history_get_join_string( sched_history ) , well_rate->name );
        break;
      case( GAS ):
        key = util_alloc_sprintf("WGPRH%s%s" , sched_history_get_join_string( sched_history ) , well_rate->name );
        break;
      case( OIL ):
        key = util_alloc_sprintf("WOPRH%s%s" , sched_history_get_join_string( sched_history ) , well_rate->name );
        break;
      default:
        key = NULL;
        util_abort("%s: unknown phase identitifier: %d \n",__func__ , well_rate->phase);
      }
    } else {
      switch(well_rate->phase) {
      case (WATER):
        key = util_alloc_sprintf("WWIRH%s%s" , sched_history_get_join_string( sched_history ) , well_rate->name );
        break;
      case( GAS ):
        key = util_alloc_sprintf("WGIRH%s%s" , sched_history_get_join_string( sched_history ) , well_rate->name );
        break;
      case( OIL ):
        key = util_alloc_sprintf("WOIRH%s%s" , sched_history_get_join_string( sched_history ) , well_rate->name );
        break;
      default:
        util_abort("%s: unknown phase identitifier: %d \n",__func__ , well_rate->phase);
        key = NULL;
      }
    }
    
    if (sched_history_has_key( sched_history , key)) {
      sched_history_init_vector( sched_history , key , well_rate->base_value );
      well_rate_eval_stat( well_rate );
    } else 
      fprintf(stderr,"** Warning - schedule history does not have key:%s - suspicious?\n", key );
    
    free( key );
  }
  return well_rate;
}
Example #23
0
double_vector_type * ecl_sum_data_alloc_data_vector( const ecl_sum_data_type * data , int data_index , bool report_only) {
  double_vector_type * data_vector = double_vector_alloc(0,0);
  ecl_sum_data_init_data_vector( data , data_vector , data_index , report_only);
  return data_vector;
}
Example #24
0
void ecl_grav_new_std_density( ecl_grav_type * grav , ecl_phase_enum phase , double default_density) {
  const char * phase_key = ecl_util_get_phase_name( phase );
  if (!hash_has_key( grav->std_density , phase_key ))
    hash_insert_hash_owned_ref( grav->std_density , phase_key , double_vector_alloc( 0 , default_density ) , double_vector_free__ );
}