Beispiel #1
0
void enkf_tui_util_get_time(enkf_fs_type * fs , const enkf_config_node_type * config_node, enkf_node_type * node , state_enum analysis_state , int get_index , int step1 , int step2 , int iens , double * x , double * y ) {
  const char * key = enkf_config_node_get_key(config_node);
  int report_step;
  int index = 0;
  for (report_step = step1; report_step <= step2; report_step++) {
    
    if (analysis_state & FORECAST) {
      node_id_type node_id = {.report_step = report_step , .iens = iens , .state = FORECAST };
      if (enkf_node_try_load(node , fs , node_id)) {
        const field_type * field = enkf_node_value_ptr( node );
        y[index] = field_iget_double(field , get_index);
      } else {
        fprintf(stderr," ** Warning field:%s is missing for member,report: %d,%d \n",key  , iens , report_step);
        y[index] = -1;
      }
      x[index] = report_step;
      index++;
    }
    
    
    if (analysis_state & ANALYZED) {
      node_id_type node_id = {.report_step = report_step , .iens = iens , .state = ANALYZED };
      if (enkf_node_try_load(node , fs , node_id)) {
        const field_type * field = enkf_node_value_ptr( node );
        y[index] = field_iget_double(field , get_index);
      } else {
        fprintf(stderr," ** Warning field:%s is missing for member,report: %d,%d \n",key , iens , report_step);
        y[index] = -1;
      }
      x[index] = report_step;
      index++;
    }
Beispiel #2
0
void enkf_tui_export_fieldP(void * arg) {
  enkf_main_type * enkf_main                   = enkf_main_safe_cast( arg );
  const ensemble_config_type * ensemble_config = enkf_main_get_ensemble_config(enkf_main);
  const enkf_config_node_type * config_node    = enkf_tui_util_scanf_key(ensemble_config , PROMPT_LEN ,  FIELD  , INVALID_VAR );
  int iens1                                    = 0;
  int iens2                                    = enkf_main_get_ensemble_size( enkf_main );
  const int last_report                        = enkf_main_get_history_length( enkf_main );
  int report_step                              = util_scanf_int_with_limits("Report step: ", PROMPT_LEN , 0 , last_report);
  double lower_limit                           = util_scanf_double("Lower limit", PROMPT_LEN);
  double upper_limit                           = util_scanf_double("Upper limit", PROMPT_LEN);
  char * export_file;
  util_printf_prompt("Filename to store file: " , PROMPT_LEN , '=' , "=> ");
  export_file = util_alloc_stdin_line();
  {
    enkf_fs_type   * fs        = enkf_main_tui_get_fs(enkf_main);
    enkf_node_type ** ensemble = enkf_node_load_alloc_ensemble( config_node , fs , report_step , iens1 , iens2 );
    enkf_node_type *  sum      = enkf_node_alloc( config_node );
    int active_ens_size        = 0;
    int iens;

    enkf_node_clear( sum );
    {
      /* OK going low level */
      field_type * sum_field = (field_type *) enkf_node_value_ptr( sum );

      for (iens = iens1; iens < iens2; iens++) {
        if (ensemble[iens - iens1] != NULL) {
          field_type * field     = (field_type *) enkf_node_value_ptr( ensemble[iens - iens1] );
          field_update_sum( sum_field , field , lower_limit , upper_limit);
          active_ens_size++;
        }
      }
      if (active_ens_size > 0) {
        field_scale( sum_field , 1.0 / active_ens_size );
        {
          char * path;
          util_alloc_file_components( export_file , &path , NULL , NULL);
          if (path != NULL) {
            util_make_path( path );
            free( path );
          }
        }
        field_export(sum_field , export_file , NULL , RMS_ROFF_FILE , false, NULL);
      } else fprintf(stderr,"Warning: no data found \n");
    }

    for (iens = iens1; iens < iens2; iens++) {
      if (ensemble[iens - iens1] != NULL)
        enkf_node_free( ensemble[iens - iens1] );
    }

    free( ensemble );
    enkf_node_free( sum );
  }
  free( export_file );
}
Beispiel #3
0
void obs_vector_measure(const obs_vector_type * obs_vector , 
                        enkf_fs_type * fs , 
                        state_enum state , 
                        int report_step , 
                        const int_vector_type * ens_active_list , 
                        meas_data_type * meas_data , 
                        const active_list_type * active_list) {
  
  void * obs_node = vector_iget( obs_vector->nodes , report_step );
  if ( obs_node != NULL ) {
    enkf_node_type * enkf_node = enkf_node_deep_alloc( obs_vector->config_node );

    node_id_type node_id = { .report_step = report_step , 
                             .state       = state , 
                             .iens        = 0 };

    for (int active_iens_index =0; active_iens_index < int_vector_size( ens_active_list ); active_iens_index++) {
      node_id.iens = int_vector_iget( ens_active_list , active_iens_index );
      
      enkf_node_load(enkf_node , fs , node_id);
      node_id.iens = active_iens_index;
      obs_vector->measure(obs_node , enkf_node_value_ptr(enkf_node) , node_id , meas_data , active_list);
    }

    enkf_node_free( enkf_node );
  }
}
Beispiel #4
0
static double obs_vector_chi2__(const obs_vector_type * obs_vector , int report_step , const enkf_node_type * node, node_id_type node_id) { 
  void * obs_node = vector_iget( obs_vector->nodes , report_step );

  if ( obs_node != NULL) 
    return obs_vector->chi2( obs_node , enkf_node_value_ptr( node ), node_id);
  else
    return 0.0;  /* Observation not active for this report step. */

}
Beispiel #5
0
void obs_vector_measure(const obs_vector_type * obs_vector , enkf_fs_type * fs , state_enum state , int report_step , const enkf_state_type * enkf_state ,  meas_data_type * meas_data , const active_list_type * active_list) {
  
  void * obs_node = vector_iget( obs_vector->nodes , report_step );
  if ( obs_node != NULL ) {
    enkf_node_type * enkf_node = enkf_state_get_node( enkf_state , obs_vector_get_state_kw( obs_vector ));
    node_id_type node_id = { .report_step = report_step , 
                             .state       = state , 
                             .iens        = enkf_state_get_iens( enkf_state ) };
    
    enkf_node_load(enkf_node , fs , node_id);
    obs_vector->measure(obs_node , enkf_node_value_ptr(enkf_node) , node_id , meas_data , active_list);
  }
Beispiel #6
0
void enkf_tui_export_gen_data(void * arg) {
  enkf_main_type * enkf_main = enkf_main_safe_cast( arg );
  const ensemble_config_type * ensemble_config = enkf_main_get_ensemble_config(enkf_main);
  {
    int report_step;
    int iens1 , iens2;
    const int last_report = enkf_main_get_history_length( enkf_main );

    const enkf_config_node_type * config_node;
    path_fmt_type * file_fmt;

    config_node    = enkf_tui_util_scanf_key(ensemble_config , PROMPT_LEN ,  GEN_DATA , INVALID_VAR);


    report_step = util_scanf_int_with_limits("Report step: ", PROMPT_LEN , 0 , last_report);
    enkf_tui_util_scanf_iens_range("Realizations members to export(0 - %d)" , enkf_main_get_ensemble_size( enkf_main ) , PROMPT_LEN , &iens1 , &iens2);
    {
      char path_fmt[512];
      util_printf_prompt("Filename to store files in (with %d) in: " , PROMPT_LEN , '=' , "=> ");
      scanf("%s" , path_fmt);
      file_fmt = path_fmt_alloc_path_fmt( path_fmt );
    }

    {
      enkf_fs_type   * fs   = enkf_main_tui_get_fs(enkf_main);
      enkf_node_type * node = enkf_node_alloc(config_node);
      gen_data_file_format_type export_type = gen_data_guess_export_type( (const gen_data_type *) enkf_node_value_ptr(node) );
      int iens;

      for (iens = iens1; iens <= iens2; iens++) {
        node_id_type node_id = {.report_step = report_step , .iens = iens};
        if (enkf_node_try_load(node , fs, node_id)) {
          char * full_path = path_fmt_alloc_path( file_fmt , false , iens);
          char * path;
          util_alloc_file_components(full_path , &path , NULL , NULL);
          if (path != NULL) util_make_path( path );

          {
            const gen_data_type * gen_data = (const gen_data_type *) enkf_node_value_ptr(node);
            gen_data_export(gen_data , full_path , export_type);
          }

          free(full_path);
          free(path);
        }
      }
      enkf_node_free(node);
    }
  }
}
Beispiel #7
0
void enkf_tui_export_field(const enkf_main_type * enkf_main , field_file_format_type file_type) {
  const ensemble_config_type * ensemble_config = enkf_main_get_ensemble_config(enkf_main);
  const bool output_transform = true;
  const enkf_config_node_type * config_node;
  const int last_report = enkf_main_get_history_length( enkf_main );
  int        iens1 , iens2 , iens , report_step;
  path_fmt_type * export_path;

  config_node    = enkf_tui_util_scanf_key(ensemble_config , PROMPT_LEN ,  FIELD  , INVALID_VAR );

  report_step = util_scanf_int_with_limits("Report step: ", PROMPT_LEN , 0 , last_report);
  enkf_tui_util_scanf_iens_range("Realizations members to export(0 - %d)" , enkf_main_get_ensemble_size( enkf_main ) , PROMPT_LEN , &iens1 , &iens2);

  {
    char * path_fmt;
    util_printf_prompt("Filename to store files in (with %d) in: " , PROMPT_LEN , '=' , "=> ");
    path_fmt = util_alloc_stdin_line();
    export_path = path_fmt_alloc_path_fmt( path_fmt );
    free( path_fmt );
  }

  {
    enkf_fs_type   * fs   = enkf_main_tui_get_fs(enkf_main);
    enkf_node_type * node = enkf_node_alloc(config_node);

    for (iens = iens1; iens <= iens2; iens++) {
      node_id_type node_id = {.report_step = report_step , .iens = iens };
      if (enkf_node_try_load(node , fs , node_id)) {
        char * filename = path_fmt_alloc_path( export_path , false , iens);
        {
          char * path;
          util_alloc_file_components(filename , &path , NULL , NULL);
          if (path != NULL) {
            util_make_path( path );
            free( path );
          }
        }

        {
          const field_type * field = (const field_type *) enkf_node_value_ptr(node);
          field_export(field , filename , NULL , file_type , output_transform, NULL);
        }
        free(filename);
      } else
        printf("Warning: could not load realization:%d \n", iens);
    }
    enkf_node_free(node);
  }
}
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);
}