Exemplo n.º 1
0
void test_correct_time_vector() {

  ecl_sum_type * ecl_sum = test_alloc_ecl_sum();
  time_t_vector_type * t = time_t_vector_alloc( 0 , 0 );
  time_t_vector_append(t, util_make_date_utc( 2,1,2010 ));
  time_t_vector_append(t, util_make_date_utc( 4,1,2010 ));
  time_t_vector_append(t, util_make_date_utc( 6,1,2010 ));
  time_t_vector_append(t, util_make_date_utc( 8,1,2010 ));
  ecl_sum_type * ecl_sum_resampled = ecl_sum_alloc_resample(ecl_sum, "kk", t);
  test_assert_int_equal(  ecl_sum_get_report_time(ecl_sum_resampled, 2)  , util_make_date_utc( 6,1,2010 ));

  const ecl_smspec_type * smspec_resampled = ecl_sum_get_smspec(ecl_sum_resampled);
  const smspec_node_type * node1 = ecl_smspec_iget_node(smspec_resampled, 1);
  const smspec_node_type * node2 = ecl_smspec_iget_node(smspec_resampled, 2);
  const smspec_node_type * node3 = ecl_smspec_iget_node(smspec_resampled, 3);
  test_assert_string_equal( "BPR" , smspec_node_get_keyword(node2) );
  test_assert_string_equal( "BARS" , smspec_node_get_unit(node2) );

  test_assert_double_equal(3.33333, ecl_sum_get_from_sim_time( ecl_sum_resampled, util_make_date_utc( 6,1,2010 ), node1) );
  test_assert_double_equal(3.33333, ecl_sum_get_from_sim_time( ecl_sum_resampled, util_make_date_utc( 2,1,2010 ), node2) );
  test_assert_double_equal(10.0000, ecl_sum_get_from_sim_time( ecl_sum_resampled, util_make_date_utc( 4,1,2010 ), node3) );


  ecl_sum_free(ecl_sum_resampled);
  time_t_vector_free(t);
  ecl_sum_free(ecl_sum);
}
Exemplo n.º 2
0
int ecl_sum_data_get_report_step_from_time(const ecl_sum_data_type * data , time_t sim_time) {
  if ((sim_time < data->data_start_time) || (sim_time > data->sim_end))
    return -1;

  {
    int report_step = -1;

    time_t_vector_type * time_map = time_t_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 );
      
      time_t_vector_iset( time_map , i , ecl_sum_tstep_get_sim_time( ministep ));
      int_vector_iset( report_map , i , ecl_sum_tstep_get_report( ministep ));
      
    }
    
    {
      int index = time_t_vector_index_sorted( time_map , sim_time );
      
      if (index >= 0)
        report_step = int_vector_iget( report_map , index );
    }
    
    int_vector_free( report_map );
    time_t_vector_free( time_map );
    return report_step;
  }
}
Exemplo n.º 3
0
int enkf_config_node_load_obs( const enkf_config_node_type * config_node , enkf_obs_type * enkf_obs ,const char * key_index , int obs_count , time_t * _sim_time , double * _y , double * _std) {
  ert_impl_type impl_type = enkf_config_node_get_impl_type(config_node);
  int num_obs = 0;
  int iobs;

  for (iobs = 0; iobs < stringlist_get_size( config_node->obs_keys ); iobs++) {
    obs_vector_type * obs_vector = enkf_obs_get_vector( enkf_obs , stringlist_iget( config_node->obs_keys , iobs));
    
    int report_step = -1;
    while (true) {
      report_step = obs_vector_get_next_active_step( obs_vector , report_step);
      if (report_step == -1) break;
      {
        bool valid;
        double value , std1;

        /**
           The user index used when calling the user_get function on the
           gen_obs data type is different depending on whether is called with a
           data context user_key (as here) or with a observation context
           user_key (as when plotting an observation plot). See more
           documentation of the function gen_obs_user_get_data_index(). 
        */

        if (impl_type == GEN_DATA)
          gen_obs_user_get_with_data_index( obs_vector_iget_node( obs_vector , report_step ) , key_index , &value , &std1 , &valid);
        else
          obs_vector_user_get( obs_vector , key_index , report_step , &value , &std1 , &valid);
        
        if (valid) {
          if (obs_count > 0) {
            _sim_time[num_obs] = enkf_obs_iget_obs_time( enkf_obs , report_step );
            _y[num_obs]        = value;
            _std[num_obs]      = std1;
          }
          num_obs++;
        }
      }
    }
  }

  /* Sorting the observations in time order. */
  if (obs_count > 0) {
    double_vector_type * y        = double_vector_alloc_shared_wrapper( 0 , 0 , _y        , obs_count );
    double_vector_type * std      = double_vector_alloc_shared_wrapper( 0 , 0 , _std      , obs_count );
    time_t_vector_type * sim_time = time_t_vector_alloc_shared_wrapper( 0 , 0 , _sim_time , obs_count );
    int * sort_perm               = time_t_vector_alloc_sort_perm( sim_time );
    
    time_t_vector_permute( sim_time , sort_perm );
    double_vector_permute( y        , sort_perm );
    double_vector_permute( std      , sort_perm );
    
    free( sort_perm );
    double_vector_free( y );
    double_vector_free( std );
    time_t_vector_free( sim_time );
  }
  return num_obs;
}
Exemplo n.º 4
0
void test_time_before() {
  ecl_sum_type * ecl_sum = test_alloc_ecl_sum();
  time_t_vector_type * t = time_t_vector_alloc( 0 , 0 );
  time_t_vector_append(t, util_make_date_utc( 1,1,2009 ));
  test_assert_NULL( ecl_sum_alloc_resample(ecl_sum, "kk", t) );
  time_t_vector_free(t);
  ecl_sum_free(ecl_sum);
}
Exemplo n.º 5
0
void sched_history_free( sched_history_type * sched_history ) {
  time_t_vector_free( sched_history->time );
  bool_vector_free( sched_history->historical );
  hash_free( sched_history->well_history );
  hash_free( sched_history->group_history );
  hash_free( sched_history->index );
  free( sched_history->sep_string );
  free( sched_history );
}
Exemplo n.º 6
0
static void sched_history_realloc( sched_history_type * sched_history ) {
  if (sched_history->well_history != NULL)
    hash_free( sched_history->well_history );
  sched_history->well_history = hash_alloc();
  
  if (sched_history->group_history != NULL)
    hash_free( sched_history->group_history );
  sched_history->group_history = hash_alloc();
  
  if (sched_history->historical != NULL)
    bool_vector_free( sched_history->historical );
  sched_history->historical = bool_vector_alloc( 0 , true );

  if (sched_history->time != NULL)
    time_t_vector_free(sched_history->time);
  sched_history->time         = time_t_vector_alloc( 0 , 0 ); 
  sched_history->last_history_step = 0;
}
Exemplo n.º 7
0
void ensemble_free( ensemble_type * ensemble ) {
  vector_free( ensemble->data );
  time_t_vector_free( ensemble->interp_time );
  free( ensemble );
}