Exemplo n.º 1
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;
}
Exemplo n.º 2
0
const enkf_config_node_type * ensemble_config_user_get_node(const ensemble_config_type * config , const char  * full_key, char ** index_key ) {
  const enkf_config_node_type * node = NULL;
  char ** key_list;
  int     keys;
  int     key_length = 1;
  int offset;
  
  *index_key = NULL;
  util_split_string(full_key , USER_KEY_JOIN_STRING , &keys , &key_list);
  while (node == NULL && key_length <= keys) {
    char * current_key = util_alloc_joined_string( (const char **) key_list , key_length , USER_KEY_JOIN_STRING );
    if (ensemble_config_has_key(config , current_key))
      node = ensemble_config_get_node(config , current_key);
    else
      key_length++;
    offset = strlen( current_key );
    free( current_key );
  }
  if (node != NULL) {
    if (offset < strlen( full_key ))
      *index_key = util_alloc_string_copy(&full_key[offset+1]);
  }
  
  util_free_stringlist(key_list , keys);
  return node;
}
Exemplo n.º 3
0
/**
   this is called by the enkf_state function while loading results,
   that code is run in parallell by many threads.
*/
void ensemble_config_ensure_static_key(ensemble_config_type * ensemble_config , const char * kw ) {
  pthread_mutex_lock( &ensemble_config->mutex );
  {
    if (!ensemble_config_has_key(ensemble_config , kw)) 
      ensemble_config_add_STATIC_node(ensemble_config , kw );
  }
  pthread_mutex_unlock( &ensemble_config->mutex );
}
Exemplo n.º 4
0
enkf_config_node_type *  ensemble_config_add_STATIC_node(ensemble_config_type * ensemble_config , 
                                                         const char    * key) {
  
  if (ensemble_config_has_key(ensemble_config , key)) 
    util_abort("%s: a configuration object:%s has already been added - aborting \n",__func__ , key);
  {
    enkf_config_node_type * node = enkf_config_node_alloc(STATIC_STATE , STATIC , false , key , NULL , NULL , NULL , NULL);
    hash_insert_hash_owned_ref(ensemble_config->config_nodes , key , node , enkf_config_node_free__);
    return node;
  }
}
Exemplo n.º 5
0
void ensemble_config_add_node( ensemble_config_type * ensemble_config , enkf_config_node_type * node) {
  if (node) {
    const char * key = enkf_config_node_get_key( node );
    if (ensemble_config_has_key(ensemble_config , key)) 
      util_abort("%s: a configuration object:%s has already been added - aborting \n",__func__ , key);
    
    hash_insert_hash_owned_ref(ensemble_config->config_nodes , key , node , enkf_config_node_free__);
    ensemble_config->have_forward_init |= enkf_config_node_use_forward_init( node );
  } else
    util_abort("%s: internal error - tried to add NULL node to ensemble configuration \n",__func__);
}
Exemplo n.º 6
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;
  }
}
Exemplo n.º 7
0
void ensemble_config_update_custom_kw_config(ensemble_config_type * config, custom_kw_config_set_type * config_set) {
    stringlist_type * keys = custom_kw_config_set_get_keys_alloc(config_set);

    for(int i = 0; i < stringlist_get_size(keys); i++) {
        const char * key = stringlist_iget(keys, i);
        if(!ensemble_config_has_key(config, key)) {
            ensemble_config_add_custom_kw(config, key, NULL, NULL);
            printf("[%s] CustomKW key: '%s' not in ensemble! Adding from storage.\n", __func__, key);
        }

        enkf_config_node_type * config_node = ensemble_config_get_node(config, key);
        custom_kw_config_type * custom_kw_config = (custom_kw_config_type*) enkf_config_node_get_ref(config_node);

        custom_kw_config_set_update_config(config_set, custom_kw_config);
    }

    stringlist_free(keys);
}
Exemplo n.º 8
0
obs_vector_type * obs_vector_alloc_from_BLOCK_OBSERVATION(const conf_instance_type * conf_instance , 
                                                          const ecl_grid_type * grid , 
                                                          const ecl_sum_type * refcase , 
                                                          const history_type * history, 
                                                          ensemble_config_type * ensemble_config) {

  if(!conf_instance_is_of_class(conf_instance, "BLOCK_OBSERVATION"))
    util_abort("%s: internal error. expected \"BLOCK_OBSERVATION\" instance, got \"%s\".\n",
               __func__, conf_instance_get_class_name_ref(conf_instance) );

  block_obs_source_type source_type = SOURCE_SUMMARY;
  const char * obs_label            = conf_instance_get_name_ref(conf_instance);
  const char * source_string        = conf_instance_get_item_value_ref(conf_instance , "SOURCE");
  const char * field_name           = conf_instance_get_item_value_ref(conf_instance , "FIELD");
  const char * sum_kw = NULL;
  bool    OK     = true;
  
  if (strcmp(source_string , "FIELD") == 0) {
    source_type = SOURCE_FIELD;
    if (!ensemble_config_has_key( ensemble_config , field_name)) {
      OK = false;
      fprintf(stderr,"** Warning the ensemble key:%s does not exist - observation:%s not added \n", field_name , obs_label);
    }
  } else if (strcmp( source_string , "SUMMARY") == 0) {
    source_type = SOURCE_SUMMARY;
    sum_kw = __summary_kw( field_name );
  } else 
    util_abort("%s: internal error \n",__func__);
  
  if (OK) {
    obs_vector_type * obs_vector = NULL;
    int          size = history_get_last_restart( history );
    int          obs_restart_nr ;
    
    stringlist_type * summary_keys    = stringlist_alloc_new();
    stringlist_type * obs_pt_keys = conf_instance_alloc_list_of_sub_instances_of_class_by_name(conf_instance, "OBS");
    int               num_obs_pts = stringlist_get_size(obs_pt_keys);
    
    double * obs_value = util_calloc(num_obs_pts , sizeof * obs_value);
    double * obs_std   = util_calloc(num_obs_pts , sizeof * obs_std  );
    int    * obs_i     = util_calloc(num_obs_pts , sizeof * obs_i    );
    int    * obs_j     = util_calloc(num_obs_pts , sizeof * obs_j    );
    int    * obs_k     = util_calloc(num_obs_pts , sizeof * obs_k    );

    obs_restart_nr = __conf_instance_get_restart_nr(conf_instance , obs_label , history  , size);  
    
    /** Build the observation. */
    for(int obs_pt_nr = 0; obs_pt_nr < num_obs_pts; obs_pt_nr++) {
      const char * obs_key    = stringlist_iget(obs_pt_keys, obs_pt_nr);
      const conf_instance_type * obs_instance = conf_instance_get_sub_instance_ref(conf_instance, obs_key);
      const char * error_mode = conf_instance_get_item_value_ref(obs_instance, "ERROR_MODE");
      double error     = conf_instance_get_item_value_double(obs_instance, "ERROR");
      double value     = conf_instance_get_item_value_double(obs_instance, "VALUE");
      double min_error = conf_instance_get_item_value_double(obs_instance, "ERROR_MIN");
      
      if (strcmp( error_mode , "REL") == 0)
        error *= value;
      else if (strcmp( error_mode , "RELMIN") == 0)
        error = util_double_max( error * value , min_error );

      obs_value[obs_pt_nr] = value;
      obs_std  [obs_pt_nr] = error;
      
      /**
         The input values i,j,k come from the user, and are offset 1. They
         are immediately shifted with -1 to become C-based offset zero.
      */
      obs_i[obs_pt_nr] = conf_instance_get_item_value_int(   obs_instance, "I") - 1;
      obs_j[obs_pt_nr] = conf_instance_get_item_value_int(   obs_instance, "J") - 1;
      obs_k[obs_pt_nr] = conf_instance_get_item_value_int(   obs_instance, "K") - 1;

      if (source_type == SOURCE_SUMMARY) {
        char * summary_key = smspec_alloc_block_ijk_key( SUMMARY_KEY_JOIN_STRING , sum_kw , 
                                                         obs_i[obs_pt_nr] + 1 , 
                                                         obs_j[obs_pt_nr] + 1 , 
                                                         obs_k[obs_pt_nr] + 1 );
        
        stringlist_append_owned_ref( summary_keys , summary_key );
      }
    }

    
    if (source_type == SOURCE_FIELD) {
      const enkf_config_node_type * config_node  = ensemble_config_get_node( ensemble_config , field_name);
      const field_config_type     * field_config = enkf_config_node_get_ref( config_node ); 
      block_obs_type * block_obs  = block_obs_alloc_complete(obs_label, source_type , NULL , field_config , grid , num_obs_pts, obs_i, obs_j, obs_k, obs_value, obs_std);
      
      if (block_obs != NULL) {
        obs_vector = obs_vector_alloc( BLOCK_OBS , obs_label , ensemble_config_get_node(ensemble_config , field_name), size );
        obs_vector_install_node( obs_vector , obs_restart_nr , block_obs);
      }
    } else if (source_type == SOURCE_SUMMARY) {
      OK = true;
      if (refcase != NULL) {
        for (int i=0; i < stringlist_get_size( summary_keys ); i++) {
          const char * sum_key = stringlist_iget( summary_keys , i );
          if (!ecl_sum_has_key(refcase , sum_key)) {
            /*
              If the 
            */
            fprintf(stderr,"** Warning missing summary %s for cell: (%d,%d,%d) in refcase - make sure that \"BPR  %d  %d  %d\" is included in ECLIPSE summary specification \n" , 
                    sum_key , obs_i[i]+1 , obs_j[i]+1 , obs_k[i]+1 , obs_i[i]+1 , obs_j[i]+1 , obs_k[i]+1  );
            //OK = false;
          }
        }
      }
      if (OK) {
        // We can create the container node and add the summary nodes.
        enkf_config_node_type * container_config = ensemble_config_add_container( ensemble_config , NULL );

        for (int i=0; i < stringlist_get_size( summary_keys ); i++) {
          const char * sum_key = stringlist_iget( summary_keys , i );
          enkf_config_node_type * child_node = ensemble_config_add_summary( ensemble_config , sum_key , LOAD_FAIL_WARN );
          enkf_config_node_update_container( container_config , child_node );
        }
        
        {
          block_obs_type * block_obs  = block_obs_alloc_complete(obs_label, source_type , summary_keys , enkf_config_node_get_ref(container_config) , 
                                                                 grid , num_obs_pts, obs_i, obs_j, obs_k, obs_value, obs_std);
          if (block_obs != NULL) {
            obs_vector = obs_vector_alloc( BLOCK_OBS , obs_label , container_config, size );
            obs_vector_install_node( obs_vector , obs_restart_nr , block_obs);
          }
        }
      }
    } else
      util_abort("%s: invalid source value \n",__func__);
    
    free(obs_value);
    free(obs_std);
    free(obs_i);
    free(obs_j);
    free(obs_k);
    stringlist_free(obs_pt_keys);
    stringlist_free(summary_keys);
    
    return obs_vector;
  } else {
    fprintf(stderr,"** Warning the ensemble key:%s does not exist - observation:%s not added \n", field_name , obs_label);
    return NULL;
  }
}
Exemplo n.º 9
0
static void enkf_tui_fs_copy_ensemble__(
  enkf_main_type * enkf_main,
  const char     * source_case,
  const char     * target_case,
  int              report_step_from,
  state_enum       state_from,
  int              report_step_to,
  state_enum       state_to,
  bool             only_parameters)
{
  msg_type       * msg          = msg_alloc("Copying: " , false);
  ensemble_config_type * config = enkf_main_get_ensemble_config(enkf_main);
  int ens_size                  = enkf_main_get_ensemble_size(enkf_main);
  char * ranking_key;
  const int  * ranking_permutation = NULL;
  int  * identity_permutation;
  ranking_table_type * ranking_table = enkf_main_get_ranking_table( enkf_main );
  

  if (ranking_table_get_size( ranking_table ) > 0) {
    util_printf_prompt("Name of ranking to resort by (or blank)" , 50  , '=' , "=> ");
    ranking_key = util_alloc_stdin_line();
    if (ranking_table_has_ranking( ranking_table , ranking_key )) 
      ranking_permutation = ranking_table_get_permutation( ranking_table , ranking_key );
    else {
      fprintf(stderr," Sorry: ranking:%s does not exist \n", ranking_key );
      return;
    }
  }
  identity_permutation = util_calloc( ens_size , sizeof * identity_permutation );
  {
    int iens;
    for (iens =0; iens < ens_size; iens++) 
      identity_permutation[iens] = iens;
  }

  if (ranking_permutation == NULL)
    ranking_permutation = identity_permutation;
  

  {
    /* If the current target_case does not exist it is automatically created by the select_write_dir function */
    enkf_fs_type * src_fs    = enkf_main_get_alt_fs( enkf_main , source_case , true , false );
    enkf_fs_type * target_fs = enkf_main_get_alt_fs( enkf_main , target_case , false, true );
    stringlist_type * nodes;
    
    if(only_parameters)
      nodes = ensemble_config_alloc_keylist_from_var_type(config, PARAMETER);
    else {
      /* Must explicitly load the static nodes. */
      stringlist_type * restart_kw_list = stringlist_alloc_new();
      int i;

      enkf_fs_fread_restart_kw_list(src_fs , report_step_from , 0 , restart_kw_list);  
      for (i = 0; i < stringlist_get_size( restart_kw_list ); i++) {
        const char * kw = stringlist_iget( restart_kw_list , i);
        if (!ensemble_config_has_key(config , kw)) 
          ensemble_config_add_STATIC_node(config , kw );
      }
      for (i=0; i < ens_size; i++) 
        enkf_fs_fwrite_restart_kw_list(target_fs , report_step_to , i , restart_kw_list);
      
      stringlist_free( restart_kw_list );
      nodes = ensemble_config_alloc_keylist(config);
    }

    /***/
    
    {
      int num_nodes = stringlist_get_size(nodes);
      msg_show(msg);
      for(int i = 0; i < num_nodes; i++) {
        const char * key = stringlist_iget(nodes, i);
        enkf_config_node_type * config_node = ensemble_config_get_node(config , key);
        msg_update(msg , key);
        enkf_node_copy_ensemble(config_node, src_fs , target_fs , report_step_from, state_from, report_step_to , state_to , ens_size , ranking_permutation);
      }
    }
   
    enkf_main_close_alt_fs( enkf_main , src_fs );
    enkf_main_close_alt_fs( enkf_main , target_fs );
    
    msg_free(msg , true);
    stringlist_free(nodes);
  }
  free( identity_permutation );
}