Merge pull request #480 from joakim-hove/thrpes-solution-section
Thrpes solution section
This commit is contained in:
@@ -54,6 +54,18 @@ namespace RestartIO {
|
||||
|
||||
|
||||
namespace {
|
||||
/*
|
||||
The RestartValue structure has an 'extra' container which can be used to
|
||||
add extra fields to the restart file. The extra field is used both to add
|
||||
OPM specific fields like 'OPMEXTRA', and eclipse standard fields like
|
||||
THPRESPR. In the case of e.g. THPRESPR this should - if present - be added
|
||||
in the SOLUTION section of the restart file. The std::set extra_solution
|
||||
just enumerates the keys which should be in the solution section.
|
||||
*/
|
||||
|
||||
static const std::set<std::string> extra_solution = {"THPRESPR"};
|
||||
|
||||
|
||||
|
||||
static const int NIWELZ = 11; //Number of data elements per well in IWEL array in restart file
|
||||
static const int NZWELZ = 3; //Number of 8-character words per well in ZWEL array restart file
|
||||
@@ -499,18 +511,27 @@ void writeHeader(ecl_rst_file_type * rst_file,
|
||||
|
||||
|
||||
|
||||
void writeSolution(ecl_rst_file_type* rst_file, const data::Solution& solution, bool write_double) {
|
||||
ecl_rst_file_start_solution( rst_file );
|
||||
for (const auto& elm: solution) {
|
||||
if (elm.second.target == data::TargetType::RESTART_SOLUTION)
|
||||
ecl_rst_file_add_kw( rst_file , ecl_kw(elm.first, elm.second.data, write_double).get());
|
||||
}
|
||||
ecl_rst_file_end_solution( rst_file );
|
||||
void writeSolution(ecl_rst_file_type* rst_file, const RestartValue& value, bool write_double) {
|
||||
ecl_rst_file_start_solution( rst_file );
|
||||
for (const auto& elm: value.solution) {
|
||||
if (elm.second.target == data::TargetType::RESTART_SOLUTION)
|
||||
ecl_rst_file_add_kw( rst_file , ecl_kw(elm.first, elm.second.data, write_double).get());
|
||||
}
|
||||
for (const auto& elm: value.extra) {
|
||||
const std::string& key = elm.first.key;
|
||||
const std::vector<double>& data = elm.second;
|
||||
if (extra_solution.find(key) != extra_solution.end())
|
||||
/*
|
||||
Observe that the extra data is unconditionally written in double precision.
|
||||
*/
|
||||
ecl_rst_file_add_kw(rst_file, ecl_kw(key, data, true).get());
|
||||
}
|
||||
ecl_rst_file_end_solution( rst_file );
|
||||
|
||||
for (const auto& elm: solution) {
|
||||
if (elm.second.target == data::TargetType::RESTART_AUXILIARY)
|
||||
ecl_rst_file_add_kw( rst_file , ecl_kw(elm.first, elm.second.data, write_double).get());
|
||||
}
|
||||
for (const auto& elm: value.solution) {
|
||||
if (elm.second.target == data::TargetType::RESTART_AUXILIARY)
|
||||
ecl_rst_file_add_kw( rst_file , ecl_kw(elm.first, elm.second.data, write_double).get());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -518,7 +539,7 @@ void writeHeader(ecl_rst_file_type * rst_file,
|
||||
for (const auto& extra_value : extra_data) {
|
||||
const std::string& key = extra_value.first.key;
|
||||
const std::vector<double>& data = extra_value.second;
|
||||
{
|
||||
if (extra_solution.find(key) == extra_solution.end()) {
|
||||
ecl_kw_type * ecl_kw = ecl_kw_alloc_new_shared( key.c_str() , data.size() , ECL_DOUBLE , const_cast<double *>(data.data()));
|
||||
ecl_rst_file_add_kw( rst_file , ecl_kw);
|
||||
ecl_kw_free( ecl_kw );
|
||||
@@ -607,7 +628,7 @@ void save(const std::string& filename,
|
||||
|
||||
writeHeader( rst_file.get(), sim_step, report_step, posix_time , sim_time, ert_phase_mask, units, schedule , grid );
|
||||
writeWell( rst_file.get(), sim_step, es , grid, schedule, value.wells);
|
||||
writeSolution( rst_file.get(), value.solution, write_double );
|
||||
writeSolution( rst_file.get(), value, write_double );
|
||||
writeExtraData( rst_file.get(), value.extra );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -605,6 +605,31 @@ BOOST_AUTO_TEST_CASE(STORE_THPRES) {
|
||||
int num_regions = setup.es.getTableManager().getEqldims().getNumEquilRegions();
|
||||
std::vector<double> thpres(num_regions * num_regions, 78);
|
||||
restart_value2.addExtra("THPRESPR", UnitSystem::measure::pressure, thpres);
|
||||
restart_value2.addExtra("EXTRA", UnitSystem::measure::pressure, thpres);
|
||||
|
||||
RestartIO::save("FILE2.UNRST", 1,
|
||||
100,
|
||||
restart_value2,
|
||||
setup.es,
|
||||
setup.grid,
|
||||
setup.schedule);
|
||||
|
||||
{
|
||||
ecl_file_type * rst_file = ecl_file_open("FILE2.UNRST", 0);
|
||||
std::map<std::string,int> kw_pos;
|
||||
for (int i=0; i < ecl_file_get_size(rst_file); i++)
|
||||
kw_pos[ ecl_file_iget_header(rst_file, i ) ] = i;
|
||||
|
||||
BOOST_CHECK( kw_pos["STARTSOL"] < kw_pos["THPRESPR"] );
|
||||
BOOST_CHECK( kw_pos["THPRESPR"] < kw_pos["ENDSOL"] );
|
||||
BOOST_CHECK( kw_pos["ENDSOL"] < kw_pos["EXTRA"] );
|
||||
|
||||
BOOST_CHECK_EQUAL( ecl_file_get_num_named_kw(rst_file, "THPRESPR"), 1);
|
||||
BOOST_CHECK_EQUAL( ecl_file_get_num_named_kw(rst_file, "EXTRA"), 1);
|
||||
BOOST_CHECK_EQUAL( ecl_kw_get_type(ecl_file_iget_named_kw(rst_file, "THPRESPR", 0)), ECL_DOUBLE_TYPE);
|
||||
ecl_file_close(rst_file);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user