void test_deselect_matching( ) { state_map_type * map = state_map_alloc( ); bool_vector_type * mask1 = bool_vector_alloc(0 , false); bool_vector_type * mask2 = bool_vector_alloc(1000 , true); state_map_iset( map , 10 , STATE_INITIALIZED ); state_map_iset( map , 10 , STATE_HAS_DATA ); state_map_iset( map , 20 , STATE_INITIALIZED ); state_map_deselect_matching( map , mask1 , STATE_HAS_DATA | STATE_INITIALIZED ); state_map_deselect_matching( map , mask2 , STATE_HAS_DATA | STATE_INITIALIZED ); test_assert_int_equal( state_map_get_size( map ) , bool_vector_size( mask1 )); for (int i=0; i < bool_vector_size( mask1 ); i++) { if (i==10) test_assert_false( bool_vector_iget( mask1 , i )); else if (i== 20) test_assert_false( bool_vector_iget( mask2 , i )); else { test_assert_false( bool_vector_iget( mask1 , i )); test_assert_true( bool_vector_iget( mask2 , i )); } } bool_vector_free( mask1 ); bool_vector_free( mask2 ); state_map_free( map ); }
static bool_vector_type * alloc_iactive_vector_from_range(const stringlist_type * range, int startindex, int ens_size) { bool_vector_type * iactive; if (stringlist_get_size(range) > startindex) { char * arg_string = stringlist_alloc_joined_substring( range, startindex, stringlist_get_size(range), ""); iactive = bool_vector_alloc(ens_size, false); string_util_update_active_mask( arg_string, iactive ); free ( arg_string ); } else { iactive = bool_vector_alloc(ens_size, true); } return iactive; }
void enkf_tui_run_exp(void * enkf_main) { const int ens_size = enkf_main_get_ensemble_size( enkf_main ); bool_vector_type * iactive = bool_vector_alloc(0,false); state_enum init_state = ANALYZED; int start_report = 0; int init_step_parameters = 0; { char * prompt = util_alloc_sprintf("Which realizations to simulate (Ex: 1,3-5) <Enter for all> [M to return to menu] : " , 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 ); } if (bool_vector_count_equal(iactive , true)) enkf_main_run_exp(enkf_main , iactive , true , init_step_parameters , start_report , init_state, true); bool_vector_free(iactive); }
static void * enkf_main_smoother_JOB__( void * self , int iter , const stringlist_type * args ) { enkf_main_type * enkf_main = enkf_main_safe_cast( self ); int ens_size = enkf_main_get_ensemble_size( enkf_main ); bool_vector_type * iactive = bool_vector_alloc( ens_size , true ); bool valid = true; const char * target_case; enkf_fs_type * target_fs = enkf_main_get_fs( enkf_main ); // Argument 0: Which case to write to. Default current case. if (stringlist_get_size(args)) { target_case = stringlist_iget( args , 0 ); if (strcmp( target_case , CURRENT_CASE_STRING) == 0) target_case = enkf_fs_get_case_name(target_fs); } else target_case = enkf_fs_get_case_name(target_fs); //Argument 1: Rerun. Default false. bool rerun = (stringlist_get_size(args) >= 2) ? stringlist_iget_as_bool(args, 1, &valid) : false; if (!valid) { fprintf(stderr, "** Warning: Function %s : Second argument must be a bool value. Exiting job\n", __func__); return NULL; } enkf_main_run_smoother( enkf_main , target_case , iactive , iter , rerun); bool_vector_free( iactive ); return NULL; }
void enkf_plot_gen_kw_load( enkf_plot_gen_kw_type * plot_gen_kw, enkf_fs_type * fs, bool transform_data , int report_step, const bool_vector_type * input_mask ) { state_map_type * state_map = enkf_fs_get_state_map( fs ); int ens_size = state_map_get_size( state_map ); bool_vector_type * mask; if (input_mask) mask = bool_vector_alloc_copy( input_mask ); else mask = bool_vector_alloc( ens_size , true ); enkf_plot_gen_kw_resize( plot_gen_kw , ens_size ); { int iens; for (iens = 0; iens < ens_size; ++iens) { if (bool_vector_iget( mask , iens)) { enkf_plot_gen_kw_vector_type * vector = enkf_plot_gen_kw_iget( plot_gen_kw , iens ); enkf_plot_gen_kw_vector_load( vector , fs , transform_data , report_step ); } } } }
void enkf_tui_run_smoother(void * arg) { enkf_main_type * enkf_main = enkf_main_safe_cast( arg ); int ens_size = enkf_main_get_ensemble_size( enkf_main ); bool_vector_type * iactive = bool_vector_alloc( ens_size , true ); enkf_main_run_smoother(enkf_main , "AUTO-SMOOTHER" , iactive , 0 , true ); bool_vector_free( iactive ); }
void enkf_tui_fs_initialize_case_from_copy(void * arg) { int prompt_len =50; char * source_case; int ens_size; int last_report; int src_step; state_enum src_state; enkf_main_type * enkf_main = enkf_main_safe_cast( arg ); ens_size = enkf_main_get_ensemble_size( enkf_main ); last_report = enkf_main_get_history_length( enkf_main ); source_case = enkf_tui_fs_alloc_existing_case( enkf_main , "Initialize from case" , prompt_len); if (source_case != NULL) { char * ranking_key = NULL; bool_vector_type * iens_mask = bool_vector_alloc( 0 , true ); src_step = util_scanf_int_with_limits("Source report step",prompt_len , 0 , last_report); src_state = enkf_tui_util_scanf_state("Source analyzed/forecast [A|F]" , prompt_len , false); enkf_main_initialize_from_existing( enkf_main , source_case , src_step , src_state , iens_mask , ranking_key ); bool_vector_free( iens_mask ); } util_safe_free( source_case ); }
int main(int argc , char ** argv) { enkf_main_install_SIGNALS(); const char * config_file = argv[1]; ert_test_context_type * test_context = ert_test_context_alloc("VerifyJobsFileTest" , config_file); enkf_main_type * enkf_main = ert_test_context_get_main(test_context); { const int ens_size = enkf_main_get_ensemble_size( enkf_main ); bool_vector_type * iactive = bool_vector_alloc(0, false); bool_vector_iset( iactive , ens_size - 1 , true ); enkf_main_create_run_path(enkf_main , iactive , 0); bool_vector_free(iactive); } const char * filename = util_alloc_filename(ert_test_context_get_cwd(test_context), "simulations/run0/jobs.py", NULL); const char * jobs_file_content = util_fread_alloc_file_content(filename, NULL); test_assert_true (strstr(jobs_file_content, "umask = 0022") != NULL); test_assert_false (strstr(jobs_file_content, "umask = 0023") != NULL); test_assert_false (strstr(jobs_file_content, "umask = 0032") != NULL); test_assert_false (strstr(jobs_file_content, "umask = 0122") != NULL); test_assert_false (strstr(jobs_file_content, "umask = 1022") != NULL); ert_test_context_free(test_context); exit(0); }
void enkf_tui_run_restart__(void * enkf_main) { const int ens_size = enkf_main_get_ensemble_size( enkf_main ); const int last_report = enkf_main_get_history_length( enkf_main ); int start_report; char * start_report_as_char; bool wronginput = false; state_enum state; bool_vector_type * iactive = bool_vector_alloc(0,true); bool_vector_iset( iactive , ens_size - 1 , true ); start_report_as_char = util_scanf_int_with_limits_return_char("Report step",PROMPT_LEN , 0 , last_report); if(strlen(start_report_as_char) != 0){ util_sscanf_int(start_report_as_char , &start_report); } else wronginput = true; if(!wronginput){ state = enkf_tui_util_scanf_state("Analyzed/forecast" , PROMPT_LEN , false); if(state == UNDEFINED) wronginput = true; } if(!wronginput) enkf_main_run_assimilation(enkf_main , iactive , start_report , start_report , state); bool_vector_free(iactive); free(start_report_as_char); }
static gen_data_config_type * gen_data_config_alloc( const char * key , bool dynamic ) { gen_data_config_type * config = util_malloc(sizeof * config ); UTIL_TYPE_ID_INIT( config , GEN_DATA_CONFIG_ID); config->key = util_alloc_string_copy( key ); config->template_file = NULL; config->template_key = NULL; config->template_buffer = NULL; gen_data_config_reset_template( config ); config->data_size = 0; config->internal_type = ECL_DOUBLE_TYPE; config->input_format = GEN_DATA_UNDEFINED; config->output_format = GEN_DATA_UNDEFINED; config->data_size_vector = int_vector_alloc( 0 , -1 ); /* The default value: -1 - indicates "NOT SET" */ config->active_report_steps= int_vector_alloc( 0 , 0 ); config->active_mask = bool_vector_alloc(0 , true ); /* Elements are explicitly set to FALSE - this MUST default to true. */ config->active_report_step = -1; config->ens_size = -1; config->read_fs = NULL; config->write_fs = NULL; config->dynamic = dynamic; pthread_mutex_init( &config->update_lock , NULL ); return config; }
void test_active_index_list() { int default_value = -1; bool_vector_type * mask = bool_vector_alloc(0 , false); bool_vector_iset(mask , 10, true); bool_vector_iset(mask , 15, true); bool_vector_iset(mask , 20, true); { int_vector_type * active_index_list = bool_vector_alloc_active_index_list(mask , default_value); test_assert_int_equal( default_value , int_vector_get_default(active_index_list)); test_assert_int_equal( 21 , int_vector_size( active_index_list )); test_assert_int_equal( default_value , int_vector_iget( active_index_list , 0)); test_assert_int_equal( default_value , int_vector_iget( active_index_list , 1)); test_assert_int_equal( default_value , int_vector_iget( active_index_list , 12)); test_assert_int_equal( default_value , int_vector_iget( active_index_list , 19)); test_assert_int_equal( 0 , int_vector_iget( active_index_list , 10)); test_assert_int_equal( 1 , int_vector_iget( active_index_list , 15)); test_assert_int_equal( 2 , int_vector_iget( active_index_list , 20)); int_vector_free( active_index_list); } bool_vector_free(mask); }
void test_set_from_mask() { int i; state_map_type * map1 = state_map_alloc(); state_map_type * map2 = state_map_alloc(); bool_vector_type * mask = bool_vector_alloc(0, false); bool_vector_iset(mask , 10 , true); bool_vector_iset(mask , 20 , true); state_map_set_from_mask(map1 , mask , STATE_INITIALIZED); state_map_set_from_inverted_mask(map2 , mask , STATE_INITIALIZED); test_assert_int_equal(21 , state_map_get_size(map1)); test_assert_int_equal(21 , state_map_get_size(map2)); for (i = 0; i < state_map_get_size(map1); i++) { if (i == 10 || i== 20) { test_assert_int_equal( STATE_INITIALIZED , state_map_iget( map1 , i) ); test_assert_int_equal( STATE_UNDEFINED , state_map_iget(map2 , i)); } else { test_assert_int_equal(STATE_UNDEFINED , state_map_iget(map1 , i )); test_assert_int_equal( STATE_INITIALIZED , state_map_iget(map2 , i)); } } }
void enkf_main_init_case_from_existing(const enkf_main_type * enkf_main, enkf_fs_type * source_case_fs, int source_report_step, state_enum source_state, enkf_fs_type * target_case_fs ) { stringlist_type * param_list = ensemble_config_alloc_keylist_from_var_type( enkf_main_get_ensemble_config(enkf_main) , PARAMETER ); /* Select only paramters - will fail for GEN_DATA of type DYNAMIC_STATE. */ int target_report_step = 0; state_enum target_state = ANALYZED; bool_vector_type * iactive = bool_vector_alloc( 0 , true ); enkf_main_copy_ensemble(enkf_main, source_case_fs, source_report_step, source_state, target_case_fs, target_report_step, target_state , iactive, NULL, param_list); enkf_fs_fsync(target_case_fs); bool_vector_free(iactive); stringlist_free(param_list); }
static bool_vector_type * alloc_mask( const int_vector_type * active_list ) { bool_vector_type * mask = bool_vector_alloc( 0 , false ); int i; for (i=0; i < int_vector_size( active_list ); i++) bool_vector_iset( mask , int_vector_iget( active_list , i) , true ); return mask; }
void enkf_tui_run_start(void * enkf_main) { const int ens_size = enkf_main_get_ensemble_size( enkf_main ); bool_vector_type * iactive = bool_vector_alloc(ens_size , true); enkf_main_run_assimilation(enkf_main , iactive , 0 , 0 , ANALYZED); bool_vector_free(iactive); }
ecl_sum_vector_type * ecl_sum_vector_alloc(const ecl_sum_type * ecl_sum){ ecl_sum_vector_type * ecl_sum_vector = util_malloc( sizeof * ecl_sum_vector ); UTIL_TYPE_ID_INIT( ecl_sum_vector , ECL_SUM_VECTOR_TYPE_ID); ecl_sum_vector->ecl_sum = ecl_sum; ecl_sum_vector->node_index_list = int_vector_alloc(0,0); ecl_sum_vector->is_rate_list = bool_vector_alloc(0,false); return ecl_sum_vector; }
void create_runpath(enkf_main_type * enkf_main ) { const int ens_size = enkf_main_get_ensemble_size( enkf_main ); bool_vector_type * iactive = bool_vector_alloc(0,false); bool_vector_iset( iactive , ens_size - 1 , true ); enkf_main_run_exp(enkf_main , iactive , false ); bool_vector_free(iactive); }
gen_data_type * gen_data_alloc(const gen_data_config_type * config) { gen_data_type * gen_data = util_malloc(sizeof * gen_data); gen_data->config = (gen_data_config_type *) config; gen_data->data = NULL; gen_data->__type_id = GEN_DATA; gen_data->active_mask = bool_vector_alloc( 0 , true ); gen_data->current_report_step = -1; /* God - if you ever read this .... */ return gen_data; }
void test_invalid_obs_vector( enkf_main_type * enkf_main , const char * obs_key) { enkf_fs_type * fs = enkf_main_get_fs(enkf_main); enkf_obs_type * enkf_obs = enkf_main_get_obs( enkf_main ); obs_vector_type * obs_vector = enkf_obs_get_vector( enkf_obs , obs_key ); bool_vector_type * active_mask = bool_vector_alloc( enkf_main_get_ensemble_size( enkf_main ) , true); test_assert_false( obs_vector_has_data( obs_vector , active_mask , fs )); bool_vector_free( active_mask ); }
void * enkf_main_assimilation_JOB( void * self , const stringlist_type * args ) { enkf_main_type * enkf_main = enkf_main_safe_cast( self ); int ens_size = enkf_main_get_ensemble_size( enkf_main ); bool_vector_type * iactive = bool_vector_alloc( 0 , true ); bool_vector_iset( iactive , ens_size - 1 , true ); enkf_main_run_assimilation( enkf_main , iactive , 0 , 0 , ANALYZED ); return NULL; }
void misfit_ensemble_initialize( misfit_ensemble_type * misfit_ensemble , const ensemble_config_type * ensemble_config , const enkf_obs_type * enkf_obs , enkf_fs_type * fs , int ens_size , int history_length, bool force_init) { if (force_init || !misfit_ensemble->initialized) { misfit_ensemble_clear( misfit_ensemble ); msg_type * msg = msg_alloc("Evaluating misfit for observation: " , false); double ** chi2_work = __2d_malloc( history_length + 1 , ens_size ); bool_vector_type * iens_valid = bool_vector_alloc( ens_size , true ); hash_iter_type * obs_iter = enkf_obs_alloc_iter( enkf_obs ); const char * obs_key = hash_iter_get_next_key( obs_iter ); misfit_ensemble->history_length = history_length; misfit_ensemble_set_ens_size( misfit_ensemble , ens_size ); msg_show( msg ); while (obs_key != NULL) { obs_vector_type * obs_vector = enkf_obs_get_vector( enkf_obs , obs_key ); msg_update( msg , obs_key ); bool_vector_reset( iens_valid ); bool_vector_iset( iens_valid , ens_size - 1 , true ); obs_vector_ensemble_chi2( obs_vector , fs , iens_valid , 0 , misfit_ensemble->history_length, 0 , ens_size , chi2_work); /** Internalizing the results from the chi2_work table into the misfit structure. */ for (int iens = 0; iens < ens_size; iens++) { misfit_member_type * node = misfit_ensemble_iget_member( misfit_ensemble , iens ); if (bool_vector_iget( iens_valid , iens)) misfit_member_update( node , obs_key , misfit_ensemble->history_length , iens , (const double **) chi2_work); } obs_key = hash_iter_get_next_key( obs_iter ); } bool_vector_free( iens_valid ); msg_free(msg , true ); hash_iter_free( obs_iter ); __2d_free( chi2_work , misfit_ensemble->history_length + 1); misfit_ensemble->initialized = true; } }
void test_container( ert_test_context_type * test_context ) { enkf_main_type * enkf_main = ert_test_context_get_main( test_context ); enkf_obs_type * enkf_obs = enkf_main_get_obs( enkf_main ); obs_vector_type * rft_obs = enkf_obs_get_vector( enkf_obs , "RFT_TEST"); enkf_fs_type * fs = enkf_main_get_fs( enkf_main ); bool_vector_type * active_mask = bool_vector_alloc( enkf_main_get_ensemble_size( enkf_main ) , true ); test_assert_true( obs_vector_has_data( rft_obs , active_mask , fs )); bool_vector_free( active_mask ); }
void create_runpath(enkf_main_type * enkf_main ) { const int ens_size = enkf_main_get_ensemble_size( enkf_main ); bool_vector_type * iactive = bool_vector_alloc(0,false); state_enum init_state = ANALYZED; int start_report = 0; int init_step_parameters = 0; bool_vector_iset( iactive , ens_size - 1 , true ); enkf_main_run_exp(enkf_main , iactive , false , init_step_parameters , start_report , init_state); bool_vector_free(iactive); }
void * enkf_main_smoother_JOB( void * self , const stringlist_type * args ) { enkf_main_type * enkf_main = enkf_main_safe_cast( self ); int ens_size = enkf_main_get_ensemble_size( enkf_main ); bool_vector_type * iactive = bool_vector_alloc( 0 , true ); bool rerun = true; const char * target_case = stringlist_iget( args , 0 ); bool_vector_iset( iactive , ens_size - 1 , true ); enkf_main_run_smoother( enkf_main , target_case , rerun); return NULL; }
void enkf_main_initialize_from_scratch(enkf_main_type * enkf_main , const stringlist_type * param_list , int iens1 , int iens2, init_mode_type init_mode) { int iens; int ens_size = enkf_main_get_ensemble_size( enkf_main ); bool_vector_type * iens_mask = bool_vector_alloc(ens_size,false); for (iens = iens1; iens <= iens2; iens++) { bool_vector_iset( iens_mask , iens , true ); } enkf_main_initialize_from_scratch_with_bool_vector(enkf_main, param_list, iens_mask, init_mode); bool_vector_free(iens_mask); }
void * enkf_main_ensemble_run_JOB( void * self , const stringlist_type * args ) { enkf_main_type * enkf_main = enkf_main_safe_cast( self ); int ens_size = enkf_main_get_ensemble_size( enkf_main ); bool_vector_type * iactive = bool_vector_alloc( 0 , true ); // Ignore args until string_utils is in place ..... // if (stringlist_get_size( args ) bool_vector_iset( iactive , ens_size - 1 , true ); enkf_main_run_exp( enkf_main , iactive , true , 0 , 0 , ANALYZED ); return NULL; }
model_config_type * model_config_alloc() { model_config_type * model_config = util_malloc(sizeof * model_config ); /** There are essentially three levels of initialisation: 1. Initialize to NULL / invalid. 2. Initialize with default values. 3. Initialize with user supplied values. */ UTIL_TYPE_ID_INIT(model_config , MODEL_CONFIG_TYPE_ID); model_config->case_names = NULL; model_config->enspath = NULL; model_config->rftpath = NULL; model_config->dbase_type = INVALID_DRIVER_ID; model_config->current_runpath = NULL; model_config->current_path_key = NULL; model_config->enkf_sched = NULL; model_config->enkf_sched_file = NULL; model_config->case_table_file = NULL; model_config->select_case = NULL; model_config->history = NULL; model_config->jobname_fmt = NULL; model_config->forward_model = NULL; model_config->internalize_state = bool_vector_alloc( 0 , false ); model_config->__load_state = bool_vector_alloc( 0 , false ); model_config->history_source = HISTORY_SOURCE_INVALID; model_config->runpath_map = hash_alloc(); model_config->gen_kw_export_file_name = NULL; model_config_set_enspath( model_config , DEFAULT_ENSPATH ); model_config_set_rftpath( model_config , DEFAULT_RFTPATH ); model_config_set_dbase_type( model_config , DEFAULT_DBASE_TYPE ); model_config_set_max_internal_submit( model_config , DEFAULT_MAX_INTERNAL_SUBMIT); model_config_add_runpath( model_config , DEFAULT_RUNPATH_KEY , DEFAULT_RUNPATH); model_config_select_runpath( model_config , DEFAULT_RUNPATH_KEY ); model_config_set_gen_kw_export_file(model_config, DEFAULT_GEN_KW_EXPORT_FILE); return model_config; }
void ecl_sum_fprintf(const ecl_sum_type * ecl_sum , FILE * stream , const stringlist_type * var_list , bool report_only , const ecl_sum_fmt_type * fmt) { bool_vector_type * has_var = bool_vector_alloc( stringlist_get_size( var_list ), false ); int_vector_type * var_index = int_vector_alloc( stringlist_get_size( var_list ), -1 ); char * date_string = util_malloc( DATE_STRING_LENGTH * sizeof * date_string); char * current_locale = NULL; if (fmt->locale != NULL) current_locale = setlocale(LC_NUMERIC , fmt->locale); { int ivar; for (ivar = 0; ivar < stringlist_get_size( var_list ); ivar++) { if (ecl_sum_has_general_var( ecl_sum , stringlist_iget( var_list , ivar) )) { bool_vector_iset( has_var , ivar , true ); int_vector_iset( var_index , ivar , ecl_sum_get_general_var_params_index( ecl_sum , stringlist_iget( var_list , ivar) )); } else { fprintf(stderr,"** Warning: could not find variable: \'%s\' in summary file \n", stringlist_iget( var_list , ivar)); bool_vector_iset( has_var , ivar , false ); } } } if (fmt->print_header) ecl_sum_fprintf_header( ecl_sum , var_list , has_var , stream , fmt); if (report_only) { int first_report = ecl_sum_get_first_report_step( ecl_sum ); int last_report = ecl_sum_get_last_report_step( ecl_sum ); int report; for (report = first_report; report <= last_report; report++) { if (ecl_sum_data_has_report_step(ecl_sum->data , report)) { int time_index; time_index = ecl_sum_data_iget_report_end( ecl_sum->data , report ); __ecl_sum_fprintf_line( ecl_sum , stream , time_index , has_var , var_index , date_string , fmt); } } } else { int time_index; for (time_index = 0; time_index < ecl_sum_get_data_length( ecl_sum ); time_index++) __ecl_sum_fprintf_line( ecl_sum , stream , time_index , has_var , var_index , date_string , fmt); } int_vector_free( var_index ); bool_vector_free( has_var ); if (current_locale != NULL) setlocale( LC_NUMERIC , current_locale); free( date_string ); }
/* (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); } }
static stepwise_type * stepwise_alloc__( int nsample , int nvar , rng_type * rng) { stepwise_type * stepwise = util_malloc( sizeof * stepwise ); stepwise->X_mean = NULL; stepwise->X_norm = NULL; stepwise->Y_mean = 0.0; stepwise->rng = rng; stepwise->X0 = NULL; stepwise->E0 = NULL; stepwise->Y0 = NULL; stepwise->active_set = bool_vector_alloc( nvar , true ); stepwise->beta = matrix_alloc( nvar , 1 ); return stepwise; }