My Project
PyMaterialState_impl.hpp
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 namespace Opm::Pybind {
21 
22 template <class TypeTag>
23 std::unique_ptr<double []>
24 PyMaterialState<TypeTag>::
25 getCellVolumes( std::size_t *size)
26 {
27  Model &model = ebosSimulator_->model();
28  *size = model.numGridDof();
29  auto array = std::make_unique<double []>(*size);
30  for (unsigned dofIdx = 0; dofIdx < *size; ++dofIdx) {
31  array[dofIdx] = model.dofTotalVolume(dofIdx);
32  }
33  return array;
34 }
35 
36 template <class TypeTag>
37 std::unique_ptr<double []>
38 PyMaterialState<TypeTag>::
39 getPorosity( std::size_t *size)
40 {
41  Problem &problem = ebosSimulator_->problem();
42  Model &model = ebosSimulator_->model();
43  *size = model.numGridDof();
44  auto array = std::make_unique<double []>(*size);
45  for (unsigned dofIdx = 0; dofIdx < *size; ++dofIdx) {
46  array[dofIdx] = problem.referencePorosity(dofIdx, /*timeIdx*/0);
47  }
48  return array;
49 }
50 
51 template <class TypeTag>
52 void
53 PyMaterialState<TypeTag>::
54 setPorosity(const double *poro, std::size_t size)
55 {
56  Problem &problem = ebosSimulator_->problem();
57  Model &model = ebosSimulator_->model();
58  auto model_size = model.numGridDof();
59  if (model_size != size) {
60  std::ostringstream message;
61  message << "Cannot set porosity. Expected array of size: "
62  << model_size << ", got array of size: " << size;
63  throw std::runtime_error(message.str());
64  }
65  for (unsigned dofIdx = 0; dofIdx < size; ++dofIdx) {
66  problem.setPorosity(poro[dofIdx], dofIdx);
67  }
68 }
69 } //namespace Opm::Pybind