int main(int argc , char ** argv) { const char * path_case = argv[1]; char * grid_file = ecl_util_alloc_filename( NULL , path_case , ECL_EGRID_FILE , false , 0 ); char * init_file = ecl_util_alloc_filename( NULL , path_case , ECL_INIT_FILE , false , 0 ); ecl_file_type * init = ecl_file_open( init_file , 0 ); ecl_grid_type * grid = ecl_grid_alloc( grid_file ); const ecl_kw_type * poro_kw = ecl_file_iget_named_kw( init , "PORO" , 0 ); const ecl_kw_type * porv_kw = ecl_file_iget_named_kw( init , "PORV" , 0 ); ecl_kw_type * multpv = NULL; ecl_kw_type * NTG = NULL; bool error_found = false; double total_volume = 0; double total_diff = 0; int error_count = 0; int iactive; if (ecl_file_has_kw( init , "NTG")) NTG = ecl_file_iget_named_kw( init , "NTG" , 0); if (ecl_file_has_kw( init , "MULTPV")) multpv = ecl_file_iget_named_kw( init , "MULTPV" , 0); for (iactive = 0; iactive < ecl_grid_get_nactive( grid ); ++iactive) { int iglobal = ecl_grid_get_global_index1A( grid , iactive ); double grid_volume = ecl_grid_get_cell_volume1( grid , iglobal ); double eclipse_volume = ecl_kw_iget_float( porv_kw , iglobal ) / ecl_kw_iget_float( poro_kw , iactive ); if (NTG) eclipse_volume /= ecl_kw_iget_float( NTG , iactive ); if (multpv) eclipse_volume *= ecl_kw_iget_float( multpv , iactive); total_volume += grid_volume; total_diff += fabs( eclipse_volume - grid_volume ); if (!util_double_approx_equal__( grid_volume , eclipse_volume , 2.5e-3, 0.00)) { double diff = 100 * (grid_volume - eclipse_volume) / eclipse_volume; printf("Error in cell: %d V1: %g V2: %g diff:%g %% \n", iglobal , grid_volume , eclipse_volume , diff); error_count++; error_found = true; } } printf("Total volume difference: %g %% \n", 100 * total_diff / total_volume ); ecl_grid_free( grid ); ecl_file_close( init ); free( grid_file ); free( init_file ); if (error_found) { printf("Error_count: %d / %d \n",error_count , ecl_grid_get_nactive( grid )); exit(1); } else exit(0); }
static ecl_subsidence_survey_type * ecl_subsidence_survey_alloc_PRESSURE(ecl_subsidence_type * ecl_subsidence , const ecl_file_view_type * restart_view , const char * name ) { ecl_subsidence_survey_type * survey = ecl_subsidence_survey_alloc_empty( ecl_subsidence , name ); ecl_grid_cache_type * grid_cache = ecl_subsidence->grid_cache; const int * global_index = ecl_grid_cache_get_global_index( grid_cache ); const int size = ecl_grid_cache_get_size( grid_cache ); int active_index; ecl_kw_type * init_porv_kw = ecl_file_iget_named_kw( ecl_subsidence->init_file , PORV_KW , 0); /*Global indexing*/ ecl_kw_type * pressure_kw = ecl_file_view_iget_named_kw( restart_view , PRESSURE_KW , 0); /*Active indexing*/ for (active_index = 0; active_index < size; active_index++){ survey->porv[ active_index ] = ecl_kw_iget_float( init_porv_kw , global_index[active_index] ); survey->pressure[ active_index ] = ecl_kw_iget_float( pressure_kw , active_index ); } return survey; }
static ecl_grav_survey_type * ecl_grav_survey_alloc_PORMOD(ecl_grav_type * ecl_grav , const ecl_file_type * restart_file , const char * name ) { ecl_grid_cache_type * grid_cache = ecl_grav->grid_cache; ecl_grav_survey_type * survey = ecl_grav_survey_alloc_empty( ecl_grav , name , GRAV_CALC_PORMOD); ecl_kw_type * init_porv_kw = ecl_file_iget_named_kw( ecl_grav->init_file , PORV_KW , 0 ); /* Global indexing */ ecl_kw_type * pormod_kw = ecl_file_iget_named_kw( restart_file , PORMOD_KW , 0 ); /* Active indexing */ const int size = ecl_grid_cache_get_size( grid_cache ); const int * global_index = ecl_grid_cache_get_global_index( grid_cache ); int active_index; for (active_index = 0; active_index < size; active_index++) survey->porv[ active_index ] = ecl_kw_iget_float( pormod_kw , active_index ) * ecl_kw_iget_float( init_porv_kw , global_index[active_index] ); ecl_grav_survey_add_phases( ecl_grav , survey , restart_file , GRAV_CALC_PORMOD); return survey; }
void test_float() { size_t N = 1000; int i; ecl_kw_type * kw = ecl_kw_alloc("KW" , N , ECL_FLOAT_TYPE); for (i=0; i < N; i++) test_assert_int_equal( 0 , ecl_kw_iget_float( kw , i )); ecl_kw_free( kw ); }
static void ecl_init_file_fwrite_poro( fortio_type * fortio , const ecl_grid_type * ecl_grid , const ecl_kw_type * poro ) { { ecl_kw_type * porv = ecl_kw_alloc( PORV_KW , ecl_grid_get_global_size( ecl_grid ) , ECL_FLOAT_TYPE); int global_index; bool global_poro = (ecl_kw_get_size( poro ) == ecl_grid_get_global_size( ecl_grid )) ? true : false; for ( global_index = 0; global_index < ecl_grid_get_global_size( ecl_grid ); global_index++) { int active_index = ecl_grid_get_active_index1( ecl_grid , global_index ); if (active_index >= 0) { int poro_index = global_poro ? global_index : active_index; ecl_kw_iset_float( porv , global_index , ecl_kw_iget_float( poro , poro_index ) * ecl_grid_get_cell_volume1( ecl_grid , global_index )); } else ecl_kw_iset_float( porv , global_index , 0 ); } ecl_kw_fwrite( porv , fortio ); ecl_kw_free( porv ); } ecl_kw_fwrite( poro , fortio ); }
void test_writable(const char * src_file ) { test_work_area_type * work_area = test_work_area_alloc("ecl_file_writable" ); char * fname = util_split_alloc_filename( src_file ); test_work_area_copy_file( work_area , src_file ); { ecl_file_type * ecl_file = ecl_file_open( fname , ECL_FILE_WRITABLE); ecl_kw_type * swat = ecl_file_iget_named_kw( ecl_file , "SWAT" , 0 ); ecl_kw_type * swat0 = ecl_kw_alloc_copy( swat ); test_assert_true( ecl_kw_equal( swat , swat0 )); ecl_kw_iset_float( swat , 0 , 1000.0 ); ecl_file_save_kw( ecl_file , swat ); test_assert_true( ecl_file_writable( ecl_file )); ecl_file_close( ecl_file ); ecl_file = ecl_file_open( fname , 0); swat = ecl_file_iget_named_kw( ecl_file , "SWAT" , 0 ); test_assert_true( util_double_approx_equal( ecl_kw_iget_float( swat , 0 ) , 1000 )); } test_work_area_free( work_area ); }
ecl_rft_node_type * ecl_rft_node_alloc(const ecl_file_view_type * rft_view) { ecl_kw_type * welletc = ecl_file_view_iget_named_kw(rft_view , WELLETC_KW , 0); ecl_rft_node_type * rft_node = ecl_rft_node_alloc_empty(ecl_kw_iget_ptr(welletc , WELLETC_TYPE_INDEX)); if (rft_node != NULL) { ecl_kw_type * date_kw = ecl_file_view_iget_named_kw( rft_view , DATE_KW , 0); rft_node->well_name = util_alloc_strip_copy( ecl_kw_iget_ptr(welletc , WELLETC_NAME_INDEX)); /* Time information. */ { int * time = ecl_kw_get_int_ptr( date_kw ); rft_node->recording_date = ecl_util_make_date( time[DATE_DAY_INDEX] , time[DATE_MONTH_INDEX] , time[DATE_YEAR_INDEX] ); } rft_node->days = ecl_kw_iget_float( ecl_file_view_iget_named_kw( rft_view , TIME_KW , 0 ) , 0); if (ecl_file_view_has_kw( rft_view , CONLENST_KW)) rft_node->MSW = true; else rft_node->MSW = false; ecl_rft_node_init_cells( rft_node , rft_view ); } return rft_node; }