Merge pull request #403 from joakim-hove/summary_state
Add SummaryState class to hold on to summary state.
This commit is contained in:
@@ -149,6 +149,7 @@ if(ENABLE_ECL_OUTPUT)
|
||||
src/opm/output/eclipse/LogiHEAD.cpp
|
||||
src/opm/output/eclipse/RestartIO.cpp
|
||||
src/opm/output/eclipse/Summary.cpp
|
||||
src/opm/output/eclipse/SummaryState.cpp
|
||||
src/opm/output/eclipse/Tables.cpp
|
||||
src/opm/output/eclipse/RegionCache.cpp
|
||||
src/opm/output/eclipse/RestartValue.cpp
|
||||
@@ -496,6 +497,7 @@ if(ENABLE_ECL_OUTPUT)
|
||||
opm/output/eclipse/RestartIO.hpp
|
||||
opm/output/eclipse/RestartValue.hpp
|
||||
opm/output/eclipse/Summary.hpp
|
||||
opm/output/eclipse/SummaryState.hpp
|
||||
opm/output/eclipse/Tables.hpp
|
||||
opm/output/eclipse/WriteRestartHelpers.hpp
|
||||
opm/output/OutputWriter.hpp
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
|
||||
|
||||
#include <opm/output/eclipse/SummaryState.hpp>
|
||||
#include <opm/output/data/Wells.hpp>
|
||||
#include <opm/output/eclipse/RegionCache.hpp>
|
||||
|
||||
@@ -68,8 +69,8 @@ class Summary {
|
||||
out::RegionCache regionCache;
|
||||
ERT::ert_unique_ptr< ecl_sum_type, ecl_sum_free > ecl_sum;
|
||||
std::unique_ptr< keyword_handlers > handlers;
|
||||
const ecl_sum_tstep_type* prev_tstep = nullptr;
|
||||
double prev_time_elapsed = 0;
|
||||
SummaryState prev_state;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
50
opm/output/eclipse/SummaryState.hpp
Normal file
50
opm/output/eclipse/SummaryState.hpp
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
Copyright 2016 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SUMMARY_STATE_H
|
||||
#define SUMMARY_STATE_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Opm{
|
||||
|
||||
|
||||
/*
|
||||
The purpose of this class is to serve as a small container object for
|
||||
computed, ready to use summary values. The values will typically be used by
|
||||
the UDQ, WTEST and ACTIONX calculations. Observe that all value *have been
|
||||
converted to the correct output units*.
|
||||
*/
|
||||
class SummaryState {
|
||||
public:
|
||||
typedef std::unordered_map<std::string, double>::const_iterator const_iterator;
|
||||
|
||||
void add(const std::string& key, double value);
|
||||
double get(const std::string&) const;
|
||||
bool has(const std::string& key) const;
|
||||
|
||||
const_iterator begin() const;
|
||||
const_iterator end() const;
|
||||
private:
|
||||
std::unordered_map<std::string,double> values;
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp>
|
||||
#include <opm/parser/eclipse/Units/UnitSystem.hpp>
|
||||
|
||||
#include <opm/output/eclipse/SummaryState.hpp>
|
||||
#include <opm/output/eclipse/Summary.hpp>
|
||||
#include <opm/output/eclipse/RegionCache.hpp>
|
||||
|
||||
@@ -955,6 +956,12 @@ Summary::Summary( const EclipseState& st,
|
||||
for ( const auto& keyword : unsupported_keywords ) {
|
||||
Opm::OpmLog::info("Keyword " + std::string(keyword) + " is unhandled");
|
||||
}
|
||||
|
||||
for (const auto& pair : this->handlers->handlers) {
|
||||
const auto * nodeptr = pair.first;
|
||||
if (smspec_node_is_total(nodeptr))
|
||||
this->prev_state.add(smspec_node_get_gen_key1(nodeptr), 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1028,6 +1035,7 @@ void Summary::add_timestep( int report_step,
|
||||
|
||||
auto* tstep = ecl_sum_add_tstep( this->ecl_sum.get(), report_step, secs_elapsed );
|
||||
const double duration = secs_elapsed - this->prev_time_elapsed;
|
||||
SummaryState st;
|
||||
|
||||
/* report_step is the number of the file we are about to write - i.e. for instance CASE.S$report_step
|
||||
* for the data in a non-unified summary file.
|
||||
@@ -1051,12 +1059,11 @@ void Summary::add_timestep( int report_step,
|
||||
this->grid,
|
||||
eff_factors});
|
||||
|
||||
const auto unit_applied_val = es.getUnits().from_si( val.unit, val.value );
|
||||
const auto res = smspec_node_is_total( f.first ) && prev_tstep
|
||||
? ecl_sum_tstep_get_from_key( prev_tstep, genkey ) + unit_applied_val
|
||||
: unit_applied_val;
|
||||
double unit_applied_val = es.getUnits().from_si( val.unit, val.value );
|
||||
if (smspec_node_is_total(f.first))
|
||||
unit_applied_val += this->prev_state.get(genkey);
|
||||
|
||||
ecl_sum_tstep_set_from_node( tstep, f.first, res );
|
||||
st.add(genkey, unit_applied_val);
|
||||
}
|
||||
|
||||
for( const auto& value_pair : single_values ) {
|
||||
@@ -1064,10 +1071,11 @@ void Summary::add_timestep( int report_step,
|
||||
const auto node_pair = this->handlers->single_value_nodes.find( key );
|
||||
if (node_pair != this->handlers->single_value_nodes.end()) {
|
||||
const auto * nodeptr = node_pair->second;
|
||||
const auto * genkey = smspec_node_get_gen_key1( nodeptr );
|
||||
const auto unit = single_values_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 );
|
||||
st.add(genkey, output_value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1077,11 +1085,13 @@ void Summary::add_timestep( int report_step,
|
||||
const auto node_pair = this->handlers->region_nodes.find( std::make_pair(key, reg+1) );
|
||||
if (node_pair != this->handlers->region_nodes.end()) {
|
||||
const auto * nodeptr = node_pair->second;
|
||||
const auto* genkey = smspec_node_get_gen_key1( nodeptr );
|
||||
const auto unit = region_units.at( key );
|
||||
|
||||
assert (smspec_node_get_num( nodeptr ) - 1 == static_cast<int>(reg));
|
||||
double si_value = value_pair.second[reg];
|
||||
double output_value = es.getUnits().from_si(unit , si_value );
|
||||
ecl_sum_tstep_set_from_node( tstep, nodeptr , output_value );
|
||||
st.add(genkey, output_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1091,14 +1101,18 @@ void Summary::add_timestep( int report_step,
|
||||
const auto node_pair = this->handlers->block_nodes.find( key );
|
||||
if (node_pair != this->handlers->block_nodes.end()) {
|
||||
const auto * nodeptr = node_pair->second;
|
||||
const auto * genkey = smspec_node_get_gen_key1( nodeptr );
|
||||
const auto unit = block_units.at( key.first );
|
||||
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 );
|
||||
st.add(genkey, output_value);
|
||||
}
|
||||
}
|
||||
|
||||
this->prev_tstep = tstep;
|
||||
for (const auto& pair: st)
|
||||
ecl_sum_tstep_set_from_key(tstep, pair.first.c_str(), pair.second);
|
||||
|
||||
this->prev_state = st;
|
||||
this->prev_time_elapsed = secs_elapsed;
|
||||
}
|
||||
|
||||
|
||||
52
src/opm/output/eclipse/SummaryState.cpp
Normal file
52
src/opm/output/eclipse/SummaryState.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
Copyright 2016 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <opm/output/eclipse/SummaryState.hpp>
|
||||
|
||||
namespace Opm{
|
||||
|
||||
void SummaryState::add(const std::string& key, double value) {
|
||||
this->values[key] = value;
|
||||
}
|
||||
|
||||
|
||||
bool SummaryState::has(const std::string& key) const {
|
||||
return (this->values.find(key) != this->values.end());
|
||||
}
|
||||
|
||||
|
||||
double SummaryState::get(const std::string& key) const {
|
||||
const auto iter = this->values.find(key);
|
||||
if (iter == this->values.end())
|
||||
throw std::invalid_argument("XX No such key: " + key);
|
||||
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
SummaryState::const_iterator SummaryState::begin() const {
|
||||
return this->values.begin();
|
||||
}
|
||||
|
||||
|
||||
SummaryState::const_iterator SummaryState::end() const {
|
||||
return this->values.end();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,11 +26,13 @@
|
||||
#include <stdexcept>
|
||||
|
||||
#include <ert/ecl/ecl_sum.h>
|
||||
#include <ert/ecl/smspec_node.h>
|
||||
#include <ert/util/util.h>
|
||||
#include <ert/util/TestArea.hpp>
|
||||
|
||||
#include <opm/output/data/Wells.hpp>
|
||||
#include <opm/output/eclipse/Summary.hpp>
|
||||
#include <opm/output/eclipse/SummaryState.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <opm/parser/eclipse/Units/UnitSystem.hpp>
|
||||
@@ -1218,3 +1220,15 @@ BOOST_AUTO_TEST_CASE(efficiency_factor) {
|
||||
BOOST_CHECK_CLOSE( 200.1, ecl_sum_get_well_completion_var( resp, 1, "W_2", "COPR", 2 ), 1e-5 );
|
||||
BOOST_CHECK_CLOSE( 200.1 * 0.2 * 0.01, ecl_sum_get_well_completion_var( resp, 1, "W_2", "COPT", 2 ), 1e-5 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Test_SummaryState) {
|
||||
Opm::SummaryState st;
|
||||
st.add("WWCT:OP_2", 100);
|
||||
BOOST_CHECK_CLOSE(st.get("WWCT:OP_2"), 100, 1e-5);
|
||||
BOOST_CHECK_THROW(st.get("NO_SUCH_KEY"), std::invalid_argument);
|
||||
BOOST_CHECK(st.has("WWCT:OP_2"));
|
||||
BOOST_CHECK(!st.has("NO_SUCH_KEY"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user