void test_get_tranLL(const char * name) { char * grid_file_name = ecl_util_alloc_filename(NULL , name , ECL_EGRID_FILE , false , -1); char * init_file_name = ecl_util_alloc_filename(NULL , name , ECL_INIT_FILE , false , -1); ecl_grid_type * grid = ecl_grid_alloc( grid_file_name ); ecl_file_type * grid_file = ecl_file_open( grid_file_name , 0 ); ecl_file_type * init_file = ecl_file_open( init_file_name , 0 ); test_tranLL( grid , init_file , ecl_grid_get_lgr_nr_from_name( grid , "LG003017" ), ecl_grid_get_lgr_nr_from_name( grid , "LG003018" ), 172 , 5.3957253 , 1.0099934); test_tranLL( grid , init_file , ecl_grid_get_lgr_nr_from_name( grid , "LG002016" ), ecl_grid_get_lgr_nr_from_name( grid , "LG002017" ), 93 , 1.4638059 , 0.36407200 ); test_tranLL( grid , init_file , ecl_grid_get_lgr_nr_from_name( grid , "LG002016" ), ecl_grid_get_lgr_nr_from_name( grid , "LG003016" ), 56 , 2.7360380 , 10.053267); test_tranLL( grid , init_file , ecl_grid_get_lgr_nr_from_name( grid , "LG009027" ), ecl_grid_get_lgr_nr_from_name( grid , "LG009026" ), 152 , 155.47754, 219.23553); test_tranLL( grid , init_file , ecl_grid_get_lgr_nr_from_name( grid , "LG009027" ), ecl_grid_get_lgr_nr_from_name( grid , "LG008027" ), 317 , 0.040260997 , 0.0066288318); free( init_file_name ); free(grid_file_name); ecl_grid_free( grid ); ecl_file_close( grid_file ); ecl_file_close( init_file ); }
char * ecl_rft_file_alloc_case_filename(const char * case_input ) { ecl_file_enum file_type; bool fmt_file; file_type = ecl_util_get_file_type( case_input , &fmt_file , NULL); if (file_type == ECL_RFT_FILE) return util_alloc_string_copy (case_input ); else { char * return_file = NULL; char * path; char * basename; util_alloc_file_components( case_input , &path , &basename , NULL); if ((file_type == ECL_OTHER_FILE) || (file_type == ECL_DATA_FILE)) { /* Impossible to infer formatted/unformatted from the case_input */ char * RFT_file = ecl_util_alloc_filename( path , basename , ECL_RFT_FILE , false , -1 ); char * FRFT_file = ecl_util_alloc_filename( path , basename , ECL_RFT_FILE , true , -1 ); if (util_file_exists( RFT_file )) return_file = util_alloc_string_copy( RFT_file ); else if (util_file_exists( FRFT_file )) return_file = util_alloc_string_copy( FRFT_file ); free( RFT_file ); free( FRFT_file ); } else { char * RFT_file = ecl_util_alloc_filename( path , basename , ECL_RFT_FILE , fmt_file , -1 ); if (util_file_exists( RFT_file )) return_file = util_alloc_string_copy( RFT_file ); free( RFT_file ); } return return_file; } }
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); }
int main(int argc , char ** argv) { const char * case_path = argv[1]; char * grid_file = ecl_util_alloc_filename( NULL , case_path , ECL_EGRID_FILE , false , 0 ); char * init_file = ecl_util_alloc_filename( NULL , case_path , ECL_INIT_FILE , false , 0 ); char * rst_file = ecl_util_alloc_filename( NULL , case_path , ECL_RESTART_FILE , false , 0 ); ecl_grid_type * ecl_grid = ecl_grid_alloc( grid_file ); ecl_file_type * RST_file = ecl_file_open( rst_file , 0); ecl_file_type * INIT_file = ecl_file_open( init_file , 0 ); ecl_file_type * GRID_file = ecl_file_open( grid_file , 0); { ecl_kw_type * actnum = ecl_file_iget_named_kw( GRID_file , "ACTNUM" , 0 ); ecl_kw_type * swat = ecl_file_iget_named_kw( RST_file , "SWAT" , 0 ); ecl_kw_type * permx = ecl_file_iget_named_kw( INIT_file , "PERMX" , 0 ); int fracture_size = ecl_grid_get_nactive_fracture( ecl_grid ); int matrix_size = ecl_grid_get_nactive( ecl_grid ); test_assert_int_equal( fracture_size + matrix_size , ecl_kw_get_size( swat )); test_assert_int_equal( fracture_size + matrix_size , ecl_kw_get_size( permx )); { int gi; int matrix_index = 0; int fracture_index = 0; for (gi = 0; gi < ecl_grid_get_global_size( ecl_grid ); gi++) { if (ecl_kw_iget_int( actnum , gi ) & CELL_ACTIVE_MATRIX) { test_assert_int_equal( ecl_grid_get_active_index1( ecl_grid , gi ) , matrix_index); test_assert_int_equal( ecl_grid_get_global_index1A( ecl_grid , matrix_index ) , gi); matrix_index++; } if (ecl_kw_iget_int( actnum , gi ) & CELL_ACTIVE_FRACTURE) { test_assert_int_equal( ecl_grid_get_active_fracture_index1( ecl_grid , gi ) , fracture_index); test_assert_int_equal( ecl_grid_get_global_index1F( ecl_grid , fracture_index ) , gi); fracture_index++; } } } } ecl_file_close( RST_file ); ecl_file_close( INIT_file ); ecl_grid_free( ecl_grid ); exit(0); }
char * ecl_util_alloc_exfilename_anyfmt(const char * path, const char * base , ecl_file_enum file_type , bool fmt_file_first , int report_nr) { char * filename = ecl_util_alloc_filename( path , base , file_type , fmt_file_first , report_nr); if (!util_file_exists( filename )) { free( filename ); filename = ecl_util_alloc_filename( path , base , file_type , !fmt_file_first , report_nr); } if (! util_file_exists(filename)) { util_safe_free( filename ); filename = NULL; } return filename; }
static void ecl_sum_data_fwrite_unified_step( const ecl_sum_data_type * data , const char * ecl_case , bool fmt_case , int report_step) { char * filename = ecl_util_alloc_filename( NULL , ecl_case , ECL_UNIFIED_SUMMARY_FILE , fmt_case , 0 ); fortio_type * fortio = fortio_open_readwrite( filename , fmt_case , ECL_ENDIAN_FLIP ); int current_step = 1; if (report_step > 1) { while (true) { if (ecl_kw_fseek_kw( SEQHDR_KW , false , false , fortio )) { if (current_step == report_step) break; current_step++; } else { current_step++; break; } } } if (current_step == report_step) { // We found the position: long size = fortio_ftell( fortio ); util_ftruncate( fortio_get_FILE( fortio ) , size ); ecl_sum_data_fwrite_report__( data , report_step , fortio ); } else util_abort("%s: hmm could not locate the position for report step:%d in summary file:%s \n",__func__ , report_step , filename); fortio_fclose( fortio ); free( filename ); }
std::string RestartConfig::getRestartFileName(const std::string& restart_base, int report_step, bool unified , bool fmt_file) { ecl_file_enum file_type = (unified) ? ECL_UNIFIED_RESTART_FILE : ECL_RESTART_FILE; char * c_str = ecl_util_alloc_filename( NULL , restart_base.c_str() , file_type, fmt_file , report_step); std::string restart_filename = c_str; free( c_str ); return restart_filename; }
static void ecl_sum_data_fwrite_multiple_step( const ecl_sum_data_type * data , const char * ecl_case , bool fmt_case , int report_step) { char * filename = ecl_util_alloc_filename( NULL , ecl_case , ECL_UNIFIED_SUMMARY_FILE , fmt_case , 0 ); fortio_type * fortio = fortio_open_readwrite( filename , fmt_case , ECL_ENDIAN_FLIP ); ecl_sum_data_fwrite_report__( data , report_step , fortio ); fortio_fclose( fortio ); free(filename); }
std::string IOConfig::getRestartFileName(const std::string& restart_base, int report_step, bool output) const { bool unified = output ? getUNIFOUT() : getUNIFIN(); bool fmt_file = output ? getFMTOUT() : getFMTIN(); ecl_file_enum file_type = (unified) ? ECL_UNIFIED_RESTART_FILE : ECL_RESTART_FILE; char * c_str = ecl_util_alloc_filename( NULL , restart_base.c_str() , file_type, fmt_file , report_step); std::string restart_filename = c_str; free( c_str ); return restart_filename; }
static void ecl_sum_data_fwrite_unified( const ecl_sum_data_type * data , const char * ecl_case , bool fmt_case ) { char * filename = ecl_util_alloc_filename( NULL , ecl_case , ECL_UNIFIED_SUMMARY_FILE , fmt_case , 0 ); fortio_type * fortio = fortio_open_writer( filename , fmt_case , ECL_ENDIAN_FLIP ); int report_step; for (report_step = data->first_report_step; report_step <= data->last_report_step; report_step++) { if (ecl_sum_data_has_report_step( data , report_step )) ecl_sum_data_fwrite_report__( data , report_step , fortio ); } fortio_fclose( fortio ); free( filename ); }
int main(int argc , char ** argv) { const char * case_path = argv[1]; char * egrid_file = ecl_util_alloc_filename( NULL , case_path , ECL_EGRID_FILE , false , 0 ); char * rst_file = ecl_util_alloc_filename( NULL , case_path , ECL_RESTART_FILE , false , 0 ); char * init_file = ecl_util_alloc_filename( NULL , case_path , ECL_INIT_FILE , false , 0 ); ecl_grid_type * GRID = ecl_grid_alloc(egrid_file ); ecl_file_type * RST_file = ecl_file_open( rst_file , 0); ecl_file_type * INIT_file = ecl_file_open( init_file , 0); { test_assert_true( ecl_grid_have_coarse_cells( GRID ) ); test_assert_int_equal( ecl_grid_get_num_coarse_groups( GRID ) , 3384); } { const ecl_kw_type * swat0 = ecl_file_iget_named_kw( RST_file , "SWAT" , 0 ); const ecl_kw_type * porv = ecl_file_iget_named_kw( INIT_file , "PORV" , 0 ); test_assert_int_equal( ecl_kw_get_size( swat0 ) , ecl_grid_get_active_size( GRID ) ); test_assert_int_equal( ecl_kw_get_size( porv ) , ecl_grid_get_global_size( GRID ) ); } { int ic; for (ic = 0; ic < ecl_grid_get_num_coarse_groups(GRID); ic++) { ecl_coarse_cell_type * coarse_cell = ecl_grid_iget_coarse_group( GRID , ic ); test_coarse_cell( GRID , coarse_cell ); } } ecl_file_close( INIT_file ); ecl_file_close( RST_file ); ecl_grid_free( GRID ); exit(0); }
// Inspired by the ecl_pack application in the ERT library void concatenateRestart(const std::string& basename) { std::string inputPath, inputBase; splitBasename(basename, inputPath, inputBase); stringlist_type* inputFiles = stringlist_alloc_new(); const int numFiles = ecl_util_select_filelist(inputPath.c_str(), inputBase.c_str(), ECL_RESTART_FILE, false, inputFiles); const char* target_file_name = ecl_util_alloc_filename(inputPath.c_str(), inputBase.c_str(), ECL_UNIFIED_RESTART_FILE, false, -1); fortio_type* target = fortio_open_writer(target_file_name, false, ECL_ENDIAN_FLIP); int dummy; ecl_kw_type* seqnum_kw = ecl_kw_alloc_new("SEQNUM", 1, ECL_INT, &dummy); int reportStep = 0; for (int i = 0; i < numFiles; ++i) { ecl_util_get_file_type(stringlist_iget(inputFiles, i), nullptr, &reportStep); ecl_file_type* src_file = ecl_file_open(stringlist_iget(inputFiles, i), 0); ecl_kw_iset_int(seqnum_kw, 0, reportStep); ecl_kw_fwrite(seqnum_kw, target); ecl_file_fwrite_fortio(src_file, target, 0); ecl_file_close(src_file); } fortio_fclose(target); stringlist_free(inputFiles); }
int main(int argc, char ** argv) { int num_files = argc - 1; if (num_files >= 1) { /* File type and formatted / unformatted is determined from the first argument on the command line. */ char * ecl_base; char * path; ecl_file_enum file_type , target_type; bool fmt_file; /** Look at the first command line argument to determine type and formatted/unformatted status. */ file_type = ecl_util_get_file_type( argv[1] , &fmt_file , NULL); if (file_type == ECL_SUMMARY_FILE) target_type = ECL_UNIFIED_SUMMARY_FILE; else if (file_type == ECL_RESTART_FILE) target_type = ECL_UNIFIED_RESTART_FILE; else { util_exit("The ecl_pack program can only be used with ECLIPSE restart files or summary files.\n"); target_type = -1; } util_alloc_file_components( argv[1] , &path , &ecl_base , NULL); /** Will pack to cwd, even though the source files might be somewhere else. To unpack to the same directory as the source files, just send in @path as first argument when creating the target_file. */ { msg_type * msg; int i , report_step , prev_report_step; char * target_file_name = ecl_util_alloc_filename( NULL , ecl_base , target_type , fmt_file , -1); stringlist_type * filelist = stringlist_alloc_argv_copy( (const char **) &argv[1] , num_files ); ecl_kw_type * seqnum_kw = NULL; fortio_type * target = fortio_open_writer( target_file_name , fmt_file , ECL_ENDIAN_FLIP); if (target_type == ECL_UNIFIED_RESTART_FILE) { int dummy; seqnum_kw = ecl_kw_alloc_new("SEQNUM" , 1 , ECL_INT_TYPE , &dummy); } { char * msg_format = util_alloc_sprintf("Packing %s <= " , target_file_name); msg = msg_alloc( msg_format , false); free( msg_format ); } msg_show( msg ); stringlist_sort( filelist , ecl_util_fname_report_cmp); prev_report_step = -1; for (i=0; i < num_files; i++) { ecl_file_enum this_file_type; this_file_type = ecl_util_get_file_type( stringlist_iget(filelist , i) , NULL , &report_step); if (this_file_type == file_type) { if (report_step == prev_report_step) util_exit("Tried to write same report step twice: %s / %s \n", stringlist_iget(filelist , i-1) , stringlist_iget(filelist , i)); prev_report_step = report_step; msg_update(msg , stringlist_iget( filelist , i)); { ecl_file_type * src_file = ecl_file_open( stringlist_iget( filelist , i) , 0 ); if (target_type == ECL_UNIFIED_RESTART_FILE) { /* Must insert the SEQNUM keyword first. */ ecl_kw_iset_int(seqnum_kw , 0 , report_step); ecl_kw_fwrite( seqnum_kw , target ); } ecl_file_fwrite_fortio( src_file , target , 0); ecl_file_close( src_file ); } } /* Else skipping file of incorrect type. */ } msg_free(msg , false); fortio_fclose( target ); free(target_file_name); stringlist_free( filelist ); if (seqnum_kw != NULL) ecl_kw_free(seqnum_kw); } free(ecl_base); util_safe_free(path); } }
void unpack_file(const char * filename) { ecl_file_enum target_type = ECL_OTHER_FILE; ecl_file_enum file_type; bool fmt_file; file_type = ecl_util_get_file_type(filename , &fmt_file , NULL); if (file_type == ECL_UNIFIED_SUMMARY_FILE) target_type = ECL_SUMMARY_FILE; else if (file_type == ECL_UNIFIED_RESTART_FILE) target_type = ECL_RESTART_FILE; else util_exit("Can only unpack unified ECLIPSE summary and restart files\n"); if (target_type == ECL_SUMMARY_FILE) { printf("** Warning: when unpacking unified summary files it as ambigous - starting with 0001 -> \n"); } { ecl_file_type * src_file = ecl_file_open( filename , 0 ); int size; int offset; int report_step = 0; int block_index = 0; char * path; char * base; msg_type * msg; util_alloc_file_components( filename , &path , &base , NULL); { char * label = util_alloc_sprintf("Unpacking %s => ", filename); msg = msg_alloc( label , false); free( label ); } msg_show(msg); if (target_type == ECL_SUMMARY_FILE) size = ecl_file_get_num_named_kw( src_file , "SEQHDR" ); else size = ecl_file_get_num_named_kw( src_file , "SEQNUM" ); while (true) { if (block_index == size) break; if (target_type == ECL_SUMMARY_FILE) { ecl_file_select_block( src_file , SEQHDR_KW , block_index ); report_step += 1; offset = 0; } else { ecl_kw_type * seqnum_kw; ecl_file_select_block( src_file , SEQNUM_KW , block_index ); seqnum_kw = ecl_file_iget_named_kw( src_file , SEQNUM_KW , 0); report_step = ecl_kw_iget_int( seqnum_kw , 0); offset = 1; } /** Will unpack to cwd, even though the source files might be somewhere else. To unpack to the same directory as the source files, just send in @path as first argument when creating the target_file. */ { char * target_file = ecl_util_alloc_filename( NULL , base , target_type , fmt_file , report_step); fortio_type * fortio_target = fortio_open_writer( target_file , fmt_file , ECL_ENDIAN_FLIP ); msg_update(msg , target_file); ecl_file_fwrite_fortio( src_file , fortio_target , offset); fortio_fclose(fortio_target); free(target_file); } block_index++; } ecl_file_close( src_file ); util_safe_free(path); free(base); msg_free(msg , true); } }
void test_get_tran(const char * name) { char * grid_file_name = ecl_util_alloc_filename(NULL , name , ECL_EGRID_FILE , false , -1); char * init_file_name = ecl_util_alloc_filename(NULL , name , ECL_INIT_FILE , false , -1); ecl_grid_type * grid = ecl_grid_alloc( grid_file_name ); ecl_file_type * grid_file = ecl_file_open( grid_file_name , 0 ); ecl_file_type * init_file = ecl_file_open( init_file_name , 0 ); /* Get global */ { ecl_kw_type * tran_kw = ecl_nnc_export_get_tran_kw( init_file , TRANNNC_KW , 0 ); test_assert_true( ecl_kw_is_instance( tran_kw )); test_assert_double_equal( 0.85582769 , ecl_kw_iget_as_double( tran_kw , 0 )); test_assert_double_equal( 0.24635284 , ecl_kw_iget_as_double( tran_kw , 7184 )); } test_assert_NULL( ecl_nnc_export_get_tran_kw( init_file , TRANGL_KW , 0 )); test_assert_NULL( ecl_nnc_export_get_tran_kw( init_file , TRANLL_KW , 0 )); test_assert_NULL( ecl_nnc_export_get_tran_kw( init_file , "INVALID" , 1)); /* Get lgr_nr: 48 */ { ecl_kw_type * tran_kw = ecl_nnc_export_get_tran_kw( init_file , TRANNNC_KW , 48 ); test_assert_true( ecl_kw_is_instance( tran_kw )); test_assert_int_equal( 0 , ecl_kw_get_size( tran_kw )); tran_kw = ecl_nnc_export_get_tran_kw( init_file , TRANGL_KW , 48 ); test_assert_int_equal( 282 , ecl_kw_get_size( tran_kw )); test_assert_double_equal( 22.922695 , ecl_kw_iget_as_double( tran_kw , 0 )); test_assert_double_equal( 16.720325 , ecl_kw_iget_as_double( tran_kw , 281 )); } /* Get lgr_nr: 99 */ { ecl_kw_type * tran_kw = ecl_nnc_export_get_tran_kw( init_file , TRANNNC_KW , 99 ); test_assert_true( ecl_kw_is_instance( tran_kw )); test_assert_int_equal( 0 , ecl_kw_get_size( tran_kw )); tran_kw = ecl_nnc_export_get_tran_kw( init_file , TRANGL_KW , 99 ); test_assert_int_equal( 693 , ecl_kw_get_size( tran_kw )); test_assert_double_equal( 0.25534782 , ecl_kw_iget_as_double( tran_kw , 0 )); test_assert_double_equal( 0.12677453 , ecl_kw_iget_as_double( tran_kw , 692 )); } /* Get lgr_nr: 10 */ { ecl_kw_type * tran_kw = ecl_nnc_export_get_tran_kw( init_file , TRANNNC_KW , 10 ); test_assert_true( ecl_kw_is_instance( tran_kw )); test_assert_int_equal( 0 , ecl_kw_get_size( tran_kw )); tran_kw = ecl_nnc_export_get_tran_kw( init_file , TRANGL_KW , 10 ); test_assert_int_equal( 260 , ecl_kw_get_size( tran_kw )); test_assert_double_equal( 0.87355447 , ecl_kw_iget_as_double( tran_kw , 0 )); test_assert_double_equal( 26.921568 , ecl_kw_iget_as_double( tran_kw , 259 )); } /* Get lgr_nr: 110 */ { ecl_kw_type * tran_kw = ecl_nnc_export_get_tran_kw( init_file , TRANNNC_KW , 110 ); test_assert_true( ecl_kw_is_instance( tran_kw )); test_assert_int_equal( 0 , ecl_kw_get_size( tran_kw )); tran_kw = ecl_nnc_export_get_tran_kw( init_file , TRANGL_KW , 110 ); test_assert_int_equal( 208 , ecl_kw_get_size( tran_kw )); test_assert_double_equal( 17.287283 , ecl_kw_iget_as_double( tran_kw , 0 )); test_assert_double_equal( 569.26312 , ecl_kw_iget_as_double( tran_kw , 207 )); } free( init_file_name ); free(grid_file_name); ecl_grid_free( grid ); ecl_file_close( grid_file ); ecl_file_close( init_file ); }