Add UDQContext class to be used while evaluating UDQ keywords
This commit is contained in:
@@ -125,6 +125,7 @@ if(ENABLE_ECL_INPUT)
|
||||
src/opm/parser/eclipse/EclipseState/Tables/Tables.cpp
|
||||
src/opm/parser/eclipse/EclipseState/UDQParams.cpp
|
||||
src/opm/parser/eclipse/EclipseState/Schedule/UDQ.cpp
|
||||
src/opm/parser/eclipse/EclipseState/Schedule/UDQContext.cpp
|
||||
src/opm/parser/eclipse/EclipseState/Schedule/UDQExpression.cpp
|
||||
src/opm/parser/eclipse/EclipseState/Schedule/VFPInjTable.cpp
|
||||
src/opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.cpp
|
||||
@@ -504,6 +505,7 @@ if(ENABLE_ECL_INPUT)
|
||||
opm/parser/eclipse/EclipseState/IOConfig/IOConfig.hpp
|
||||
opm/parser/eclipse/EclipseState/checkDeck.hpp
|
||||
opm/parser/eclipse/EclipseState/Runspec.hpp
|
||||
opm/parser/eclipse/EclipseState/Schedule/UDQContext.hpp
|
||||
opm/parser/eclipse/EclipseState/Schedule/UDQ.hpp
|
||||
opm/parser/eclipse/EclipseState/UDQParams.hpp
|
||||
opm/parser/eclipse/EclipseState/Schedule/UDQExpression.hpp
|
||||
|
||||
43
opm/parser/eclipse/EclipseState/Schedule/UDQContext.hpp
Normal file
43
opm/parser/eclipse/EclipseState/Schedule/UDQContext.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
Copyright 2019 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 UDQ_CONTEXT_HPP
|
||||
#define UDQ_CONTEXT_HPP
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Opm {
|
||||
class SummaryState;
|
||||
|
||||
class UDQContext{
|
||||
public:
|
||||
explicit UDQContext(const SummaryState& summary_state);
|
||||
double get(const std::string& key) const;
|
||||
void add(const std::string& key, double value);
|
||||
private:
|
||||
const SummaryState& summary_state;
|
||||
std::unordered_map<std::string, double> values;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
60
src/opm/parser/eclipse/EclipseState/Schedule/UDQContext.cpp
Normal file
60
src/opm/parser/eclipse/EclipseState/Schedule/UDQContext.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
Copyright 2019 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/parser/eclipse/EclipseState/Schedule/TimeMap.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/UDQContext.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
|
||||
|
||||
|
||||
namespace Opm {
|
||||
|
||||
UDQContext::UDQContext(const SummaryState& summary_state) :
|
||||
summary_state(summary_state)
|
||||
{
|
||||
for (const auto& pair : TimeMap::eclipseMonthIndices())
|
||||
this->add(pair.first, pair.second);
|
||||
|
||||
/*
|
||||
Simulator performance keywords which are expected to be available for
|
||||
UDQ keywords; probably better to guarantee that they are present in
|
||||
the underlying summary state object.
|
||||
*/
|
||||
|
||||
this->add("ELAPSED", 0.0);
|
||||
this->add("MSUMLINS", 0.0);
|
||||
this->add("MSUMNEWT", 0.0);
|
||||
this->add("NEWTON", 0.0);
|
||||
this->add("TCPU", 0.0);
|
||||
this->add("TIME", 0.0);
|
||||
this->add("TIMESTEP", 0.0);
|
||||
}
|
||||
|
||||
|
||||
void UDQContext::add(const std::string& key, double value) {
|
||||
this->values[key] = value;
|
||||
}
|
||||
|
||||
double UDQContext::get(const std::string& key) const {
|
||||
const auto& pair_ptr = this->values.find(key);
|
||||
if (pair_ptr == this->values.end())
|
||||
return this->summary_state.get(key);
|
||||
|
||||
return pair_ptr->second;
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,8 @@
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/UDQ.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/UDQExpression.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/UDQContext.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
@@ -99,6 +101,11 @@ UDQ
|
||||
|
||||
BOOST_CHECK_THROW( udq.unit("NO_SUCH_KEY"), std::invalid_argument );
|
||||
BOOST_CHECK_EQUAL( udq.unit("WUBHP"), "BARSA");
|
||||
|
||||
Parser parser;
|
||||
auto deck = parser.parseString(input);
|
||||
auto udq_params = UDQParams(deck);
|
||||
BOOST_CHECK_EQUAL(0.25, udq_params.cmpEpsilon());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(UDQ_CHANGE_UNITS_ILLEGAL) {
|
||||
@@ -180,3 +187,17 @@ DEFINE WUMW1 WBHP 'P*1*' UMAX WBHP 'P*4*' /
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(UDQ_CONTEXT) {
|
||||
SummaryState st;
|
||||
UDQContext ctx(st);
|
||||
BOOST_CHECK_EQUAL(ctx.get("JAN"), 1.0);
|
||||
|
||||
BOOST_REQUIRE_THROW(ctx.get("NO_SUCH_KEY"), std::out_of_range);
|
||||
|
||||
for (std::string& key : std::vector<std::string>({"ELAPSED", "MSUMLINS", "MSUMNEWT", "NEWTON", "TCPU", "TIME", "TIMESTEP"}))
|
||||
BOOST_CHECK_NO_THROW( ctx.get(key) );
|
||||
|
||||
st.add("SUMMARY:KEY", 1.0);
|
||||
BOOST_CHECK_EQUAL(ctx.get("SUMMARY:KEY") , 1.0 );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user