예제 #1
0
void test_measure( ert_test_context_type * test_context ) {
  enkf_main_type * enkf_main = ert_test_context_get_main( test_context );
  enkf_fs_type * fs = enkf_main_get_fs( enkf_main );
  enkf_obs_type * enkf_obs = enkf_main_get_obs( enkf_main );
  obs_vector_type * rft_obs = enkf_obs_get_vector( enkf_obs , "RFT_TEST");
  int_vector_type * ens_active_list = int_vector_alloc(0,0);
  active_list_type * active_list = active_list_alloc( );
  meas_data_type * meas_data_RFT;

  for (int i=0; i < enkf_main_get_ensemble_size( enkf_main ); i++)
    int_vector_append( ens_active_list , i );

  {
    bool_vector_type * ens_mask;
    ens_mask = int_vector_alloc_mask( ens_active_list );
    meas_data_RFT = meas_data_alloc( ens_mask );
    bool_vector_free( ens_mask );
  }

  obs_vector_measure( rft_obs , fs , 20 , ens_active_list , meas_data_RFT , active_list );

  int_vector_free( ens_active_list );
  active_list_free( active_list );
  meas_data_free( meas_data_RFT );
}
예제 #2
0
void * enkf_main_std_scale_correlated_obs_JOB(void * self, const stringlist_type * args)  {

  if (stringlist_get_size(args) > 0) {
    enkf_main_type * enkf_main              = enkf_main_safe_cast( self );
    int ensemble_size                       = enkf_main_get_ensemble_size(enkf_main);
    enkf_fs_type * fs                       = enkf_main_get_fs( enkf_main );
    enkf_obs_type * obs                     = enkf_main_get_obs( enkf_main );
    int_vector_type * realizations          = int_vector_alloc(1, 0);
    local_obsdata_type * obsdata = local_obsdata_alloc( "OBS-JOB" );

    int_vector_init_range(realizations, 0, ensemble_size, 1);

    for (int iarg = 0; iarg < stringlist_get_size(args); iarg++) {
      const char * arg_key = stringlist_iget( args , iarg );
      stringlist_type * key_list = enkf_obs_alloc_matching_keylist(obs, arg_key);
      for (int iobs=0; iobs < stringlist_get_size( key_list ); iobs++) {
        const char * obs_key = stringlist_iget( key_list , iobs);
        const obs_vector_type * obs_vector = enkf_obs_get_vector(obs, obs_key);
        local_obsdata_add_node( obsdata , obs_vector_alloc_local_node(obs_vector) );
      }
      stringlist_free( key_list );
    }

    if (local_obsdata_get_size(obsdata) > 0)
      enkf_obs_scale_correlated_std(obs, fs, realizations, obsdata );

    local_obsdata_free( obsdata );
  }

  return NULL;
}
예제 #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;
}
예제 #4
0
void test_invalid_obs_vector( enkf_main_type * enkf_main , const char * obs_key) {
  enkf_fs_type * fs = enkf_main_get_fs(enkf_main);
  enkf_obs_type * enkf_obs = enkf_main_get_obs( enkf_main );
  obs_vector_type * obs_vector = enkf_obs_get_vector( enkf_obs , obs_key );
  bool_vector_type * active_mask = bool_vector_alloc( enkf_main_get_ensemble_size( enkf_main ) , true);

  test_assert_false( obs_vector_has_data( obs_vector , active_mask , fs ));
  bool_vector_free( active_mask );
}
예제 #5
0
파일: misfit_ensemble.c 프로젝트: jokva/ert
void misfit_ensemble_initialize( misfit_ensemble_type * misfit_ensemble ,
                                 const ensemble_config_type * ensemble_config ,
                                 const enkf_obs_type * enkf_obs ,
                                 enkf_fs_type * fs ,
                                 int ens_size ,
                                 int history_length,
                                 bool force_init) {

    if (force_init || !misfit_ensemble->initialized) {
        misfit_ensemble_clear( misfit_ensemble );

        msg_type * msg                 = msg_alloc("Evaluating misfit for observation: " , false);
        double ** chi2_work            = __2d_malloc( history_length + 1 , ens_size );
        bool_vector_type * iens_valid  = bool_vector_alloc( ens_size , true );

        hash_iter_type * obs_iter = enkf_obs_alloc_iter( enkf_obs );
        const char * obs_key      = hash_iter_get_next_key( obs_iter );

        misfit_ensemble->history_length = history_length;
        misfit_ensemble_set_ens_size( misfit_ensemble , ens_size );

        msg_show( msg );
        while (obs_key != NULL) {
            obs_vector_type * obs_vector = enkf_obs_get_vector( enkf_obs , obs_key );
            msg_update( msg , obs_key );

            bool_vector_reset( iens_valid );
            bool_vector_iset( iens_valid , ens_size - 1 , true );
            obs_vector_ensemble_chi2( obs_vector ,
                                      fs ,
                                      iens_valid ,
                                      0 ,
                                      misfit_ensemble->history_length,
                                      0 ,
                                      ens_size ,
                                      chi2_work);

            /**
                Internalizing the results from the chi2_work table into the misfit structure.
            */
            for (int iens = 0; iens < ens_size; iens++) {
                misfit_member_type * node = misfit_ensemble_iget_member( misfit_ensemble , iens );
                if (bool_vector_iget( iens_valid , iens))
                    misfit_member_update( node , obs_key , misfit_ensemble->history_length , iens , (const double **) chi2_work);
            }
            obs_key = hash_iter_get_next_key( obs_iter );
        }

        bool_vector_free( iens_valid );
        msg_free(msg , true );
        hash_iter_free( obs_iter );

        __2d_free( chi2_work , misfit_ensemble->history_length + 1);
        misfit_ensemble->initialized = true;
    }
}
예제 #6
0
void test_container( ert_test_context_type * test_context ) {
  enkf_main_type * enkf_main = ert_test_context_get_main( test_context );
  enkf_obs_type * enkf_obs = enkf_main_get_obs( enkf_main );
  obs_vector_type * rft_obs = enkf_obs_get_vector( enkf_obs , "RFT_TEST");
  enkf_fs_type * fs = enkf_main_get_fs( enkf_main );
  bool_vector_type * active_mask = bool_vector_alloc( enkf_main_get_ensemble_size( enkf_main ) , true );

  test_assert_true( obs_vector_has_data( rft_obs , active_mask , fs ));
  bool_vector_free( active_mask );
}
예제 #7
0
파일: enkf_obs_fs.c 프로젝트: akva2/ert
void test_iget(ert_test_context_type * test_context) {
  enkf_main_type * enkf_main = ert_test_context_get_main( test_context );
  enkf_obs_type * enkf_obs = enkf_main_get_obs( enkf_main );

  test_assert_int_equal( 32 , enkf_obs_get_size( enkf_obs ) );
  for (int iobs = 0; iobs < enkf_obs_get_size( enkf_obs ); iobs++) {
    obs_vector_type * vec1 = enkf_obs_iget_vector( enkf_obs , iobs );
    obs_vector_type * vec2 = enkf_obs_get_vector( enkf_obs , obs_vector_get_key( vec1 ));

    test_assert_ptr_equal( vec1 , vec2 );
  }
}
예제 #8
0
void test_gendata( enkf_main_type * enkf_main , const char * obs_key , int report_step ) {
    enkf_obs_type * enkf_obs = enkf_main_get_obs( enkf_main );

    obs_vector_type * obs_vector = enkf_obs_get_vector( enkf_obs , obs_key);

    {
        enkf_plot_gendata_type * gen_data = enkf_plot_gendata_alloc_from_obs_vector( obs_vector );

        enkf_fs_type * fs = enkf_main_get_fs( enkf_main );
        gen_obs_type * gen_obs = obs_vector_iget_node( obs_vector , report_step );

        {

            double  value;
            double  std;
            bool valid;
            gen_obs_user_get_with_data_index(gen_obs , "0" , &value , &std , &valid );
            test_assert_double_equal( 0.143841 , value );
            test_assert_double_equal( 0.0300 ,  std );
            test_assert_true( valid );

        }

        enkf_plot_gendata_load(gen_data, fs, report_step, FORECAST, NULL);

        test_assert_int_equal( enkf_main_get_ensemble_size( enkf_main ) , enkf_plot_gendata_get_size( gen_data ));

        {
            enkf_plot_genvector_type * vector = enkf_plot_gendata_iget( gen_data , 24);
            test_assert_true( enkf_plot_genvector_is_instance( vector ));
            test_assert_double_equal(  0.675537 , enkf_plot_genvector_iget( vector , 0 ));
            test_assert_double_equal( 0.682635 , enkf_plot_genvector_iget( vector , 1 ));
            test_assert_double_equal( 0.616371 , enkf_plot_genvector_iget( vector , 2 ));


        }

        {
            enkf_plot_genvector_type * vector = enkf_plot_gendata_iget( gen_data , 9 );
            test_assert_true( enkf_plot_genvector_is_instance( vector ));
            test_assert_double_equal( -0.515033 , enkf_plot_genvector_iget( vector , 0 ));
            test_assert_double_equal( -0.507350 , enkf_plot_genvector_iget( vector , 1 ));
            test_assert_double_equal( -0.541030 , enkf_plot_genvector_iget( vector , 2 ));
        }


        enkf_plot_gendata_free( gen_data );
    }


}