Loading...
Searching...
No Matches
MultisegmentWellEquations.hpp
/*
Copyright 2017 SINTEF Digital, Mathematics and Cybernetics.
Copyright 2017 Statoil ASA.
Copyright 2016 - 2017 IRIS AS.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_MULTISEGMENTWELL_EQUATIONS_HEADER_INCLUDED
#define OPM_MULTISEGMENTWELL_EQUATIONS_HEADER_INCLUDED
#include <opm/simulators/utils/ParallelCommunication.hpp>
#include <opm/simulators/wells/ParallelWellInfo.hpp>
#include <opm/simulators/wells/MSWellHelpers.hpp>
#include <dune/common/fmatrix.hh>
#include <dune/common/fvector.hh>
#include <dune/istl/bcrsmatrix.hh>
#include <dune/istl/bvector.hh>
#include <memory>
namespace Dune {
template<class M> class UMFPack;
}
namespace Opm
{
template<class Scalar, typename IndexTraits, int numWellEq, int numEq> class MultisegmentWellEquationAccess;
template<class Scalar, typename IndexTraits> class MultisegmentWellGeneric;
#if COMPILE_GPU_BRIDGE
template<class Scalar> class WellContributions;
#endif
template<typename Scalar, typename IndexTraits> class WellInterfaceGeneric;
template<typename Scalar, typename IndexTraits> class WellState;
template<class Scalar, typename IndexTraits, int numWellEq, int numEq>
class MultisegmentWellEquations
{
public:
// sparsity pattern for the matrices
// [A C^T [x = [ res
// B D ] x_well] res_well]
// the vector type for the res_well and x_well
using VectorBlockWellType = Dune::FieldVector<Scalar,numWellEq>;
using BVectorWell = Dune::BlockVector<VectorBlockWellType>;
using VectorBlockType = Dune::FieldVector<Scalar,numEq>;
using BVector = Dune::BlockVector<VectorBlockType>;
// the matrix type for the diagonal matrix D
using DiagMatrixBlockWellType = Dune::FieldMatrix<Scalar,numWellEq,numWellEq>;
using DiagMatWell = Dune::BCRSMatrix<DiagMatrixBlockWellType>;
// the matrix type for the non-diagonal matrix B and C^T
using OffDiagMatrixBlockWellType = Dune::FieldMatrix<Scalar,numWellEq,numEq>;
using OffDiagMatWell = Dune::BCRSMatrix<OffDiagMatrixBlockWellType>;
MultisegmentWellEquations(const MultisegmentWellGeneric<Scalar, IndexTraits>& well, const ParallelWellInfo<Scalar>& pw_info);
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);
void clear();
void apply(const BVector& x, BVector& Ax) const;
void apply(BVector& r) const;
void createSolver();
BVectorWell solve() const;
BVectorWell solve(const BVectorWell& rhs) const;
void recoverSolutionWell(const BVector& x, BVectorWell& xw) const;
#if COMPILE_GPU_BRIDGE
void extract(WellContributions<Scalar>& wellContribs) const;
#endif
template<class SparseMatrixAdapter>
void extract(SparseMatrixAdapter& jacobian) const;
template<class PressureMatrix>
void extractCPRPressureMatrix(PressureMatrix& jacobian,
const BVector& weights,
const int pressureVarIndex,
const bool /*use_well_weights*/,
const WellInterfaceGeneric<Scalar, IndexTraits>& well,
const int seg_pressure_var_ind,
const WellState<Scalar, IndexTraits>& well_state) const;
void sumDistributed(Parallel::Communication comm);
const BVectorWell& residual() const
{
return resWell_;
}
private:
friend class MultisegmentWellEquationAccess<Scalar,IndexTraits,numWellEq,numEq>;
// two off-diagonal matrices
OffDiagMatWell duneB_;
OffDiagMatWell duneC_;
// "diagonal" matrix for the well. It has offdiagonal entries for inlets and outlets.
DiagMatWell duneD_;
mutable std::shared_ptr<Dune::UMFPack<DiagMatWell>> duneDSolver_;
// residuals of the well equations
BVectorWell resWell_;
const MultisegmentWellGeneric<Scalar, IndexTraits>& well_;
// Store the global index of well perforated cells
std::vector<int> cells_;
const ParallelWellInfo<Scalar>& pw_info_;
// Wrapper for the parallel application of B for distributed wells
mswellhelpers::ParallellMSWellB<OffDiagMatWell> parallelB_;
};
}
#endif // OPM_MULTISEGMENTWELLWELL_EQUATIONS_HEADER_INCLUDED
Dune::UMFPack
Definition MSWellHelpers.hpp:29
Opm::MultisegmentWellEquationAccess
Class administering assembler access to equation system.
Definition MultisegmentWellAssemble.cpp:44
Opm::MultisegmentWellEquations::sumDistributed
void sumDistributed(Parallel::Communication comm)
Sum with off-process contribution.
Definition MultisegmentWellEquations.cpp:441
Opm::MultisegmentWellEquations::solve
BVectorWell solve(const BVectorWell &rhs) const
Apply inverted D matrix to rhs and return result.
Definition MultisegmentWellEquations.cpp:220
Opm::MultisegmentWellEquations::solve
BVectorWell solve() const
Apply inverted D matrix to residual and return result.
Definition MultisegmentWellEquations.cpp:210
Opm::MultisegmentWellEquations::apply
void apply(BVector &r) const
Apply linear operator to vector.
Definition MultisegmentWellEquations.cpp:173
Opm::MultisegmentWellEquations::residual
const BVectorWell & residual() const
Returns a const reference to the residual.
Definition MultisegmentWellEquations.hpp:130
Opm::MultisegmentWellEquations::extractCPRPressureMatrix
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.
Definition MultisegmentWellEquations.cpp:356
Opm::MultisegmentWellEquations::extract
void extract(SparseMatrixAdapter &jacobian) const
Add the matrices of this well to the sparse matrix adapter.
Definition MultisegmentWellEquations.cpp:319
Opm::MultisegmentWellEquations::clear
void clear()
Set all coefficients to 0.
Definition MultisegmentWellEquations.cpp:141
Opm::MultisegmentWellEquations::apply
void apply(const BVector &x, BVector &Ax) const
Apply linear operator to vector.
Definition MultisegmentWellEquations.cpp:152
Opm::MultisegmentWellEquations::createSolver
void createSolver()
Compute the LU-decomposition of D matrix.
Definition MultisegmentWellEquations.cpp:189
Opm::MultisegmentWellEquations::init
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)
Setup sparsity pattern for the matrices.
Definition MultisegmentWellEquations.cpp:63
Opm::MultisegmentWellEquations::recoverSolutionWell
void recoverSolutionWell(const BVector &x, BVectorWell &xw) const
Recover well solution.
Definition MultisegmentWellEquations.cpp:230
Opm::MultisegmentWellGeneric
Definition MultisegmentWellGeneric.hpp:39
Opm::ParallelWellInfo
Class encapsulating some information about parallel wells.
Definition ParallelWellInfo.hpp:198
Opm::WellContributions
This class serves to eliminate the need to include the WellContributions into the matrix (with –matri...
Definition WellContributions.hpp:51
Opm::WellInterfaceGeneric
Definition WellInterfaceGeneric.hpp:53
Opm::WellState
The state of a set of wells, tailored for use by the fully implicit blackoil simulator.
Definition WellState.hpp:66
Opm::mswellhelpers::ParallellMSWellB
A wrapper around the B matrix for distributed MS wells.
Definition MSWellHelpers.hpp:54
Opm
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43