changed: introduce EclGenericVanguard::SimulationModelParams

this is a struct that holds the information transferred
from the simulator prior to vanguard instantation.
this way we can avoid the static members for state,
which causes issues for serialization (in particular, it makes
it impossible to compare two instances like we do in tests).
This commit is contained in:
Arne Morten Kvarving 2023-02-01 10:35:20 +01:00
parent 70e9a503a0
commit c33240f5c1
3 changed files with 48 additions and 60 deletions

View File

@ -53,37 +53,26 @@
namespace Opm { namespace Opm {
double EclGenericVanguard::setupTime_ = 0.0;
std::shared_ptr<EclipseState> EclGenericVanguard::eclState_;
std::shared_ptr<Schedule> EclGenericVanguard::eclSchedule_;
std::shared_ptr<SummaryConfig> EclGenericVanguard::eclSummaryConfig_;
std::unique_ptr<UDQState> EclGenericVanguard::udqState_;
std::unique_ptr<Action::State> EclGenericVanguard::actionState_;
std::unique_ptr<WellTestState> EclGenericVanguard::wtestState_;
std::unique_ptr<Parallel::Communication> EclGenericVanguard::comm_; std::unique_ptr<Parallel::Communication> EclGenericVanguard::comm_;
EclGenericVanguard::SimulationModelParams EclGenericVanguard::modelParams_;
EclGenericVanguard::EclGenericVanguard() EclGenericVanguard::EclGenericVanguard()
: python(std::make_shared<Python>()) : python(std::make_shared<Python>())
{ {
defineSimulationModel(std::move(modelParams_));
} }
EclGenericVanguard::~EclGenericVanguard() = default; EclGenericVanguard::~EclGenericVanguard() = default;
void EclGenericVanguard::defineSimulationModel(double setupTime, void EclGenericVanguard::defineSimulationModel(SimulationModelParams&& params)
std::shared_ptr<EclipseState> eclState,
std::shared_ptr<Schedule> schedule,
std::unique_ptr<UDQState> udqState,
std::unique_ptr<Action::State> actionState,
std::unique_ptr<WellTestState> wtestState,
std::shared_ptr<SummaryConfig> summaryConfig)
{ {
EclGenericVanguard::setupTime_ = setupTime; actionState_ = std::move(params.actionState_);
EclGenericVanguard::eclState_ = std::move(eclState); eclSchedule_ = std::move(params.eclSchedule_);
EclGenericVanguard::eclSchedule_ = std::move(schedule); eclState_ = std::move(params.eclState_);
EclGenericVanguard::udqState_ = std::move(udqState); eclSummaryConfig_ = std::move(params.eclSummaryConfig_);
EclGenericVanguard::actionState_ = std::move(actionState); setupTime_ = params.setupTime_;
EclGenericVanguard::wtestState_ = std::move(wtestState); udqState_ = std::move(params.udqState_);
EclGenericVanguard::eclSummaryConfig_ = std::move(summaryConfig); wtestState_ = std::move(params.wtestState_);
} }
void EclGenericVanguard::readDeck(const std::string& filename) void EclGenericVanguard::readDeck(const std::string& filename)
@ -91,24 +80,16 @@ void EclGenericVanguard::readDeck(const std::string& filename)
Dune::Timer setupTimer; Dune::Timer setupTimer;
setupTimer.start(); setupTimer.start();
std::shared_ptr<Opm::EclipseState> eclipseState;
std::shared_ptr<Opm::Schedule> schedule;
std::unique_ptr<Opm::UDQState> udqState;
std::unique_ptr<Opm::Action::State> actionState;
std::unique_ptr<Opm::WellTestState> wtestState;
std::shared_ptr<Opm::SummaryConfig> summaryConfig;
Opm::readDeck(EclGenericVanguard::comm(), Opm::readDeck(EclGenericVanguard::comm(),
filename, eclipseState, schedule, udqState, filename,
actionState, wtestState, modelParams_.eclState_,
summaryConfig, nullptr, false, modelParams_.eclSchedule_,
false, false, {}); modelParams_.udqState_,
modelParams_.actionState_,
EclGenericVanguard::defineSimulationModel(setupTimer.elapsed(), modelParams_.wtestState_,
eclipseState, schedule, modelParams_.eclSummaryConfig_,
std::move(udqState), nullptr, false, false, false, {});
std::move(actionState), modelParams_.setupTime_ = setupTimer.stop();
std::move(wtestState), summaryConfig);
} }
std::string EclGenericVanguard::canonicalDeckPath(const std::string& caseName) std::string EclGenericVanguard::canonicalDeckPath(const std::string& caseName)

View File

@ -66,6 +66,19 @@ class EclGenericVanguard {
public: public:
using ParallelWellStruct = std::vector<std::pair<std::string,bool>>; using ParallelWellStruct = std::vector<std::pair<std::string,bool>>;
struct SimulationModelParams {
double setupTime_;
std::unique_ptr<Parallel::Communication> comm_;
std::unique_ptr<UDQState> udqState_;
std::unique_ptr<Action::State> actionState_;
std::unique_ptr<WellTestState> wtestState_;
std::shared_ptr<EclipseState> eclState_;
std::shared_ptr<Schedule> eclSchedule_;
std::shared_ptr<SummaryConfig> eclSummaryConfig_;
};
static SimulationModelParams modelParams_;
/*! /*!
* \brief Constructor. * \brief Constructor.
* \details Needs to be in compile unit. * \details Needs to be in compile unit.
@ -89,7 +102,7 @@ public:
/*! /*!
* \brief Returns the wall time required to set up the simulator before it was born. * \brief Returns the wall time required to set up the simulator before it was born.
*/ */
static double setupTime() double setupTime()
{ return setupTime_; } { return setupTime_; }
/*! /*!
@ -101,13 +114,7 @@ public:
/*! /*!
* \brief Set the simulation configuration objects. * \brief Set the simulation configuration objects.
*/ */
static void defineSimulationModel(double setupTime, void defineSimulationModel(SimulationModelParams&& params);
std::shared_ptr<EclipseState> eclState,
std::shared_ptr<Schedule> schedule,
std::unique_ptr<UDQState> udqState,
std::unique_ptr<Action::State> actionState,
std::unique_ptr<WellTestState> wtestState,
std::shared_ptr<SummaryConfig> summaryConfig);
/*! /*!
* \brief Return a reference to the internalized ECL deck. * \brief Return a reference to the internalized ECL deck.
@ -258,7 +265,7 @@ protected:
void init(); void init();
static double setupTime_; double setupTime_;
// These variables may be owned by both Python and the simulator // These variables may be owned by both Python and the simulator
static std::unique_ptr<Parallel::Communication> comm_; static std::unique_ptr<Parallel::Communication> comm_;
@ -285,22 +292,22 @@ protected:
bool enableExperiments_; bool enableExperiments_;
std::unique_ptr<SummaryState> summaryState_; std::unique_ptr<SummaryState> summaryState_;
static std::unique_ptr<UDQState> udqState_; std::unique_ptr<UDQState> udqState_;
static std::unique_ptr<Action::State> actionState_; std::unique_ptr<Action::State> actionState_;
// Observe that this instance is handled differently from the other state // Observe that this instance is handled differently from the other state
// variables, it will only be initialized for a restart run. While // variables, it will only be initialized for a restart run. While
// initializing a restarted run this instance is transferred to the WGState // initializing a restarted run this instance is transferred to the WGState
// member in the well model. // member in the well model.
static std::unique_ptr<WellTestState> wtestState_; std::unique_ptr<WellTestState> wtestState_;
// these attributes point either to the internal or to the external version of the // these attributes point either to the internal or to the external version of the
// parser objects. // parser objects.
std::shared_ptr<Python> python; std::shared_ptr<Python> python;
// These variables may be owned by both Python and the simulator // These variables may be owned by both Python and the simulator
static std::shared_ptr<EclipseState> eclState_; std::shared_ptr<EclipseState> eclState_;
static std::shared_ptr<Schedule> eclSchedule_; std::shared_ptr<Schedule> eclSchedule_;
static std::shared_ptr<SummaryConfig> eclSummaryConfig_; std::shared_ptr<SummaryConfig> eclSummaryConfig_;
/*! \brief Information about wells in parallel /*! \brief Information about wells in parallel
* *

View File

@ -211,13 +211,13 @@ void Main::readDeck(const std::string& deckFilename,
void Main::setupVanguard() void Main::setupVanguard()
{ {
EclGenericVanguard::defineSimulationModel(this->setupTime_, EclGenericVanguard::modelParams_.setupTime_ = this->setupTime_;
this->eclipseState_, EclGenericVanguard::modelParams_.actionState_ = std::move(this->actionState_);
this->schedule_, EclGenericVanguard::modelParams_.eclSchedule_ = this->schedule_;
std::move(this->udqState_), EclGenericVanguard::modelParams_.eclState_ = this->eclipseState_;
std::move(this->actionState_), EclGenericVanguard::modelParams_.eclSummaryConfig_ = this->summaryConfig_;
std::move(this->wtestState_), EclGenericVanguard::modelParams_.udqState_ = std::move(udqState_);
this->summaryConfig_); EclGenericVanguard::modelParams_.wtestState_ = std::move(wtestState_);
} }
#if HAVE_DAMARIS #if HAVE_DAMARIS