bool ECLFilesComparator::gridCompare() const { const int globalGridCount1 = ecl_grid_get_global_size(ecl_grid1); const int activeGridCount1 = ecl_grid_get_active_size(ecl_grid1); const int globalGridCount2 = ecl_grid_get_global_size(ecl_grid2); const int activeGridCount2 = ecl_grid_get_active_size(ecl_grid2); if (globalGridCount1 != globalGridCount2) { OPM_THROW(std::runtime_error, "Grid file: The total number of cells are different."); return false; } if (activeGridCount1 != activeGridCount2) { OPM_THROW(std::runtime_error, "Grid file: The number of active cells are different."); return false; } return true; }
ecl_grid_cache_type * ecl_grid_cache_alloc( const ecl_grid_type * grid ) { ecl_grid_cache_type * grid_cache = util_malloc( sizeof * grid_cache ); grid_cache->grid = grid; grid_cache->volume = NULL; grid_cache->size = ecl_grid_get_active_size( grid ); grid_cache->xpos = util_calloc( grid_cache->size , sizeof * grid_cache->xpos ); grid_cache->ypos = util_calloc( grid_cache->size , sizeof * grid_cache->ypos ); grid_cache->zpos = util_calloc( grid_cache->size , sizeof * grid_cache->zpos ); grid_cache->global_index = util_calloc( grid_cache->size , sizeof * grid_cache->global_index ); { int active_index; /* Go trough all the active cells and extract the cell center position and store it in xpos/ypos/zpos. */ for (active_index = 0; active_index < grid_cache->size; active_index++) { int global_index = ecl_grid_get_global_index1A( grid , active_index ); grid_cache->global_index[ active_index ] = global_index; ecl_grid_get_xyz1( grid , global_index , &grid_cache->xpos[ active_index ] , &grid_cache->ypos[ active_index ] , &grid_cache->zpos[ active_index ]); } } return grid_cache; }
void IntegrationTest::setCellVolumes() { double absTolerance = getAbsTolerance(); double relTolerance = getRelTolerance(); const unsigned int globalGridCount1 = ecl_grid_get_global_size(ecl_grid1); const unsigned int activeGridCount1 = ecl_grid_get_active_size(ecl_grid1); const unsigned int globalGridCount2 = ecl_grid_get_global_size(ecl_grid2); const unsigned int activeGridCount2 = ecl_grid_get_active_size(ecl_grid2); if (globalGridCount1 != globalGridCount2) { OPM_THROW(std::runtime_error, "In grid file:" << "\nCells in first file: " << globalGridCount1 << "\nCells in second file: " << globalGridCount2 << "\nThe number of global cells differ."); } if (activeGridCount1 != activeGridCount2) { OPM_THROW(std::runtime_error, "In grid file:" << "\nCells in first file: " << activeGridCount1 << "\nCells in second file: " << activeGridCount2 << "\nThe number of active cells differ."); } for (unsigned int cell = 0; cell < globalGridCount1; ++cell) { const double cellVolume1 = ecl_grid_get_cell_volume1(ecl_grid1, cell); const double cellVolume2 = ecl_grid_get_cell_volume1(ecl_grid2, cell); Deviation dev = calculateDeviations(cellVolume1, cellVolume2); if (dev.abs > absTolerance && dev.rel > relTolerance) { int i, j, k; ecl_grid_get_ijk1(ecl_grid1, cell, &i, &j, &k); // Coordinates from this function are zero-based, hence incrementing i++, j++, k++; OPM_THROW(std::runtime_error, "In grid file: Deviations of cell volume exceed tolerances. " << "\nFor cell with coordinate (" << i << ", " << j << ", " << k << "):" << "\nCell volume in first file: " << cellVolume1 << "\nCell volume in second file: " << cellVolume2 << "\nThe absolute deviation is " << dev.abs << ", and the tolerance limit is " << absTolerance << "." << "\nThe relative deviation is " << dev.rel << ", and the tolerance limit is " << relTolerance << "."); } // The second input case is used as reference. cellVolumes.push_back(cellVolume2); } }
static ecl_kw_type * ecl_init_file_alloc_INTEHEAD( const ecl_grid_type * ecl_grid , int phases, time_t start_date , int simulator) { ecl_kw_type * intehead_kw = ecl_kw_alloc( INTEHEAD_KW , INTEHEAD_INIT_SIZE , ECL_INT_TYPE ); ecl_kw_scalar_set_int( intehead_kw , 0 ); ecl_kw_iset_int( intehead_kw , INTEHEAD_UNIT_INDEX , INTEHEAD_METRIC_VALUE ); ecl_kw_iset_int( intehead_kw , INTEHEAD_NX_INDEX , ecl_grid_get_nx( ecl_grid )); ecl_kw_iset_int( intehead_kw , INTEHEAD_NY_INDEX , ecl_grid_get_ny( ecl_grid )); ecl_kw_iset_int( intehead_kw , INTEHEAD_NZ_INDEX , ecl_grid_get_nz( ecl_grid )); ecl_kw_iset_int( intehead_kw , INTEHEAD_NACTIVE_INDEX , ecl_grid_get_active_size( ecl_grid )); ecl_kw_iset_int( intehead_kw , INTEHEAD_PHASE_INDEX , phases ); { int mday,month,year; ecl_util_set_date_values( start_date , &mday , &month , &year ); ecl_kw_iset_int( intehead_kw , INTEHEAD_DAY_INDEX , mday ); ecl_kw_iset_int( intehead_kw , INTEHEAD_MONTH_INDEX , month ); ecl_kw_iset_int( intehead_kw , INTEHEAD_YEAR_INDEX , year ); } ecl_kw_iset_int( intehead_kw , INTEHEAD_IPROG_INDEX , simulator); return intehead_kw; }
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); }
int field_config_get_data_size_from_grid(const field_config_type * config) { return config->keep_inactive_cells ? ecl_grid_get_global_size(config->grid) : ecl_grid_get_active_size(config->grid); }
static double gravity_response(const ecl_grid_type * ecl_grid , const ecl_file_type * init_file , const ecl_file_type * restart_file1 , const ecl_file_type * restart_file2 , const grav_station_type * grav_station , int model_phases, int file_phases) { ecl_kw_type * rporv1_kw = NULL; ecl_kw_type * rporv2_kw = NULL; ecl_kw_type * oil_den1_kw = NULL; ecl_kw_type * oil_den2_kw = NULL; ecl_kw_type * gas_den1_kw = NULL; ecl_kw_type * gas_den2_kw = NULL; ecl_kw_type * wat_den1_kw = NULL; ecl_kw_type * wat_den2_kw = NULL; ecl_kw_type * sgas1_kw = NULL; ecl_kw_type * sgas2_kw = NULL; ecl_kw_type * swat1_kw = NULL; ecl_kw_type * swat2_kw = NULL; ecl_kw_type * aquifern_kw = NULL ; double local_deltag = 0; /* Extracting the pore volumes */ rporv1_kw = ecl_file_iget_named_kw( restart_file1 , "RPORV" , 0); rporv2_kw = ecl_file_iget_named_kw( restart_file2 , "RPORV" , 0); /** Extracting the densities */ { // OIL_DEN if( has_phase(model_phases , OIL) ) { if (simulator == ECLIPSE100) { oil_den1_kw = ecl_file_iget_named_kw(restart_file1, "OIL_DEN", 0); oil_den2_kw = ecl_file_iget_named_kw(restart_file2, "OIL_DEN", 0); } else { // ECLIPSE300 oil_den1_kw = ecl_file_iget_named_kw(restart_file1, "DENO", 0); oil_den2_kw = ecl_file_iget_named_kw(restart_file2, "DENO", 0); } ; } // GAS_DEN if( has_phase( model_phases , GAS) ) { if (simulator == ECLIPSE100) { gas_den1_kw = ecl_file_iget_named_kw(restart_file1, "GAS_DEN", 0); gas_den2_kw = ecl_file_iget_named_kw(restart_file2, "GAS_DEN", 0); } else { // ECLIPSE300 gas_den1_kw = ecl_file_iget_named_kw(restart_file1, "DENG", 0); gas_den2_kw = ecl_file_iget_named_kw(restart_file2, "DENG", 0); } ; } // WAT_DEN if( has_phase( model_phases , WATER) ) { if (simulator == ECLIPSE100) { wat_den1_kw = ecl_file_iget_named_kw(restart_file1, "WAT_DEN", 0); wat_den2_kw = ecl_file_iget_named_kw(restart_file2, "WAT_DEN", 0); } else { // ECLIPSE300 wat_den1_kw = ecl_file_iget_named_kw(restart_file1, "DENW", 0); wat_den2_kw = ecl_file_iget_named_kw(restart_file2, "DENW", 0); } ; } } /* Extracting the saturations */ { // SGAS if( has_phase( file_phases , GAS )) { sgas1_kw = ecl_file_iget_named_kw(restart_file1, "SGAS", 0); sgas2_kw = ecl_file_iget_named_kw(restart_file2, "SGAS", 0); } // SWAT if( has_phase( file_phases , WATER )) { swat1_kw = ecl_file_iget_named_kw(restart_file1, "SWAT", 0); swat2_kw = ecl_file_iget_named_kw(restart_file2, "SWAT", 0); } } /* The numerical aquifer information */ if( ecl_file_has_kw( init_file , "AQUIFERN")) aquifern_kw = ecl_file_iget_named_kw(init_file, "AQUIFERN", 0); { int nactive = ecl_grid_get_active_size( ecl_grid ); float * zero = util_calloc( nactive , sizeof * zero ); /* Fake vector of zeros used for densities / sturations when you do not have data. */ int * int_zero = util_calloc( nactive , sizeof * int_zero ); /* Fake vector of zeros used for AQUIFER when the init file does not supply data. */ /* Observe that the fake vectors are only a coding simplification, they should not be really used. */ { int i; for (i=0; i < nactive; i++) { zero[i] = 0; int_zero[i] = 0; } } { const float * sgas1_v = safe_get_float_ptr( sgas1_kw , NULL ); const float * swat1_v = safe_get_float_ptr( swat1_kw , NULL ); const float * oil_den1 = safe_get_float_ptr( oil_den1_kw , zero ); const float * gas_den1 = safe_get_float_ptr( gas_den1_kw , zero ); const float * wat_den1 = safe_get_float_ptr( wat_den1_kw , zero ); const float * sgas2_v = safe_get_float_ptr( sgas2_kw , NULL ); const float * swat2_v = safe_get_float_ptr( swat2_kw , NULL ); const float * oil_den2 = safe_get_float_ptr( oil_den2_kw , zero ); const float * gas_den2 = safe_get_float_ptr( gas_den2_kw , zero ); const float * wat_den2 = safe_get_float_ptr( wat_den2_kw , zero ); const float * rporv1 = ecl_kw_get_float_ptr(rporv1_kw); const float * rporv2 = ecl_kw_get_float_ptr(rporv2_kw); double utm_x = grav_station->utm_x; double utm_y = grav_station->utm_y; double tvd = grav_station->depth; int * aquifern; int global_index; if (aquifern_kw != NULL) aquifern = ecl_kw_get_int_ptr( aquifern_kw ); else aquifern = int_zero; for (global_index=0;global_index < ecl_grid_get_global_size( ecl_grid ); global_index++){ const int act_index = ecl_grid_get_active_index1( ecl_grid , global_index ); if (act_index >= 0) { // Not numerical aquifer if(aquifern[act_index] >= 0){ float swat1 = swat1_v[act_index]; float swat2 = swat2_v[act_index]; float sgas1 = 0; float sgas2 = 0; float soil1 = 0; float soil2 = 0; truncate_saturation( &swat1 ); truncate_saturation( &swat2 ); if (has_phase( model_phases , GAS)) { if (has_phase( file_phases , GAS )) { sgas1 = sgas1_v[act_index]; sgas2 = sgas2_v[act_index]; truncate_saturation( &sgas1 ); truncate_saturation( &sgas2 ); } else { sgas1 = 1 - swat1; sgas2 = 1 - swat2; } } if (has_phase( model_phases , OIL )) { soil1 = 1 - sgas1 - swat1; soil2 = 1 - sgas2 - swat2; truncate_saturation( &soil1 ); truncate_saturation( &soil2 ); } /* We have found all the info we need for one cell. */ { double mas1 , mas2; double xpos , ypos , zpos; mas1 = rporv1[act_index]*(soil1 * oil_den1[act_index] + sgas1 * gas_den1[act_index] + swat1 * wat_den1[act_index] ); mas2 = rporv2[act_index]*(soil2 * oil_den2[act_index] + sgas2 * gas_den2[act_index] + swat2 * wat_den2[act_index] ); ecl_grid_get_xyz1(ecl_grid , global_index , &xpos , &ypos , &zpos); { double dist_x = xpos - utm_x; double dist_y = ypos - utm_y; double dist_d = zpos - tvd; double dist_sq = dist_x*dist_x + dist_y*dist_y + dist_d*dist_d; if(dist_sq == 0){ exit(1); } local_deltag += 6.67428E-3*(mas2 - mas1)*dist_d/pow(dist_sq, 1.5); // Gravity in units of \mu Gal = 10^{-8} m/s^2 } } } } } } free( zero ); free( int_zero ); } return local_deltag; }