PyMaterialState_impl.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
20#include <fmt/format.h>
21
22namespace Opm::Pybind {
23
24template <class TypeTag>
25std::vector<double>
28{
29 Model &model = this->simulator_->model();
30 auto size = model.numGridDof();
31 std::vector<double> array(size);
32 for (unsigned dof_idx = 0; dof_idx < size; ++dof_idx) {
33 array[dof_idx] = model.dofTotalVolume(dof_idx);
34 }
35 return array;
36}
37
38template <class TypeTag>
39std::vector<double>
42{
43 Problem &problem = this->simulator_->problem();
44 Model &model = this->simulator_->model();
45 auto size = model.numGridDof();
46 std::vector<double> array(size);
47 for (unsigned dof_idx = 0; dof_idx < size; ++dof_idx) {
48 array[dof_idx] = problem.referencePorosity(dof_idx, /*timeIdx*/0);
49 }
50 return array;
51}
52
53template <class TypeTag>
54void
56setPorosity(const double* poro, std::size_t size)
57{
58 Problem& problem = this->simulator_->problem();
59 Model& model = this->simulator_->model();
60 auto model_size = model.numGridDof();
61 if (model_size != size) {
62 const std::string msg = fmt::format(
63 "Cannot set porosity. Expected array of size: {}, got array of size: ",
64 model_size, size);
65 throw std::runtime_error(msg);
66 }
67 for (unsigned dof_idx = 0; dof_idx < size; ++dof_idx) {
68 problem.setPorosity(poro[dof_idx], dof_idx);
69 }
70}
71} //namespace Opm::Pybind
std::vector< double > getPorosity()
Definition: PyMaterialState_impl.hpp:41
void setPorosity(const double *poro, std::size_t size)
Definition: PyMaterialState_impl.hpp:56
std::vector< double > getCellVolumes()
Definition: PyMaterialState_impl.hpp:27
Definition: Pybind11Exporter.hpp:11