void ecl_init_file_fwrite_header( fortio_type * fortio , const ecl_grid_type * ecl_grid , const ecl_kw_type * poro , int phases , time_t start_date) { int simulator = INTEHEAD_ECLIPSE100_VALUE; { ecl_kw_type * intehead_kw = ecl_init_file_alloc_INTEHEAD( ecl_grid , phases , start_date , simulator ); ecl_kw_fwrite( intehead_kw , fortio ); ecl_kw_free( intehead_kw ); } { ecl_kw_type * logihead_kw = ecl_init_file_alloc_LOGIHEAD( simulator ); ecl_kw_fwrite( logihead_kw , fortio ); ecl_kw_free( logihead_kw ); } { ecl_kw_type * doubhead_kw = ecl_init_file_alloc_DOUBHEAD( ); ecl_kw_fwrite( doubhead_kw , fortio ); ecl_kw_free( doubhead_kw ); } if (poro) { int poro_size = ecl_kw_get_size( poro ); if ((poro_size == ecl_grid_get_nactive( ecl_grid )) || (poro_size == ecl_grid_get_global_size(ecl_grid))) ecl_init_file_fwrite_poro( fortio , ecl_grid , poro ); else util_abort("%s: keyword PORO has wrong size:%d Grid: %d/%d \n",__func__ , ecl_kw_get_size( poro ) , ecl_grid_get_nactive( ecl_grid ) , ecl_grid_get_global_size( ecl_grid )); } }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool RifEclipseInputFileTools::readDataFromKeyword(ecl_kw_type* eclipseKeywordData, RigEclipseCaseData* caseData, const QString& resultName) { CVF_ASSERT(caseData); CVF_ASSERT(eclipseKeywordData); bool mathingItemCount = false; { size_t itemCount = static_cast<size_t>(ecl_kw_get_size(eclipseKeywordData)); if (itemCount == caseData->mainGrid()->cellCount()) { mathingItemCount = true; } if (itemCount == caseData->activeCellInfo(RiaDefines::MATRIX_MODEL)->reservoirActiveCellCount()) { mathingItemCount = true; } } if (!mathingItemCount) return false; size_t resultIndex = RifEclipseInputFileTools::findOrCreateResult(resultName, caseData); if (resultIndex == cvf::UNDEFINED_SIZE_T) return false; std::vector< std::vector<double> >& newPropertyData = caseData->results(RiaDefines::MATRIX_MODEL)->cellScalarResults(resultIndex); newPropertyData.push_back(std::vector<double>()); newPropertyData[0].resize(ecl_kw_get_size(eclipseKeywordData), HUGE_VAL); ecl_kw_get_data_as_double(eclipseKeywordData, newPropertyData[0].data()); return true; }
int main( int argc , char ** argv) { const char * egrid_file = argv[1]; ecl_grid_type * grid = ecl_grid_alloc( egrid_file ); ecl_file_type * gfile = ecl_file_open( egrid_file , 0 ); const ecl_kw_type * nnc1_kw = ecl_file_iget_named_kw( gfile , "NNC1" ,0 ); const ecl_kw_type * nnc2_kw = ecl_file_iget_named_kw( gfile , "NNC2" ,0 ); const int_vector_type * index_list = ecl_grid_get_nnc_index_list( grid ); { int_vector_type * nnc = int_vector_alloc(0,0); int_vector_set_many( nnc , 0 , ecl_kw_get_ptr( nnc1_kw ) , ecl_kw_get_size( nnc1_kw )); int_vector_append_many( nnc , ecl_kw_get_ptr( nnc2_kw ) , ecl_kw_get_size( nnc2_kw )); int_vector_select_unique( nnc ); test_assert_int_equal( int_vector_size( index_list ) , int_vector_size( nnc )); { int i; for (i=0; i < int_vector_size( nnc ); i++) test_assert_int_equal( int_vector_iget( nnc , i ) - 1 , int_vector_iget(index_list , i )); } int_vector_free( nnc ); } ecl_file_close( gfile ); ecl_grid_free( grid ); 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); }
unsigned int ECLFilesComparator::getEclKeywordData(ecl_kw_type*& ecl_kw1, ecl_kw_type*& ecl_kw2, const std::string& keyword, int occurrence1, int occurrence2) const { ecl_kw1 = ecl_file_iget_named_kw(ecl_file1, keyword.c_str(), occurrence1); ecl_kw2 = ecl_file_iget_named_kw(ecl_file2, keyword.c_str(), occurrence2); const unsigned int numCells1 = ecl_kw_get_size(ecl_kw1); const unsigned int numCells2 = ecl_kw_get_size(ecl_kw2); if (numCells1 != numCells2) { OPM_THROW(std::runtime_error, "For keyword " << keyword << ":" << "\nOccurrence in first file " << occurrence1 << "\nOccurrence in second file " << occurrence2 << "\nCells in first file: " << numCells1 << "\nCells in second file: " << numCells2 << "\nThe number of cells differ."); } return numCells1; }
void test_create_simple() { test_work_area_type * work_area = test_work_area_alloc("nnc-INIT"); { int nx = 10; int ny = 10; int nz = 10; ecl_grid_type * grid0 = ecl_grid_alloc_rectangular(nx,ny,nz,1,1,1,NULL); ecl_grid_add_self_nnc(grid0, 0 ,nx*ny + 0, 0 ); ecl_grid_add_self_nnc(grid0, 1 ,nx*ny + 1, 1 ); ecl_grid_add_self_nnc(grid0, 2 ,nx*ny + 2, 2 ); { ecl_nnc_geometry_type * nnc_geo = ecl_nnc_geometry_alloc( grid0 ); test_assert_int_equal( ecl_nnc_geometry_size( nnc_geo ) , 3 ); /* Create a dummy INIT file which *ony* contains a TRANNC keyword with the correct size. */ { ecl_kw_type * trann_nnc = ecl_kw_alloc(TRANNNC_KW , ecl_nnc_geometry_size( nnc_geo ), ECL_FLOAT); fortio_type * f = fortio_open_writer( "TEST.INIT" , false, ECL_ENDIAN_FLIP ); for (int i=0; i < ecl_kw_get_size( trann_nnc); i++) ecl_kw_iset_float( trann_nnc , i , i*1.0 ); ecl_kw_fwrite( trann_nnc , f ); fortio_fclose( f ); ecl_kw_free( trann_nnc ); } } ecl_grid_free( grid0 ); } test_work_area_free( work_area ); }
bool fault_block_layer_scan_kw( fault_block_layer_type * layer , const ecl_kw_type * fault_block_kw) { bool assign_zero = true; if (ecl_kw_get_size( fault_block_kw) != ecl_grid_get_global_size(layer->grid)) return false; else if (!ecl_type_is_int(ecl_kw_get_data_type( fault_block_kw ))) return false; else { int i,j; int max_block_id = 0; layer_type * work_layer = layer_alloc( ecl_grid_get_nx( layer->grid ) , ecl_grid_get_ny( layer->grid )); for (j=0; j < ecl_grid_get_ny( layer->grid ); j++) { for (i=0; i < ecl_grid_get_nx( layer->grid ); i++) { int g = ecl_grid_get_global_index3( layer->grid , i , j , layer->k ); int block_id = ecl_kw_iget_int( fault_block_kw , g ); if (block_id > 0) { layer_iset_cell_value( work_layer , i , j , block_id ); max_block_id = util_int_max( block_id , max_block_id ); } } } if (assign_zero) layer_replace_cell_values( work_layer , 0 , max_block_id + 1); fault_block_layer_scan_layer( layer , work_layer ); layer_free( work_layer ); return true; } }
static void ecl_rft_node_init_RFT_cells( ecl_rft_node_type * rft_node , const ecl_file_view_type * rft_view) { const ecl_kw_type * conipos = ecl_file_view_iget_named_kw( rft_view , CONIPOS_KW , 0); const ecl_kw_type * conjpos = ecl_file_view_iget_named_kw( rft_view , CONJPOS_KW , 0); const ecl_kw_type * conkpos = ecl_file_view_iget_named_kw( rft_view , CONKPOS_KW , 0); const ecl_kw_type * depth_kw = ecl_file_view_iget_named_kw( rft_view , DEPTH_KW , 0); const ecl_kw_type * swat_kw = ecl_file_view_iget_named_kw( rft_view , SWAT_KW , 0); const ecl_kw_type * sgas_kw = ecl_file_view_iget_named_kw( rft_view , SGAS_KW , 0); const ecl_kw_type * pressure_kw = ecl_rft_node_get_pressure_kw( rft_node , rft_view ); const float * SW = ecl_kw_get_float_ptr( swat_kw ); const float * SG = ecl_kw_get_float_ptr( sgas_kw ); const float * P = ecl_kw_get_float_ptr( pressure_kw ); const float * depth = ecl_kw_get_float_ptr( depth_kw ); const int * i = ecl_kw_get_int_ptr( conipos ); const int * j = ecl_kw_get_int_ptr( conjpos ); const int * k = ecl_kw_get_int_ptr( conkpos ); { int c; for (c = 0; c < ecl_kw_get_size( conipos ); c++) { /* The connection coordinates are shifted -= 1; i.e. all internal usage is offset 0. */ ecl_rft_cell_type * cell = ecl_rft_cell_alloc_RFT( i[c] - 1 , j[c] - 1 , k[c] - 1 , depth[c] , P[c] , SW[c] , SG[c]); ecl_rft_node_append_cell( rft_node , cell ); } } }
void restoreTemperatureData(const ecl_file_type* file, EclipseStateConstPtr eclipse_state, int numcells, SimulatorState& simulator_state) { const char* temperature = "TEMP"; if (ecl_file_has_kw(file , temperature)) { ecl_kw_type* temperature_kw = ecl_file_iget_named_kw(file, temperature, 0); if (ecl_kw_get_size(temperature_kw) != numcells) { throw std::runtime_error("Read of restart file: Could not restore temperature data, length of data from file not equal number of cells"); } float* temperature_data = ecl_kw_get_float_ptr(temperature_kw); // factor and offset from the temperature values given in the deck to Kelvin double scaling = eclipse_state->getDeckUnitSystem().parse("Temperature")->getSIScaling(); double offset = eclipse_state->getDeckUnitSystem().parse("Temperature")->getSIOffset(); for (size_t index = 0; index < simulator_state.temperature().size(); ++index) { simulator_state.temperature()[index] = unit::convert::from((double)temperature_data[index] - offset, scaling); } } else { throw std::runtime_error("Read of restart file: File does not contain TEMP data\n"); } }
bool fault_block_layer_load_kw( fault_block_layer_type * layer , const ecl_kw_type * fault_block_kw) { if (ecl_kw_get_size( fault_block_kw) != ecl_grid_get_global_size(layer->grid)) return false; else if (!ecl_type_is_int(ecl_kw_get_data_type( fault_block_kw ))) return false; else { int i,j; for (j=0; j < ecl_grid_get_ny( layer->grid ); j++) { for (i=0; i < ecl_grid_get_nx( layer->grid ); i++) { int g = ecl_grid_get_global_index3( layer->grid , i , j , layer->k ); int block_id = ecl_kw_iget_int( fault_block_kw , g ); if (block_id > 0) { fault_block_layer_add_block( layer , block_id ); { fault_block_type * fault_block = fault_block_layer_get_block( layer , block_id ); fault_block_add_cell( fault_block , i,j ); } } } } return true; } }
void test_kw_io_charlength() { test_work_area_type * work_area = test_work_area_alloc("ecl_kw_io_charlength"); { const char * KW0 = "QWERTYUI"; const char * KW1 = "ABCDEFGHIJTTTTTTTTTTTTTTTTTTTTTTABCDEFGHIJKLMNOP"; ecl_kw_type * ecl_kw_out0 = ecl_kw_alloc(KW0 , 5, ECL_FLOAT); ecl_kw_type * ecl_kw_out1 = ecl_kw_alloc(KW1 , 5, ECL_FLOAT); for (int i=0; i < ecl_kw_get_size( ecl_kw_out1); i++) { ecl_kw_iset_float( ecl_kw_out0 , i , i*1.5 ); ecl_kw_iset_float( ecl_kw_out1 , i , i*1.5 ); } { fortio_type * f = fortio_open_writer( "TEST1" , false, ECL_ENDIAN_FLIP ); test_assert_true( ecl_kw_fwrite( ecl_kw_out0, f )); test_assert_false(ecl_kw_fwrite( ecl_kw_out1, f )); fortio_fclose( f ); } { test_assert_false( util_file_exists( "TEST1")); } { FILE * file = util_fopen("TEST2", "w"); ecl_kw_fprintf_grdecl(ecl_kw_out1 , file); fclose(file); } { FILE * file = util_fopen("TEST2", "r"); ecl_kw_type * ecl_kw_in = ecl_kw_fscanf_alloc_grdecl( file , KW1 , -1 , ECL_FLOAT); test_assert_string_equal(KW1, ecl_kw_get_header(ecl_kw_in) ); test_assert_int_equal(5, ecl_kw_get_size( ecl_kw_in) ); test_assert_double_equal(ecl_kw_iget_as_double(ecl_kw_in, 0), 0.0); test_assert_double_equal(ecl_kw_iget_as_double(ecl_kw_in, 4), 6.0); fclose(file); } ecl_kw_free( ecl_kw_out0 ); ecl_kw_free( ecl_kw_out1 ); } test_work_area_free( work_area ); }
void getErtData(ecl_kw_type *eclKeyword, std::vector<int> &data) { size_t kwSize = ecl_kw_get_size(eclKeyword); int* ertData = static_cast<int*>(ecl_kw_iget_ptr(eclKeyword, 0)); data.resize(kwSize); std::copy(ertData, ertData + kwSize, data.begin()); }
void ECLFilesComparator::deviationsForOccurence(const std::string& keyword, int occurence) { ecl_kw_type* ecl_kw1 = ecl_file_iget_named_kw(ecl_file1, keyword.c_str(), occurence); ecl_kw_type* ecl_kw2 = ecl_file_iget_named_kw(ecl_file2, keyword.c_str(), occurence); const unsigned int numCells1 = ecl_kw_get_size(ecl_kw1); const unsigned int numCells2 = ecl_kw_get_size(ecl_kw2); if (numCells1 != numCells2) { std::cout << "For keyword " << keyword << " and occurence " << occurence << ":\n"; OPM_THROW(std::runtime_error, "Number of active cells are different."); } std::vector<double> values1(numCells1), values2(numCells2); ecl_kw_get_data_as_double(ecl_kw1, values1.data()); ecl_kw_get_data_as_double(ecl_kw2, values2.data()); auto it = std::find(keywordWhitelist.begin(), keywordWhitelist.end(), keyword); for (unsigned int cell = 0; cell < values1.size(); cell++) { deviationsForCell(values1[cell], values2[cell], keyword, occurence, cell, it == keywordWhitelist.end()); } }
static void ecl_file_kw_assert_kw( const ecl_file_kw_type * file_kw ) { if (file_kw->ecl_type != ecl_kw_get_type( file_kw->kw )) util_abort("%s: type mismatch between header and file.\n",__func__); if (file_kw->kw_size != ecl_kw_get_size( file_kw->kw )) util_abort("%s: size mismatch between header and file.\n",__func__); if (strcmp( file_kw->header , ecl_kw_get_header( file_kw->kw )) != 0 ) util_abort("%s: name mismatch between header and file.\n",__func__); }
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); }
void test_tranLL( const ecl_grid_type * grid , const ecl_file_type * init_file , int lgr_nr1 , int lgr_nr2, int size, double first , double last) { ecl_kw_type * ecl_kw = ecl_nnc_export_get_tranll_kw(grid , init_file , lgr_nr1 , lgr_nr2 ); printf("lgr: %d -> %d \n",lgr_nr1 , lgr_nr2); test_assert_not_NULL(ecl_kw); test_assert_true(ecl_kw_is_instance( ecl_kw )); test_assert_int_equal( size , ecl_kw_get_size( ecl_kw )); test_assert_double_equal( first , ecl_kw_iget_as_double( ecl_kw , 0 )); test_assert_double_equal( last , ecl_kw_iget_as_double( ecl_kw , size - 1 )); }
void ecl_file_kw_replace_kw( ecl_file_kw_type * file_kw , fortio_type * target , ecl_kw_type * new_kw ) { if ((file_kw->ecl_type == ecl_kw_get_type( new_kw )) && (file_kw->kw_size == ecl_kw_get_size( new_kw ))) { if (file_kw->kw != NULL) ecl_kw_free( file_kw->kw ); file_kw->kw = new_kw; fortio_fseek( target , file_kw->file_offset , SEEK_SET ); ecl_kw_fwrite( file_kw->kw , target ); } else util_abort("%s: sorry size/type mismatch between in-file keyword and new keyword \n",__func__); }
static void ecl_rft_node_init_PLT_cells( ecl_rft_node_type * rft_node , const ecl_file_view_type * rft_view) { /* For PLT there is quite a lot of extra information which is not yet internalized. */ const ecl_kw_type * conipos = ecl_file_view_iget_named_kw( rft_view , CONIPOS_KW , 0); const ecl_kw_type * conjpos = ecl_file_view_iget_named_kw( rft_view , CONJPOS_KW , 0); const ecl_kw_type * conkpos = ecl_file_view_iget_named_kw( rft_view , CONKPOS_KW , 0); const int * i = ecl_kw_get_int_ptr( conipos ); const int * j = ecl_kw_get_int_ptr( conjpos ); const int * k = ecl_kw_get_int_ptr( conkpos ); const float * WR = ecl_kw_get_float_ptr( ecl_file_view_iget_named_kw( rft_view , CONWRAT_KW , 0)); const float * GR = ecl_kw_get_float_ptr( ecl_file_view_iget_named_kw( rft_view , CONGRAT_KW , 0)); const float * OR = ecl_kw_get_float_ptr( ecl_file_view_iget_named_kw( rft_view , CONORAT_KW , 0)); const float * P = ecl_kw_get_float_ptr( ecl_rft_node_get_pressure_kw( rft_node , rft_view )); const float * depth = ecl_kw_get_float_ptr( ecl_file_view_iget_named_kw( rft_view , CONDEPTH_KW , 0)); const float * flowrate = ecl_kw_get_float_ptr( ecl_file_view_iget_named_kw( rft_view , CONVTUB_KW , 0)); const float * oil_flowrate = ecl_kw_get_float_ptr( ecl_file_view_iget_named_kw( rft_view , CONOTUB_KW , 0)); const float * gas_flowrate = ecl_kw_get_float_ptr( ecl_file_view_iget_named_kw( rft_view , CONGTUB_KW , 0)); const float * water_flowrate = ecl_kw_get_float_ptr( ecl_file_view_iget_named_kw( rft_view , CONWTUB_KW , 0)); const float * connection_start = NULL; const float * connection_end = NULL; /* The keywords CONLENST_KW and CONLENEN_KW are ONLY present if we are dealing with a MSW well. */ if (ecl_file_view_has_kw( rft_view , CONLENST_KW)) connection_start = ecl_kw_get_float_ptr( ecl_file_view_iget_named_kw( rft_view , CONLENST_KW , 0)); if (ecl_file_view_has_kw( rft_view , CONLENEN_KW)) connection_end = ecl_kw_get_float_ptr( ecl_file_view_iget_named_kw( rft_view , CONLENEN_KW , 0)); { int c; for ( c = 0; c < ecl_kw_get_size( conipos ); c++) { ecl_rft_cell_type * cell; double cs = 0; double ce = 0; if (connection_start) cs = connection_start[c]; if (connection_end) ce = connection_end[c]; /* The connection coordinates are shifted -= 1; i.e. all internal usage is offset 0. */ cell = ecl_rft_cell_alloc_PLT( i[c] -1 , j[c] -1 , k[c] -1 , depth[c] , P[c] , OR[c] , GR[c] , WR[c] , cs , ce, flowrate[c] , oil_flowrate[c] , gas_flowrate[c] , water_flowrate[c]); ecl_rft_node_append_cell( rft_node , cell ); } } }
bool fault_block_layer_export( const fault_block_layer_type * layer , ecl_kw_type * faultblock_kw) { if (ecl_type_is_int(ecl_kw_get_data_type( faultblock_kw )) && (ecl_kw_get_size( faultblock_kw ) == ecl_grid_get_global_size( layer->grid ))) { int i,j; for (j=0; j < ecl_grid_get_ny( layer->grid ); j++) { for (i=0; i < ecl_grid_get_nx( layer->grid ); i++) { int g = ecl_grid_get_global_index3( layer->grid , i, j , layer->k ); int cell_value = layer_iget_cell_value( layer->layer , i , j ); ecl_kw_iset_int( faultblock_kw , g , cell_value); } } return true; } else return false; }
void ecl_file_kw_replace_kw( ecl_file_kw_type * file_kw , fortio_type * target , ecl_kw_type * new_kw ) { if (!ecl_type_is_equal( ecl_file_kw_get_data_type(file_kw), ecl_kw_get_data_type(new_kw) )) util_abort("%s: sorry type mismatch between in-file keyword and new keyword \n",__func__); if(file_kw->kw_size != ecl_kw_get_size(new_kw)) util_abort("%s: sorry size mismatch between in-file keyword and new keyword \n",__func__); if (file_kw->kw != NULL) ecl_kw_free( file_kw->kw ); file_kw->kw = new_kw; fortio_fseek( target , file_kw->file_offset , SEEK_SET ); ecl_kw_fwrite( file_kw->kw , target ); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool RifEclipseOutputFileTools::keywordData(ecl_file_type* ecl_file, const QString& keyword, size_t fileKeywordOccurrence, std::vector<int>* values) { ecl_kw_type* kwData = ecl_file_iget_named_kw(ecl_file, keyword.toAscii().data(), static_cast<int>(fileKeywordOccurrence)); if (kwData) { size_t numValues = ecl_kw_get_size(kwData); std::vector<int> integerData; integerData.resize(numValues); ecl_kw_get_memcpy_int_data(kwData, integerData.data()); values->insert(values->end(), integerData.begin(), integerData.end()); return true; } return false; }
static ecl_grav_survey_type * ecl_grav_survey_alloc_RPORV(ecl_grav_type * ecl_grav , const ecl_file_type * restart_file , const char * name ) { ecl_grav_survey_type * survey = ecl_grav_survey_alloc_empty( ecl_grav , name , GRAV_CALC_RPORV); if (ecl_file_has_kw( restart_file , RPORV_KW)) { ecl_kw_type * rporv_kw = ecl_file_iget_named_kw( restart_file , RPORV_KW , 0); int iactive; for (iactive = 0; iactive < ecl_kw_get_size( rporv_kw ); iactive++) survey->porv[ iactive ] = ecl_kw_iget_as_double( rporv_kw , iactive ); } else util_abort("%s: restart file did not contain %s keyword??\n",__func__ , RPORV_KW); { const ecl_file_type * init_file = ecl_grav->init_file; ecl_grav_survey_assert_RPORV( survey , init_file ); ecl_grav_survey_add_phases( ecl_grav , survey , restart_file , GRAV_CALC_RPORV); } return survey; }
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 ); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool RifEclipseOutputFileTools::keywordData(ecl_file_type* ecl_file, const QString& keyword, size_t fileKeywordOccurrence, std::vector<int>* values) { bool result = false; #pragma omp critical(critical_section_keywordData_int) { ecl_kw_type* kwData = ecl_file_iget_named_kw(ecl_file, RiaStringEncodingTools::toNativeEncoded(keyword).data(), static_cast<int>(fileKeywordOccurrence)); if (kwData) { size_t numValues = ecl_kw_get_size(kwData); std::vector<int> integerData; integerData.resize(numValues); ecl_kw_get_memcpy_int_data(kwData, integerData.data()); values->insert(values->end(), integerData.begin(), integerData.end()); result = true; } } return result; }
void restorePressureData(const ecl_file_type* file, EclipseStateConstPtr eclipse_state, int numcells, SimulatorState& simulator_state) { const char* pressure = "PRESSURE"; if (ecl_file_has_kw(file , pressure)) { ecl_kw_type* pressure_kw = ecl_file_iget_named_kw(file, pressure, 0); if (ecl_kw_get_size(pressure_kw) != numcells) { throw std::runtime_error("Read of restart file: Could not restore pressure data, length of data from file not equal number of cells"); } float* pressure_data = ecl_kw_get_float_ptr(pressure_kw); const double deck_pressure_unit = (eclipse_state->getDeckUnitSystem().getType() == UnitSystem::UNIT_TYPE_METRIC) ? Opm::unit::barsa : Opm::unit::psia; for (size_t index = 0; index < simulator_state.pressure().size(); ++index) { simulator_state.pressure()[index] = unit::convert::from((double)pressure_data[index], deck_pressure_unit); } } else { throw std::runtime_error("Read of restart file: File does not contain PRESSURE data\n"); } }
ecl_sum_tstep_type * ecl_sum_tstep_alloc_from_file( int report_step , int ministep_nr , const ecl_kw_type * params_kw , const char * src_file , const ecl_smspec_type * smspec) { int data_size = ecl_kw_get_size( params_kw ); if (data_size == ecl_smspec_get_params_size( smspec )) { ecl_sum_tstep_type * ministep = ecl_sum_tstep_alloc( report_step , ministep_nr , smspec); ecl_kw_get_memcpy_data( params_kw , ministep->data ); ecl_sum_tstep_set_time_info( ministep , smspec ); return ministep; } else { /* This is actually a fatal error / bug; the difference in smspec header structure should have been detected already in the ecl_smspec_load_restart() function and the restart case discarded. */ fprintf(stderr , "** Warning size mismatch between timestep loaded from:%s and header:%s - timestep discarded.\n" , src_file , ecl_smspec_get_header_file( smspec )); return NULL; } }
ecl_file_kw_type * ecl_file_kw_alloc( const ecl_kw_type * ecl_kw , offset_type offset ) { return ecl_file_kw_alloc0( ecl_kw_get_header( ecl_kw ) , ecl_kw_get_data_type( ecl_kw ) , ecl_kw_get_size( ecl_kw ) , offset ); }
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 ); }
size_t size() const { return static_cast<size_t>( ecl_kw_get_size( m_kw.get() )); }