コード例 #1
0
ファイル: obs_vector.c プロジェクト: patricknraanes/ert
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
ファイル: ensemble_config.c プロジェクト: danielfmva/ert
void ensemble_config_set_gen_kw_format( ensemble_config_type * ensemble_config , const char * gen_kw_format_string) {
  if (!util_string_equal( gen_kw_format_string , ensemble_config->gen_kw_format_string)) {
    stringlist_type * gen_kw_keys = ensemble_config_alloc_keylist_from_impl_type( ensemble_config , GEN_KW );
    int i;
    ensemble_config->gen_kw_format_string = util_realloc_string_copy( ensemble_config->gen_kw_format_string , gen_kw_format_string );
    for (i=0; i < stringlist_get_size( gen_kw_keys ); i++) {
      enkf_config_node_type * config_node = ensemble_config_get_node( ensemble_config , stringlist_iget( gen_kw_keys , i ));
      gen_kw_config_update_tag_format( enkf_config_node_get_ref( config_node ) , gen_kw_format_string );
    }
    stringlist_free( gen_kw_keys );
  }
}
コード例 #3
0
ファイル: enkf_main_manage_fs.c プロジェクト: Ensembles/ert
static void enkf_main_gen_data_special( enkf_main_type * enkf_main , enkf_fs_type * fs ) {
  stringlist_type * gen_data_keys = ensemble_config_alloc_keylist_from_impl_type( enkf_main->ensemble_config , GEN_DATA);
  for (int i=0; i < stringlist_get_size( gen_data_keys ); i++) {
    enkf_config_node_type * config_node = ensemble_config_get_node( enkf_main->ensemble_config , stringlist_iget( gen_data_keys , i));
    gen_data_config_type * gen_data_config = enkf_config_node_get_ref( config_node );

    if (gen_data_config_is_dynamic( gen_data_config )) 
      gen_data_config_set_ens_size( gen_data_config , enkf_main->ens_size );
    
  }
  stringlist_free( gen_data_keys );
}
コード例 #4
0
ファイル: ensemble_config.c プロジェクト: chflo/ert
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);
}
コード例 #5
0
ファイル: ensemble_config.c プロジェクト: chflo/ert
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;
}
コード例 #6
0
ファイル: ensemble_config.c プロジェクト: danielfmva/ert
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;
}
コード例 #7
0
ファイル: obs_vector.c プロジェクト: patricknraanes/ert
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;
  }
}
コード例 #8
0
int main(int argc , char ** argv) {
  enkf_main_install_SIGNALS();

  const char * config_file = argv[1];
  const char * init_file   = argv[2];
  const char * key         = "PORO";
  int iens                 = 0;

  ert_test_context_type * test_context         = ert_test_context_alloc("ExportInactiveCellsTest" , config_file);
  enkf_main_type * enkf_main                   = ert_test_context_get_main(test_context);
  enkf_fs_type * fs                            = enkf_main_get_fs(enkf_main);
  const ensemble_config_type * ensemble_config = enkf_main_get_ensemble_config(enkf_main);
  const enkf_config_node_type * config_node    = ensemble_config_get_node(ensemble_config , key);
  const field_config_type * field_config       = enkf_config_node_get_ref( config_node );
  enkf_state_type * state                      = enkf_main_iget_state( enkf_main , iens );
  enkf_node_type * field_node                  = enkf_state_get_node( state , key );
  field_type * field                           = enkf_node_value_ptr(field_node);

  {
    forward_initialize_node(enkf_main, init_file, field_node);
    node_id_type node_id = {.report_step = 0 , .iens = iens , .state = BOTH };
    test_assert_true(enkf_node_try_load(field_node , fs , node_id));
    field_scale(field, 3.0);
  }

  int nx,ny,nz;
  field_config_get_dims(field_config , &nx , &ny , &nz);
  const char * export_file_grdecl = "my_test_dir/exported_field_test_file_grdecl";
  const char * export_file_roff   = "my_test_dir/exported_field_test_file_roff";
  field_file_format_type file_type;

  char * found_init_file = enkf_main_alloc_abs_path_to_init_file(enkf_main, config_node);
  {
    file_type = ECL_GRDECL_FILE;
    field_export(field, export_file_grdecl, NULL, file_type, false, found_init_file);
    check_exported_data(export_file_grdecl, init_file, file_type, field_config, field, nx, ny, nz);
  }
  {
    file_type = RMS_ROFF_FILE;
    field_export(field, export_file_roff, NULL, file_type, false, found_init_file);
    check_exported_data(export_file_roff, init_file, file_type, field_config, field, nx, ny, nz);
  }

  free(found_init_file);
  found_init_file = NULL;
  {
    file_type = ECL_GRDECL_FILE;
    field_export(field, export_file_grdecl, NULL, file_type, false, found_init_file);
    check_exported_data(export_file_grdecl, found_init_file, file_type, field_config, field, nx, ny, nz);
  }
  {
    file_type = RMS_ROFF_FILE;
    field_export(field, export_file_roff, NULL, file_type, false, found_init_file);
    check_exported_data(export_file_roff, found_init_file, file_type, field_config, field, nx, ny, nz);
  }



  ert_test_context_free(test_context);
  exit(0);
}
コード例 #9
0
ファイル: enkf_node.c プロジェクト: arielalmendral/ert
void enkf_node_alloc_domain_object(enkf_node_type * node) {
  if (node->data != NULL)
    node->freef( node->data );
  node->data = node->alloc(enkf_config_node_get_ref(node->config));
}
コード例 #10
0
ファイル: enkf_plot_gen_kw.c プロジェクト: Ensembles/ert
bool enkf_plot_gen_kw_should_use_log_scale(const enkf_plot_gen_kw_type * gen_kw , int index) {
    const gen_kw_config_type * gen_kw_config = enkf_config_node_get_ref( gen_kw->config_node );
    return gen_kw_config_should_use_log_scale(gen_kw_config, index);
}
コード例 #11
0
ファイル: enkf_plot_gen_kw.c プロジェクト: Ensembles/ert
int enkf_plot_gen_kw_get_keyword_count( const enkf_plot_gen_kw_type * gen_kw ){
    const gen_kw_config_type * gen_kw_config = enkf_config_node_get_ref( gen_kw->config_node );
    return gen_kw_config_get_data_size(gen_kw_config);
}
コード例 #12
0
ファイル: enkf_plot_gen_kw.c プロジェクト: Ensembles/ert
const char * enkf_plot_gen_kw_iget_key( const enkf_plot_gen_kw_type * plot_gen_kw, int index) {
  const gen_kw_config_type * gen_kw_config = enkf_config_node_get_ref( plot_gen_kw->config_node );
  return gen_kw_config_iget_name( gen_kw_config , index );
}