Miscellaneous Cleanup Changes

In particular, include standard library headers as needed, fix
function declarations (operator<<() for Well::WellProductionProperties),
and make a few helper functions 'static' to avoid warnings of the
form "no previous declaration for".

For the Schedule's keyword handlers, also switch to storing member
function pointers directly instead of std::function objects.  This
saves space and does not incur function pointer conversions.  Use
std::invoke to call those handlers to avoid having to spell out the
'->*' operator.
This commit is contained in:
Bård Skaflestad 2020-10-07 00:25:24 +02:00
parent 36e3a25782
commit de5e3d90cd
7 changed files with 57 additions and 47 deletions

View File

@ -21,8 +21,15 @@
#ifndef WELL2_HPP
#define WELL2_HPP
#include <cstddef>
#include <iosfwd>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include <stddef.h>
#include <opm/parser/eclipse/EclipseState/Runspec.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
@ -45,8 +52,6 @@ namespace Opm {
class DeckRecord;
class EclipseGrid;
class DeckKeyword;
struct WellInjectionProperties;
class WellProductionProperties;
class UDQActive;
class UDQConfig;
class SICD;
@ -638,7 +643,7 @@ private:
};
std::ostream& operator<<( std::ostream&, const Well::WellInjectionProperties& );
std::ostream& operator<<( std::ostream&, const WellProductionProperties& );
std::ostream& operator<<( std::ostream&, const Well::WellProductionProperties& );
int eclipseControlMode(const Well::InjectorCMode imode,
const InjectorType itype);

View File

@ -25,6 +25,8 @@
#include <opm/common/utility/ActiveGridCells.hpp>
#include <stddef.h>
namespace Opm {
class EclipseGrid;
class FieldPropsManager;

View File

@ -17,6 +17,7 @@
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <exception>
#include <fnmatch.h>
#include <functional>
#include <iostream>
@ -1680,7 +1681,7 @@ namespace {
bool Schedule::handleNormalKeyword(const HandlerContext& handlerContext, const ParseContext& parseContext, ErrorGuard& errors) {
using handler_function = std::function<void(Schedule*, const HandlerContext&, const ParseContext&, ErrorGuard&)>;
using handler_function = void (Schedule::*)(const HandlerContext&, const ParseContext&, ErrorGuard&);
static const std::unordered_map<std::string,handler_function> handler_functions = {
{ "BRANPROP", &Schedule::handleBRANPROP },
{ "COMPDAT" , &Schedule::handleCOMPDAT },
@ -1757,27 +1758,24 @@ namespace {
{ "WTRACER" , &Schedule::handleWTRACER },
};
const auto function_iterator = handler_functions.find(handlerContext.keyword.name());
if (function_iterator != handler_functions.end()) {
const auto& handler = function_iterator->second;
try {
handler(this, handlerContext, parseContext, errors);
} catch (const OpmInputError&) {
throw;
} catch (const std::exception& e) {
const OpmInputError opm_error { e, handlerContext.keyword.location() } ;
OpmLog::error(opm_error.what());
std::throw_with_nested(opm_error);
}
return true;
} else {
auto function_iterator = handler_functions.find(handlerContext.keyword.name());
if (function_iterator == handler_functions.end()) {
return false;
}
try {
std::invoke(function_iterator->second, this, handlerContext, parseContext, errors);
} catch (const OpmInputError&) {
throw;
} catch (const std::exception& e) {
const OpmInputError opm_error { e, handlerContext.keyword.location() } ;
OpmLog::error(opm_error.what());
std::throw_with_nested(opm_error);
}
return true;
}
}

View File

@ -17,10 +17,15 @@
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include <cassert>
#include <cmath>
#include <limits>
#include <cstddef>
#include <iostream>
#include <limits>
#include <stdexcept>
#include <string>
#include <utility>
#include <opm/parser/eclipse/Units/Units.hpp>
#include <opm/io/eclipse/rst/connection.hpp>

View File

@ -17,6 +17,7 @@
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <cstddef>
#include <stdexcept>
#include <iostream>
#include <boost/filesystem.hpp>
@ -28,6 +29,7 @@
#include <opm/parser/eclipse/Python/Python.hpp>
#include <opm/parser/eclipse/Parser/Parser.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/Deck/DeckItem.hpp>
#include <opm/parser/eclipse/Deck/DeckRecord.hpp>
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
@ -41,6 +43,22 @@
#include <opm/parser/eclipse/EclipseState/Runspec.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
namespace {
Opm::WellConnections loadCOMPDAT(const std::string& compdat_keyword) {
Opm::EclipseGrid grid(10,10,10);
Opm::TableManager tables;
Opm::Parser parser;
const auto deck = parser.parseString(compdat_keyword);
Opm::FieldPropsManager field_props(deck, Opm::Phases{true, true, true}, grid, Opm::TableManager());
const auto& keyword = deck.getKeyword("COMPDAT", 0);
Opm::WellConnections connections(Opm::Connection::Order::TRACK, 10,10);
for (const auto& rec : keyword)
connections.loadCOMPDAT(rec, grid, field_props);
return connections;
}
}
namespace Opm {
inline std::ostream& operator<<( std::ostream& stream, const Connection& c ) {
@ -150,20 +168,6 @@ BOOST_AUTO_TEST_CASE(ActiveCompletions) {
BOOST_CHECK_EQUAL( completion3, active_completions.get(1));
}
Opm::WellConnections loadCOMPDAT(const std::string& compdat_keyword) {
Opm::EclipseGrid grid(10,10,10);
Opm::TableManager tables;
Opm::Parser parser;
const auto deck = parser.parseString(compdat_keyword);
Opm::FieldPropsManager field_props(deck, Opm::Phases{true, true, true}, grid, Opm::TableManager());
const auto& keyword = deck.getKeyword("COMPDAT", 0);
Opm::WellConnections connections(Opm::Connection::Order::TRACK, 10,10);
for (const auto& rec : keyword)
connections.loadCOMPDAT(rec, grid, field_props);
return connections;
}
BOOST_AUTO_TEST_CASE(loadCOMPDATTEST) {
Opm::UnitSystem units(Opm::UnitSystem::UnitType::UNIT_TYPE_METRIC); // Unit system used in deck FIRST_SIM.DATA.
{

View File

@ -17,19 +17,17 @@
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdexcept>
#include <algorithm>
#include <iostream>
#include <boost/filesystem.hpp>
#include <stdexcept>
#define BOOST_TEST_MODULE ScheduleTests
#include <boost/test/unit_test.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <opm/common/utility/TimeService.hpp>
#include <opm/common/utility/OpmInputError.hpp>
#include <opm/parser/eclipse/Python/Python.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/FieldPropsManager.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
@ -61,7 +59,7 @@
using namespace Opm;
Schedule make_schedule(const std::string& deck_string) {
static Schedule make_schedule(const std::string& deck_string) {
const auto& deck = Parser{}.parseString(deck_string);
auto python = std::make_shared<Python>();
EclipseGrid grid(10,10,10);
@ -408,7 +406,7 @@ BOOST_AUTO_TEST_CASE(CreateScheduleDeckWellsOrdered) {
}
bool has_well( const std::vector<Well>& wells, const std::string& well_name) {
static bool has_well( const std::vector<Well>& wells, const std::string& well_name) {
for (const auto& well : wells )
if (well.name( ) == well_name)
return true;
@ -3159,7 +3157,7 @@ BOOST_AUTO_TEST_CASE(WTEST_CONFIG) {
}
bool has(const std::vector<std::string>& l, const std::string& s) {
static bool has(const std::vector<std::string>& l, const std::string& s) {
auto f = std::find(l.begin(), l.end(), s);
return (f != l.end());
}

View File

@ -59,8 +59,6 @@ inline std::ostream& operator<<( std::ostream& stream, const Well& well ) {
}
}
BOOST_AUTO_TEST_CASE(WellCOMPDATtestTRACK) {
Opm::Parser parser;
std::string input =