mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-01-16 01:31:59 -06:00
Implement Python step_init() method.
The step_init() method initializes the simulation. It is required for the Python script to run step_init() before calling the step() method (which will be implemented in the next commit).
This commit is contained in:
parent
b125ad415d
commit
11eaa3d7d4
@ -47,7 +47,7 @@ void flowEbosBlackoilSetDeck(double setupTime, Deck &deck, EclipseState& eclStat
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Opm::FlowMainEbos<TTAG(EclFlowProblem)>>
|
std::unique_ptr<Opm::FlowMainEbos<TTAG(EclFlowProblem)>>
|
||||||
flowEbosBlackoilMain_init(int argc, char** argv, bool outputCout, bool outputFiles)
|
flowEbosBlackoilMainInit(int argc, char** argv, bool outputCout, bool outputFiles)
|
||||||
{
|
{
|
||||||
// we always want to use the default locale, and thus spare us the trouble
|
// we always want to use the default locale, and thus spare us the trouble
|
||||||
// with incorrect locale settings.
|
// with incorrect locale settings.
|
||||||
@ -65,7 +65,7 @@ flowEbosBlackoilMain_init(int argc, char** argv, bool outputCout, bool outputFil
|
|||||||
// ----------------- Main program -----------------
|
// ----------------- Main program -----------------
|
||||||
int flowEbosBlackoilMain(int argc, char** argv, bool outputCout, bool outputFiles)
|
int flowEbosBlackoilMain(int argc, char** argv, bool outputCout, bool outputFiles)
|
||||||
{
|
{
|
||||||
auto mainfunc = flowEbosBlackoilMain_init(argc, argv, outputCout, outputFiles);
|
auto mainfunc = flowEbosBlackoilMainInit(argc, argv, outputCout, outputFiles);
|
||||||
return mainfunc->execute(argc, argv, outputCout, outputFiles);
|
return mainfunc->execute(argc, argv, outputCout, outputFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,10 +21,13 @@
|
|||||||
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
|
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
|
||||||
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
|
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
|
||||||
#include <opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp>
|
#include <opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp>
|
||||||
|
#include <opm/simulators/flow/FlowMainEbos.hpp>
|
||||||
|
|
||||||
namespace Opm {
|
namespace Opm {
|
||||||
void flowEbosBlackoilSetDeck(double setupTime, Deck &deck, EclipseState& eclState, Schedule& schedule, SummaryConfig& summaryConfig);
|
void flowEbosBlackoilSetDeck(double setupTime, Deck &deck, EclipseState& eclState, Schedule& schedule, SummaryConfig& summaryConfig);
|
||||||
int flowEbosBlackoilMain(int argc, char** argv, bool outputCout, bool outputFiles);
|
int flowEbosBlackoilMain(int argc, char** argv, bool outputCout, bool outputFiles);
|
||||||
|
std::unique_ptr<Opm::FlowMainEbos<TTAG(EclFlowProblem)>>
|
||||||
|
flowEbosBlackoilMainInit(int argc, char** argv, bool outputCout, bool outputFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // FLOW_EBOS_BLACKOIL_HPP
|
#endif // FLOW_EBOS_BLACKOIL_HPP
|
||||||
|
@ -243,12 +243,17 @@ namespace Opm
|
|||||||
/// This is the main function of Flow. It runs a complete simulation with the
|
/// This is the main function of Flow. It runs a complete simulation with the
|
||||||
/// given grid and simulator classes, based on the user-specified command-line
|
/// given grid and simulator classes, based on the user-specified command-line
|
||||||
/// input.
|
/// input.
|
||||||
int execute(int argc, char** argv, bool output_cout, bool output_to_files)
|
int execute(int argc, char** argv, bool outputCout, bool outputToFiles)
|
||||||
{
|
{
|
||||||
return execute_(argc, argv, output_cout, output_to_files,
|
return execute_(argc, argv, outputCout, outputToFiles,
|
||||||
&FlowMainEbos::runSimulator);
|
&FlowMainEbos::runSimulator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int executeInitStep(int argc, char** argv, bool outputCout, bool outputToFiles)
|
||||||
|
{
|
||||||
|
return execute_(argc, argv, outputCout, outputToFiles,
|
||||||
|
&FlowMainEbos::runSimulatorInit);
|
||||||
|
}
|
||||||
|
|
||||||
// Print an ASCII-art header to the PRT and DEBUG files.
|
// Print an ASCII-art header to the PRT and DEBUG files.
|
||||||
// \return Whether unkown keywords were seen during parsing.
|
// \return Whether unkown keywords were seen during parsing.
|
||||||
@ -296,7 +301,7 @@ namespace Opm
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// called by execute() or executeInitStep()
|
// called by execute() or executeInitStep()
|
||||||
int execute_(int argc, char** argv, bool output_cout, bool output_to_files,
|
int execute_(int argc, char** argv, bool outputCout, bool outputToFiles,
|
||||||
void (FlowMainEbos::* runOrInitFunc)(bool))
|
void (FlowMainEbos::* runOrInitFunc)(bool))
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@ -307,15 +312,15 @@ namespace Opm
|
|||||||
return status;
|
return status;
|
||||||
|
|
||||||
setupParallelism();
|
setupParallelism();
|
||||||
setupEbosSimulator(output_cout);
|
setupEbosSimulator(outputCout);
|
||||||
runDiagnostics(output_cout);
|
runDiagnostics(outputCout);
|
||||||
createSimulator();
|
createSimulator();
|
||||||
|
|
||||||
// if run, do the actual work, else just initialize
|
// if run, do the actual work, else just initialize
|
||||||
(this->*runOrInitFunc)(output_cout);
|
(this->*runOrInitFunc)(outputCout);
|
||||||
|
|
||||||
// clean up
|
// clean up
|
||||||
mergeParallelLogFiles(output_to_files);
|
mergeParallelLogFiles(outputToFiles);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -323,7 +328,7 @@ namespace Opm
|
|||||||
std::ostringstream message;
|
std::ostringstream message;
|
||||||
message << "Program threw an exception: " << e.what();
|
message << "Program threw an exception: " << e.what();
|
||||||
|
|
||||||
if (output_cout) {
|
if (outputCout) {
|
||||||
// in some cases exceptions are thrown before the logging system is set
|
// in some cases exceptions are thrown before the logging system is set
|
||||||
// up.
|
// up.
|
||||||
if (OpmLog::hasBackend("STREAMLOG")) {
|
if (OpmLog::hasBackend("STREAMLOG")) {
|
||||||
@ -467,24 +472,35 @@ namespace Opm
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run the simulator.
|
// Run the simulator.
|
||||||
void runSimulator(bool output_cout)
|
void runSimulator(bool outputCout)
|
||||||
{
|
{
|
||||||
runSimulatorInitOrRun_(output_cout, &FlowMainEbos::runSimulatorRunCallback_);
|
runSimulatorInitOrRun_(outputCout, &FlowMainEbos::runSimulatorRunCallback_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void runSimulatorInit(bool outputCout)
|
||||||
|
{
|
||||||
|
runSimulatorInitOrRun_(outputCout, &FlowMainEbos::runSimulatorInitCallback_);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Callback that will be called from runSimulatorInitOrRun_().
|
// Callback that will be called from runSimulatorInitOrRun_().
|
||||||
void runSimulatorRunCallback_(bool output_cout)
|
void runSimulatorRunCallback_(bool outputCout)
|
||||||
{
|
{
|
||||||
SimulatorReport successReport = simulator_->run(*simtimer_);
|
SimulatorReport successReport = simulator_->run(*simtimer_);
|
||||||
runSimulatorAfterSim_(output_cout, successReport);
|
runSimulatorAfterSim_(outputCout, successReport);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Callback that will be called from runSimulatorInitOrRun_().
|
||||||
|
void runSimulatorInitCallback_(bool outputCout)
|
||||||
|
{
|
||||||
|
simulator_->runInit(*simtimer_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output summary after simulation has completed
|
// Output summary after simulation has completed
|
||||||
void runSimulatorAfterSim_(bool output_cout, SimulatorReport &successReport)
|
void runSimulatorAfterSim_(bool outputCout, SimulatorReport &successReport)
|
||||||
{
|
{
|
||||||
SimulatorReport failureReport = simulator_->failureReport();
|
SimulatorReport failureReport = simulator_->failureReport();
|
||||||
if (output_cout) {
|
if (outputCout) {
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
ss << "\n\n================ End of simulation ===============\n\n";
|
ss << "\n\n================ End of simulation ===============\n\n";
|
||||||
ss << "Number of MPI processes: " << std::setw(6) << mpi_size_ << "\n";
|
ss << "Number of MPI processes: " << std::setw(6) << mpi_size_ << "\n";
|
||||||
@ -501,7 +517,7 @@ namespace Opm
|
|||||||
|
|
||||||
// Run the simulator.
|
// Run the simulator.
|
||||||
void runSimulatorInitOrRun_(
|
void runSimulatorInitOrRun_(
|
||||||
bool output_cout, void (FlowMainEbos::* initOrRunFunc)(bool))
|
bool outputCout, void (FlowMainEbos::* initOrRunFunc)(bool))
|
||||||
{
|
{
|
||||||
const auto& schedule = this->schedule();
|
const auto& schedule = this->schedule();
|
||||||
const auto& timeMap = schedule.getTimeMap();
|
const auto& timeMap = schedule.getTimeMap();
|
||||||
@ -512,7 +528,7 @@ namespace Opm
|
|||||||
const auto& initConfig = eclState().getInitConfig();
|
const auto& initConfig = eclState().getInitConfig();
|
||||||
simtimer_->init(timeMap, (size_t)initConfig.getRestartStep());
|
simtimer_->init(timeMap, (size_t)initConfig.getRestartStep());
|
||||||
|
|
||||||
if (output_cout) {
|
if (outputCout) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
|
|
||||||
// This allows a user to catch typos and misunderstandings in the
|
// This allows a user to catch typos and misunderstandings in the
|
||||||
@ -525,15 +541,15 @@ namespace Opm
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!ioConfig.initOnly()) {
|
if (!ioConfig.initOnly()) {
|
||||||
if (output_cout) {
|
if (outputCout) {
|
||||||
std::string msg;
|
std::string msg;
|
||||||
msg = "\n\n================ Starting main simulation loop ===============\n";
|
msg = "\n\n================ Starting main simulation loop ===============\n";
|
||||||
OpmLog::info(msg);
|
OpmLog::info(msg);
|
||||||
}
|
}
|
||||||
(this->*initOrRunFunc)(output_cout);
|
(this->*initOrRunFunc)(outputCout);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (output_cout) {
|
if (outputCout) {
|
||||||
std::cout << "\n\n================ Simulation turned off ===============\n" << std::flush;
|
std::cout << "\n\n================ Simulation turned off ===============\n" << std::flush;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -276,6 +276,25 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int step_init()
|
||||||
|
{
|
||||||
|
if (hasRunInit_) {
|
||||||
|
// Running step_init() multiple times is not implemented yet,
|
||||||
|
// currently we just do nothing and return
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
if (prepareRun_()) {
|
||||||
|
mainfunc_ = Opm::flowEbosBlackoilMainInit(
|
||||||
|
argc_, argv_, outputCout_, outputFiles_);
|
||||||
|
int result = mainfunc_->executeInitStep(
|
||||||
|
argc_, argv_, outputCout_, outputFiles_);
|
||||||
|
hasRunInit_ = true;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool prepareRun_()
|
bool prepareRun_()
|
||||||
@ -433,11 +452,14 @@ private:
|
|||||||
char **argv_;
|
char **argv_;
|
||||||
bool outputCout_; // copy of EWOMS parameter "EnableTerminalOutput"
|
bool outputCout_; // copy of EWOMS parameter "EnableTerminalOutput"
|
||||||
bool outputFiles_; // output files?
|
bool outputFiles_; // output files?
|
||||||
|
bool hasRunInit_{false};
|
||||||
|
|
||||||
std::shared_ptr<Opm::Deck> deck_;
|
std::shared_ptr<Opm::Deck> deck_;
|
||||||
std::shared_ptr<Opm::EclipseState> eclipseState_;
|
std::shared_ptr<Opm::EclipseState> eclipseState_;
|
||||||
std::shared_ptr<Opm::Schedule> schedule_;
|
std::shared_ptr<Opm::Schedule> schedule_;
|
||||||
std::shared_ptr<Opm::SummaryConfig> summaryConfig_;
|
std::shared_ptr<Opm::SummaryConfig> summaryConfig_;
|
||||||
|
|
||||||
|
std::unique_ptr<Opm::FlowMainEbos<TTAG(EclFlowProblem)>> mainfunc_;
|
||||||
};
|
};
|
||||||
|
|
||||||
PYBIND11_MODULE(simulators, m)
|
PYBIND11_MODULE(simulators, m)
|
||||||
@ -449,5 +471,6 @@ PYBIND11_MODULE(simulators, m)
|
|||||||
.def("set_deck", &BlackOilSimulator::setDeck)
|
.def("set_deck", &BlackOilSimulator::setDeck)
|
||||||
.def("set_eclipse_state", &BlackOilSimulator::setEclipseState)
|
.def("set_eclipse_state", &BlackOilSimulator::setEclipseState)
|
||||||
.def("set_schedule", &BlackOilSimulator::setSchedule)
|
.def("set_schedule", &BlackOilSimulator::setSchedule)
|
||||||
.def("set_summary_config", &BlackOilSimulator::setSummaryConfig);
|
.def("set_summary_config", &BlackOilSimulator::setSummaryConfig)
|
||||||
|
.def("step_init", &BlackOilSimulator::step_init);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user