My Project
Loading...
Searching...
No Matches
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
20namespace Opm::Pybind {
21
22template <class TypeTag>
23std::unique_ptr<double []>
24PyMaterialState<TypeTag>::
25getCellVolumes( 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
36template <class TypeTag>
37std::unique_ptr<double []>
38PyMaterialState<TypeTag>::
39getPorosity( 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
51template <class TypeTag>
52void
53PyMaterialState<TypeTag>::
54setPorosity(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