Merge pull request #1967 from joakim-hove/throw-opm-error

Throw opm error
This commit is contained in:
Joakim Hove
2020-09-28 12:50:36 +02:00
committed by GitHub
7 changed files with 101 additions and 47 deletions

View File

@@ -16,14 +16,15 @@
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_ERROR_HPP
#define OPM_ERROR_HPP
#include <stdexcept>
#include <string>
#include <fmt/format.h>
#ifndef OPM_ERROR_HPP
#define OPM_ERROR_HPP
#include <opm/common/OpmLog/KeywordLocation.hpp>
namespace Opm {
@@ -73,10 +74,7 @@ public:
OpmInputError(const std::string& msg_fmt, const KeywordLocation& loc) :
m_what(fmt::format(msg_fmt,
fmt::arg("keyword", loc.keyword),
fmt::arg("file", loc.filename),
fmt::arg("line", loc.lineno))),
m_what(OpmInputError::format(msg_fmt, loc)),
location(loc)
{}
@@ -86,6 +84,14 @@ public:
}
static std::string format(const std::string& msg_fmt, const KeywordLocation& loc) {
return fmt::format(msg_fmt,
fmt::arg("keyword", loc.keyword),
fmt::arg("file", loc.filename),
fmt::arg("line", loc.lineno));
}
private:
std::string m_what;

View File

@@ -22,6 +22,7 @@
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/common/OpmLog/KeywordLocation.hpp>
#include <opm/common/utility/OpmInputError.hpp>
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
#include <opm/parser/eclipse/EclipseState/IOConfig/IOConfig.hpp>

View File

@@ -19,7 +19,10 @@
#include <set>
#include <fmt/format.h>
#include <opm/common/OpmLog/LogUtil.hpp>
#include <opm/common/utility/OpmInputError.hpp>
#include <opm/parser/eclipse/Deck/DeckSection.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
@@ -47,18 +50,19 @@ namespace Opm {
EclipseState::EclipseState(const Deck& deck) :
m_tables( deck ),
m_runspec( deck ),
m_eclipseConfig( deck ),
m_deckUnitSystem( deck.getActiveUnitSystem() ),
m_inputNnc( deck ),
m_inputEditNnc( deck ),
m_inputGrid( deck, nullptr ),
m_gridDims( deck ),
field_props( deck, m_runspec.phases(), m_inputGrid, m_tables),
m_simulationConfig( m_eclipseConfig.getInitConfig().restartRequested(), deck, field_props),
m_transMult( GridDims(deck), deck, field_props)
EclipseState::EclipseState(const Deck& deck)
try
: m_tables( deck ),
m_runspec( deck ),
m_eclipseConfig( deck ),
m_deckUnitSystem( deck.getActiveUnitSystem() ),
m_inputNnc( deck ),
m_inputEditNnc( deck ),
m_inputGrid( deck, nullptr ),
m_gridDims( deck ),
field_props( deck, m_runspec.phases(), m_inputGrid, m_tables),
m_simulationConfig( m_eclipseConfig.getInitConfig().restartRequested(), deck, field_props),
m_transMult( GridDims(deck), deck, field_props)
{
m_inputGrid.resetACTNUM(this->field_props.actnum());
if( this->runspec().phases().size() < 3 )
@@ -80,6 +84,15 @@ namespace Opm {
initFaults(deck);
this->field_props.reset_actnum( this->m_inputGrid.getACTNUM() );
}
catch (const OpmInputError& opm_error) {
throw;
}
catch (const std::exception& std_error) {
OpmLog::error(fmt::format("An error occured while creating the reservoir properties\n",
"Internal error: {}", std_error.what()));
throw;
}
const UnitSystem& EclipseState::getDeckUnitSystem() const {

View File

@@ -25,9 +25,12 @@
#include <unordered_set>
#include <vector>
#include <fmt/format.h>
#include <opm/common/OpmLog/LogUtil.hpp>
#include <opm/common/utility/numeric/cmp.hpp>
#include <opm/common/utility/String.hpp>
#include <opm/common/utility/OpmInputError.hpp>
#include <opm/parser/eclipse/Python/Python.hpp>
#include <opm/parser/eclipse/Deck/DeckItem.hpp>
@@ -97,7 +100,8 @@ namespace {
const ParseContext& parseContext,
ErrorGuard& errors,
[[maybe_unused]] std::shared_ptr<const Python> python,
const RestartIO::RstState * rst) :
const RestartIO::RstState * rst)
try :
python_handle(python),
m_timeMap( deck , restart_info( rst )),
m_oilvaporizationproperties( this->m_timeMap, OilVaporizationProperties(runspec.tabdims().getNumPVTTables()) ),
@@ -143,6 +147,16 @@ namespace {
if (DeckSection::hasSCHEDULE(deck))
iterateScheduleSection( python, deck.getInputPath(), parseContext, errors, SCHEDULESection( deck ), grid, fp);
}
catch (const OpmInputError& opm_error) {
throw;
}
catch (const std::exception& std_error) {
OpmLog::error(fmt::format("An error occured while creating the reservoir schedule\n",
"Internal error: {}", std_error.what()));
throw;
}
template <typename T>

View File

@@ -22,6 +22,8 @@
#include <cmath>
#include <iostream>
#include <fmt/format.h>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/Deck/DeckItem.hpp>

View File

@@ -29,6 +29,7 @@
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
#include <opm/parser/eclipse/Parser/ErrorGuard.hpp>
#include <opm/common/utility/OpmInputError.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/Deck/DeckItem.hpp>
@@ -1126,40 +1127,46 @@ SummaryConfig::SummaryConfig( const Deck& deck,
const ParseContext& parseContext,
ErrorGuard& errors,
const GridDims& dims) {
SUMMARYSection section( deck );
try {
SUMMARYSection section( deck );
const auto node_names = need_node_names(section)
? collect_node_names(schedule)
: std::vector<std::string>{};
const auto node_names = need_node_names(section) ? collect_node_names(schedule) : std::vector<std::string> {};
for (const auto &kw : section) {
if (is_processing_instruction(kw.name())) {
handleProcessingInstruction(kw.name());
} else {
handleKW(this->m_keywords, node_names, kw, schedule, tables, parseContext, errors, dims);
}
}
for (const auto& meta_pair : meta_keywords) {
if( section.hasKeyword( meta_pair.first ) ) {
const auto& deck_keyword = section.getKeyword(meta_pair.first);
for (const auto& kw : meta_pair.second) {
if (!this->hasKeyword(kw))
handleKW(this->m_keywords, kw, deck_keyword.location(), schedule, parseContext, errors);
for (const auto& kw : section) {
if (is_processing_instruction(kw.name())) {
handleProcessingInstruction(kw.name());
} else {
handleKW(this->m_keywords, node_names, kw, schedule, tables, parseContext, errors, dims);
}
}
}
uniq( this->m_keywords );
for (const auto& kw: this->m_keywords) {
this->short_keywords.insert( kw.keyword() );
this->summary_keywords.insert( kw.uniqueNodeKey() );
for (const auto& meta_pair : meta_keywords) {
if (section.hasKeyword(meta_pair.first)) {
const auto& deck_keyword = section.getKeyword(meta_pair.first);
for (const auto& kw : meta_pair.second) {
if (!this->hasKeyword(kw))
handleKW(this->m_keywords, kw, deck_keyword.location(), schedule, parseContext, errors);
}
}
}
uniq(this->m_keywords);
for (const auto& kw : this->m_keywords) {
this->short_keywords.insert(kw.keyword());
this->summary_keywords.insert(kw.uniqueNodeKey());
}
}
catch (const OpmInputError& opm_error) {
throw;
}
catch (const std::exception& std_error) {
OpmLog::error(fmt::format("An error occured while configuring the summary properties\n",
"Internal error: {}", std_error.what()));
throw;
}
}
SummaryConfig::SummaryConfig( const Deck& deck,
const Schedule& schedule,
const TableManager& tables,

View File

@@ -31,6 +31,7 @@
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/common/OpmLog/LogUtil.hpp>
#include <opm/common/utility/OpmInputError.hpp>
#include <opm/json/JsonObject.hpp>
@@ -920,15 +921,25 @@ bool parseState( ParserState& parserState, const Parser& parser ) {
*rawKeyword,
parserState.deck.getActiveUnitSystem(),
parserState.deck.getDefaultUnitSystem()));
} catch (const std::exception& exc) {
} catch (const OpmInputError& opm_error) {
throw;
}
catch (const std::exception& std_error) {
/*
This catch-all of parsing errors is to be able to write a good
error message; the parser is quite confused at this state and
we should not be tempted to continue the parsing.
We log a error message with the name of the problematic
keyword and the location in the input deck. We rethrow the
same exception without updating the what() message of the
exception.
*/
const auto& location = rawKeyword->location();
std::string msg = Log::fileMessage(location, "Parse error: " + std::string{ exc.what() });
OpmLog::error(msg);
std::string msg_fmt = fmt::format("Problem parsing keyword {{keyword}}\n"
"In {{file}} line {{line}}.\n"
"Internal error message: {}" , std_error.what());
OpmLog::error( OpmInputError::format(msg_fmt, location) );
throw;
}
} else {