opm-simulators
ThermalGasWaterFlowProblem.hpp
1 /*
2  Copyright 2026 Equinor ASA
3  This file is part of the Open Porous Media project (OPM).
4  OPM is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8  OPM is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12  You should have received a copy of the GNU General Public License
13  along with OPM. If not, see <http://www.gnu.org/licenses/>.
14 */
15 
16 #ifndef THERMAL_GASWATER_FLOW_PROBLEM_HPP
17 #define THERMAL_GASWATER_FLOW_PROBLEM_HPP
18 
19 #include <opm/common/ErrorMacros.hpp>
20 #include <opm/common/utility/VectorWithDefaultAllocator.hpp>
21 #include <opm/common/utility/gpuDecorators.hpp>
22 #include <opm/common/utility/gpuistl_if_available.hpp>
23 
24 /*
25  A simple gas-water flow problem with thermal effects that is GPU compatible
26 */
27 
28 namespace Opm
29 {
30 
31 template <class Scalar, template <class> class Storage = Opm::VectorWithDefaultAllocator>
33 {
34 public:
36 
37  ThermalGasWaterFlowProblem() = default;
38 
39  ThermalGasWaterFlowProblem(Storage<Scalar> alpha0,
40  Storage<Scalar> alpha1,
41  Storage<Scalar> alpha2,
42  ModuleParams moduleParams)
43  : alpha0_(alpha0)
44  , alpha1_(alpha1)
45  , alpha2_(alpha2)
46  , moduleParams_(moduleParams)
47  {
48  }
49 
50  OPM_HOST_DEVICE Scalar getAlpha(unsigned globalIndex, unsigned boundaryFaceIndex) const
51  {
52  if (boundaryFaceIndex == 0) {
53  return alpha0_[globalIndex];
54  } else if (boundaryFaceIndex == 1) {
55  return alpha1_[globalIndex];
56  } else if (boundaryFaceIndex == 2) {
57  return alpha2_[globalIndex];
58  } else {
59  OPM_THROW(std::logic_error, "Invalid boundary face index");
60  }
61  }
62 
63  OPM_HOST_DEVICE const ModuleParams& moduleParams() const
64  {
65  return moduleParams_;
66  }
67  OPM_HOST_DEVICE ModuleParams& moduleParams()
68  {
69  return moduleParams_;
70  }
71 
72  Storage<Scalar>& alpha0()
73  {
74  return alpha0_;
75  }
76 
77  Storage<Scalar>& alpha1()
78  {
79  return alpha1_;
80  }
81 
82  Storage<Scalar>& alpha2()
83  {
84  return alpha2_;
85  }
86 
87 private:
88  Storage<Scalar> alpha0_;
89  Storage<Scalar> alpha1_;
90  Storage<Scalar> alpha2_;
91  ModuleParams moduleParams_;
92 };
93 
94 namespace gpuistl
95 {
96 
97  template <class Scalar>
100  {
103  GpuBuffer<Scalar>(cpuProblem.alpha0()),
104  GpuBuffer<Scalar>(cpuProblem.alpha1()),
105  GpuBuffer<Scalar>(cpuProblem.alpha2()),
106  ModuleParams {copy_to_gpu(cpuProblem.moduleParams().convectiveMixingModuleParam)});
107  }
108 
109  template <class Scalar>
112  {
115  make_view(buffer.alpha0()),
116  make_view(buffer.alpha1()),
117  make_view(buffer.alpha2()),
118  ModuleParams {make_view(buffer.moduleParams().convectiveMixingModuleParam)});
119  }
120 
121 } // namespace gpuistl
122 
123 } // namespace Opm
124 
125 #endif // THERMAL_GASWATER_FLOW_PROBLEM_HPP
Definition: ThermalGasWaterFlowProblem.hpp:32
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45