Esempio n. 1
0
void * enkf_main_load_results_JOB( void * self , const stringlist_type * args) {
  enkf_main_type * enkf_main = enkf_main_safe_cast( self );
  int iter = 0;
  {
    const model_config_type * model_config = enkf_main_get_model_config( enkf_main );
    if (model_config_runpath_requires_iter( model_config ))
      fprintf(stderr,"**Warning: the runpath format:%s requires an iteration number - using default:0. Use the job: LOAD_RESULT_ITER instead.\n" , model_config_get_runpath_as_char( model_config ));
  }
  return enkf_main_load_results_JOB__(enkf_main , iter , args );
}
Esempio n. 2
0
void test_case_initialized() {
  test_work_area_type * work_area = test_work_area_alloc("enkf_main_case_initialized" );
  {
    enkf_main_type * enkf_main = enkf_main_alloc_empty();
    model_config_type * model_config = enkf_main_get_model_config(enkf_main);
    const char * new_case = "fs/case";
    char * mount_point = util_alloc_sprintf("%s/%s" , model_config_get_enspath(model_config) , new_case);
    enkf_fs_create_fs(mount_point , BLOCK_FS_DRIVER_ID , NULL);

    test_assert_false(enkf_main_case_is_initialized(enkf_main , "does/not/exist" , NULL));
    test_assert_true(enkf_main_case_is_initialized(enkf_main , new_case , NULL));

    enkf_main_free(enkf_main);
  }
  test_work_area_free(work_area);
}
Esempio n. 3
0
void * enkf_main_export_runpath_file_JOB(void * self, const stringlist_type * args)  {
  enkf_main_type * enkf_main              = enkf_main_safe_cast( self );
  int ensemble_size                       = enkf_main_get_ensemble_size(enkf_main);
  analysis_config_type * analysis_config  = enkf_main_get_analysis_config(enkf_main);
  analysis_iter_config_type * iter_config = analysis_config_get_iter_config(analysis_config);
  int num_iterations                      = analysis_iter_config_get_num_iterations(iter_config);
  const model_config_type * model_config  = enkf_main_get_model_config(enkf_main);
  int_vector_type * realizations          = int_vector_alloc(1, 0);
  int_vector_init_range(realizations, 0, ensemble_size, 1);
  int_vector_type * iterations            = int_vector_alloc(1, 0);


  if (stringlist_get_size(args) > 0) {
    int offset = 0;
    while (true) {
      if (offset == stringlist_get_size( args ))
        break;
      if (0 == strcmp("|" , stringlist_iget( args, offset )))
        break;
       ++offset;
    }

    if (0 != strcmp("*", stringlist_iget(args,0))) {
      char * range_str = stringlist_alloc_joined_substring( args, 0, offset, "");
      string_util_init_value_list(range_str, realizations);
      free(range_str);
    }

    if ((offset < stringlist_get_size(args)) && model_config_runpath_requires_iter(model_config)) {
      if (0 == strcmp("*", stringlist_iget(args, (offset+1))))
        int_vector_init_range(iterations, 0, num_iterations, 1);
      else {
        char * range_str = stringlist_alloc_joined_substring( args, offset+1, stringlist_get_size(args), "");
        string_util_init_value_list(range_str, iterations);
        free(range_str);
       }
    }
  }

  enkf_main_export_runpath_file(enkf_main, realizations, iterations);

  int_vector_free(realizations);
  int_vector_free(iterations);

  return NULL;
}
Esempio n. 4
0
void enkf_tui_simple_menu(void * arg) {
  enkf_main_type * enkf_main = enkf_main_safe_cast(arg);
  menu_type * menu = menu_alloc("Simple menu" , "Quit" , "qQ");
  menu_add_item(menu , "Sensitivity run: No data conditioning"                , "sS" , enkf_tui_run_exp         , enkf_main , NULL);
  const model_config_type * model_config = enkf_main_get_model_config( enkf_main );
  menu_item_type * ES_item           = menu_add_item(menu , "Assimilation run: Smoother update"               , "aA" , enkf_tui_run_smoother      , enkf_main , NULL);
  menu_item_type * it_ES_item        = menu_add_item(menu , "Assimilation run: Iterated smoother [RML-EnKF]"  , "iI" , enkf_tui_run_iterated_ES   , enkf_main , NULL);

  if (!model_config_has_history( model_config )) {
    menu_item_disable( it_ES_item );
    menu_item_disable( ES_item );
  }
  menu_add_separator( menu );
  menu_add_item(menu , "Help"                                  , "hH" , enkf_tui_help_menu_simple   , enkf_main , NULL);
  menu_add_item(menu , "Advanced menu"                         , "dD" , enkf_tui_main_menu        , enkf_main , NULL);
  menu_run(menu);
  menu_free(menu);

}
Esempio n. 5
0
static void enkf_main_export_runpath_file(enkf_main_type * enkf_main,
                                          const int_vector_type * realizations,
                                          const int_vector_type * iterations) {

  ecl_config_type * ecl_config            = enkf_main_get_ecl_config(enkf_main);
  const model_config_type * model_config  = enkf_main_get_model_config(enkf_main);
  const char * basename_fmt               = ecl_config_get_eclbase(ecl_config);
  const char * runpath_fmt                = model_config_get_runpath_as_char(model_config);
  const qc_module_type * qc_module        = enkf_main_get_qc_module( enkf_main );

  runpath_list_type * runpath_list = runpath_list_alloc( qc_module_get_runpath_list_file( qc_module ));

  for (int iter = 0; iter < int_vector_size(iterations); ++iter) {
    for (int iens = 0; iens < int_vector_size(realizations); ++iens) {
      int iter_value = int_vector_iget(iterations, iter);
      int iens_value = int_vector_iget(realizations, iens);
      char * basename;
      char * runpath;

      if (basename_fmt)
        basename = util_alloc_sprintf(basename_fmt, iens_value);
      else
        basename = util_alloc_sprintf("--%d", iens_value);

      if (model_config_runpath_requires_iter(model_config))
        runpath = util_alloc_sprintf(runpath_fmt, iens_value, iter_value);
      else
        runpath = util_alloc_sprintf(runpath_fmt, iens_value);

      runpath_list_add(runpath_list, iens_value, iter_value, runpath, basename);

      free(basename);
      free(runpath);
    }
  }
  runpath_list_fprintf(runpath_list);
  runpath_list_free(runpath_list);
}
Esempio n. 6
0
enkf_fs_type * enkf_main_mount_alt_fs(const enkf_main_type * enkf_main , const char * case_path , bool create) {
    if (enkf_main_case_is_current( enkf_main , case_path )) {
        // Fast path - we just return a reference to the currently selected case;
        // with increased refcount.
        enkf_fs_incref( enkf_main->dbase );
        return enkf_main->dbase;
    } else {
        // We have asked for an alterantive fs - must mount and possibly create that first.
        enkf_fs_type * new_fs = NULL;
        if (case_path != NULL) {
            char * new_mount_point    = enkf_main_alloc_mount_point( enkf_main , case_path );

            if (!enkf_fs_exists( new_mount_point )) {
                if (create)
                    enkf_main_create_fs( enkf_main , case_path );
            }

            new_fs = enkf_fs_mount( new_mount_point );
            if (new_fs) {
                const model_config_type * model_config = enkf_main_get_model_config( enkf_main );
                const ecl_sum_type * refcase = model_config_get_refcase( model_config );

                if (refcase) {
                    time_map_type * time_map = enkf_fs_get_time_map( new_fs );
                    if (time_map_attach_refcase( time_map , refcase))
                        time_map_set_strict( time_map , false );
                    else
                        ert_log_add_fmt_message(1 , stderr , "Warning mismatch between refcase:%s and existing case:%s" , ecl_sum_get_case( refcase ) , new_mount_point);
                }
            }

            free( new_mount_point );
        }
        return new_fs;
    }
}
Esempio n. 7
0
void enkf_tui_init(enkf_main_type * enkf_main, bool all_members , bool all_parameters , bool interval ) {
  const int prompt_len                         = 35;
  const ensemble_config_type * ensemble_config = enkf_main_get_ensemble_config(enkf_main);
  int   ens_size                               = enkf_main_get_ensemble_size( enkf_main );
  int iens1, iens2;
  bool iens_valid = false;

  /* iens2 should be interpreted as __inclusive__ */
  if ( all_members ) {
    iens1 = 0;
    iens2 = ens_size - 1;
    iens_valid = true;
  } else {
    if( interval ) {
      char * iens1char = util_scanf_int_with_limits_return_char("First ensemble member in interval"  , prompt_len , 0 , ens_size - 1);
      if (strlen(iens1char)) {
        util_sscanf_int(iens1char , &iens1);
        char * iens2char = util_scanf_int_with_limits_return_char("Second ensemble member in interval" , prompt_len , iens1 , ens_size - 1);
        if (strlen(iens2char)) {
          util_sscanf_int(iens2char , &iens2);
          iens_valid = true;
        }
        free(iens2char);
      }
      free(iens1char);
    } else {
      char * iens1char = util_scanf_int_with_limits_return_char("Initialize ensemble member" , prompt_len , 0 , ens_size - 1);
      if (strlen(iens1char)) {
        util_sscanf_int(iens1char , &iens1);
        iens2 = iens1;
        iens_valid = true;
      }
      free(iens1char);
    }
  }

  if (iens_valid) {
    stringlist_type * param_list = NULL;
    if (all_parameters)
      param_list = ensemble_config_alloc_keylist_from_var_type( ensemble_config , PARAMETER );
    else {
      const enkf_config_node_type * config_node = NULL;
      param_list = stringlist_alloc_new();
      config_node = enkf_tui_util_scanf_key(ensemble_config , prompt_len , INVALID , INVALID_VAR);
      if( config_node != NULL )
        stringlist_append_copy( param_list , enkf_config_node_get_key(config_node));
    }

    if (param_list != NULL) {
      enkf_fs_type * init_fs = enkf_main_tui_get_fs( enkf_main );
      bool_vector_type * iens_mask = bool_vector_alloc( ens_size , false );
      path_fmt_type * runpath_fmt = model_config_get_runpath_fmt(enkf_main_get_model_config(enkf_main));
      subst_list_type * subst_list = enkf_main_get_data_kw(enkf_main);
      int iter = 0;
      bool_vector_iset_block( iens_mask , iens1 , iens2 - iens1 + 1, true );
      {
        ert_run_context_type * run_context = ert_run_context_alloc_INIT_ONLY(init_fs, INIT_CONDITIONAL, iens_mask, runpath_fmt, subst_list , iter );
        enkf_main_initialize_from_scratch(enkf_main , param_list , run_context);
        ert_run_context_free(run_context);
      }
      stringlist_free( param_list );
      bool_vector_free( iens_mask );
    }
  }
}
Esempio n. 8
0
void enkf_tui_run_menu(void * arg) {
  enkf_main_type  * enkf_main  = enkf_main_safe_cast( arg );
  model_config_type * model_config = enkf_main_get_model_config( enkf_main );
  path_fmt_type     * runpath_fmt  = model_config_get_runpath_fmt( model_config );
  menu_type       * menu;

  {
    char   * title = util_alloc_sprintf("Run menu [case:%s  Runpath:%s]" , enkf_main_get_current_fs( enkf_main ) , path_fmt_get_fmt ( runpath_fmt ));
    menu = menu_alloc(title , "Back" , "bB");
    free(title);
  }
  menu_add_item(menu , "Ensemble run: history"                , "xX" , enkf_tui_run_exp         , enkf_main , NULL);
  menu_add_separator( menu );
  {
    const ecl_config_type * ecl_config = enkf_main_get_ecl_config( enkf_main );
    const model_config_type * model_config = enkf_main_get_model_config( enkf_main );
    const analysis_config_type * analysis_config = enkf_main_get_analysis_config(enkf_main);
    
    menu_item_type * enkf_item         = menu_add_item(menu , "Start EnKF run from beginning"          , "sS" , enkf_tui_run_start         , enkf_main , NULL);
    menu_item_type * restart_enkf_item = menu_add_item(menu , "Restart EnKF run from arbitrary state"  , "rR" , enkf_tui_run_restart__       , enkf_main , NULL);
    menu_item_type * ES_item           = menu_add_item(menu , "Integrated smoother update"             , "iI" , enkf_tui_run_smoother      , enkf_main , NULL);
    menu_item_type * it_ES_item        = menu_add_item(menu , "Iterated smoother [RML-EnKF]"           , "tT" , enkf_tui_run_iterated_ES   , enkf_main , NULL);
    menu_item_type * one_more_item     = menu_add_item(menu , "One more iteration (disabled)"          , "mM" , enkf_tui_run_one_more_iteration , enkf_main , NULL);
              
    if (!ecl_config_has_schedule( ecl_config )) {
      menu_item_disable( enkf_item );
      menu_item_disable( restart_enkf_item );
    }
    
    if (!ecl_config_has_init_section( ecl_config )) 
      menu_item_disable( enkf_item );

    menu_item_disable( one_more_item );
    if (!analysis_config_get_module_option(analysis_config , ANALYSIS_ITERABLE)) {
      menu_item_disable( it_ES_item );
      menu_item_disable( one_more_item );
    } else {
      menu_item_disable( enkf_item );
      menu_item_disable( restart_enkf_item );
      menu_item_disable( ES_item );
    }
      
    if (!model_config_has_history( model_config )) {
      menu_item_disable( it_ES_item );
      menu_item_disable( ES_item );
      menu_item_disable( one_more_item );
    }
  }
  menu_add_separator(menu);
  menu_add_item(menu , "Create runpath directories - NO simulation" , "cC" , enkf_tui_run_create_runpath__ , enkf_main , NULL );
  menu_add_item(menu , "Load results manually"                               , "lL"  , enkf_tui_run_manual_load__ , enkf_main , NULL);
  menu_add_separator(menu);
  {
    menu_item_type * analysis_item = menu_add_item(menu , "Analysis menu"             , "aA" , enkf_tui_analysis_menu , enkf_main , NULL);
    
    if (!enkf_main_have_obs( enkf_main )) 
      menu_item_disable( analysis_item );
  }
  /*
    Option to set runpath runtime - currently dismantled.
    
    menu_add_separator(menu);
    {
    model_config_type * model_config = enkf_main_get_model_config( enkf_main );
    path_fmt_type     * runpath_fmt  = model_config_get_runpath_fmt( model_config );
    arg_pack_type * arg_pack = arg_pack_alloc();  
    char * runpath_label = util_alloc_sprintf("Set new value for RUNPATH:%s" , path_fmt_get_fmt ( runpath_fmt ));
    
    arg_pack_append_ptr(arg_pack , model_config);
    arg_pack_append_ptr(arg_pack , menu_add_item(menu , runpath_label , "dD" , enkf_tui_run_set_runpath , arg_pack , arg_pack_free__));
    
    free(runpath_label);
    }
  */
  menu_add_item(menu , "Help"                                  , "hH" , enkf_tui_help_menu_run   , enkf_main , NULL); 
  menu_run(menu);
  menu_free(menu);
}
Esempio n. 9
0
void enkf_tui_run_manual_load__( void * arg ) {
  enkf_main_type * enkf_main = enkf_main_safe_cast( arg );
  const int ens_size         = enkf_main_get_ensemble_size( enkf_main );
  bool_vector_type * iactive = bool_vector_alloc( 0 , false );
  run_mode_type run_mode     = ENSEMBLE_EXPERIMENT;
  int iter = 0;
  
  enkf_main_init_run(enkf_main , iactive , run_mode , INIT_NONE);  /* This is ugly */

  {
    char * prompt = util_alloc_sprintf("Which realizations to load  (Ex: 1,3-5) <Enter for all> [M to return to menu] : [ensemble size:%d] : " , ens_size);
    char * select_string;
    util_printf_prompt(prompt , PROMPT_LEN , '=' , "=> ");
    select_string = util_alloc_stdin_line();

    enkf_tui_util_sscanf_active_list( iactive , select_string , ens_size );
    util_safe_free( select_string );
    
    free( prompt );
  }

  {
    const model_config_type * model_config = enkf_main_get_model_config( enkf_main );
    if (model_config_runpath_requires_iter( model_config )) {
      const char * prompt = "Which iteration to load from [0...?) : ";
      char * input;
      bool OK;
      util_printf_prompt(prompt , PROMPT_LEN , '=' , "=> ");

      input = util_alloc_stdin_line();
      if (input == NULL) 
        return;

      OK = util_sscanf_int( input , &iter ); 

      free( input );
      if (!OK)
        return;
    }
  }
  

  if (bool_vector_count_equal( iactive , true )) {
    stringlist_type ** realizations_msg_list = util_calloc( ens_size , sizeof * realizations_msg_list );
    int iens = 0;
    for (; iens < ens_size; ++iens) {
      realizations_msg_list[iens] = stringlist_alloc_new();
    }

    enkf_main_load_from_forward_model(enkf_main, iter , iactive, realizations_msg_list);

    {
      qc_module_type * qc_module = enkf_main_get_qc_module( enkf_main );
      runpath_list_type * runpath_list = qc_module_get_runpath_list( qc_module );

      for (iens = 0; iens < ens_size; ++iens) {
        if (bool_vector_iget(iactive , iens)) {
          const enkf_state_type * state = enkf_main_iget_state( enkf_main , iens );
          runpath_list_add( runpath_list , iens , enkf_state_get_run_path( state ) , enkf_state_get_eclbase( state ));
        }
      }
      qc_module_export_runpath_list( qc_module );
    }

    for (iens = 0; iens < ens_size; ++iens) {
      stringlist_type * msg_list = realizations_msg_list[iens];
      if (bool_vector_iget(iactive, iens)) {
        if (stringlist_get_size( msg_list )) {
          enkf_tui_display_load_msg( iens , msg_list );
        }
      }
      stringlist_free(msg_list);
    }
    free(realizations_msg_list);
  }

  bool_vector_free( iactive );
}
Esempio n. 10
0
static void test_export_runpath_file(ert_test_context_type * test_context,
                                    const char * job_name,
                                    const char * job_file,
                                    stringlist_type * args,
                                    int_vector_type * iens_values,
                                    int_vector_type * iter_values) {

  ert_test_context_install_workflow_job( test_context , job_name , job_file );
  test_assert_true( ert_test_context_run_worklow_job( test_context , job_name , args) );

  {
    const enkf_main_type * enkf_main = ert_test_context_get_main(test_context);
    qc_module_type * qc_module       = enkf_main_get_qc_module( enkf_main );
    const char * runpath_file_name   = qc_module_get_runpath_list_file(qc_module);

    ecl_config_type * ecl_config            = enkf_main_get_ecl_config(enkf_main);
    const model_config_type * model_config  = enkf_main_get_model_config(enkf_main);
    const char * base_fmt                   = ecl_config_get_eclbase(ecl_config);
    const char * runpath_fmt                = model_config_get_runpath_as_char(model_config);

    test_assert_true(util_file_exists(runpath_file_name));
    FILE * file = util_fopen(runpath_file_name, "r");

    int file_iens = 0;
    char file_path[256];
    char file_base[256];
    int file_iter = 0;
    char * cwd = util_alloc_cwd();
    int counter = 0;
    int iens_index = 0;
    int iter_index = 0;

    while (4 == fscanf( file , "%d %s %s %d" , &file_iens , file_path , file_base, &file_iter)) {
      ++ counter;

      test_assert_true(int_vector_size(iens_values) >= iens_index+1);
      test_assert_true(int_vector_size(iter_values) >= iter_index+1);

      int iens = int_vector_iget(iens_values, iens_index);
      int iter = int_vector_iget(iter_values, iter_index);

      test_assert_int_equal(file_iens, iens);
      test_assert_int_equal(file_iter, iter);

      char * base = util_alloc_sprintf("--%d", iens);
      if (base_fmt && (util_int_format_count(base_fmt) == 1))
        base = util_alloc_sprintf(base_fmt, iens);

      test_assert_string_equal(base, file_base);

      char * runpath = "";
      if (util_int_format_count(runpath_fmt) == 1)
        runpath = util_alloc_sprintf(runpath_fmt, iens);
      else if (util_int_format_count(runpath_fmt) == 2)
        runpath = util_alloc_sprintf(runpath_fmt, iens,iter);

      test_assert_string_equal(runpath, file_path);

      if (iens_index+1 < int_vector_size(iens_values))
        ++iens_index;
      else if ((iens_index+1 == int_vector_size(iens_values))) {
        ++iter_index;
        iens_index = 0;
      }

      free(base);
      free(runpath);
    }

    int linecount = int_vector_size(iens_values) * int_vector_size(iter_values);
    test_assert_int_equal(linecount, counter);
    free(cwd);
    fclose(file);
  }
}