Merge pull request #556 from joakim-hove/summarystate-well-api

Summarystate well api
This commit is contained in:
Joakim Hove 2018-11-16 09:42:01 +01:00 committed by GitHub
commit 8b8285ae2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 141 additions and 80 deletions

View File

@ -91,6 +91,7 @@ if(ENABLE_ECL_INPUT)
src/opm/parser/eclipse/EclipseState/Schedule/OilVaporizationProperties.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp
src/opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.cpp
src/opm/parser/eclipse/EclipseState/Schedule/SummaryState.cpp
src/opm/parser/eclipse/EclipseState/Schedule/TimeMap.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Tuning.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Well.cpp
@ -157,7 +158,6 @@ 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
@ -451,6 +451,7 @@ if(ENABLE_ECL_INPUT)
opm/parser/eclipse/EclipseState/Schedule/Well.hpp
opm/parser/eclipse/EclipseState/Schedule/WellInjectionProperties.hpp
opm/parser/eclipse/EclipseState/Schedule/DynamicVector.hpp
opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp
opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp
opm/parser/eclipse/EclipseState/Schedule/WellEconProductionLimits.hpp
opm/parser/eclipse/EclipseState/Schedule/WellPolymerProperties.hpp
@ -516,7 +517,6 @@ 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/WindowedArray.hpp
opm/output/eclipse/WriteRestartHelpers.hpp

View File

@ -21,8 +21,6 @@
#define OPM_AGGREGATE_MSW_DATA_HPP
#include <opm/output/data/Wells.hpp>
#include <opm/output/eclipse/SummaryState.hpp>
#include <opm/output/eclipse/CharArrayNullTerm.hpp>
#include <opm/output/eclipse/WindowedArray.hpp>

View File

@ -35,7 +35,6 @@
#include <opm/output/data/Solution.hpp>
#include <opm/output/data/Wells.hpp>
#include <opm/output/eclipse/RestartValue.hpp>
#include <opm/output/eclipse/SummaryState.hpp>
namespace Opm {

View File

@ -27,10 +27,9 @@
#include <ert/ecl/ecl_sum.h>
#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
#include <opm/output/data/Wells.hpp>
#include <opm/output/eclipse/SummaryState.hpp>
#include <opm/output/eclipse/RegionCache.hpp>
namespace Opm {

View File

@ -1,50 +0,0 @@
/*
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 <string>
#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

View File

@ -0,0 +1,84 @@
/*
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 <string>
#include <unordered_map>
#include <ert/ecl/smspec_node.h>
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*.
The main key used to access the content of this container is the eclipse style
colon separated string - i.e. 'WWCT:OPX' to get the watercut in well 'OPX'.
The main usage of the SummaryState class is a temporary holding ground while
assembling data for the summary output, but it is also used as a context
object when evaulating the condition in ACTIONX keywords. For that reason some
of the data is duplicated both in the general structure and a specialized
structure:
SummaryState st;
st.add_well_var("OPX", "WWCT", 0.75);
st.add("WGOR:OPY", 120);
// The WWCT:OPX key has been added with the specialized add_well_var()
// method and this data is available both with the general
// st.has("WWCT:OPX") and the specialized st.has_well_var("OPX", "WWCT");
st.has("WWCT:OPX") => True
st.has_well_var("OPX", "WWCT") => True
// The WGOR:OPY key is added with the general add("WGOR:OPY") and is *not*
// accessible through the specialized st.has_well_var("OPY", "WGOR").
st.has("WGOR:OPY") => True
st.has_well_var("OPY", "WGOR") => False
*/
class SummaryState {
public:
typedef std::unordered_map<std::string, double>::const_iterator const_iterator;
double get(const std::string&) const;
bool has(const std::string& key) const;
void add(const std::string& key, double value);
void add(const smspec_node_type * node_ptr, double value);
void add_well_var(const std::string& well, const std::string& var, double value);
bool has_well_var(const std::string& well, const std::string& var) const;
double get_well_var(const std::string& well, const std::string& var) const;
const_iterator begin() const;
const_iterator end() const;
private:
std::unordered_map<std::string,double> values;
std::unordered_map<std::string, std::unordered_map<std::string, double>> well_values;
};
}
#endif

View File

@ -18,12 +18,11 @@
*/
#include <opm/output/eclipse/AggregateGroupData.hpp>
#include <opm/output/eclipse/SummaryState.hpp>
#include <opm/output/eclipse/WriteRestartHelpers.hpp>
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
#include <opm/parser/eclipse/EclipseState/Runspec.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Well.hpp>

View File

@ -20,9 +20,9 @@
#include <opm/output/eclipse/AggregateMSWData.hpp>
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
#include <opm/output/eclipse/SummaryState.hpp>
#include <opm/parser/eclipse/EclipseState/Runspec.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Well.hpp>

View File

@ -24,10 +24,9 @@
#include <opm/output/data/Wells.hpp>
#include <opm/output/eclipse/SummaryState.hpp>
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
#include <opm/parser/eclipse/EclipseState/Runspec.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Well.hpp>

View File

@ -39,7 +39,6 @@
#include <opm/output/eclipse/RestartIO.hpp>
#include <opm/output/eclipse/Summary.hpp>
#include <opm/output/eclipse/SummaryState.hpp>
#include <opm/output/eclipse/Tables.hpp>
#include <cstdlib>

View File

@ -28,11 +28,11 @@
#include <opm/output/eclipse/AggregateWellData.hpp>
#include <opm/output/eclipse/AggregateConnectionData.hpp>
#include <opm/output/eclipse/AggregateMSWData.hpp>
#include <opm/output/eclipse/SummaryState.hpp>
#include <opm/output/eclipse/WriteRestartHelpers.hpp>
#include <opm/output/eclipse/libECLRestart.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>

View File

@ -38,8 +38,8 @@
#include <opm/parser/eclipse/EclipseState/Schedule/WellProductionProperties.hpp>
#include <opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp>
#include <opm/parser/eclipse/Units/UnitSystem.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
#include <opm/output/eclipse/SummaryState.hpp>
#include <opm/output/eclipse/Summary.hpp>
#include <opm/output/eclipse/RegionCache.hpp>
@ -1331,7 +1331,7 @@ Summary::Summary( const EclipseState& st,
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);
this->prev_state.add(nodeptr, 0);
}
}
@ -1431,7 +1431,6 @@ void Summary::add_timestep( int report_step,
for( auto& f : this->handlers->handlers ) {
const int num = smspec_node_get_num( f.first );
const auto* genkey = smspec_node_get_gen_key1( f.first );
const auto schedule_wells = find_wells( schedule, f.first, sim_step, this->regionCache );
auto eff_factors = well_efficiency_factors( f.first, schedule, schedule_wells, sim_step );
@ -1446,22 +1445,22 @@ void Summary::add_timestep( int report_step,
eff_factors});
double unit_applied_val = es.getUnits().from_si( val.unit, val.value );
if (smspec_node_is_total(f.first))
if (smspec_node_is_total(f.first)) {
const auto* genkey = smspec_node_get_gen_key1( f.first );
unit_applied_val += this->prev_state.get(genkey);
}
st.add(genkey, unit_applied_val);
st.add(f.first, unit_applied_val);
}
for( const auto& value_pair : single_values ) {
const std::string key = value_pair.first;
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 );
st.add(genkey, output_value);
st.add(node_pair->second, output_value);
}
}
@ -1471,13 +1470,12 @@ 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 );
st.add(genkey, output_value);
st.add(nodeptr, output_value);
}
}
}
@ -1487,11 +1485,10 @@ 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 );
st.add(genkey, output_value);
st.add(nodeptr, output_value);
}
}

View File

@ -18,9 +18,17 @@
*/
#include <opm/output/eclipse/SummaryState.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
namespace Opm{
void SummaryState::add(const smspec_node_type * node_ptr, double value) {
if (smspec_node_get_var_type(node_ptr) == ECL_SMSPEC_WELL_VAR)
this->add_well_var(smspec_node_get_wgname(node_ptr),
smspec_node_get_keyword(node_ptr),
value);
else
this->add(smspec_node_get_gen_key1(node_ptr), value);
}
void SummaryState::add(const std::string& key, double value) {
this->values[key] = value;
@ -40,6 +48,28 @@ namespace Opm{
return iter->second;
}
void SummaryState::add_well_var(const std::string& well, const std::string& var, double value) {
this->add(var + ":" + well, value);
this->well_values[well][var] = value;
}
bool SummaryState::has_well_var(const std::string& well, const std::string& var) const {
const auto& well_iter = this->well_values.find(well);
if (well_iter == this->well_values.end())
return false;
const auto& var_iter = well_iter->second.find(var);
if (var_iter == well_iter->second.end())
return false;
return true;
}
double SummaryState::get_well_var(const std::string& well, const std::string& var) const {
return this->well_values.at(well).at(var);
}
SummaryState::const_iterator SummaryState::begin() const {
return this->values.begin();
}

View File

@ -23,8 +23,7 @@
#include <opm/output/eclipse/AggregateWellData.hpp>
#include <opm/output/eclipse/SummaryState.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
#include <opm/output/eclipse/VectorItems/intehead.hpp>
#include <opm/output/eclipse/VectorItems/well.hpp>

View File

@ -38,6 +38,8 @@
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
#include <opm/parser/eclipse/Parser/Parser.hpp>
#include <opm/parser/eclipse/Utility/Functional.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
// ERT stuff
#include <ert/ecl/ecl_kw.h>

View File

@ -35,8 +35,8 @@
#include <opm/output/data/Wells.hpp>
#include <opm/output/eclipse/Summary.hpp>
#include <opm/output/eclipse/SummaryState.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/Units/UnitSystem.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
@ -1324,6 +1324,12 @@ BOOST_AUTO_TEST_CASE(Test_SummaryState) {
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"));
st.add_well_var("OP1", "WWCT", 0.75);
BOOST_CHECK( st.has_well_var("OP1", "WWCT"));
BOOST_CHECK_EQUAL( st.get_well_var("OP1", "WWCT"), 0.75);
BOOST_CHECK_EQUAL( st.get_well_var("OP1", "WWCT"), st.get("WWCT:OP1"));
}
BOOST_AUTO_TEST_SUITE_END()