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
60 {
62 }
63
64 void advance(int report_step);
65
67
68 int currentStep();
69
70 py::array_t<double>
71 getFluidStateVariable(const std::string& name) const;
72
73 py::array_t<double> getCellVolumes();
74
75 double getDT();
76
77 py::array_t<double> getPorosity();
78
79 py::array_t<double> getPrimaryVariable(const std::string& variable) const;
80 py::array_t<int> getPrimaryVarMeaning(const std::string& variable) const;
81
82 std::map<std::string, int>
83 getPrimaryVarMeaningMap(const std::string& variable) const;
84
85 int run();
86
87 using PyCArray = py::array_t<double, py::array::c_style | py::array::forcecast>;
88
89 void setPorosity(PyCArray array);
90
91 void setPrimaryVariable(const std::string& idx_name,
92 PyCArray array);
93
94 void setupMpi(bool init_mpi, bool finalize_mpi);
95 int step();
96 int stepCleanup();
97 int stepInit();
98
99protected:
100 FlowMain<TypeTag>& getFlowMain() const;
103
104 const std::string deck_filename_{};
105 bool has_run_init_{false};
106 bool has_run_cleanup_{false};
107 bool mpi_init_{true};
108 bool mpi_finalize_{true};
109
110 // NOTE: the main_ pointer *must* be declared before the flow_main_ pointer
111 // to ensure that it is destroyed before the main object since the main object
112 // destructor will call MPI_Finalize() and flow_main_ object destructor will call
113 // MPI_Comm_free().
114 std::unique_ptr<PyMain<TypeTag>> main_{};
115 std::unique_ptr<FlowMain<TypeTag>> flow_main_{};
116 Simulator* simulator_{nullptr};
117 std::unique_ptr<PyFluidState<TypeTag>> fluid_state_{};
118 std::unique_ptr<PyMaterialState<TypeTag>> material_state_{};
119 std::shared_ptr<Deck> deck_{};
120 std::shared_ptr<EclipseState> eclipse_state_{};
121 std::shared_ptr<Schedule> schedule_{};
122 std::shared_ptr<SummaryConfig> summary_config_{};
123 std::vector<std::string> args_{};
124}; // class PyBaseSimulator
125
126} // namespace Opm::Pybind
127
129
130#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:114
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:116
bool checkSimulationFinished()
Definition: PyBaseSimulator_impl.hpp:68
std::shared_ptr< SummaryConfig > summary_config_
Definition: PyBaseSimulator.hpp:122
const std::string deck_filename_
Definition: PyBaseSimulator.hpp:104
PyMaterialState< TypeTag > & getMaterialState() const
Definition: PyBaseSimulator_impl.hpp:282
std::shared_ptr< Schedule > schedule_
Definition: PyBaseSimulator.hpp:121
py::array_t< double > getCellVolumes()
Definition: PyBaseSimulator_impl.hpp:87
std::unique_ptr< PyFluidState< TypeTag > > fluid_state_
Definition: PyBaseSimulator.hpp:117
bool mpi_finalize_
Definition: PyBaseSimulator.hpp:108
virtual ~PyBaseSimulator()
Definition: PyBaseSimulator.hpp:59
bool has_run_cleanup_
Definition: PyBaseSimulator.hpp:106
bool has_run_init_
Definition: PyBaseSimulator.hpp:105
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:115
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:119
void setupMpi(bool init_mpi, bool finalize_mpi)
Definition: PyBaseSimulator_impl.hpp:164
std::vector< std::string > args_
Definition: PyBaseSimulator.hpp:123
bool mpi_init_
Definition: PyBaseSimulator.hpp:107
std::shared_ptr< EclipseState > eclipse_state_
Definition: PyBaseSimulator.hpp:120
FlowMain< TypeTag > & getFlowMain() const
Definition: PyBaseSimulator_impl.hpp:252
py::array_t< double, py::array::c_style|py::array::forcecast > PyCArray
Definition: PyBaseSimulator.hpp:87
std::unique_ptr< PyMaterialState< TypeTag > > material_state_
Definition: PyBaseSimulator.hpp:118
Definition: PyFluidState.hpp:36
Definition: PyMaterialState.hpp:33
void reset()
Reset parameter system.
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.