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); }
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 )); } }
int main(int argc , char ** argv) { const int nx = 5; const int ny = 4; const int nz = 2; const int g = nx*ny*nz; const int nactive = g - 9; const int actnum1[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; const int actnum2[] = {0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0}; ecl_grid_type * grid = ecl_grid_alloc_rectangular(nx , ny , nz , 1 , 1 , 1 , actnum1 ); test_assert_int_equal( g , ecl_grid_get_nactive( grid )); ecl_grid_reset_actnum(grid , actnum2 ); test_assert_int_equal( nactive , ecl_grid_get_nactive( grid )); test_assert_int_equal( -1 , ecl_grid_get_active_index1( grid , 0 )); test_assert_int_equal( 0 , ecl_grid_get_active_index1( grid , 1 )); test_assert_int_equal( -1 , ecl_grid_get_active_index1( grid , 2 )); test_assert_int_equal( 1 , ecl_grid_get_global_index1A( grid , 0 )); test_assert_int_equal( 3 , ecl_grid_get_global_index1A( grid , 1 )); test_assert_int_equal( 5 , ecl_grid_get_global_index1A( grid , 2 )); ecl_grid_reset_actnum(grid , NULL ); test_assert_int_equal( g , ecl_grid_get_nactive( grid )); test_assert_int_equal( 0 , ecl_grid_get_active_index1( grid , 0 )); test_assert_int_equal( 1 , ecl_grid_get_active_index1( grid , 1 )); test_assert_int_equal( 2 , ecl_grid_get_active_index1( grid , 2 )); test_assert_int_equal( 0 , ecl_grid_get_global_index1A( grid , 0 )); test_assert_int_equal( 1 , ecl_grid_get_global_index1A( grid , 1 )); test_assert_int_equal( 2 , ecl_grid_get_global_index1A( grid , 2 )); 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); }
//-------------------------------------------------------------------------------------------------- /// Read geometry from file given by name into given reservoir object //-------------------------------------------------------------------------------------------------- bool RifReaderEclipseOutput::transferGeometry(const ecl_grid_type* mainEclGrid, RigReservoir* reservoir) { CVF_ASSERT(reservoir); if (!mainEclGrid) { // Some error return false; } RigMainGrid* mainGrid = reservoir->mainGrid(); { cvf::Vec3st gridPointDim(0,0,0); gridPointDim.x() = ecl_grid_get_nx(mainEclGrid) + 1; gridPointDim.y() = ecl_grid_get_ny(mainEclGrid) + 1; gridPointDim.z() = ecl_grid_get_nz(mainEclGrid) + 1; mainGrid->setGridPointDimensions(gridPointDim); } // Get and set grid and lgr metadata size_t totalCellCount = static_cast<size_t>(ecl_grid_get_global_size(mainEclGrid)); int numLGRs = ecl_grid_get_num_lgr(mainEclGrid); int lgrIdx; for (lgrIdx = 0; lgrIdx < numLGRs; ++lgrIdx) { ecl_grid_type* localEclGrid = ecl_grid_iget_lgr(mainEclGrid, lgrIdx); std::string lgrName = ecl_grid_get_name(localEclGrid); cvf::Vec3st gridPointDim(0,0,0); gridPointDim.x() = ecl_grid_get_nx(localEclGrid) + 1; gridPointDim.y() = ecl_grid_get_ny(localEclGrid) + 1; gridPointDim.z() = ecl_grid_get_nz(localEclGrid) + 1; RigLocalGrid* localGrid = new RigLocalGrid(mainGrid); mainGrid->addLocalGrid(localGrid); localGrid->setIndexToStartOfCells(totalCellCount); localGrid->setGridName(lgrName); localGrid->setGridPointDimensions(gridPointDim); totalCellCount += ecl_grid_get_global_size(localEclGrid); } // Reserve room for the cells and nodes and fill them with data mainGrid->cells().reserve(totalCellCount); mainGrid->nodes().reserve(8*totalCellCount); caf::ProgressInfo progInfo(3 + numLGRs, ""); progInfo.setProgressDescription("Main Grid"); progInfo.setNextProgressIncrement(3); transferGridCellData(mainGrid, mainGrid, mainEclGrid, 0, 0); progInfo.setProgress(3); size_t globalMatrixActiveSize = ecl_grid_get_nactive(mainEclGrid); size_t globalFractureActiveSize = ecl_grid_get_nactive_fracture(mainEclGrid); mainGrid->setMatrixModelActiveCellCount(globalMatrixActiveSize); mainGrid->setFractureModelActiveCellCount(globalFractureActiveSize); for (lgrIdx = 0; lgrIdx < numLGRs; ++lgrIdx) { progInfo.setProgressDescription("LGR number " + QString::number(lgrIdx+1)); ecl_grid_type* localEclGrid = ecl_grid_iget_lgr(mainEclGrid, lgrIdx); RigLocalGrid* localGrid = static_cast<RigLocalGrid*>(mainGrid->gridByIndex(lgrIdx+1)); transferGridCellData(mainGrid, localGrid, localEclGrid, globalMatrixActiveSize, globalFractureActiveSize); int activeCellCount = ecl_grid_get_nactive(localEclGrid); localGrid->setMatrixModelActiveCellCount(activeCellCount); globalMatrixActiveSize += activeCellCount; activeCellCount = ecl_grid_get_nactive_fracture(localEclGrid); localGrid->setFractureModelActiveCellCount(activeCellCount); globalFractureActiveSize += activeCellCount; progInfo.setProgress(3 + lgrIdx); } mainGrid->setGlobalMatrixModelActiveCellCount(globalMatrixActiveSize); mainGrid->setGlobalFractureModelActiveCellCount(globalFractureActiveSize); return true; }