示例#1
0
obs_vector_type * obs_vector_alloc_from_GENERAL_OBSERVATION(const conf_instance_type * conf_instance , const history_type * history, const ensemble_config_type * ensemble_config) {
  if(!conf_instance_is_of_class(conf_instance, "GENERAL_OBSERVATION"))
    util_abort("%s: internal error. expected \"GENERAL_OBSERVATION\" instance, got \"%s\".\n",
               __func__, conf_instance_get_class_name_ref(conf_instance) );
  const char * obs_key         = conf_instance_get_name_ref(conf_instance);
  const char * state_kw        = conf_instance_get_item_value_ref(   conf_instance, "DATA" );              
  if (ensemble_config_has_key( ensemble_config , state_kw )) {
    const char * obs_key         = conf_instance_get_name_ref(conf_instance);
    int          size            = history_get_last_restart( history );
    obs_vector_type * obs_vector = obs_vector_alloc( GEN_OBS , obs_key , ensemble_config_get_node(ensemble_config , state_kw ), size);
    int          obs_restart_nr   = __conf_instance_get_restart_nr(conf_instance , obs_key , history , size);
    const char * index_file       = NULL;
    const char * index_list       = NULL;
    const char * obs_file         = NULL;
    const char * error_covar_file = NULL; 

    if (conf_instance_has_item(conf_instance , "INDEX_FILE"))
      index_file = conf_instance_get_item_value_ref(   conf_instance, "INDEX_FILE" );              

    if (conf_instance_has_item(conf_instance , "INDEX_LIST"))
      index_list = conf_instance_get_item_value_ref(   conf_instance, "INDEX_LIST" );              

    if (conf_instance_has_item(conf_instance , "OBS_FILE"))
      obs_file = conf_instance_get_item_value_ref(   conf_instance, "OBS_FILE" );              
    
    if (conf_instance_has_item(conf_instance , "ERROR_COVAR"))
      error_covar_file = conf_instance_get_item_value_ref(   conf_instance, "ERROR_COVAR" );              
    
    {
      const enkf_config_node_type * config_node  = ensemble_config_get_node( ensemble_config , state_kw);
      if (enkf_config_node_get_impl_type(config_node) == GEN_DATA) {
        double scalar_error = -1;
        double scalar_value = -1;
        gen_obs_type * gen_obs ;

        if (conf_instance_has_item(conf_instance , "VALUE")) {
          scalar_value = conf_instance_get_item_value_double(conf_instance , "VALUE");
          scalar_error = conf_instance_get_item_value_double(conf_instance , "ERROR");
        }

        /** The config system has ensured that we have either OBS_FILE or (VALUE and ERROR). */
        gen_obs = gen_obs_alloc( enkf_config_node_get_ref( config_node ) , obs_key , obs_file , scalar_value , scalar_error , index_file , index_list , error_covar_file); 
        obs_vector_install_node( obs_vector , obs_restart_nr , gen_obs );
      } else {
        ert_impl_type impl_type = enkf_config_node_get_impl_type(config_node);
        util_abort("%s: %s has implementation type:\'%s\' - expected:\'%s\'.\n",__func__ , state_kw , enkf_types_get_impl_name(impl_type) , enkf_types_get_impl_name(GEN_DATA));
      }
    }
    return obs_vector;
  } else {
    fprintf(stderr,"** Warning the ensemble key:%s does not exist - observation:%s not added \n", state_kw , obs_key);
    return NULL;
  }
}
示例#2
0
const enkf_config_node_type * enkf_tui_util_scanf_key(const ensemble_config_type * config , int prompt_len , ert_impl_type impl_type ,  enkf_var_type var_type) {
  char * kw;
  bool OK;
  const enkf_config_node_type * config_node = NULL;
  do {
    OK = true;
    util_printf_prompt("Keyword" , prompt_len , '=' , "=> ");
    kw = util_alloc_stdin_line();
    if(kw==NULL){
      OK = true;
  }
    else if (ensemble_config_has_key(config , kw)) {
      config_node = ensemble_config_get_node(config , kw);
      
      if (impl_type != INVALID) 
        if (enkf_config_node_get_impl_type(config_node) != impl_type) 
          OK = false;
      
      if (var_type != INVALID_VAR)
        if (enkf_config_node_get_var_type(config_node) != var_type) 
          OK = false;
    } else OK = false;
    free(kw);
  } while (!OK);
  return config_node;
}
示例#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
ert_impl_type ensemble_config_impl_type(const ensemble_config_type *ensemble_config, const char * ecl_kw_name) {
  ert_impl_type impl_type = INVALID;

  if (hash_has_key(ensemble_config->config_nodes , ecl_kw_name)) {
    enkf_config_node_type * node = hash_get(ensemble_config->config_nodes , ecl_kw_name);
    impl_type = enkf_config_node_get_impl_type(node);
  } else
    util_abort("%s: internal error: asked for implementation type of unknown node:%s \n",__func__ , ecl_kw_name);

  return impl_type;
}
示例#5
0
stringlist_type * ensemble_config_alloc_keylist_from_impl_type(const ensemble_config_type * config , ert_impl_type impl_type) {
  stringlist_type * key_list = stringlist_alloc_new();
  hash_iter_type * iter = hash_iter_alloc(config->config_nodes);
  while (!hash_iter_is_complete( iter )) {
    const char * key = hash_iter_get_next_key(iter);
    if (enkf_config_node_get_impl_type( hash_get(config->config_nodes , key)) == impl_type)
      stringlist_append_copy( key_list , key );

  }
  hash_iter_free(iter);
  return key_list;
}
示例#6
0
bool ensemble_config_has_impl_type(const  ensemble_config_type * config, const ert_impl_type impl_type) {
  bool ret = false; 
  hash_iter_type * iter = hash_iter_alloc(config->config_nodes);
  while (!hash_iter_is_complete( iter )) {
    const char * key = hash_iter_get_next_key(iter);
    if (enkf_config_node_get_impl_type( hash_get(config->config_nodes , key)) == impl_type) {
      ret = true; 
      break; 
    }
  }
  hash_iter_free(iter);
  return ret; 
}
示例#7
0
enkf_plot_gen_kw_type * enkf_plot_gen_kw_alloc( const enkf_config_node_type * config_node ) {
  if (enkf_config_node_get_impl_type( config_node ) == GEN_KW) {
    enkf_plot_gen_kw_type * plot_gen_kw = util_malloc( sizeof * plot_gen_kw );
    UTIL_TYPE_ID_INIT( plot_gen_kw , ENKF_PLOT_GEN_KW_TYPE_ID );
    plot_gen_kw->config_node = config_node;
    plot_gen_kw->size = 0;
    plot_gen_kw->ensemble = NULL;
    return plot_gen_kw;
  }
  else {
    return NULL;
  }
}
示例#8
0
/*
(defun insert-curly ()
 (interactive)
 (insert "{}"))
*/
void enkf_config_node_set_internalize(enkf_config_node_type * node, int report_step) {
  ert_impl_type impl_type = enkf_config_node_get_impl_type( node );
  if (impl_type == CONTAINER) {
    int inode;
    int container_size = enkf_config_node_container_size( node );
    for (inode == 0; inode < container_size; inode++) {
      enkf_config_node_type * child_node = enkf_config_node_container_iget( node , inode );
      enkf_config_node_set_internalize( child_node , report_step );
    }
  } else {
    if (node->internalize == NULL)
      node->internalize = bool_vector_alloc( 0 , false );
    bool_vector_iset( node->internalize , report_step , true);
  }
}
示例#9
0
void test_write_gen_kw_export_file(enkf_main_type * enkf_main)
{
  test_assert_not_NULL(enkf_main);
  enkf_state_type * state = enkf_main_iget_state( enkf_main , 0 );
  test_assert_not_NULL(state);
  enkf_node_type * enkf_node = enkf_state_get_node( state , "MULTFLT" );
  test_assert_not_NULL(enkf_node);
  const enkf_config_node_type * config_node = enkf_node_get_config(enkf_node);
  test_assert_not_NULL(config_node);

  if (GEN_KW == enkf_config_node_get_impl_type(config_node)) {
    enkf_fs_type * fs = enkf_main_get_fs(enkf_main);
    enkf_state_ecl_write(state, fs);
    test_assert_true(util_file_exists("parameters.txt"));
  }
}
示例#10
0
void test_send_fortio_to_gen_kw_ecl_write(void * arg) {
  enkf_main_type * enkf_main = arg;
  test_assert_not_NULL(enkf_main);
  fortio_type * fortio  = fortio_open_writer("my_new_file", false, ECL_ENDIAN_FLIP);
  test_assert_not_NULL(fortio);

  enkf_state_type * state  = enkf_main_iget_state( enkf_main , 0 );
  test_assert_not_NULL(state);
  enkf_node_type * enkf_node = enkf_state_get_node( state , "MULTFLT" );
  test_assert_not_NULL(enkf_node);
  const enkf_config_node_type * config_node = enkf_node_get_config(enkf_node);
  test_assert_not_NULL(config_node);

  if (GEN_KW == enkf_config_node_get_impl_type(config_node)) {
    const char * dummy_path = "dummy_path";
    enkf_node_ecl_write(enkf_node, dummy_path, fortio, 0);
  }
}
示例#11
0
void test_write_gen_kw_export_file(enkf_main_type * enkf_main)
{
  test_assert_not_NULL(enkf_main);
  enkf_fs_type * init_fs = enkf_main_get_fs( enkf_main );
  enkf_state_type * state = enkf_main_iget_state( enkf_main , 0 );
  run_arg_type * run_arg = run_arg_alloc_INIT_ONLY( init_fs , 0 ,0 , "simulations/run0");
  test_assert_not_NULL(state);
  enkf_node_type * enkf_node = enkf_state_get_node( state , "MULTFLT" );

  test_assert_not_NULL(enkf_node);
  const enkf_config_node_type * config_node = enkf_node_get_config(enkf_node);
  test_assert_not_NULL(config_node);

  if (GEN_KW == enkf_config_node_get_impl_type(config_node)) {
    enkf_state_ecl_write(state, run_arg , init_fs);
    test_assert_true(util_file_exists("simulations/run0/parameters.txt"));
  }
  run_arg_free( run_arg );
}
示例#12
0
enkf_config_node_type * ensemble_config_add_summary(ensemble_config_type * ensemble_config , const char * key , load_fail_type load_fail) {
  enkf_config_node_type * config_node = NULL;

  if (hash_has_key(ensemble_config->config_nodes, key)) {
    config_node = hash_get(ensemble_config->config_nodes, key);
    if (enkf_config_node_get_impl_type( config_node ) != SUMMARY) {
      util_abort("%s: ensemble key:%s already exists - but it is not of summary type\n",__func__ , key);
    }

    summary_config_type * summary_config = enkf_config_node_get_ref( config_node );
    summary_config_update_load_fail_mode( summary_config , load_fail );

  } else {
    config_node = enkf_config_node_alloc_summary( key , load_fail);
    ensemble_config_add_node(ensemble_config , config_node );
  }

  return config_node;
}
示例#13
0
enkf_config_node_type * ensemble_config_add_summary(ensemble_config_type * ensemble_config , const char * key , load_fail_type load_fail) {
  enkf_config_node_type * config_node = NULL;

  if (hash_has_key(ensemble_config->config_nodes, key)) {
    config_node = hash_get(ensemble_config->config_nodes, key);
    if (enkf_config_node_get_impl_type( config_node ) != SUMMARY)
      util_abort("%s: ensemble key:%s already exists - but it is not of summary type\n",__func__ , key);
    {
      summary_config_type * summary_config = enkf_config_node_get_ref( config_node );
      summary_config_update_load_fail_mode( summary_config , load_fail );
    }
  } else {
    if ((ensemble_config->refcase == NULL) || (ecl_sum_has_general_var( ensemble_config->refcase , key ))) {
      config_node = enkf_config_node_alloc_summary( key , load_fail);
      ensemble_config_add_node(ensemble_config , config_node );
    } else
      fprintf(stderr,"** warning: the refcase:%s does not contain the summary key:\"%s\" - will be ignored.\n", ecl_sum_get_case( ensemble_config->refcase ) , key);
  }

  return config_node;
}
示例#14
0
ert_impl_type enkf_node_get_impl_type(const enkf_node_type * enkf_node) {
  return enkf_config_node_get_impl_type(enkf_node->config);
}