bool stringlist_iget_as_bool( const stringlist_type * stringlist, int index, bool * valid) { const char * string_value = stringlist_iget( stringlist, index); bool value = false; if (valid != NULL) *valid = false; if (util_sscanf_bool(string_value , &value)) if (valid != NULL) *valid = true; return value; }
int main(int argc , char ** argv) { enkf_main_install_SIGNALS(); const char * root_path = argv[1]; const char * config_file = argv[2]; const char * init_file = argv[3]; const char * forward_init_string = argv[4]; test_work_area_type * work_area = test_work_area_alloc(config_file ); test_work_area_copy_directory_content( work_area , root_path ); test_work_area_install_file( work_area , init_file ); test_work_area_set_store(work_area, true); bool strict = true; enkf_main_type * enkf_main = enkf_main_bootstrap( NULL , config_file , strict , true ); enkf_fs_type * init_fs = enkf_main_get_fs(enkf_main); enkf_state_type * state = enkf_main_iget_state( enkf_main , 0 ); run_arg_type * run_arg = run_arg_alloc_ENSEMBLE_EXPERIMENT( init_fs , 0 ,0 , "simulations/run0"); enkf_node_type * field_node = enkf_state_get_node( state , "PORO" ); bool forward_init; test_assert_true( util_sscanf_bool( forward_init_string , &forward_init)); test_assert_bool_equal( enkf_node_use_forward_init( field_node ) , forward_init ); test_assert_bool_equal( forward_init, ensemble_config_have_forward_init( enkf_main_get_ensemble_config( enkf_main ))); util_clear_directory( "Storage" , true , true ); create_runpath( enkf_main ); test_assert_true( util_is_directory( "simulations/run0" )); if (forward_init) util_copy_file( init_file , "simulations/run0/petro.grdecl"); { bool_vector_type * iactive = bool_vector_alloc( enkf_main_get_ensemble_size(enkf_main) , true); int error = 0; stringlist_type * msg_list = stringlist_alloc_new(); enkf_state_load_from_forward_model( state , run_arg , &error , false , msg_list ); stringlist_free( msg_list ); bool_vector_free( iactive ); test_assert_int_equal(error, 0); } test_assert_true(check_original_exported_data_equal(field_node)); run_arg_free( run_arg ); enkf_main_free(enkf_main); test_work_area_free(work_area); }
void ensemble_config_init_SURFACE( ensemble_config_type * ensemble_config , const config_type * config ) { const config_content_item_type * item = config_get_content_item( config , SURFACE_KEY ); if (item != NULL) { int i; for (i=0; i < config_content_item_get_size( item ); i++) { const config_content_node_type * node = config_content_item_iget_node( item , i ); const char * key = config_content_node_iget( node , 0 ); { hash_type * options = hash_alloc(); /* INIT_FILE:<init_files> OUTPUT_FILE:<outfile> BASE_SURFACE:<base_file> */ config_content_node_init_opt_hash( node , options , 1 ); { const char * init_file_fmt = hash_safe_get( options , INIT_FILES_KEY ); const char * output_file = hash_safe_get( options , OUTPUT_FILE_KEY); const char * base_surface = hash_safe_get( options , BASE_SURFACE_KEY); const char * min_std_file = hash_safe_get( options , MIN_STD_KEY); const char * forward_string = hash_safe_get( options , FORWARD_INIT_KEY ); bool forward_init = false; if (forward_string) { if (!util_sscanf_bool( forward_string , &forward_init)) fprintf(stderr,"** Warning: parsing %s as bool failed - using FALSE \n",forward_string); } if ((init_file_fmt == NULL) || (output_file == NULL) || (base_surface == NULL)) { fprintf(stderr,"** error: when entering a surface you must provide arguments:\n"); fprintf(stderr,"** %s:/path/to/input/files%%d \n",INIT_FILES_KEY); fprintf(stderr,"** %s:name_of_output_file\n", OUTPUT_FILE_KEY); fprintf(stderr,"** %s:base_surface_file\n",BASE_SURFACE_KEY); exit(1); } { enkf_config_node_type * config_node = ensemble_config_add_surface( ensemble_config , key , forward_init); enkf_config_node_update_surface( config_node , base_surface , init_file_fmt , output_file , min_std_file ); } } hash_free( options ); } } } }
int main( int argc , char ** argv) { const char * case1 = argv[1]; const char * case2 = argv[2]; const char * compatible_string = argv[3]; bool compatible; ecl_sum_type * ecl_sum1 = ecl_sum_fread_alloc_case( case1 , ":"); ecl_sum_type * ecl_sum2 = ecl_sum_fread_alloc_case( case2 , ":"); test_assert_true( ecl_sum_is_instance( ecl_sum1 )); test_assert_true( ecl_sum_is_instance( ecl_sum2 )); test_assert_true( ecl_sum_report_step_compatible( ecl_sum1 , ecl_sum1) ); test_assert_true( util_sscanf_bool( compatible_string , &compatible )); test_assert_true( ecl_sum_report_step_compatible( ecl_sum1 , ecl_sum1) ); test_assert_true( ecl_sum_report_step_compatible( ecl_sum2 , ecl_sum2) ); test_assert_bool_equal( compatible , ecl_sum_report_step_compatible( ecl_sum1 , ecl_sum2 )); ecl_sum_free( ecl_sum1 ); ecl_sum_free( ecl_sum2 ); exit(0); }
bool config_schema_item_valid_string(config_item_types value_type , const char * value) { switch(value_type) { case(CONFIG_ISODATE): return util_sscanf_isodate( value , NULL ); break; case(CONFIG_INT): return util_sscanf_int( value , NULL ); break; case(CONFIG_FLOAT): return util_sscanf_double( value , NULL ); break; case(CONFIG_BOOL): return util_sscanf_bool( value , NULL ); break; case(CONFIG_BYTESIZE): return util_sscanf_bytesize( value , NULL); break; default: return true; } }
void plot_config_init(plot_config_type * plot_config , const config_type * config ) { if (config_item_set( config , PLOT_PATH_KEY)) plot_config_set_path( plot_config , config_get_value( config , PLOT_PATH_KEY )); if (config_item_set( config , PLOT_DRIVER_KEY)) plot_config_set_driver( plot_config , config_get_value( config , PLOT_DRIVER_KEY )); if (config_item_set( config , IMAGE_VIEWER_KEY)) plot_config_set_viewer( plot_config , config_get_value( config , IMAGE_VIEWER_KEY )); if (config_item_set( config , PLOT_DRIVER_KEY)) plot_config_set_driver( plot_config , config_get_value( config , PLOT_DRIVER_KEY )); if (config_item_set( config , PLOT_ERRORBAR_MAX_KEY)) plot_config_set_errorbar_max( plot_config , config_get_value_as_int( config , PLOT_ERRORBAR_MAX_KEY )); if (config_item_set( config , PLOT_ERRORBAR_KEY)) plot_config_set_plot_errorbar( plot_config , config_get_value_as_bool( config , PLOT_ERRORBAR_KEY )); if (config_item_set( config , PLOT_HEIGHT_KEY)) plot_config_set_height( plot_config , config_get_value_as_int( config , PLOT_HEIGHT_KEY )); if (config_item_set( config , PLOT_WIDTH_KEY)) plot_config_set_width( plot_config , config_get_value_as_int( config , PLOT_WIDTH_KEY )); if (config_item_set( config , PLOT_REFCASE_KEY)) { const char * plot_refcase_string = config_get_value( config , PLOT_REFCASE_KEY ); bool plot_refcase; if (!util_sscanf_bool( plot_refcase_string , &plot_refcase)) { fprintf(stderr , "Warning: The PLOT_REFCASE option should have value True | False. The value:%s will be interpreted as True" , plot_refcase_string); plot_refcase = true; } plot_config_set_plot_refcase( plot_config , plot_refcase ); } }
bool analysis_module_set_var( analysis_module_type * module , const char * var_name , const char * string_value ) { bool set_ok = false; { int int_value; if (util_sscanf_int( string_value , &int_value )) set_ok = analysis_module_set_int( module , var_name , int_value ); if (set_ok) return true; } { double double_value; if (util_sscanf_double( string_value , &double_value )) set_ok = analysis_module_set_double( module , var_name , double_value ); if (set_ok) return true; } { bool bool_value; if (util_sscanf_bool( string_value , &bool_value)) set_ok = analysis_module_set_bool( module , var_name , bool_value ); if (set_ok) return true; } set_ok = analysis_module_set_string( module , var_name , string_value ); if (!set_ok) fprintf(stderr,"** Warning: failed to set %s=%s for analysis module:%s\n", var_name , string_value , module->user_name); return set_ok; }
void ensemble_config_init_GEN_KW( ensemble_config_type * ensemble_config , const config_type * config ) { const config_content_item_type * gen_kw_item = config_get_content_item( config , GEN_KW_KEY ); if (gen_kw_item != NULL) { int i; for (i=0; i < config_content_item_get_size( gen_kw_item ); i++) { config_content_node_type * node = config_content_item_iget_node( gen_kw_item , i ); const char * key = config_content_node_iget( node , 0 ); const char * template_file = config_content_node_iget_as_path( node , 1 ); const char * enkf_outfile = config_content_node_iget( node , 2 ); const char * parameter_file = config_content_node_iget_as_path( node , 3 ); hash_type * opt_hash = hash_alloc(); config_content_node_init_opt_hash( node , opt_hash , 4 ); { const char * forward_string = hash_safe_get( opt_hash , FORWARD_INIT_KEY ); enkf_config_node_type * config_node; bool forward_init = false; if (forward_string) { if (!util_sscanf_bool( forward_string , &forward_init)) fprintf(stderr,"** Warning: parsing %s as bool failed - using FALSE \n",forward_string); } config_node = ensemble_config_add_gen_kw( ensemble_config , key , forward_init); enkf_config_node_update_gen_kw( config_node , enkf_outfile , template_file , parameter_file , hash_safe_get( opt_hash , MIN_STD_KEY ) , hash_safe_get( opt_hash , INIT_FILES_KEY)); } hash_free( opt_hash ); } } }
bool config_content_item_iget_as_bool(const config_content_item_type * item, int occurence , int index) { bool value; config_schema_item_assure_type(item->schema , index , CONFIG_BOOL); util_sscanf_bool( config_content_item_iget(item , occurence ,index) , &value ); return value; }
int main(int argc , char ** argv) { enkf_main_install_SIGNALS(); const char * root_path = argv[1]; const char * config_file = argv[2]; const char * forward_init_string = argv[3]; test_work_area_type * work_area = test_work_area_alloc(config_file , false); test_work_area_copy_directory_content( work_area , root_path ); { bool forward_init; bool strict = true; enkf_main_type * enkf_main; test_assert_true( util_sscanf_bool( forward_init_string , &forward_init)); util_clear_directory( "Storage" , true , true ); enkf_main = enkf_main_bootstrap( NULL , config_file , strict , true ); { enkf_state_type * state = enkf_main_iget_state( enkf_main , 0 ); enkf_node_type * gen_param_node = enkf_state_get_node( state , "PARAM" ); { const enkf_config_node_type * gen_param_config_node = enkf_node_get_config( gen_param_node ); char * init_file1 = enkf_config_node_alloc_initfile( gen_param_config_node , NULL , 0); char * init_file2 = enkf_config_node_alloc_initfile( gen_param_config_node , "/tmp", 0); test_assert_bool_equal( enkf_config_node_use_forward_init( gen_param_config_node ) , forward_init ); test_assert_string_equal( init_file1 , "PARAM_INIT"); test_assert_string_equal( init_file2 , "/tmp/PARAM_INIT"); free( init_file1 ); free( init_file2 ); } test_assert_bool_equal( enkf_node_use_forward_init( gen_param_node ) , forward_init ); if (forward_init) test_assert_bool_not_equal( enkf_node_initialize( gen_param_node , 0 , enkf_state_get_rng( state )) , forward_init); // else hard_failure() } test_assert_bool_equal( forward_init, ensemble_config_have_forward_init( enkf_main_get_ensemble_config( enkf_main ))); if (forward_init) { enkf_state_type * state = enkf_main_iget_state( enkf_main , 0 ); enkf_fs_type * fs = enkf_main_get_fs( enkf_main ); enkf_node_type * gen_param_node = enkf_state_get_node( state , "PARAM" ); node_id_type node_id = {.report_step = 0 , .iens = 0, .state = ANALYZED }; create_runpath( enkf_main ); test_assert_true( util_is_directory( "simulations/run0" )); { run_mode_type run_mode = ENSEMBLE_EXPERIMENT; enkf_main_init_run(enkf_main , run_mode); /* This is ugly */ test_assert_false( enkf_node_has_data( gen_param_node , fs, node_id )); util_unlink_existing( "simulations/run0/PARAM_INIT" ); } { FILE * stream = util_fopen("simulations/run0/PARAM_INIT" , "w"); fprintf(stream , "0\n1\n2\n3\n" ); fclose( stream ); } { bool loadOK = true; stringlist_type * msg_list = stringlist_alloc_new(); { run_mode_type run_mode = ENSEMBLE_EXPERIMENT; enkf_main_init_run(enkf_main , run_mode); /* This is ugly */ } test_assert_true( enkf_node_forward_init( gen_param_node , "simulations/run0" , 0 )); enkf_state_forward_init( state , fs , &loadOK ); test_assert_true( loadOK ); enkf_state_load_from_forward_model( state , fs , &loadOK , false , msg_list ); stringlist_free( msg_list ); test_assert_true( loadOK ); { double value; test_assert_true( enkf_node_user_get( gen_param_node , fs , "0" , node_id , &value)); test_assert_double_equal( 0 , value); test_assert_true( enkf_node_user_get( gen_param_node , fs , "1" , node_id , &value)); test_assert_double_equal( 1 , value); test_assert_true( enkf_node_user_get( gen_param_node , fs , "2" , node_id , &value)); test_assert_double_equal( 2 , value); } } util_clear_directory( "simulations" , true , true ); create_runpath( enkf_main ); test_assert_true( util_is_directory( "simulations/run0" )); test_assert_true( util_is_file( "simulations/run0/PARAM.INC" )); { FILE * stream = util_fopen("simulations/run0/PARAM.INC" , "r"); double v0,v1,v2,v3; fscanf(stream , "%lg %lg %lg %lg" , &v0,&v1,&v2,&v3); fclose( stream ); test_assert_double_equal( 0 , v0); test_assert_double_equal( 1 , v1); test_assert_double_equal( 2 , v2); test_assert_double_equal( 3 , v3); } util_clear_directory( "simulations" , true , true ); } enkf_main_free( enkf_main ); } test_work_area_free( work_area ); }
bool config_schema_item_validate_set(const config_schema_item_type * item , stringlist_type * token_list , const char * config_file, const config_path_elm_type * path_elm , config_error_type * error_list) { bool OK = true; int argc = stringlist_get_size( token_list ) - 1; if (item->validate->argc_min >= 0) { if (argc < item->validate->argc_min) { OK = false; { char * error_message; if (config_file != NULL) error_message = util_alloc_sprintf("Error when parsing config_file:\"%s\" Keyword:%s must have at least %d arguments.",config_file , item->kw , item->validate->argc_min); else error_message = util_alloc_sprintf("Error:: Keyword:%s must have at least %d arguments.",item->kw , item->validate->argc_min); config_error_add( error_list , error_message ); } } } if (item->validate->argc_max >= 0) { if (argc > item->validate->argc_max) { OK = false; { char * error_message; if (config_file != NULL) error_message = util_alloc_sprintf("Error when parsing config_file:\"%s\" Keyword:%s must have maximum %d arguments.",config_file , item->kw , item->validate->argc_max); else error_message = util_alloc_sprintf("Error:: Keyword:%s must have maximum %d arguments.",item->kw , item->validate->argc_max); config_error_add( error_list , error_message ); } } } /* OK - now we have verified that the number of arguments is correct. Then we start actually looking at the values. */ if (OK) { /* Validating selection set - first common, then indexed */ if (item->validate->common_selection_set) { for (int iarg = 0; iarg < argc; iarg++) { if (!set_has_key(item->validate->common_selection_set , stringlist_iget( token_list , iarg + 1))) { config_error_add( error_list , util_alloc_sprintf("%s: is not a valid value for: %s.",stringlist_iget( token_list , iarg + 1) , item->kw)); OK = false; } } } else if (item->validate->indexed_selection_set != NULL) { for (int iarg = 0; iarg < argc; iarg++) { if ((item->validate->argc_max > 0) || (iarg < item->validate->argc_min)) { /* Without this test we might go out of range on the indexed selection set. */ const set_type * selection_set = validate_iget_selection_set( item->validate , iarg); if (selection_set) { if (!set_has_key( selection_set, stringlist_iget( token_list , iarg + 1))) { config_error_add( error_list , util_alloc_sprintf("%s: is not a valid value for item %d of \'%s\'.",stringlist_iget( token_list , iarg + 1) , iarg + 1 , item->kw)); OK = false; } } } } } /* Observe that the following code might rewrite the content of argv for arguments referring to path locations. */ /* Validate the TYPE of the various argumnents */ { for (int iarg = 0; iarg < argc; iarg++) { const char * value = stringlist_iget(token_list , iarg + 1); switch (validate_iget_type( item->validate , iarg)) { case(CONFIG_STRING): /* This never fails ... */ break; case(CONFIG_ISODATE): if (!util_sscanf_isodate( value , NULL )) config_error_add( error_list , util_alloc_sprintf("Failed to parse:%s as an ISO date: YYYY-MM-DD.",value)); break; case(CONFIG_INT): if (!util_sscanf_int( value , NULL )) config_error_add( error_list , util_alloc_sprintf("Failed to parse:%s as an integer.",value)); break; case(CONFIG_FLOAT): if (!util_sscanf_double( value , NULL )) { config_error_add( error_list , util_alloc_sprintf("Failed to parse:%s as a floating point number.", value)); OK = false; } break; case(CONFIG_PATH): // As long as we do not reuqire the path to exist it is just a string. break; case(CONFIG_EXISTING_PATH): { char * path = config_path_elm_alloc_abspath( path_elm , value ); if (!util_entry_exists(path)) { config_error_add( error_list , util_alloc_sprintf("Can not find entry %s in %s ",value , config_path_elm_get_relpath( path_elm) )); OK = false; } free( path ); } break; case(CONFIG_EXECUTABLE): { /* 1. If the supplied value is an abolute path - do nothing. 2. If the supplied is _not_ an absolute path: a. Try if the relocated exists - then use that. b. Else - try if the util_alloc_PATH_executable() exists. */ if (!util_is_abs_path( value )) { char * relocated = __alloc_relocated__(path_elm , value); char * path_exe = util_alloc_PATH_executable( value ); if (util_file_exists(relocated)) { if (util_is_executable(relocated)) stringlist_iset_copy( token_list , iarg , relocated); } else if (path_exe != NULL) stringlist_iset_copy( token_list , iarg , path_exe); else config_error_add( error_list , util_alloc_sprintf("Could not locate executable:%s ", value)); free(relocated); util_safe_free(path_exe); } else { if (!util_is_executable( value )) config_error_add( error_list , util_alloc_sprintf("Could not locate executable:%s ", value)); } } break; case(CONFIG_BOOL): if (!util_sscanf_bool( value , NULL )) { config_error_add( error_list , util_alloc_sprintf("Failed to parse:%s as a boolean.", value)); OK = false; } break; case(CONFIG_BYTESIZE): if (!util_sscanf_bytesize( value , NULL)) { config_error_add( error_list , util_alloc_sprintf("Failed to parse:\"%s\" as number of bytes." , value)); OK = false; } break; default: util_abort("%s: config_item_type:%d not recognized \n",__func__ , validate_iget_type(item->validate , iarg)); } } } } return OK; }
void ensemble_config_init_FIELD( ensemble_config_type * ensemble_config , const config_type * config , ecl_grid_type * grid) { const config_content_item_type * item = config_get_content_item( config , FIELD_KEY ); if (item != NULL) { int i; for (i=0; i < config_content_item_get_size( item ); i++) { const config_content_node_type * node = config_content_item_iget_node( item , i ); const char * key = config_content_node_iget( node , 0 ); const char * var_type_string = config_content_node_iget( node , 1 ); enkf_config_node_type * config_node; { hash_type * options = hash_alloc(); int truncation = TRUNCATE_NONE; double value_min = -1; double value_max = -1; config_content_node_init_opt_hash( node , options , 2 ); if (hash_has_key( options , MIN_KEY)) { truncation |= TRUNCATE_MIN; value_min = atof(hash_get( options , MIN_KEY)); } if (hash_has_key( options , MAX_KEY)) { truncation |= TRUNCATE_MAX; value_max = atof(hash_get( options , MAX_KEY)); } if (strcmp(var_type_string , DYNAMIC_KEY) == 0) { config_node = ensemble_config_add_field( ensemble_config , key , grid , false); enkf_config_node_update_state_field( config_node , truncation , value_min , value_max ); } else if (strcmp(var_type_string , PARAMETER_KEY) == 0) { const char * ecl_file = config_content_node_iget( node , 2 ); const char * init_file_fmt = hash_safe_get( options , INIT_FILES_KEY ); const char * init_transform = hash_safe_get( options , INIT_TRANSFORM_KEY ); const char * output_transform = hash_safe_get( options , OUTPUT_TRANSFORM_KEY ); const char * min_std_file = hash_safe_get( options , MIN_STD_KEY ); const char * forward_string = hash_safe_get( options , FORWARD_INIT_KEY ); bool forward_init = false; if (forward_string) { if (!util_sscanf_bool( forward_string , &forward_init)) fprintf(stderr,"** Warning: parsing %s as bool failed - using FALSE \n",forward_string); } config_node = ensemble_config_add_field( ensemble_config , key , grid , forward_init); enkf_config_node_update_parameter_field( config_node, ecl_file , init_file_fmt , min_std_file , truncation , value_min , value_max , init_transform , output_transform ); } else if (strcmp(var_type_string , GENERAL_KEY) == 0) { /* General - not really interesting .. */ const char * ecl_file = config_content_node_iget( node , 2 ); const char * enkf_infile = config_content_node_iget( node , 3 ); const char * init_file_fmt = hash_safe_get( options , INIT_FILES_KEY ); const char * init_transform = hash_safe_get( options , INIT_TRANSFORM_KEY ); const char * output_transform = hash_safe_get( options , OUTPUT_TRANSFORM_KEY ); const char * input_transform = hash_safe_get( options , INPUT_TRANSFORM_KEY ); const char * min_std_file = hash_safe_get( options , MIN_STD_KEY ); const char * forward_string = hash_safe_get( options , FORWARD_INIT_KEY ); bool forward_init = false; if (forward_string) { if (!util_sscanf_bool( forward_string , &forward_init)) fprintf(stderr,"** Warning: parsing %s as bool failed - using FALSE \n",forward_string); } config_node = ensemble_config_add_field( ensemble_config , key , grid , forward_init); enkf_config_node_update_general_field( config_node, ecl_file , enkf_infile , init_file_fmt , min_std_file , truncation , value_min , value_max , init_transform , input_transform , output_transform); } else util_abort("%s: field type: %s is not recognized\n",__func__ , var_type_string); hash_free( options ); } } } }
int main(int argc , char ** argv) { enkf_main_install_SIGNALS(); const char * root_path = argv[1]; const char * config_file = argv[2]; const char * init_file = argv[3]; const char * forward_init_string = argv[4]; test_work_area_type * work_area = test_work_area_alloc(config_file ); test_work_area_copy_directory_content( work_area , root_path ); test_work_area_install_file( work_area , init_file ); { bool forward_init; bool strict = true; enkf_main_type * enkf_main; test_assert_true( util_sscanf_bool( forward_init_string , &forward_init)); util_clear_directory( "Storage" , true , true ); enkf_main = enkf_main_bootstrap( config_file , strict , true ); { enkf_state_type * state = enkf_main_iget_state( enkf_main , 0 ); enkf_node_type * surface_node = enkf_state_get_node( state , "SURFACE" ); { const enkf_config_node_type * surface_config_node = enkf_node_get_config( surface_node ); char * init_file1 = enkf_config_node_alloc_initfile( surface_config_node , NULL , 0); char * init_file2 = enkf_config_node_alloc_initfile( surface_config_node , "/tmp", 0); test_assert_bool_equal( enkf_config_node_use_forward_init( surface_config_node ) , forward_init ); test_assert_string_equal( init_file1 , "Surface.irap"); test_assert_string_equal( init_file2 , "/tmp/Surface.irap"); free( init_file1 ); free( init_file2 ); } test_assert_bool_equal( enkf_node_use_forward_init( surface_node ) , forward_init ); if (forward_init) test_assert_bool_not_equal( enkf_node_initialize( surface_node , 0 , enkf_state_get_rng( state )) , forward_init); // else hard_failure() } test_assert_bool_equal( forward_init, ensemble_config_have_forward_init( enkf_main_get_ensemble_config( enkf_main ))); if (forward_init) { enkf_state_type * state = enkf_main_iget_state( enkf_main , 0 ); enkf_fs_type * fs = enkf_main_get_fs( enkf_main ); run_arg_type * run_arg = run_arg_alloc_ENSEMBLE_EXPERIMENT( fs , 0 ,0 , "simulations/run0"); enkf_node_type * surface_node = enkf_state_get_node( state , "SURFACE" ); node_id_type node_id = {.report_step = 0 , .iens = 0, .state = ANALYZED }; create_runpath( enkf_main ); test_assert_true( util_is_directory( "simulations/run0" )); { int error = 0; stringlist_type * msg_list = stringlist_alloc_new(); test_assert_false( enkf_node_has_data( surface_node , fs, node_id )); util_unlink_existing( "simulations/run0/Surface.irap" ); test_assert_false( enkf_node_forward_init( surface_node , "simulations/run0" , 0 )); enkf_state_forward_init( state , run_arg , &error ); test_assert_true(LOAD_FAILURE & error); error = 0; { enkf_fs_type * fs = enkf_main_get_fs(enkf_main); state_map_type * state_map = enkf_fs_get_state_map(fs); state_map_iset(state_map, 0, STATE_INITIALIZED); } enkf_state_load_from_forward_model(state, run_arg , &error, false, msg_list); stringlist_free( msg_list ); test_assert_true(LOAD_FAILURE & error); } util_copy_file( init_file , "simulations/run0/Surface.irap"); { int error = 0; stringlist_type * msg_list = stringlist_alloc_new(); test_assert_true( enkf_node_forward_init( surface_node , "simulations/run0" , 0 )); enkf_state_forward_init( state , run_arg , &error ); test_assert_int_equal(0, error); enkf_state_load_from_forward_model( state , run_arg , &error , false , msg_list ); stringlist_free( msg_list ); test_assert_int_equal(0, error); { double value; test_assert_true( enkf_node_user_get( surface_node , fs , "0" , node_id , &value)); test_assert_double_equal( 2735.7461 , value); test_assert_true( enkf_node_user_get( surface_node , fs , "5" , node_id , &value)); test_assert_double_equal( 2737.0122 , value); } } util_clear_directory( "simulations" , true , true ); create_runpath( enkf_main ); test_assert_true( util_is_directory( "simulations/run0" )); test_assert_true( util_is_file( "simulations/run0/SURFACE.INC" )); test_assert_true( enkf_node_fload( surface_node , "simulations/run0/SURFACE.INC")); { double value; test_assert_true( enkf_node_user_get( surface_node , fs , "0" , node_id , &value)); test_assert_double_equal( 2735.7461 , value); test_assert_true( enkf_node_user_get( surface_node , fs , "5" , node_id , &value)); test_assert_double_equal( 2737.0122 , value); } util_clear_directory( "simulations" , true , true ); } enkf_main_free( enkf_main ); } }
int main(int argc , char ** argv) { const char * Xfile = argv[1]; bool MSW; ecl_file_type * rst_file = ecl_file_open( Xfile , 0 ); ecl_rsthead_type * rst_head = ecl_rsthead_alloc( ecl_file_get_global_view(rst_file) , ecl_util_filename_report_nr( Xfile )); test_install_SIGNALS(); test_assert_true( util_sscanf_bool( argv[2] , &MSW )); test_assert_not_NULL( rst_file ); test_assert_not_NULL( rst_head ); { int iwell; const ecl_kw_type * iwel_kw = ecl_file_iget_named_kw( rst_file , IWEL_KW , 0 ); const ecl_kw_type * icon_kw = ecl_file_iget_named_kw( rst_file , ICON_KW , 0 ); ecl_kw_type * scon_kw = NULL; bool caseMSW = false; for (iwell = 0; iwell < rst_head->nwells; iwell++) { const int iwel_offset = rst_head->niwelz * iwell; int num_connections = ecl_kw_iget_int( iwel_kw , iwel_offset + IWEL_CONNECTIONS_INDEX ); int iconn; well_conn_collection_type * wellcc = well_conn_collection_alloc( ); well_conn_collection_type * wellcc_ref = well_conn_collection_alloc(); for (iconn = 0; iconn < num_connections; iconn++) { well_conn_type * conn = well_conn_alloc_from_kw( icon_kw , scon_kw , rst_head , iwell , iconn ); test_assert_true( well_conn_is_instance( conn )); test_assert_not_NULL( conn ); if (!MSW) test_assert_bool_equal( well_conn_MSW( conn ) , MSW); else caseMSW |= well_conn_MSW( conn ); well_conn_collection_add( wellcc , conn ); well_conn_collection_add_ref( wellcc_ref , conn ); test_assert_int_equal( iconn + 1 , well_conn_collection_get_size( wellcc )); test_assert_ptr_equal( well_conn_collection_iget_const( wellcc , iconn) , conn); test_assert_ptr_equal( well_conn_collection_iget_const( wellcc_ref , iconn) , conn); } well_conn_collection_free( wellcc_ref ); { int i; for (i=0; i < well_conn_collection_get_size( wellcc ); i++) test_assert_true( well_conn_is_instance( well_conn_collection_iget_const( wellcc , i ))); } { well_conn_collection_type * wellcc2 = well_conn_collection_alloc(); int i; test_assert_int_equal( well_conn_collection_get_size( wellcc ) , well_conn_collection_load_from_kw( wellcc2 , iwel_kw , icon_kw , scon_kw , iwell , rst_head)); for (i=0; i < well_conn_collection_get_size( wellcc2 ); i++) { test_assert_true( well_conn_is_instance( well_conn_collection_iget_const( wellcc2 , i ))); test_assert_true( well_conn_equal( well_conn_collection_iget_const( wellcc2 , i ) , well_conn_collection_iget_const( wellcc , i ))); } well_conn_collection_free( wellcc2 ); } well_conn_collection_free( wellcc ); } test_assert_bool_equal( caseMSW , MSW); } exit( 0 ); }
int main(int argc , char ** argv) { enkf_main_install_SIGNALS(); const char * root_path = argv[1]; const char * config_file = argv[2]; const char * forward_init_string = argv[3]; test_work_area_type * work_area = test_work_area_alloc(config_file ); test_work_area_copy_directory_content( work_area , root_path ); { bool forward_init; bool strict = true; enkf_main_type * enkf_main; test_assert_true( util_sscanf_bool( forward_init_string , &forward_init)); util_clear_directory( "Storage" , true , true ); enkf_main = enkf_main_bootstrap( NULL , config_file , strict , true ); { enkf_state_type * state = enkf_main_iget_state( enkf_main , 0 ); enkf_node_type * gen_kw_node = enkf_state_get_node( state , "MULTFLT" ); { const enkf_config_node_type * gen_kw_config_node = enkf_node_get_config( gen_kw_node ); char * init_file1 = enkf_config_node_alloc_initfile( gen_kw_config_node , NULL , 0); char * init_file2 = enkf_config_node_alloc_initfile( gen_kw_config_node , "/tmp", 0); test_assert_bool_equal( enkf_config_node_use_forward_init( gen_kw_config_node ) , forward_init ); test_assert_string_equal( init_file1 , "MULTFLT_INIT"); test_assert_string_equal( init_file2 , "/tmp/MULTFLT_INIT"); free( init_file1 ); free( init_file2 ); } test_assert_bool_equal( enkf_node_use_forward_init( gen_kw_node ) , forward_init ); if (forward_init) test_assert_bool_not_equal( enkf_node_initialize( gen_kw_node , 0 , enkf_state_get_rng( state )) , forward_init); // else hard_failure() } test_assert_bool_equal( forward_init, ensemble_config_have_forward_init( enkf_main_get_ensemble_config( enkf_main ))); if (forward_init) { enkf_state_type * state = enkf_main_iget_state( enkf_main , 0 ); enkf_fs_type * fs = enkf_main_get_fs( enkf_main ); run_arg_type * run_arg = run_arg_alloc_ENSEMBLE_EXPERIMENT( fs , 0 , 0 , "simulations/run0"); enkf_node_type * gen_kw_node = enkf_state_get_node( state , "MULTFLT" ); node_id_type node_id = {.report_step = 0 , .iens = 0, .state = ANALYZED }; create_runpath( enkf_main ); test_assert_true( util_is_directory( "simulations/run0" )); { int error = 0; stringlist_type * msg_list = stringlist_alloc_new(); bool_vector_type * iactive = bool_vector_alloc( enkf_main_get_ensemble_size( enkf_main ) , true); test_assert_false( enkf_node_has_data( gen_kw_node , fs, node_id )); util_unlink_existing( "simulations/run0/MULTFLT_INIT" ); test_assert_false( enkf_node_forward_init( gen_kw_node , "simulations/run0" , 0 )); enkf_state_forward_init( state , run_arg , &error ); test_assert_true(LOAD_FAILURE & error); error = 0; { enkf_fs_type * fs = enkf_main_get_fs( enkf_main ); state_map_type * state_map = enkf_fs_get_state_map(fs); state_map_iset(state_map , 0 , STATE_INITIALIZED); } enkf_state_load_from_forward_model( state , run_arg , &error , false , msg_list ); stringlist_free( msg_list ); bool_vector_free( iactive ); test_assert_true(LOAD_FAILURE & error); } { FILE * stream = util_fopen("simulations/run0/MULTFLT_INIT" , "w"); fprintf(stream , "123456.0\n" ); fclose( stream ); } { int error = 0; stringlist_type * msg_list = stringlist_alloc_new(); test_assert_true( enkf_node_forward_init( gen_kw_node , "simulations/run0" , 0 )); enkf_state_forward_init( state , run_arg , &error ); test_assert_int_equal(0, error); enkf_state_load_from_forward_model( state , run_arg , &error , false , msg_list ); stringlist_free( msg_list ); test_assert_int_equal(0, error); { double value; test_assert_true( enkf_node_user_get( gen_kw_node , fs , "MULTFLT" , node_id , &value)); test_assert_double_equal( 123456.0 , value); } } test_assert_true( util_is_file ("simulations/run0/parameters.txt")); //Export of gen kw params util_clear_directory( "simulations" , true , true ); create_runpath( enkf_main ); test_assert_true( util_is_directory( "simulations/run0" )); test_assert_true( util_is_file( "simulations/run0/MULTFLT.INC" )); { FILE * stream = util_fopen("simulations/run0/MULTFLT.INC" , "r"); double value; fscanf(stream , "%lg" , &value); fclose( stream ); test_assert_double_equal( 123456.0 , value); } util_clear_directory( "simulations" , true , true ); run_arg_free( run_arg ); } enkf_main_free( enkf_main ); } test_work_area_free( work_area ); }
int main(int argc , char ** argv) { enkf_main_install_SIGNALS(); { const char * config_file = argv[1]; const char * init_file = argv[2]; const char * forward_init_string = argv[3]; bool forward_init; bool strict = true; enkf_main_type * enkf_main; test_assert_true( util_sscanf_bool( forward_init_string , &forward_init)); util_clear_directory( "/tmp/Storage" , true , true ); enkf_main = enkf_main_bootstrap( NULL , config_file , strict , true ); { enkf_state_type * state = enkf_main_iget_state( enkf_main , 0 ); enkf_node_type * surface_node = enkf_state_get_node( state , "SURFACE" ); { const enkf_config_node_type * surface_config_node = enkf_node_get_config( surface_node ); char * init_file1 = enkf_config_node_alloc_initfile( surface_config_node , NULL , 0); char * init_file2 = enkf_config_node_alloc_initfile( surface_config_node , "/tmp", 0); test_assert_bool_equal( enkf_config_node_use_forward_init( surface_config_node ) , forward_init ); test_assert_string_equal( init_file1 , "Surface.irap"); test_assert_string_equal( init_file2 , "/tmp/Surface.irap"); free( init_file1 ); free( init_file2 ); } test_assert_bool_equal( enkf_node_use_forward_init( surface_node ) , forward_init ); if (forward_init) test_assert_bool_not_equal( enkf_node_initialize( surface_node , 0 , enkf_state_get_rng( state )) , forward_init); // else hard_failure() } test_assert_bool_equal( forward_init, ensemble_config_have_forward_init( enkf_main_get_ensemble_config( enkf_main ))); if (forward_init) { enkf_state_type * state = enkf_main_iget_state( enkf_main , 0 ); enkf_fs_type * fs = enkf_main_get_fs( enkf_main ); enkf_node_type * surface_node = enkf_state_get_node( state , "SURFACE" ); node_id_type node_id = {.report_step = 0 , .iens = 0, .state = ANALYZED }; create_runpath( enkf_main ); test_assert_true( util_is_directory( "/tmp/simulations/run0" )); { bool loadOK = true; stringlist_type * msg_list = stringlist_alloc_new(); { run_mode_type run_mode = ENSEMBLE_EXPERIMENT; enkf_main_init_run(enkf_main , run_mode); /* This is ugly */ } test_assert_false( enkf_node_has_data( surface_node , fs, node_id )); util_unlink_existing( "/tmp/simulations/run0/Surface.irap" ); test_assert_false( enkf_node_forward_init( surface_node , "/tmp/simulations/run0" , 0 )); enkf_state_forward_init( state , fs , &loadOK ); test_assert_false( loadOK ); loadOK = true; enkf_state_load_from_forward_model( state , fs , &loadOK , false , msg_list ); stringlist_free( msg_list ); test_assert_false( loadOK ); } util_copy_file( init_file , "/tmp/simulations/run0/Surface.irap"); { bool loadOK = true; stringlist_type * msg_list = stringlist_alloc_new(); { run_mode_type run_mode = ENSEMBLE_EXPERIMENT; enkf_main_init_run(enkf_main , run_mode); /* This is ugly */ } test_assert_true( enkf_node_forward_init( surface_node , "/tmp/simulations/run0" , 0 )); enkf_state_forward_init( state , fs , &loadOK ); test_assert_true( loadOK ); enkf_state_load_from_forward_model( state , fs , &loadOK , false , msg_list ); stringlist_free( msg_list ); test_assert_true( loadOK ); { double value; test_assert_true( enkf_node_user_get( surface_node , fs , "0" , node_id , &value)); test_assert_double_equal( 2735.7461 , value); test_assert_true( enkf_node_user_get( surface_node , fs , "5" , node_id , &value)); test_assert_double_equal( 2737.0122 , value); } } util_clear_directory( "/tmp/simulations" , true , true ); create_runpath( enkf_main ); test_assert_true( util_is_directory( "/tmp/simulations/run0" )); test_assert_true( util_is_file( "/tmp/simulations/run0/SURFACE.INC" )); test_assert_true( enkf_node_fload( surface_node , "/tmp/simulations/run0/SURFACE.INC")); { double value; test_assert_true( enkf_node_user_get( surface_node , fs , "0" , node_id , &value)); test_assert_double_equal( 2735.7461 , value); test_assert_true( enkf_node_user_get( surface_node , fs , "5" , node_id , &value)); test_assert_double_equal( 2737.0122 , value); } util_clear_directory( "/tmp/simulations" , true , true ); } enkf_main_free( enkf_main ); } }