void test_write_header() { int nx = 10; int ny = 10; int nz = 5; int_vector_type * actnum = int_vector_alloc( nx*ny*nz , 1 ); test_work_area_type * test_area = test_work_area_alloc( "ecl_init_file" ); time_t start_time = util_make_date(15 , 12 , 2010 ); ecl_grid_type * ecl_grid; int_vector_iset( actnum , 10 , 0 ); int_vector_iset( actnum , 100 , 0 ); ecl_grid = ecl_grid_alloc_rectangular(nx, ny, nz, 1, 1, 1, int_vector_get_ptr( actnum )); // Write poro with global size. { fortio_type * f = fortio_open_writer( "FOO1.INIT" , false , ECL_ENDIAN_FLIP ); ecl_kw_type * poro = ecl_kw_alloc( "PORO" , ecl_grid_get_global_size( ecl_grid ) , ECL_FLOAT_TYPE ); ecl_kw_scalar_set_float( poro , 0.10 ); ecl_init_file_fwrite_header( f , ecl_grid , poro , 7 , start_time ); ecl_kw_free( poro ); fortio_fclose( f ); } // Write poro with nactive size. { fortio_type * f = fortio_open_writer( "FOO2.INIT" , false , ECL_ENDIAN_FLIP ); ecl_kw_type * poro = ecl_kw_alloc( "PORO" , ecl_grid_get_global_size( ecl_grid ) , ECL_FLOAT_TYPE ); ecl_kw_scalar_set_float( poro , 0.10 ); ecl_init_file_fwrite_header( f , ecl_grid , poro , 7 , start_time ); ecl_kw_free( poro ); fortio_fclose( f ); } { ecl_file_type * file1 = ecl_file_open( "FOO1.INIT" , 0 ); ecl_file_type * file2 = ecl_file_open( "FOO2.INIT" , 0 ); test_assert_true( ecl_kw_equal( ecl_file_iget_named_kw( file1 , "PORV" , 0 ) , ecl_file_iget_named_kw( file2 , "PORV" , 0))); ecl_file_close( file2 ); ecl_file_close( file1 ); } // Poro == NULL { fortio_type * f = fortio_open_writer( "FOO3.INIT" , false , ECL_ENDIAN_FLIP ); ecl_init_file_fwrite_header( f , ecl_grid , NULL , 7 , start_time ); fortio_fclose( f ); } test_work_area_free( test_area ); }
static ecl_grav_phase_type * ecl_grav_phase_alloc( ecl_grav_type * ecl_grav , ecl_grav_survey_type * survey , ecl_phase_enum phase , const ecl_file_type * restart_file, grav_calc_type calc_type) { const ecl_file_type * init_file = ecl_grav->init_file; const ecl_grid_cache_type * grid_cache = ecl_grav->grid_cache; const char * sat_kw_name = ecl_util_get_phase_name( phase ); { ecl_grav_phase_type * grav_phase = util_malloc( sizeof * grav_phase ); const int size = ecl_grid_cache_get_size( grid_cache ); UTIL_TYPE_ID_INIT( grav_phase , ECL_GRAV_PHASE_TYPE_ID ); grav_phase->grid_cache = grid_cache; grav_phase->aquifer_cell = ecl_grav->aquifer_cell; grav_phase->fluid_mass = util_calloc( size , sizeof * grav_phase->fluid_mass ); grav_phase->phase = phase; grav_phase->work = NULL; if (calc_type == GRAV_CALC_FIP) { ecl_kw_type * pvtnum_kw = ecl_file_iget_named_kw( init_file , PVTNUM_KW , 0 ); double_vector_type * std_density = hash_get( ecl_grav->std_density , ecl_util_get_phase_name( phase )); ecl_kw_type * fip_kw; if ( phase == ECL_OIL_PHASE) fip_kw = ecl_file_iget_named_kw( restart_file , FIPOIL_KW , 0 ); else if (phase == ECL_GAS_PHASE) fip_kw = ecl_file_iget_named_kw( restart_file , FIPGAS_KW , 0 ); else fip_kw = ecl_file_iget_named_kw( restart_file , FIPWAT_KW , 0 ); { int iactive; for (iactive=0; iactive < size; iactive++) { double fip = ecl_kw_iget_as_double( fip_kw , iactive ); int pvtnum = ecl_kw_iget_int( pvtnum_kw , iactive ); grav_phase->fluid_mass[ iactive ] = fip * double_vector_safe_iget( std_density , pvtnum ); } } } else { ecl_version_enum ecl_version = ecl_file_get_ecl_version( init_file ); const char * den_kw_name = get_den_kw( phase , ecl_version ); const ecl_kw_type * den_kw = ecl_file_iget_named_kw( restart_file , den_kw_name , 0 ); if (calc_type == GRAV_CALC_RFIP) { ecl_kw_type * rfip_kw; if ( phase == ECL_OIL_PHASE) rfip_kw = ecl_file_iget_named_kw( restart_file , RFIPOIL_KW , 0 ); else if (phase == ECL_GAS_PHASE) rfip_kw = ecl_file_iget_named_kw( restart_file , RFIPGAS_KW , 0 ); else rfip_kw = ecl_file_iget_named_kw( restart_file , RFIPWAT_KW , 0 ); { int iactive; for (iactive=0; iactive < size; iactive++) { double rho = ecl_kw_iget_as_double( den_kw , iactive ); double rfip = ecl_kw_iget_as_double( rfip_kw , iactive ); grav_phase->fluid_mass[ iactive ] = rho * rfip; } } } else { /* (calc_type == GRAV_CALC_RPORV) || (calc_type == GRAV_CALC_PORMOD) */ ecl_kw_type * sat_kw; bool private_sat_kw = false; if (ecl_file_has_kw( restart_file , sat_kw_name )) sat_kw = ecl_file_iget_named_kw( restart_file , sat_kw_name , 0 ); else { /* We are targeting the residual phase, e.g. the OIL phase in a three phase system. */ const ecl_kw_type * swat_kw = ecl_file_iget_named_kw( restart_file , "SWAT" , 0 ); sat_kw = ecl_kw_alloc_copy( swat_kw ); ecl_kw_scalar_set_float( sat_kw , 1.0 ); ecl_kw_inplace_sub( sat_kw , swat_kw ); /* sat = 1 - SWAT */ if (ecl_file_has_kw( restart_file , "SGAS" )) { const ecl_kw_type * sgas_kw = ecl_file_iget_named_kw( restart_file , "SGAS" , 0 ); ecl_kw_inplace_sub( sat_kw , sgas_kw ); /* sat -= SGAS */ } private_sat_kw = true; } { int iactive; for (iactive=0; iactive < size; iactive++) { double rho = ecl_kw_iget_as_double( den_kw , iactive ); double sat = ecl_kw_iget_as_double( sat_kw , iactive ); grav_phase->fluid_mass[ iactive ] = rho * sat * survey->porv[ iactive ]; } } if (private_sat_kw) ecl_kw_free( sat_kw ); } } return grav_phase; } }