2022-11-11 14:37:08 -06:00
|
|
|
/*
|
|
|
|
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_STANDARDWELL_EQUATIONS_HEADER_INCLUDED
|
|
|
|
#define OPM_STANDARDWELL_EQUATIONS_HEADER_INCLUDED
|
|
|
|
|
2022-11-11 14:41:24 -06:00
|
|
|
#include <opm/simulators/utils/ParallelCommunication.hpp>
|
2022-11-11 14:37:08 -06:00
|
|
|
#include <opm/simulators/wells/WellHelpers.hpp>
|
|
|
|
|
|
|
|
#include <dune/common/dynmatrix.hh>
|
|
|
|
#include <dune/common/dynvector.hh>
|
|
|
|
#include <dune/istl/bcrsmatrix.hh>
|
|
|
|
#include <dune/istl/bvector.hh>
|
|
|
|
|
|
|
|
namespace Opm
|
|
|
|
{
|
|
|
|
|
|
|
|
class ParallelWellInfo;
|
2022-11-18 06:00:01 -06:00
|
|
|
template<class Scalar, int numEq> class StandardWellEquationAccess;
|
2022-11-11 14:41:24 -06:00
|
|
|
class WellContributions;
|
2022-11-11 14:41:24 -06:00
|
|
|
class WellInterfaceGeneric;
|
|
|
|
class WellState;
|
2022-11-11 14:37:08 -06:00
|
|
|
|
|
|
|
template<class Scalar, int numEq>
|
|
|
|
class StandardWellEquations
|
|
|
|
{
|
|
|
|
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::DynamicVector<Scalar>;
|
|
|
|
using BVectorWell = Dune::BlockVector<VectorBlockWellType>;
|
|
|
|
|
|
|
|
// the matrix type for the diagonal matrix D
|
|
|
|
using DiagMatrixBlockWellType = Dune::DynamicMatrix<Scalar>;
|
|
|
|
using DiagMatWell = Dune::BCRSMatrix<DiagMatrixBlockWellType>;
|
|
|
|
|
|
|
|
// the matrix type for the non-diagonal matrix B and C^T
|
|
|
|
using OffDiagMatrixBlockWellType = Dune::DynamicMatrix<Scalar>;
|
|
|
|
using OffDiagMatWell = Dune::BCRSMatrix<OffDiagMatrixBlockWellType>;
|
|
|
|
|
|
|
|
// block vector type
|
|
|
|
using BVector = Dune::BlockVector<Dune::FieldVector<Scalar,numEq>>;
|
|
|
|
|
|
|
|
StandardWellEquations(const ParallelWellInfo& parallel_well_info);
|
|
|
|
|
2022-11-11 14:41:24 -06:00
|
|
|
//! \brief Setup sparsity pattern for the matrices.
|
|
|
|
//! \param num_cells Total number of cells
|
|
|
|
//! \param numWellEq Number of well equations
|
|
|
|
//! \param numPerfs Number of perforations
|
|
|
|
//! \param cells Cell indices for perforations
|
|
|
|
void init(const int num_cells,
|
|
|
|
const int numWellEq,
|
|
|
|
const int numPerfs,
|
|
|
|
const std::vector<int>& cells);
|
|
|
|
|
2022-11-11 14:41:24 -06:00
|
|
|
//! \brief Set all coefficients to 0.
|
|
|
|
void clear();
|
|
|
|
|
2022-11-11 14:41:24 -06:00
|
|
|
//! \brief Apply linear operator to vector.
|
|
|
|
void apply(const BVector& x, BVector& Ax) const;
|
|
|
|
|
2022-11-11 14:41:24 -06:00
|
|
|
//! \brief Apply linear operator to vector.
|
|
|
|
void apply(BVector& r) const;
|
|
|
|
|
2022-11-11 14:41:24 -06:00
|
|
|
//! \brief Apply inverted D matrix to residual and store in vector.
|
|
|
|
void solve(BVectorWell& dx_well) const;
|
|
|
|
|
2022-11-11 14:41:24 -06:00
|
|
|
//! \brief Invert D matrix.
|
|
|
|
void invert();
|
|
|
|
|
2022-11-11 14:41:24 -06:00
|
|
|
//! \brief Recover well solution.
|
|
|
|
//! \details xw = inv(D)*(rw - C*x)
|
|
|
|
void recoverSolutionWell(const BVector& x, BVectorWell& xw) const;
|
|
|
|
|
2022-11-11 14:41:24 -06:00
|
|
|
//! \brief Add the matrices of this well to the WellContributions object.
|
|
|
|
void extract(const int numStaticWellEq,
|
|
|
|
WellContributions& wellContribs) const;
|
|
|
|
|
2022-11-11 14:41:24 -06:00
|
|
|
//! \brief Add the matrices of this well to the sparse matrix adapter.
|
|
|
|
template<class SparseMatrixAdapter>
|
|
|
|
void extract(SparseMatrixAdapter& jacobian) const;
|
|
|
|
|
2022-11-11 14:41:24 -06:00
|
|
|
//! \brief Extract CPR pressure matrix.
|
|
|
|
template<class PressureMatrix>
|
|
|
|
void extractCPRPressureMatrix(PressureMatrix& jacobian,
|
|
|
|
const BVector& weights,
|
|
|
|
const int pressureVarIndex,
|
|
|
|
const bool use_well_weights,
|
|
|
|
const WellInterfaceGeneric& well,
|
|
|
|
const int bhp_var_index,
|
|
|
|
const WellState& well_state) const;
|
|
|
|
|
2022-11-11 14:41:24 -06:00
|
|
|
//! \brief Get the number of blocks of the C and B matrices.
|
|
|
|
unsigned int getNumBlocks() const;
|
|
|
|
|
2022-11-11 14:41:24 -06:00
|
|
|
//! \brief Sum with off-process contribution.
|
|
|
|
void sumDistributed(Parallel::Communication comm);
|
|
|
|
|
2022-11-18 05:59:16 -06:00
|
|
|
//! \brief Returns a const reference to the residual.
|
|
|
|
const BVectorWell& residual() const
|
|
|
|
{
|
|
|
|
return resWell_;
|
|
|
|
}
|
|
|
|
|
2022-11-18 06:00:01 -06:00
|
|
|
private:
|
|
|
|
friend class StandardWellEquationAccess<Scalar,numEq>;
|
|
|
|
|
2022-11-11 14:37:08 -06:00
|
|
|
// two off-diagonal matrices
|
|
|
|
OffDiagMatWell duneB_;
|
|
|
|
OffDiagMatWell duneC_;
|
|
|
|
// diagonal matrix for the well
|
|
|
|
DiagMatWell invDuneD_;
|
|
|
|
DiagMatWell duneD_;
|
|
|
|
|
|
|
|
// Wrapper for the parallel application of B for distributed wells
|
|
|
|
wellhelpers::ParallelStandardWellB<Scalar> parallelB_;
|
|
|
|
|
|
|
|
// residuals of the well equations
|
|
|
|
BVectorWell resWell_;
|
|
|
|
|
|
|
|
// several vector used in the matrix calculation
|
|
|
|
mutable BVectorWell Bx_;
|
|
|
|
mutable BVectorWell invDrw_;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // OPM_STANDARDWELL_EQUATIONS_HEADER_INCLUDED
|