Merge pull request #275 from joakim-hove/use-OpmLog

Using OpmLog instead of explicit logger
This commit is contained in:
Joakim Hove 2015-03-09 08:08:07 +01:00
commit 8e9cc4728e
2 changed files with 71 additions and 48 deletions

View File

@ -47,6 +47,9 @@
#include <opm/autodiff/SimulatorFullyImplicitBlackoil.hpp> #include <opm/autodiff/SimulatorFullyImplicitBlackoil.hpp>
#include <opm/autodiff/BlackoilPropsAdFromDeck.hpp> #include <opm/autodiff/BlackoilPropsAdFromDeck.hpp>
#include <opm/parser/eclipse/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/OpmLog/StreamLog.hpp>
#include <opm/parser/eclipse/OpmLog/CounterLog.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp> #include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/Parser/Parser.hpp> #include <opm/parser/eclipse/Parser/Parser.hpp>
#include <opm/parser/eclipse/EclipseState/checkDeck.hpp> #include <opm/parser/eclipse/EclipseState/checkDeck.hpp>
@ -103,29 +106,48 @@ try
double gravity[3] = { 0.0 }; double gravity[3] = { 0.0 };
std::string deck_filename = param.get<std::string>("deck_filename"); std::string deck_filename = param.get<std::string>("deck_filename");
// Write parameters used for later reference.
bool output = param.getDefault("output", true);
std::string output_dir;
if (output) {
// Create output directory if needed.
output_dir =
param.getDefault("output_dir", std::string("output"));
boost::filesystem::path fpath(output_dir);
try {
create_directories(fpath);
}
catch (...) {
OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath);
}
// Write simulation parameters.
param.writeParam(output_dir + "/simulation.param");
}
std::string logFile = output_dir + "/LOGFILE.txt";
Opm::ParserPtr parser(new Opm::Parser()); Opm::ParserPtr parser(new Opm::Parser());
Opm::LoggerPtr logger(new Opm::Logger()); {
std::shared_ptr<Opm::StreamLog> streamLog = std::make_shared<Opm::StreamLog>(logFile , Opm::Log::DefaultMessageTypes);
std::shared_ptr<Opm::CounterLog> counterLog = std::make_shared<Opm::CounterLog>(Opm::Log::DefaultMessageTypes);
Opm::OpmLog::addBackend( "STREAM" , streamLog );
Opm::OpmLog::addBackend( "COUNTER" , counterLog );
}
Opm::DeckConstPtr deck; Opm::DeckConstPtr deck;
std::shared_ptr<EclipseState> eclipseState; std::shared_ptr<EclipseState> eclipseState;
try { try {
deck = parser->parseFile(deck_filename, logger); deck = parser->parseFile(deck_filename);
Opm::checkDeck(deck, logger); Opm::checkDeck(deck);
eclipseState.reset(new Opm::EclipseState(deck, logger)); eclipseState.reset(new Opm::EclipseState(deck));
} }
catch (const std::invalid_argument& e) { catch (const std::invalid_argument& e) {
if (logger->size() > 0) { std::cerr << "Failed to create valid ECLIPSESTATE object. See logfile: " << logFile << std::endl;
std::cerr << "Issues found while parsing the deck file:\n"; std::cerr << "Exception caught: " << e.what() << std::endl;
logger->printAll(std::cerr);
}
std::cerr << "error while parsing the deck file: " << e.what() << "\n";
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (logger->size() > 0) {
std::cerr << "Issues found while parsing the deck file:\n";
logger->printAll(std::cerr);
}
// Grid init // Grid init
std::vector<double> porv = eclipseState->getDoubleGridProperty("PORV")->getData(); std::vector<double> porv = eclipseState->getDoubleGridProperty("PORV")->getData();
grid.reset(new GridManager(eclipseState->getEclipseGrid(), porv)); grid.reset(new GridManager(eclipseState->getEclipseGrid(), porv));
@ -191,24 +213,6 @@ try
fis_solver.reset(new NewtonIterationBlackoilSimple(param)); fis_solver.reset(new NewtonIterationBlackoilSimple(param));
} }
// Write parameters used for later reference.
bool output = param.getDefault("output", true);
std::string output_dir;
if (output) {
// Create output directory if needed.
output_dir =
param.getDefault("output_dir", std::string("output"));
boost::filesystem::path fpath(output_dir);
try {
create_directories(fpath);
}
catch (...) {
OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath);
}
// Write simulation parameters.
param.writeParam(output_dir + "/simulation.param");
}
Opm::TimeMapConstPtr timeMap(eclipseState->getSchedule()->getTimeMap()); Opm::TimeMapConstPtr timeMap(eclipseState->getSchedule()->getTimeMap());
SimulatorTimer simtimer; SimulatorTimer simtimer;

View File

@ -72,6 +72,9 @@
#include <opm/core/utility/share_obj.hpp> #include <opm/core/utility/share_obj.hpp>
#include <opm/parser/eclipse/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/OpmLog/StreamLog.hpp>
#include <opm/parser/eclipse/OpmLog/CounterLog.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp> #include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/Parser/Parser.hpp> #include <opm/parser/eclipse/Parser/Parser.hpp>
#include <opm/parser/eclipse/EclipseState/checkDeck.hpp> #include <opm/parser/eclipse/EclipseState/checkDeck.hpp>
@ -131,30 +134,46 @@ try
// int max_well_control_iterations = 0; // int max_well_control_iterations = 0;
double gravity[3] = { 0.0 }; double gravity[3] = { 0.0 };
std::string deck_filename = param.get<std::string>("deck_filename"); std::string deck_filename = param.get<std::string>("deck_filename");
bool output = param.getDefault("output", true);
std::string output_dir;
if (output) {
// Create output directory if needed.
output_dir =
param.getDefault("output_dir", std::string("output"));
boost::filesystem::path fpath(output_dir);
try {
create_directories(fpath);
}
catch (...) {
OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath);
}
// Write simulation parameters.
param.writeParam(output_dir + "/simulation.param");
}
std::string logFile = output_dir + "/LOGFILE.txt";
Opm::ParserPtr parser(new Opm::Parser()); Opm::ParserPtr parser(new Opm::Parser());
Opm::LoggerPtr logger(new Opm::Logger()); {
std::shared_ptr<Opm::StreamLog> streamLog = std::make_shared<Opm::StreamLog>(logFile , Opm::Log::DefaultMessageTypes);
std::shared_ptr<Opm::CounterLog> counterLog = std::make_shared<Opm::CounterLog>(Opm::Log::DefaultMessageTypes);
Opm::OpmLog::addBackend( "STREAM" , streamLog );
Opm::OpmLog::addBackend( "COUNTER" , counterLog );
}
Opm::DeckConstPtr deck; Opm::DeckConstPtr deck;
std::shared_ptr<EclipseState> eclipseState; std::shared_ptr<EclipseState> eclipseState;
try { try {
deck = parser->parseFile(deck_filename, logger); deck = parser->parseFile(deck_filename);
checkDeck(deck, logger); Opm::checkDeck(deck, logger);
eclipseState.reset(new EclipseState(deck, logger)); eclipseState.reset(new Opm::EclipseState(deck));
} }
catch (const std::invalid_argument& e) { catch (const std::invalid_argument& e) {
if (logger->size() > 0) { std::cerr << "Failed to create valid ECLIPSESTATE object. See logfile: " << logFile << std::endl;
std::cerr << "Issues found while parsing the deck file:\n"; std::cerr << "Exception caught: " << e.what() << std::endl;
logger->printAll(std::cerr);
}
std::cerr << "error while parsing the deck file: " << e.what() << "\n";
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (logger->size() > 0) {
std::cerr << "Issues found while parsing the deck file:\n";
logger->printAll(std::cerr);
}
// Grid init // Grid init
grid.reset(new Dune::CpGrid); grid.reset(new Dune::CpGrid);
std::vector<double> porv = eclipseState->getDoubleGridProperty("PORV")->getData(); std::vector<double> porv = eclipseState->getDoubleGridProperty("PORV")->getData();