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 ); }
int_vector_type * bool_vector_alloc_active_index_list(const bool_vector_type * mask , int default_value) { int_vector_type * index_list = int_vector_alloc(bool_vector_size( mask) , default_value); int active_index = 0; int i; for (i=0; i < bool_vector_size(mask); i++) { if (bool_vector_iget( mask , i)) { int_vector_iset(index_list , i , active_index); active_index++; } } return index_list; }
void rml_enkf_common_store_state( matrix_type * state , const matrix_type * A , const bool_vector_type * ens_mask ) { matrix_resize( state , matrix_get_rows( A ) , bool_vector_size( ens_mask ) , false); { const int ens_size = bool_vector_size( ens_mask ); int active_index = 0; for (int iens = 0; iens < ens_size; iens++) { if (bool_vector_iget( ens_mask , iens )) matrix_copy_column( state , A , iens , active_index ); else matrix_set_const_column( state , iens , 0); } } }
static void state_map_set_from_mask__( state_map_type * map , const bool_vector_type * mask , realisation_state_enum state, bool invert) { const bool * mask_ptr = bool_vector_get_ptr(mask); for (int i=0; i < bool_vector_size( mask); i++) { if (mask_ptr[i] != invert) state_map_iset(map , i , state); } }
void sched_history_fprintf( const sched_history_type * sched_history , const stringlist_type * key_list , FILE * stream) { int step = 1; time_t start_time = time_t_vector_iget( sched_history->time , 0); int total_length = bool_vector_size( sched_history->historical ); while (true) { if (bool_vector_safe_iget( sched_history->historical , step)) { { int mday,month,year; time_t t = time_t_vector_iget( sched_history->time , step ); double days = (t - start_time) * 1.0 / 86400; util_set_date_values_utc( t , &mday , &month , &year); //fprintf(stream , "%02d-%02d-%4d " , mday , month , year ); fprintf(stream , " %5.0f " , days); } for (int ikey =0; ikey < stringlist_get_size( key_list ); ikey++) fprintf(stream , "%16.3f " , sched_history_iget( sched_history , stringlist_iget( key_list , ikey) , step)); fprintf( stream, "\n"); } else break; // We have completed the historical period - and switched to prediction step++; if (step == total_length) break; } }
void matrix_column_compressed_memcpy(matrix_type * target, const matrix_type * src, const bool_vector_type * mask) { if (bool_vector_count_equal( mask , true ) != matrix_get_columns( target )) util_abort("%s: size mismatch. \n",__func__); if (bool_vector_size( mask ) != matrix_get_columns( src)) util_abort("%s: size mismatch. \n",__func__); { int target_col = 0; int src_col; for (src_col = 0; src_col < bool_vector_size( mask ); src_col++) { if (bool_vector_iget( mask , src_col)) { matrix_copy_column( target , src , target_col , src_col); target_col++; } } } }
int_vector_type * bool_vector_alloc_active_list( const bool_vector_type * mask ) { int_vector_type * active_list = int_vector_alloc(0,0); int i; for (i =0; i < bool_vector_size( mask ); i++) if (bool_vector_iget( mask , i )) int_vector_append( active_list , i ); return active_list; }
matrix_type * matrix_alloc_column_compressed_copy(const matrix_type * src, const bool_vector_type * mask) { if (bool_vector_size( mask ) != matrix_get_columns( src )) util_abort("%s: size mismatch. Src matrix has %d rows mask has:%d elements\n", __func__ , matrix_get_rows( src ) , bool_vector_size( mask )); { int target_columns = bool_vector_count_equal( mask , true ); matrix_type * target = matrix_alloc( matrix_get_rows( src ) , target_columns ); matrix_column_compressed_memcpy( target , src , mask ); return target; } }
stringlist_type * ert_run_context_alloc_runpath_list(const bool_vector_type * iactive , path_fmt_type * runpath_fmt , subst_list_type * subst_list , int iter) { stringlist_type * runpath_list = stringlist_alloc_new(); for (int iens = 0; iens < bool_vector_size( iactive ); iens++) { if (bool_vector_iget( iactive , iens )) stringlist_append_owned_ref( runpath_list , ert_run_context_alloc_runpath(iens , runpath_fmt , subst_list , iter)); else stringlist_append_ref( runpath_list , NULL ); } return runpath_list; }
static bool obs_vector_has_vector_data( const obs_vector_type * obs_vector , const bool_vector_type * active_mask , enkf_fs_type * fs) { int vec_size = bool_vector_size( active_mask ); for (int iens = 0; iens < vec_size; iens++) { const enkf_config_node_type * data_config = obs_vector->config_node; if (bool_vector_iget( active_mask , iens )) { if (!enkf_config_node_has_vector(data_config , fs , iens)) { return false; } } } return true; }
void rml_enkf_common_recover_state( const matrix_type * state , matrix_type * A , const bool_vector_type * ens_mask ) { const int ens_size = bool_vector_size( ens_mask ); const int active_size = bool_vector_count_equal( ens_mask , true ); const int rows = matrix_get_rows( state ); matrix_resize( A , rows , active_size , false ); { int active_index = 0; for (int iens = 0; iens < ens_size; iens++) { if (bool_vector_iget( ens_mask , iens )) matrix_copy_column( A , state , active_index , iens ); } } }
static void state_map_select_matching__( state_map_type * map , bool_vector_type * select_target , int select_mask , bool select) { state_map_assert_writable(map); pthread_rwlock_rdlock( &map->rw_lock ); { { const int * map_ptr = int_vector_get_ptr( map->state ); int size = util_int_min(int_vector_size( map->state ), bool_vector_size(select_target)); for (int i=0; i < size; i++) { int state_value = map_ptr[i]; if (state_value & select_mask) bool_vector_iset( select_target , i , select); } } pthread_rwlock_unlock( &map->rw_lock ); } }
ert_run_context_type * ert_run_context_alloc_ENSEMBLE_EXPERIMENT(enkf_fs_type * fs , const bool_vector_type * iactive , path_fmt_type * runpath_fmt , subst_list_type * subst_list , int iter) { ert_run_context_type * context = ert_run_context_alloc( iactive , ENSEMBLE_EXPERIMENT , fs , fs , NULL , iter); { stringlist_type * runpath_list = ert_run_context_alloc_runpath_list( iactive , runpath_fmt , subst_list , iter ); for (int iens = 0; iens < bool_vector_size( iactive ); iens++) { if (bool_vector_iget( iactive , iens )) { run_arg_type * arg = run_arg_alloc_ENSEMBLE_EXPERIMENT( fs , iens , iter , stringlist_iget( runpath_list , iens)); vector_append_owned_ref( context->run_args , arg , run_arg_free__); } } stringlist_free( runpath_list ); } return context; }
void test_index_list() { int_vector_type * index_list = int_vector_alloc( 0 , 0 ); int_vector_append( index_list , 10 ); int_vector_append( index_list , 20 ); int_vector_append( index_list , 30 ); { bool_vector_type * mask = int_vector_alloc_mask( index_list ); test_assert_false( bool_vector_get_default( mask )); test_assert_int_equal( 31 , bool_vector_size( mask )); test_assert_true( bool_vector_iget( mask , 10 )); test_assert_true( bool_vector_iget( mask , 20 )); test_assert_true( bool_vector_iget( mask , 30 )); test_assert_int_equal( 3 , bool_vector_count_equal( mask , true )); bool_vector_free( mask ); } int_vector_free( index_list ); }
static bool obs_vector_has_vector_data( const obs_vector_type * obs_vector , const bool_vector_type * active_mask , enkf_fs_type * fs) { bool has_data = true; int iens = 0; while (true) { const enkf_config_node_type * data_config = obs_vector->config_node; if (bool_vector_iget( active_mask , iens )) { if (!enkf_config_node_has_vector(data_config , fs , iens , FORECAST)) { has_data = false; break; } } iens++; if (iens >= bool_vector_size( active_mask )) break; } return has_data; }
static bool obs_vector_has_data_at_report_step( const obs_vector_type * obs_vector , const bool_vector_type * active_mask , enkf_fs_type * fs, int report_step) { void * obs_node = vector_iget( obs_vector->nodes , report_step ); if ( obs_node ) { node_id_type node_id = {.report_step = report_step }; for (int iens = 0; iens < bool_vector_size( active_mask ); iens++) { if (bool_vector_iget( active_mask , iens)) { node_id.iens = iens; if (! enkf_config_node_has_node(obs_vector->config_node , fs , node_id )) return false; } } } /* Will return true unconditionally if we do not have observation data at this report step; or alternatively if the active_mask is all false. */ return true; }
ert_run_context_type * ert_run_context_alloc_SMOOTHER_RUN(enkf_fs_type * simulate_fs , enkf_fs_type * target_update_fs , const bool_vector_type * iactive , path_fmt_type * runpath_fmt , subst_list_type * subst_list , int iter) { ert_run_context_type * context = ert_run_context_alloc( iactive , SMOOTHER_UPDATE , simulate_fs , simulate_fs , target_update_fs , iter); { stringlist_type * runpath_list = ert_run_context_alloc_runpath_list( iactive , runpath_fmt , subst_list , iter ); for (int iens = 0; iens < bool_vector_size( iactive ); iens++) { if (bool_vector_iget( iactive , iens )) { run_arg_type * arg = run_arg_alloc_SMOOTHER_RUN( simulate_fs , target_update_fs , iens , iter , stringlist_iget( runpath_list , iens)); vector_append_owned_ref( context->run_args , arg , run_arg_free__); } } stringlist_free( runpath_list ); } return context; }
static stringlist_type * ert_run_context_alloc_runpath_list(const bool_vector_type * iactive , path_fmt_type * runpath_fmt , subst_list_type * subst_list , int iter) { stringlist_type * runpath_list = stringlist_alloc_new(); for (int iens = 0; iens < bool_vector_size( iactive ); iens++) { if (bool_vector_iget( iactive , iens )) { char * tmp1 = path_fmt_alloc_path(runpath_fmt , false , iens, iter); /* 1: Replace first %d with iens, if a second %d replace with iter */ char * tmp2 = tmp1; if (subst_list) tmp2 = subst_list_alloc_filtered_string( subst_list , tmp1 ); /* 2: Filter out various magic strings like <CASE> and <CWD>. */ stringlist_append_copy( runpath_list , tmp2 ); if (subst_list) free( tmp2 ); free( tmp1 ); } else stringlist_append_ref( runpath_list , NULL ); } return runpath_list; }
void gen_data_config_update_active(gen_data_config_type * config, int report_step , const bool_vector_type * data_mask) { pthread_mutex_lock( &config->update_lock ); { if ( int_vector_iget( config->data_size_vector , report_step ) > 0) { if (config->active_report_step != report_step) { /* This is the first ensemeble member loading for this particular report_step. */ bool_vector_reset( config->active_mask ); bool_vector_iset( config->active_mask , int_vector_iget( config->data_size_vector , report_step ) - 1 , true ); config->mask_modified = true; } { int i; for (i=0; i < bool_vector_size( data_mask ); i++) { if (!bool_vector_iget( data_mask , i )) { bool_vector_iset( config->active_mask , i , false ); config->mask_modified = true; } } } if (config->mask_modified) { /** The global mask has been modified after the last load; i.e. we update the on-disk representation. */ char * filename = util_alloc_sprintf("%s_active" , config->key ); FILE * stream = enkf_fs_open_case_tstep_file( config->write_fs , filename , report_step , "w"); bool_vector_fwrite( config->active_mask , stream ); fclose( stream ); free( filename ); config->mask_modified = false; } } config->active_report_step = report_step; } pthread_mutex_unlock( &config->update_lock ); }
bool string_util_update_active_list( const char * range_string , int_vector_type * active_list ) { int_vector_sort( active_list ); { bool_vector_type * mask = alloc_mask( active_list ); bool valid = false; if (string_util_update_active_mask( range_string , mask )) { int_vector_reset( active_list ); { int i; for (i=0; i < bool_vector_size(mask); i++) { bool active = bool_vector_iget( mask , i ); if (active) int_vector_append( active_list , i ); } } valid = true; } bool_vector_free( mask ); return valid; } }
ert_run_context_type * ert_run_context_alloc_ENKF_ASSIMILATION(enkf_fs_type * fs , const bool_vector_type * iactive , path_fmt_type * runpath_fmt , subst_list_type * subst_list , init_mode_type init_mode , state_enum init_state_parameter , state_enum init_state_dynamic , int step1 , int step2 , int iter) { ert_run_context_type * context = ert_run_context_alloc( iactive , SMOOTHER_UPDATE , fs , fs , fs , init_mode , iter); { stringlist_type * runpath_list = ert_run_context_alloc_runpath_list( iactive , runpath_fmt , subst_list , iter ); for (int iens = 0; iens < bool_vector_size( iactive ); iens++) { if (bool_vector_iget( iactive , iens )) { run_arg_type * arg = run_arg_alloc_ENKF_ASSIMILATION( fs , iens , init_state_parameter , init_state_dynamic , step1 , step2 , stringlist_iget( runpath_list , iens)); vector_append_owned_ref( context->run_args , arg , run_arg_free__); } } stringlist_free( runpath_list ); } return context; }