PyBaseSimulator.hpp
Go to the documentation of this file.
1/*
2 Copyright 2020 Equinor ASA.
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef OPM_PY_BASE_SIMULATOR_HEADER_INCLUDED
20#define OPM_PY_BASE_SIMULATOR_HEADER_INCLUDED
21
24
30
31#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
32#include <opm/input/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp>
33#include <opm/input/eclipse/Schedule/Schedule.hpp>
34#include <opm/input/eclipse/Deck/Deck.hpp>
35
36#include <map>
37#include <memory>
38#include <string>
39#include <vector>
40
41namespace Opm::Pybind {
42
43template<class TypeTag>
45{
46private:
48
49public:
50 PyBaseSimulator(const std::string& deckFilename,
51 const std::vector<std::string>& args);
52
53 PyBaseSimulator(std::shared_ptr<Deck> deck,
54 std::shared_ptr<EclipseState> state,
55 std::shared_ptr<Schedule> schedule,
56 std::shared_ptr<SummaryConfig> summary_config,
57 const std::vector<std::string>& args);
58
59 void advance(int report_step);
60
62
63 int currentStep();
64
65 py::array_t<double>
66 getFluidStateVariable(const std::string& name) const;
67
68 py::array_t<double> getCellVolumes();
69
70 double getDT();
71
72 py::array_t<double> getPorosity();
73
74 py::array_t<double> getPrimaryVariable(const std::string& variable) const;
75 py::array_t<int> getPrimaryVarMeaning(const std::string& variable) const;
76
77 std::map<std::string, int>
78 getPrimaryVarMeaningMap(const std::string& variable) const;
79
80 int run();
81
82 using PyCArray = py::array_t<double, py::array::c_style | py::array::forcecast>;
83
84 void setPorosity(PyCArray array);
85
86 void setPrimaryVariable(const std::string& idx_name,
87 PyCArray array);
88
89 void setupMpi(bool init_mpi, bool finalize_mpi);
90 int step();
91 int stepCleanup();
92 int stepInit();
93
94protected:
95 FlowMain<TypeTag>& getFlowMain() const;
98
99 const std::string deck_filename_{};
100 bool has_run_init_{false};
101 bool has_run_cleanup_{false};
102 bool mpi_init_{true};
103 bool mpi_finalize_{true};
104
105 // NOTE: the main_ pointer *must* be declared before the flow_main_ pointer
106 // to ensure that it is destroyed before the main object since the main object
107 // destructor will call MPI_Finalize() and flow_main_ object destructor will call
108 // MPI_Comm_free().
109 std::unique_ptr<PyMain<TypeTag>> main_{};
110 std::unique_ptr<FlowMain<TypeTag>> flow_main_{};
111 Simulator* simulator_{nullptr};
112 std::unique_ptr<PyFluidState<TypeTag>> fluid_state_{};
113 std::unique_ptr<PyMaterialState<TypeTag>> material_state_{};
114 std::shared_ptr<Deck> deck_{};
115 std::shared_ptr<EclipseState> eclipse_state_{};
116 std::shared_ptr<Schedule> schedule_{};
117 std::shared_ptr<SummaryConfig> summary_config_{};
118 std::vector<std::string> args_{};
119}; // class PyBaseSimulator
120
121} // namespace Opm::Pybind
122
124
125#endif // OPM_PY_BASE_SIMULATOR_HEADER_INCLUDED
Definition: PyBaseSimulator.hpp:45
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
std::unique_ptr< PyMain< TypeTag > > main_
Definition: PyBaseSimulator.hpp:109
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
Simulator * simulator_
Definition: PyBaseSimulator.hpp:111
bool checkSimulationFinished()
Definition: PyBaseSimulator_impl.hpp:68
std::shared_ptr< SummaryConfig > summary_config_
Definition: PyBaseSimulator.hpp:117
const std::string deck_filename_
Definition: PyBaseSimulator.hpp:99
PyMaterialState< TypeTag > & getMaterialState() const
Definition: PyBaseSimulator_impl.hpp:282
std::shared_ptr< Schedule > schedule_
Definition: PyBaseSimulator.hpp:116
py::array_t< double > getCellVolumes()
Definition: PyBaseSimulator_impl.hpp:87
std::unique_ptr< PyFluidState< TypeTag > > fluid_state_
Definition: PyBaseSimulator.hpp:112
bool mpi_finalize_
Definition: PyBaseSimulator.hpp:103
bool has_run_cleanup_
Definition: PyBaseSimulator.hpp:101
bool has_run_init_
Definition: PyBaseSimulator.hpp:100
py::array_t< int > getPrimaryVarMeaning(const std::string &variable) const
Definition: PyBaseSimulator_impl.hpp:128
std::unique_ptr< FlowMain< TypeTag > > flow_main_
Definition: PyBaseSimulator.hpp:110
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
std::shared_ptr< Deck > deck_
Definition: PyBaseSimulator.hpp:114
void setupMpi(bool init_mpi, bool finalize_mpi)
Definition: PyBaseSimulator_impl.hpp:164
std::vector< std::string > args_
Definition: PyBaseSimulator.hpp:118
bool mpi_init_
Definition: PyBaseSimulator.hpp:102
std::shared_ptr< EclipseState > eclipse_state_
Definition: PyBaseSimulator.hpp:115
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
std::unique_ptr< PyMaterialState< TypeTag > > material_state_
Definition: PyBaseSimulator.hpp:113
Definition: PyFluidState.hpp:36
Definition: PyMaterialState.hpp:33
Definition: PyBaseSimulator.hpp:41
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:233
This file provides the infrastructure to retrieve run-time parameters.
The Opm property system, traits with inheritance.