opm-simulators
CompWellEquations.hpp
1 /*
2  Copyright 2024, SINTEF Digital
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 #ifndef OPM_COMP_WELL_EQUATIONS_HPP
21 #define OPM_COMP_WELL_EQUATIONS_HPP
22 
23 #include <dune/common/fmatrix.hh>
24 #include <dune/common/fvector.hh>
25 #include <dune/istl/bcrsmatrix.hh>
26 #include <dune/istl/bvector.hh>
27 
28 namespace Opm {
29 
30 // we should look into whether to use dynamic matrix and vector here
31 template <typename Scalar, int numWellEq, int numEq>
33 {
34 public:
35  // sparsity pattern for the matrices
36  //[A C^T [x = [ res
37  // B D ] x_well] res_well]
38 
40 
41  // the vector type for the res_well and x_well
42  using VectorBlockWellType = Dune::FieldVector<Scalar, numWellEq>;
43  using BVectorWell = Dune::BlockVector<VectorBlockWellType>;
44 
45  // for res
46  using VectorBlockType = Dune::FieldVector<Scalar, numEq>;
47  using BVector = Dune::BlockVector<VectorBlockType>;
48 
49  // the matrix type for the diagonal matrix D
50  using DiagMatrixBlockWellType = Dune::FieldMatrix<Scalar, numWellEq>;
51  using DiagMatWell = Dune::BCRSMatrix<DiagMatrixBlockWellType>;
52 
53  // the matrix type for the non-diagonal matrix B and C^T
54  using OffDiagMatrixBlockWellType = Dune::FieldMatrix<Scalar, numWellEq, numEq>;
55  using OffDiagMatWell = Dune::BCRSMatrix<OffDiagMatrixBlockWellType>;
56 
57  void init(const int num_conn, const std::vector<std::size_t>& cells);
58 
59  void clear();
60 
61  DiagMatWell& D()
62  {
63  return duneD_;
64  }
65 
66  OffDiagMatWell& B()
67  {
68  return duneB_;
69  }
70 
71  OffDiagMatWell& C()
72  {
73  return duneC_;
74  }
75 
76  BVectorWell& residual()
77  {
78  return resWell_;
79  }
80 
81  const BVectorWell& residual() const
82  {
83  return resWell_;
84  }
85 
86  void solve(BVectorWell& dx_well) const;
87 
88  void invert();
89 
90  void apply(BVector& r) const;
91 
92  void recoverSolutionWell(const BVector& x, BVectorWell& xw) const;
93 
94 private:
95  // two off-diagonal matrices
96  OffDiagMatWell duneB_;
97  OffDiagMatWell duneC_;
98 
99  // diagonal matrix for the well
100  DiagMatWell invDuneD_;
101  DiagMatWell duneD_;
102 
103  // residuals of the well equations
104  BVectorWell resWell_;
105 
106  // several vector used in the matrix calculation
107  mutable BVectorWell Bx_;
108  mutable BVectorWell invDrw_;
109 
110 
111  // Store the global index of the well connection cells
112  std::vector<std::size_t> cells_;
113 };
114 
115 } // end of namespace Opm
116 
117 #include "CompWellEquations_impl.hpp"
118 
119 #endif // OPM_COMP_WELL_EQUATIONS_HPP
Definition: CompWellEquations.hpp:32
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45