19#ifndef OPM_PY_BASE_SIMULATOR_IMPL_HEADER_INCLUDED
20#define OPM_PY_BASE_SIMULATOR_IMPL_HEADER_INCLUDED
23#ifndef OPM_PY_BASE_SIMULATOR_HEADER_INCLUDED
30namespace py = pybind11;
34template<
class TypeTag>
36 const std::vector<std::string>& args)
37 : deck_filename_{deck_filename}
42template<
class TypeTag>
45 std::shared_ptr<EclipseState> state,
46 std::shared_ptr<Schedule> schedule,
47 std::shared_ptr<SummaryConfig> summary_config,
48 const std::vector<std::string>& args)
49 : deck_{std::move(deck)}
50 , eclipse_state_{std::move(state)}
51 , schedule_{std::move(schedule)}
52 , summary_config_{std::move(summary_config)}
59template<
class TypeTag>
62 while (currentStep() < report_step) {
67template<
class TypeTag>
70 return getFlowMain().getSimTimer()->done();
75template<
class TypeTag>
78 return getFlowMain().getSimTimer()->currentStepNum();
85template<
class TypeTag>
89 auto vector = getMaterialState().getCellVolumes();
90 return py::array(vector.size(), vector.data());
93template<
class TypeTag>
96 return getFlowMain().getPreviousReportStepSize();
99template<
class TypeTag>
103 auto vector = getMaterialState().getPorosity();
104 return py::array(vector.size(), vector.data());
107template<
class TypeTag>
112 auto vector = getFluidState().getFluidStateVariable(name);
113 return py::array(vector.size(), vector.data());
116template<
class TypeTag>
121 auto vector = getFluidState().getPrimaryVariable(variable);
122 return py::array(vector.size(), vector.data());
125template<
class TypeTag>
130 auto vector = getFluidState().getPrimaryVarMeaning(variable);
131 return py::array(vector.size(), vector.data());
134template<
class TypeTag>
135std::map<std::string, int>
140 return getFluidState().getPrimaryVarMeaningMap(variable);
143template<
class TypeTag>
146 std::size_t size_ = array.size();
147 const double *poro = array.data();
148 getMaterialState().setPorosity(poro, size_);
151template<
class TypeTag>
157 std::size_t size_ = array.size();
158 const double *data = array.data();
159 getFluidState().setPrimaryVariable(variable, data, size_);
162template<
class TypeTag>
164setupMpi(
bool mpi_init,
bool mpi_finalize)
166 if (this->has_run_init_) {
167 throw std::logic_error(
"mpi_init() called after step_init()");
169 this->mpi_init_ = mpi_init;
170 this->mpi_finalize_ = mpi_finalize;
173template<
class TypeTag>
176 if (!this->has_run_init_) {
177 throw std::logic_error(
"step() called before step_init()");
179 if (this->has_run_cleanup_) {
180 throw std::logic_error(
"step() called after step_cleanup().");
182 if(checkSimulationFinished()) {
183 throw std::logic_error(
"step() called, but simulation is done");
185 auto result = getFlowMain().executeStep();
189template<
class TypeTag>
192 this->has_run_cleanup_ =
true;
193 return getFlowMain().executeStepsCleanup();
196template<
class TypeTag>
199 if (this->has_run_init_) {
201 if (this->has_run_cleanup_) {
202 throw std::logic_error(
"step_init() called again");
209 this->main_ = std::make_unique<PyMain<TypeTag>>(
210 this->deck_->getDataFile(),
211 this->eclipse_state_,
213 this->summary_config_,
219 this->main_ = std::make_unique<PyMain<TypeTag>>(
220 this->deck_filename_,
225 this->main_->setArguments(args_);
226 int exit_code = EXIT_SUCCESS;
227 this->flow_main_ = this->main_->initFlowBlackoil(exit_code);
228 if (this->flow_main_) {
229 const int result = this->flow_main_->executeInitStep();
230 this->has_run_init_ =
true;
231 this->simulator_ = this->flow_main_->getSimulatorPtr();
232 this->fluid_state_ = std::make_unique<PyFluidState<TypeTag>>(this->simulator_);
233 this->material_state_ = std::make_unique<PyMaterialState<TypeTag>>(this->simulator_);
241template<
class TypeTag>
244 auto main_object =
Main( this->deck_filename_ );
245 return main_object.runStatic<TypeTag>();
250template<
class TypeTag>
254 if (this->flow_main_) {
255 return *this->flow_main_;
258 throw std::runtime_error(
259 "BlackOilSimulator not initialized: "
260 "Cannot get reference to FlowMain object"
265template<
class TypeTag>
269 if (this->fluid_state_) {
270 return *this->fluid_state_;
273 throw std::runtime_error(
274 "BlackOilSimulator not initialized: "
275 "Cannot get reference to fluid state object"
280template<
class TypeTag>
284 if (this->material_state_) {
285 return *this->material_state_;
288 throw std::runtime_error(
289 "BlackOilSimulator not initialized: "
290 "Cannot get reference to material state object"
PyFluidState< TypeTag > & getFluidState() const
Definition: PyBaseSimulator_impl.hpp:267
int stepCleanup()
Definition: PyBaseSimulator_impl.hpp:190
void setPrimaryVariable(const std::string &idx_name, PyCArray array)
Definition: PyBaseSimulator_impl.hpp:154
int currentStep()
Definition: PyBaseSimulator_impl.hpp:76
PyBaseSimulator(const std::string &deckFilename, const std::vector< std::string > &args)
Definition: PyBaseSimulator_impl.hpp:35
int step()
Definition: PyBaseSimulator_impl.hpp:174
std::map< std::string, int > getPrimaryVarMeaningMap(const std::string &variable) const
Definition: PyBaseSimulator_impl.hpp:137
int run()
Definition: PyBaseSimulator_impl.hpp:242
py::array_t< double > getPorosity()
Definition: PyBaseSimulator_impl.hpp:101
void advance(int report_step)
Definition: PyBaseSimulator_impl.hpp:60
void setPorosity(PyCArray array)
Definition: PyBaseSimulator_impl.hpp:144
bool checkSimulationFinished()
Definition: PyBaseSimulator_impl.hpp:68
PyMaterialState< TypeTag > & getMaterialState() const
Definition: PyBaseSimulator_impl.hpp:282
py::array_t< double > getCellVolumes()
Definition: PyBaseSimulator_impl.hpp:87
py::array_t< int > getPrimaryVarMeaning(const std::string &variable) const
Definition: PyBaseSimulator_impl.hpp:128
double getDT()
Definition: PyBaseSimulator_impl.hpp:94
int stepInit()
Definition: PyBaseSimulator_impl.hpp:197
py::array_t< double > getFluidStateVariable(const std::string &name) const
Definition: PyBaseSimulator_impl.hpp:110
py::array_t< double > getPrimaryVariable(const std::string &variable) const
Definition: PyBaseSimulator_impl.hpp:119
void setupMpi(bool init_mpi, bool finalize_mpi)
Definition: PyBaseSimulator_impl.hpp:164
FlowMain< TypeTag > & getFlowMain() const
Definition: PyBaseSimulator_impl.hpp:252
py::array_t< double, py::array::c_style|py::array::forcecast > PyCArray
Definition: PyBaseSimulator.hpp:82
Definition: PyFluidState.hpp:36
Definition: PyMaterialState.hpp:33
Definition: PyBaseSimulator.hpp:41