Skip to content

Commit

Permalink
Merge pull request #191 from joakim-hove/summary-extra
Browse files Browse the repository at this point in the history
Ability to pass misc values to summary writer.
  • Loading branch information
atgeirr committed Jun 8, 2017
2 parents b5d8b43 + ecffd73 commit 7d68753
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 94 deletions.
8 changes: 5 additions & 3 deletions opm/output/eclipse/EclipseIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ void EclipseIO::writeTimeStep(int report_step,
double secs_elapsed,
data::Solution cells,
data::Wells wells,
std::map<std::string, std::vector<double>> extra,
std::map<std::string, double> misc_summary_values,
std::map<std::string, std::vector<double>> extra_restart,
bool write_double)
{

Expand All @@ -404,7 +405,8 @@ void EclipseIO::writeTimeStep(int report_step,
secs_elapsed,
es,
wells ,
cells );
cells ,
misc_summary_values );
this->impl->summary.write();
}

Expand All @@ -422,7 +424,7 @@ void EclipseIO::writeTimeStep(int report_step,
report_step,
ioConfig.getFMTOUT() );

RestartIO::save( filename , report_step, secs_elapsed, cells, wells, es , grid , extra , write_double);
RestartIO::save( filename , report_step, secs_elapsed, cells, wells, es , grid , extra_restart , write_double);
}


Expand Down
23 changes: 19 additions & 4 deletions opm/output/eclipse/EclipseIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ class EclipseIO {
* can be added here are represented with mnenonics in the RPTRST
* keyword.
*
* The extra argument is an optional aergument which can be used
* to store arbitrary double vectors in the restart file. The
* following rules apply for the extra data:
* The extra_restart argument is an optional aergument which can
* be used to store arbitrary double vectors in the restart
* file. The following rules apply for the extra data:
*
* 1. There is no size constraints.
*
Expand All @@ -139,14 +139,29 @@ class EclipseIO {
* precision. OPM can load and restart from files with double
* precision keywords, but this is non-standard, and other third
* party applications might choke on those.
*
* The misc_summary_values argument is used to pass pass various
* summary values which are of type 'ECL_SMSPEC_MISC_VAR' to the
* summary writer. The ability to pass miscellanous values to the
* summary writer is not very flexible:
*
* 1. The keyword must be an already well defined ECLIPSE keyword
* like e.g. one of the performance related keywords.
*
* 2. The keyword must have been requested in the SUMMARY section
* of the input deck.
*
* 3. The dimension of the keyword must have specified in the
* hardcoded static map misc_units in Summary.cpp.
*/

void writeTimeStep( int report_step,
bool isSubstep,
double seconds_elapsed,
data::Solution,
data::Wells,
std::map<std::string, std::vector<double>> extra = {},
std::map<std::string, double> misc_summary_values,
std::map<std::string, std::vector<double>> extra_restart = {},
bool write_double = false);


Expand Down
125 changes: 88 additions & 37 deletions opm/output/eclipse/Summary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,6 @@ quantity bsgas( const fn_args& args) {
}


quantity extra_time( const fn_args& args) {
return { 0.0, measure::time };
}


template< typename F, typename G >
Expand Down Expand Up @@ -736,12 +733,26 @@ static const std::unordered_map< std::string, ofun > funs = {
{"BWSAT" , bswat},
{"BSGAS" , bsgas},
{"BGSAS" , bsgas},

/* Misc keywords, the 'extra' handlers will only set the value 0 - with the correct dimension*/
{"TCPU" , extra_time}
};


static const std::unordered_map< std::string, UnitSystem::measure> misc_units = {
{"TCPU" , UnitSystem::measure::identity },
{"ELAPSED" , UnitSystem::measure::identity },
{"NEWTON" , UnitSystem::measure::identity },
{"NLINERS" , UnitSystem::measure::identity },
{"NLINSMIN" , UnitSystem::measure::identity },
{"NLINSMAX" , UnitSystem::measure::identity },
{"MLINEARS" , UnitSystem::measure::identity },
{"MSUMLINS" , UnitSystem::measure::identity },
{"MSUMNEWT" , UnitSystem::measure::identity },
{"TCPUTS" , UnitSystem::measure::identity },
{"TIMESTEP" , UnitSystem::measure::time },
{"TCPUDAY" , UnitSystem::measure::time },
{"STEPTYPE" , UnitSystem::measure::identity },
{"TELAPLIN" , UnitSystem::measure::time }
};

inline std::vector< const Well* > find_wells( const Schedule& schedule,
const smspec_node_type* node,
size_t timestep ) {
Expand Down Expand Up @@ -784,6 +795,7 @@ class Summary::keyword_handlers {
public:
using fn = ofun;
std::vector< std::pair< smspec_node_type*, fn > > handlers;
std::map< std::string, smspec_node_type* > misc_nodes;
};

Summary::Summary( const EclipseState& st,
Expand Down Expand Up @@ -826,43 +838,69 @@ Summary::Summary( const EclipseState& st,
*/
for( const auto& node : sum ) {
const auto* keyword = node.keyword();
if( funs.find( keyword ) == funs.end() ) continue;

if ((node.type() == ECL_SMSPEC_COMPLETION_VAR) || (node.type() == ECL_SMSPEC_BLOCK_VAR)) {
int global_index = node.num() - 1;
if (!this->grid.cellActive(global_index))
continue;
}

/* get unit strings by calling each function with dummy input */
const auto handle = funs.find( keyword )->second;
const std::vector< const Well* > dummy_wells;

const fn_args no_args { dummy_wells, // Wells from Schedule object
0, // Duration of time step
0, // Timestep number
node.num(), // NUMS value for the summary output.
{}, // Well results - data::Wells
{}, // Solution::State
{}, // Region <-> cell mappings.
this->grid,
this->initial_oip,
{} };

const auto val = handle( no_args );
const auto* unit = st.getUnits().name( val.unit );

auto* nodeptr = ecl_sum_add_var( this->ecl_sum.get(), keyword,
node.wgname(), node.num(), unit, 0 );
this->handlers->handlers.emplace_back( nodeptr, handle );

/*
All summary values of the type ECL_SMSPEC_MISC_VAR must be
passed explicitly in the misc_values map when calling
add_timestep.
*/
if (node.type() == ECL_SMSPEC_MISC_VAR) {
const auto pair = misc_units.find( keyword );
if (pair == misc_units.end())
continue;

auto* nodeptr = ecl_sum_add_var( this->ecl_sum.get(),
keyword,
node.wgname(),
node.num(),
st.getUnits().name( pair->second ),
0 );

this->handlers->misc_nodes.emplace( keyword, nodeptr );
} else {
if( funs.find( keyword ) == funs.end() ) continue;

if ((node.type() == ECL_SMSPEC_COMPLETION_VAR) || (node.type() == ECL_SMSPEC_BLOCK_VAR)) {
int global_index = node.num() - 1;
if (!this->grid.cellActive(global_index))
continue;
}

/* get unit strings by calling each function with dummy input */
const auto handle = funs.find( keyword )->second;
const std::vector< const Well* > dummy_wells;

const fn_args no_args { dummy_wells, // Wells from Schedule object
0, // Duration of time step
0, // Timestep number
node.num(), // NUMS value for the summary output.
{}, // Well results - data::Wells
{}, // Solution::State
{}, // Region <-> cell mappings.
this->grid,
this->initial_oip,
{} };

const auto val = handle( no_args );

auto* nodeptr = ecl_sum_add_var( this->ecl_sum.get(),
keyword,
node.wgname(),
node.num(),
st.getUnits().name( val.unit ),
0 );

this->handlers->handlers.emplace_back( nodeptr, handle );
}
}
}

void Summary::add_timestep( int report_step,
double secs_elapsed,
const EclipseState& es,
const data::Wells& wells ,
const data::Solution& state) {
const data::Solution& state,
const std::map<std::string, double>& misc_values) {

auto* tstep = ecl_sum_add_tstep( this->ecl_sum.get(), report_step, secs_elapsed );
const double duration = secs_elapsed - this->prev_time_elapsed;
Expand Down Expand Up @@ -891,7 +929,20 @@ void Summary::add_timestep( int report_step,
? ecl_sum_tstep_get_from_key( prev_tstep, genkey ) + unit_applied_val
: unit_applied_val;

ecl_sum_tstep_set_from_node( tstep, f.first, res );
ecl_sum_tstep_set_from_node( tstep, f.first, res );
}


for( const auto& value_pair : misc_values ) {
const std::string key = value_pair.first;
const auto node_pair = this->handlers->misc_nodes.find( key );
if (node_pair != this->handlers->misc_nodes.end()) {
const auto * nodeptr = node_pair->second;
const auto unit = misc_units.at( key );
double si_value = value_pair.second;
double output_value = es.getUnits().from_si(unit , si_value );
ecl_sum_tstep_set_from_node( tstep, nodeptr , output_value );
}
}

this->prev_tstep = tstep;
Expand Down
3 changes: 2 additions & 1 deletion opm/output/eclipse/Summary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class Summary {
double secs_elapsed,
const EclipseState& es,
const data::Wells&,
const data::Solution& );
const data::Solution&,
const std::map<std::string, double>& misc_values);

void set_initial( const data::Solution& );
void write();
Expand Down
10 changes: 6 additions & 4 deletions tests/test_EclipseIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,12 @@ BOOST_AUTO_TEST_CASE(EclipseIOIntegration) {

auto first_step = ecl_util_make_date( 10 + i, 11, 2008 );
eclWriter.writeTimeStep( i,
false,
first_step - start_time,
sol,
wells);
false,
first_step - start_time,
sol,
wells,
{});



checkRestartFile( i );
Expand Down
3 changes: 2 additions & 1 deletion tests/test_RFT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ BOOST_AUTO_TEST_CASE(test_RFT) {
false,
step_time - start_time,
createBlackoilState( 2, numCells ),
wells);
wells,
{});
}

verifyRFTFile("TESTRFT.RFT");
Expand Down
2 changes: 1 addition & 1 deletion tests/test_Restart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ RestartValue first_sim(const EclipseState& es, EclipseIO& eclWriter, bool write_
eclWriter.writeTimeStep( 1,
false,
first_step - start_time,
sol, wells , {}, write_double);
sol, wells , {}, {}, write_double);

return { sol, wells , {}};
}
Expand Down
Loading

0 comments on commit 7d68753

Please sign in to comment.