Initialize blackoil simulator from schedule shared with Python.

Adds a new constructor to Main.hpp that takes shared pointers to Deck,
EclipseState, Schedule, and SummaryConfig. This makes it possible to
share these variables with Python without worrying about lifetime issues
of the underlying C++ objects. For example, a Python script can first
create an opm.io.schedule.Schedule object which is modified from Python.
Then, assume the same Python script creates an
opm.simulators.BlackOilSimulator which is initialized with the same
schedule object. Since the underlying C++ object is a shared pointer,
the Schedule object in Python may go out of scope (get deleted by Python)
without having the C++ schedule object being deleted. And the Python
BlackOilSimulator may continue to be used after the Python Schedule object
has been deleted since it still has a valid C++ schedule object.
This commit is contained in:
Håkon Hægland
2021-09-21 01:13:39 +02:00
parent 2f86231b8d
commit 5ad65c70ee
38 changed files with 1048 additions and 248 deletions

View File

@@ -128,12 +128,14 @@ public:
* management of these two objects, i.e., they are not allowed to be deleted as long
* as the simulator vanguard object is alive.
*/
static void setExternalDeck(std::shared_ptr<Deck>& deck);
static void setExternalDeck(std::unique_ptr<Deck> deck);
/*!
* \brief Set the Opm::EclipseState object which ought to be used when the simulator
* vanguard is instantiated.
*/
static void setExternalEclState(std::shared_ptr<EclipseState>& eclState);
static void setExternalEclState(std::unique_ptr<EclipseState> eclState);
/*!
@@ -142,6 +144,7 @@ public:
* The lifetime of this object is not managed by the vanguard, i.e., the object must
* stay valid until after the vanguard gets destroyed.
*/
static void setExternalSchedule(std::shared_ptr<Schedule>& schedule);
static void setExternalSchedule(std::unique_ptr<Schedule> schedule);
/*!
@@ -150,6 +153,7 @@ public:
* The lifetime of this object is not managed by the vanguard, i.e., the object must
* stay valid until after the vanguard gets destroyed.
*/
static void setExternalSummaryConfig(std::shared_ptr<SummaryConfig>& summaryConfig);
static void setExternalSummaryConfig(std::unique_ptr<SummaryConfig> summaryConfig);
static void setExternalUDQState(std::unique_ptr<UDQState> udqState);
@@ -296,11 +300,14 @@ protected:
static double externalSetupTime_;
static std::unique_ptr<ParseContext> externalParseContext_;
static std::unique_ptr<ErrorGuard> externalErrorGuard_;
static std::unique_ptr<Deck> externalDeck_;
// These variables may be owned by both Python and the simulator
static std::shared_ptr<Deck> externalDeck_;
static std::shared_ptr<EclipseState> externalEclState_;
static std::shared_ptr<Schedule> externalEclSchedule_;
static std::shared_ptr<SummaryConfig> externalEclSummaryConfig_;
static bool externalDeckSet_;
static std::unique_ptr<EclipseState> externalEclState_;
static std::unique_ptr<Schedule> externalEclSchedule_;
static std::unique_ptr<SummaryConfig> externalEclSummaryConfig_;
static std::unique_ptr<UDQState> externalUDQState_;
static std::unique_ptr<Action::State> externalActionState_;
static std::unique_ptr<CommunicationType> comm_;
@@ -326,11 +333,12 @@ protected:
// parser objects.
std::unique_ptr<ParseContext> parseContext_;
std::unique_ptr<ErrorGuard> errorGuard_;
std::unique_ptr<Deck> deck_;
std::unique_ptr<EclipseState> eclState_;
std::unique_ptr<Schedule> eclSchedule_;
std::unique_ptr<SummaryConfig> eclSummaryConfig_;
std::shared_ptr<Python> python;
// These variables may be owned by both Python and the simulator
std::shared_ptr<Deck> deck_;
std::shared_ptr<EclipseState> eclState_;
std::shared_ptr<Schedule> eclSchedule_;
std::shared_ptr<SummaryConfig> eclSummaryConfig_;
/*! \brief Information about wells in parallel
*