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( 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 ); 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) { 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 ); } }
int main(int argc , char ** argv) { enkf_main_install_SIGNALS(); const char * config_file = argv[1]; const char * init_file = argv[2]; const char * key = "PORO"; int iens = 0; ert_test_context_type * test_context = ert_test_context_alloc("ExportInactiveCellsTest" , config_file); enkf_main_type * enkf_main = ert_test_context_get_main(test_context); enkf_fs_type * fs = enkf_main_get_fs(enkf_main); const ensemble_config_type * ensemble_config = enkf_main_get_ensemble_config(enkf_main); const enkf_config_node_type * config_node = ensemble_config_get_node(ensemble_config , key); const field_config_type * field_config = enkf_config_node_get_ref( config_node ); enkf_state_type * state = enkf_main_iget_state( enkf_main , iens ); enkf_node_type * field_node = enkf_state_get_node( state , key ); field_type * field = enkf_node_value_ptr(field_node); { forward_initialize_node(enkf_main, init_file, field_node); node_id_type node_id = {.report_step = 0 , .iens = iens }; test_assert_true(enkf_node_try_load(field_node , fs , node_id)); field_scale(field, 3.0); } int nx,ny,nz; field_config_get_dims(field_config , &nx , &ny , &nz); const char * export_file_grdecl = "my_test_dir/exported_field_test_file_grdecl"; const char * export_file_roff = "my_test_dir/exported_field_test_file_roff"; field_file_format_type file_type; char * found_init_file = enkf_main_alloc_abs_path_to_init_file(enkf_main, config_node); { file_type = ECL_GRDECL_FILE; field_export(field, export_file_grdecl, NULL, file_type, false, found_init_file); check_exported_data(export_file_grdecl, init_file, file_type, field_config, field, nx, ny, nz); } { file_type = RMS_ROFF_FILE; field_export(field, export_file_roff, NULL, file_type, false, found_init_file); check_exported_data(export_file_roff, init_file, file_type, field_config, field, nx, ny, nz); } free(found_init_file); found_init_file = NULL; { file_type = ECL_GRDECL_FILE; field_export(field, export_file_grdecl, NULL, file_type, false, found_init_file); check_exported_data(export_file_grdecl, found_init_file, file_type, field_config, field, nx, ny, nz); } { file_type = RMS_ROFF_FILE; field_export(field, export_file_roff, NULL, file_type, false, found_init_file); check_exported_data(export_file_roff, found_init_file, file_type, field_config, field, nx, ny, nz); } ert_test_context_free(test_context); exit(0); }
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( 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 ); run_arg_type * run_arg = run_arg_alloc_ENSEMBLE_EXPERIMENT( fs , 0 , 0 , "simulations/run0"); 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" )); 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 ); } { int error = 0; stringlist_type * msg_list = stringlist_alloc_new(); test_assert_true( enkf_node_forward_init( gen_param_node , "simulations/run0" , 0 )); enkf_state_forward_init( state , run_arg , &error ); test_assert_int_equal(0, error); { 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_int_equal(0, error); { 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 ); run_arg_free( run_arg ); } enkf_main_free( enkf_main ); } test_work_area_free( work_area ); }
void enkf_tui_run_manual_load__( void * arg ) { enkf_main_type * enkf_main = enkf_main_safe_cast( arg ); enkf_fs_type * fs = enkf_main_get_fs( enkf_main ); const int last_report = -1; const int ens_size = enkf_main_get_ensemble_size( enkf_main ); int step1,step2; bool_vector_type * iactive = bool_vector_alloc( 0 , false ); run_mode_type run_mode = ENSEMBLE_EXPERIMENT; enkf_main_init_run(enkf_main , run_mode); /* This is ugly */ step1 = 0; step2 = last_report; /** Observe that for the summary data it will load all the available data anyway. */ { 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 ); } if (bool_vector_count_equal( iactive , true )) { int iens; arg_pack_type ** arg_list = util_calloc( ens_size , sizeof * arg_list ); thread_pool_type * tp = thread_pool_alloc( 4 , true ); /* num_cpu - HARD coded. */ for (iens = 0; iens < ens_size; iens++) { arg_pack_type * arg_pack = arg_pack_alloc(); arg_list[iens] = arg_pack; if (bool_vector_iget(iactive , iens)) { enkf_state_type * enkf_state = enkf_main_iget_state( enkf_main , iens ); arg_pack_append_ptr( arg_pack , enkf_state); /* 0: */ arg_pack_append_ptr( arg_pack , fs ); /* 1: */ arg_pack_append_int( arg_pack , step1 ); /* 2: This will be the load start parameter for the run_info struct. */ arg_pack_append_int( arg_pack , step1 ); /* 3: Step1 */ arg_pack_append_int( arg_pack , step2 ); /* 4: Step2 For summary data it will load the whole goddamn thing anyway.*/ arg_pack_append_bool( arg_pack , true ); /* 5: Interactive */ arg_pack_append_owned_ptr( arg_pack , stringlist_alloc_new() , stringlist_free__); /* 6: List of interactive mode messages. */ thread_pool_add_job( tp , enkf_state_load_from_forward_model_mt , arg_pack); } } thread_pool_join( tp ); thread_pool_free( tp ); printf("\n"); { 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++) { if (bool_vector_iget(iactive , iens)) { stringlist_type * msg_list = arg_pack_iget_ptr( arg_list[iens] , 6 ); if (stringlist_get_size( msg_list )) enkf_tui_display_load_msg( iens , msg_list ); } } for (iens = 0; iens < ens_size; iens++) arg_pack_free( arg_list[iens]); free( arg_list ); } bool_vector_free( iactive ); }
int main(int argc, char ** argv) { const char * config_file = argv[1]; test_work_area_type * work_area = test_work_area_alloc( "enkf_main_fs" ); char * model_config; util_alloc_file_components( config_file , NULL , &model_config , NULL); test_work_area_copy_parent_content( work_area , config_file ); { const char * site_config = "/project/res/etc/ERT/site-config"; enkf_main_type * enkf_main = enkf_main_bootstrap( site_config , model_config , false , false ); enkf_main_select_fs( enkf_main , "enkf"); test_assert_true( enkf_main_case_is_current( enkf_main , "enkf")); test_assert_false( enkf_main_case_is_current( enkf_main , "default_fs")); test_assert_false( enkf_main_case_is_current( enkf_main , "does_not_exist")); test_assert_int_equal( 1 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main ))); { enkf_fs_type * fs_ref = enkf_main_get_fs_ref( enkf_main ); test_assert_int_equal( 2 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main ))); enkf_fs_decref( fs_ref ); test_assert_int_equal( 1 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main ))); } { state_map_type * map1 = enkf_fs_get_state_map( enkf_main_get_fs( enkf_main )); state_map_type * map2 = enkf_main_alloc_readonly_state_map(enkf_main , "enkf"); test_assert_true(state_map_equal( map1 , map2 )); state_map_free( map2 ); } { enkf_fs_type * fs1 = enkf_main_mount_alt_fs( enkf_main , "default" , false ); enkf_fs_type * fs2 = enkf_main_mount_alt_fs( enkf_main , "enkf" , false ); test_assert_int_equal( 2 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main ))); test_assert_int_equal( 2 , enkf_fs_get_refcount( fs2 )); test_assert_int_equal( 1 , enkf_fs_get_refcount( fs1 )); enkf_fs_decref( fs1 ); enkf_fs_decref( fs2 ); } { enkf_fs_type * enkf_fs = enkf_main_mount_alt_fs( enkf_main , "enkf" , false ); enkf_main_select_fs( enkf_main , "default"); test_assert_int_equal( 1 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main ))); enkf_fs_decref( enkf_fs ); } { enkf_fs_type * default_fs = enkf_main_mount_alt_fs( enkf_main , "default" , false ); test_assert_int_equal( 2 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main ))); enkf_main_select_fs( enkf_main , "default"); test_assert_int_equal( 2 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main ))); enkf_fs_decref( default_fs ); test_assert_int_equal( 1 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main ))); } /*****************************************************************/ { enkf_fs_type * fs = enkf_main_mount_alt_fs( enkf_main , "default" , false ); test_assert_int_equal( 2 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main ))); enkf_main_set_fs( enkf_main , fs , NULL ); enkf_fs_decref( fs ); test_assert_int_equal( 1 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main ))); } { enkf_fs_type * fs = enkf_main_mount_alt_fs( enkf_main , "enkf" , false ); enkf_fs_type * current = enkf_main_mount_alt_fs( enkf_main , "default" , false ); test_assert_int_equal( 2 , enkf_fs_get_refcount( current )); test_assert_int_equal( 1 , enkf_fs_get_refcount( fs)); enkf_main_set_fs( enkf_main , fs , NULL); test_assert_int_equal( 2 , enkf_fs_get_refcount( fs)); test_assert_int_equal( 1 , enkf_fs_get_refcount( current )); enkf_fs_decref( current ); enkf_fs_decref( fs); } test_assert_int_equal( 1 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main ))); enkf_main_free( enkf_main ); } test_work_area_free( work_area ); exit(0); }