MultisegmentWellEquations.hpp
Go to the documentation of this file.
1/*
2 Copyright 2017 SINTEF Digital, Mathematics and Cybernetics.
3 Copyright 2017 Statoil ASA.
4 Copyright 2016 - 2017 IRIS AS.
5
6 This file is part of the Open Porous Media project (OPM).
7
8 OPM is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 OPM is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with OPM. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#ifndef OPM_MULTISEGMENTWELL_EQUATIONS_HEADER_INCLUDED
23#define OPM_MULTISEGMENTWELL_EQUATIONS_HEADER_INCLUDED
24
28#include <dune/common/fmatrix.hh>
29#include <dune/common/fvector.hh>
30#include <dune/istl/bcrsmatrix.hh>
31#include <dune/istl/bvector.hh>
32
33#include <memory>
34#include <type_traits>
35
36namespace Dune {
37template<class M> class UMFPack;
38}
39
40namespace Opm
41{
42
43template<class Scalar, typename IndexTraits, int numWellEq, int numEq> class MultisegmentWellEquationAccess;
44template<class Scalar, typename IndexTraits> class MultisegmentWellGeneric;
45#if COMPILE_GPU_BRIDGE
46template<class Scalar> class WellContributions;
47#endif
48template<typename Scalar, typename IndexTraits> class WellInterfaceGeneric;
49template<typename Scalar, typename IndexTraits> class WellState;
50
51template<class Scalar, typename IndexTraits, int numWellEq, int numEq>
53{
54public:
55 // sparsity pattern for the matrices
56 // [A C^T [x = [ res
57 // B D ] x_well] res_well]
58
59 // the vector type for the res_well and x_well
60 using VectorBlockWellType = Dune::FieldVector<Scalar,numWellEq>;
61 using BVectorWell = Dune::BlockVector<VectorBlockWellType>;
62
63 using VectorBlockType = Dune::FieldVector<Scalar,numEq>;
64 using BVector = Dune::BlockVector<VectorBlockType>;
65
66 // the matrix type for the diagonal matrix D
67 using DiagMatrixBlockWellType = Dune::FieldMatrix<Scalar,numWellEq,numWellEq>;
68 using DiagMatWell = Dune::BCRSMatrix<DiagMatrixBlockWellType>;
69
70 // the matrix type for the non-diagonal matrix B and C^T
71 using OffDiagMatrixBlockWellType = Dune::FieldMatrix<Scalar,numWellEq,numEq>;
72 using OffDiagMatWell = Dune::BCRSMatrix<OffDiagMatrixBlockWellType>;
73
75
82 void init(const int numPerfs,
83 const std::vector<int>& cells,
84 const std::vector<std::vector<int>>& segment_inlets,
85 const std::vector<std::vector<int>>& segment_perforations,
86 const ParallelWellInfo<Scalar>& parallel_well_info);
87
89 void clear();
90
92 void apply(const BVector& x, BVector& Ax) const;
93
95 void apply(BVector& r) const;
96
99
102
104 BVectorWell solve(const BVectorWell& rhs) const;
105
108 void recoverSolutionWell(const BVector& x, BVectorWell& xw) const;
109
110#if COMPILE_GPU_BRIDGE
112 void extract(WellContributions<Scalar>& wellContribs) const;
113#endif
114
116 template<class SparseMatrixAdapter>
117 void extract(SparseMatrixAdapter& jacobian) const;
118
120 template<class PressureMatrix>
121 void extractCPRPressureMatrix(PressureMatrix& jacobian,
122 const BVector& weights,
123 const int pressureVarIndex,
124 const bool /*use_well_weights*/,
126 const int seg_pressure_var_ind,
127 const WellState<Scalar, IndexTraits>& well_state) const;
128
131
133 const BVectorWell& residual() const
134 {
135 return resWell_;
136 }
137
138 private:
139 friend class MultisegmentWellEquationAccess<Scalar,IndexTraits,numWellEq,numEq>;
140 // two off-diagonal matrices
141 OffDiagMatWell duneB_;
142 OffDiagMatWell duneC_;
143 // "diagonal" matrix for the well. It has offdiagonal entries for inlets and outlets.
144 DiagMatWell duneD_;
145
149 struct EmptyType {};
150 using UMFPackSolver = std::conditional_t<std::is_same_v<Scalar,double>,
151 std::shared_ptr<Dune::UMFPack<DiagMatWell>>,
152 EmptyType>; // TODO: c++20: add no_unique_address
153 mutable UMFPackSolver duneDSolver_;
154
155 // residuals of the well equations
156 BVectorWell resWell_;
157
158 const MultisegmentWellGeneric<Scalar, IndexTraits>& well_;
159
160 // Store the global index of well perforated cells
161 std::vector<int> cells_;
162
163 // Wrapper for the parallel application of B for distributed wells
164 mswellhelpers::ParallellMSWellB<OffDiagMatWell> parallelB_;
165};
166
167}
168
169#endif // OPM_MULTISEGMENTWELLWELL_EQUATIONS_HEADER_INCLUDED
Definition: MultisegmentWellEquations.hpp:43
Definition: MultisegmentWellEquations.hpp:53
Dune::FieldVector< Scalar, numWellEq > VectorBlockWellType
Definition: MultisegmentWellEquations.hpp:60
void sumDistributed(Parallel::Communication comm)
Sum with off-process contribution.
void init(const int numPerfs, const std::vector< int > &cells, const std::vector< std::vector< int > > &segment_inlets, const std::vector< std::vector< int > > &segment_perforations, const ParallelWellInfo< Scalar > &parallel_well_info)
Setup sparsity pattern for the matrices.
BVectorWell solve(const BVectorWell &rhs) const
Apply inverted D matrix to rhs and return result.
Dune::BCRSMatrix< DiagMatrixBlockWellType > DiagMatWell
Definition: MultisegmentWellEquations.hpp:68
Dune::FieldMatrix< Scalar, numWellEq, numEq > OffDiagMatrixBlockWellType
Definition: MultisegmentWellEquations.hpp:71
void apply(BVector &r) const
Apply linear operator to vector.
const BVectorWell & residual() const
Returns a const reference to the residual.
Definition: MultisegmentWellEquations.hpp:133
Dune::BCRSMatrix< OffDiagMatrixBlockWellType > OffDiagMatWell
Definition: MultisegmentWellEquations.hpp:72
void extractCPRPressureMatrix(PressureMatrix &jacobian, const BVector &weights, const int pressureVarIndex, const bool, const WellInterfaceGeneric< Scalar, IndexTraits > &well, const int seg_pressure_var_ind, const WellState< Scalar, IndexTraits > &well_state) const
Extract CPR pressure matrix.
BVectorWell solve() const
Apply inverted D matrix to residual and return result.
Dune::BlockVector< VectorBlockWellType > BVectorWell
Definition: MultisegmentWellEquations.hpp:61
void extract(SparseMatrixAdapter &jacobian) const
Add the matrices of this well to the sparse matrix adapter.
void clear()
Set all coefficients to 0.
MultisegmentWellEquations(const MultisegmentWellGeneric< Scalar, IndexTraits > &well, const ParallelWellInfo< Scalar > &parallel_well_info)
void apply(const BVector &x, BVector &Ax) const
Apply linear operator to vector.
void createSolver()
Compute the LU-decomposition of D matrix.
Dune::FieldMatrix< Scalar, numWellEq, numWellEq > DiagMatrixBlockWellType
Definition: MultisegmentWellEquations.hpp:67
Dune::FieldVector< Scalar, numEq > VectorBlockType
Definition: MultisegmentWellEquations.hpp:63
Dune::BlockVector< VectorBlockType > BVector
Definition: MultisegmentWellEquations.hpp:64
void recoverSolutionWell(const BVector &x, BVectorWell &xw) const
Recover well solution.
Definition: MultisegmentWellGeneric.hpp:39
Class encapsulating some information about parallel wells.
Definition: ParallelWellInfo.hpp:198
Definition: WellContributions.hpp:51
Definition: WellInterfaceGeneric.hpp:53
Definition: WellState.hpp:66
Definition: fvbaseprimaryvariables.hh:161
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Definition: blackoilbioeffectsmodules.hh:43