25 #ifndef ISTL_SOLVER_TPSA_HPP 26 #define ISTL_SOLVER_TPSA_HPP 28 #include <dune/istl/owneroverlapcopy.hh> 30 #include <opm/common/CriticalError.hpp> 31 #include <opm/common/ErrorMacros.hpp> 32 #include <opm/common/Exceptions.hpp> 34 #include <opm/models/tpsa/tpsabaseproperties.hpp> 38 #include <opm/simulators/linalg/AbstractISTLSolver.hpp> 39 #include <opm/simulators/linalg/ExtractParallelGridInformationToISTL.hpp> 40 #include <opm/simulators/linalg/ISTLSolver.hpp> 41 #include <opm/simulators/linalg/PropertyTree.hpp> 42 #include <opm/simulators/linalg/setupPropertyTree.hpp> 43 #include <opm/simulators/linalg/TPSALinearSolverParameters.hpp> 44 #include <opm/simulators/linalg/WriteSystemMatrixHelper.hpp> 55 #include <fmt/format.h> 65 template <
class TypeTag>
67 GetPropType<TypeTag, Properties::GlobalEqVectorTPSA>>
74 using Matrix =
typename SparseMatrixAdapter::IstlMatrix;
78 using CommunicationType = Dune::OwnerOverlapCopyCommunication<int,int>;
80 using CommunicationType = Dune::Communication<int>;
90 : simulator_(simulator)
121 comm_.reset(
new CommunicationType( simulator_.vanguard().grid().comm() ) );
128 const std::size_t size = simulator_.vanguard().grid().leafGridView().size(0);
129 detail::copyParValues(parallelInformation_, size, *comm_);
134 ElementMapper elemMapper(simulator_.vanguard().gridView(), Dune::mcmgElementLayout());
135 std::vector<int> dummyInteriorRows;
136 detail::findOverlapAndInterior(simulator_.vanguard().grid(), elemMapper, overlapRows_, dummyInteriorRows);
139 flexibleSolver_.interiorCellNum_ = detail::numMatrixRowsToUseInSolver(simulator_.vanguard().grid(),
true);
142 detail::printLinearSolverParameters(parameters_, prm_, simulator_.gridView().comm());
154 const bool firstcall = (matrix_ ==
nullptr);
159 matrix_ =
const_cast<Matrix*
>(&M);
164 OPM_THROW(std::logic_error,
"TPSA: Matrix objects are expected to be reused when reassembling!");
173 std::string type = prm_.template get<std::string>(
"preconditioner.type",
"paroverilu0");
174 std::transform(type.begin(), type.end(), type.begin(), ::tolower);
176 detail::makeOverlapRowsInvalid(
getMatrix(), overlapRows_);
183 void prepare(
const Matrix& M, Vector& b)
override 190 OPM_CATCH_AND_RETHROW_AS_CRITICAL_ERROR
191 (
"TPSA: Failure likely due to a faulty linear solver JSON specification. " 192 "Check for errors related to missing nodes.");
198 void prepare(
const SparseMatrixAdapter& M, Vector& b)
override 212 if (!flexibleSolver_.solver_) {
215 std::function<Vector()> weightCalculator;
228 flexibleSolver_.pre_->update();
241 const int verbosity = prm_.
get(
"verbosity", 0);
242 if (verbosity > 10) {
244 Helper::writeSystem(simulator_,
251 Dune::InverseOperatorResult result;
252 assert(flexibleSolver_.solver_);
253 flexibleSolver_.solver_->apply(x, *rhs_, result);
256 iterations_ = result.iterations;
335 const CommunicationType*
comm()
const override 351 return comm_->communicator().size() > 1;
379 OPM_THROW(std::runtime_error,
"TPSA: System matrix \"M\" not defined!");
392 OPM_THROW(std::runtime_error,
"TPSA: System matrix \"M\" not defined!");
398 std::any parallelInformation_;
409 std::shared_ptr<CommunicationType> comm_;
410 std::vector<int> overlapRows_;
ISTLSolverTPSA(const Simulator &simulator)
Constructor.
Definition: ISTLSolverTPSA.hpp:89
static void registerParameters()
Register runtime/default parameters for linear solver.
Definition: ISTLSolverTPSA.hpp:106
const Matrix & getMatrix() const
Get reference to system matrix object.
Definition: ISTLSolverTPSA.hpp:389
static bool checkConvergence(const Dune::InverseOperatorResult &result, const FlowLinearSolverParameters ¶meters)
Check the convergence of the linear solver.
Definition: AbstractISTLSolver.hpp:192
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(...))
Definition: propertysystem.hh:233
T get(const std::string &key) const
Retrieve property value given hierarchical property key.
Definition: PropertyTree.cpp:59
void initialize()
Setup linear solver object based on runtime/default parameters.
Definition: ISTLSolverTPSA.hpp:114
Parametern for linear solver and preconditioner.
Definition: TPSALinearSolverParameters.hpp:55
void prepareFlexibleSolver()
Prepare linear solver.
Definition: ISTLSolverTPSA.hpp:209
void prepare(const SparseMatrixAdapter &M, Vector &b) override
Prepare the solver with the given matrix and right-hand side vector.
Definition: ISTLSolverTPSA.hpp:198
void resetSolveCount()
Reset number of solver calls to zero.
Definition: ISTLSolverTPSA.hpp:265
This file provides the infrastructure to retrieve run-time parameters.
void setActiveSolver(int) override
Set the active solver by its index.
Definition: ISTLSolverTPSA.hpp:282
const CommunicationType * comm() const override
Get the communication object used by the solver.
Definition: ISTLSolverTPSA.hpp:335
Class for setting up ISTL linear solvers for TPSA.
Definition: ISTLSolverTPSA.hpp:66
int getSolveCount() const override
Get the count of how many times the solver has been called.
Definition: ISTLSolverTPSA.hpp:319
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
void eraseMatrix() override
Signals that the memory for the matrix internally in the solver could be erased.
Definition: ISTLSolverTPSA.hpp:276
bool isParallel() const
Check for parallel session.
Definition: ISTLSolverTPSA.hpp:348
int iterations() const override
Get the number of iterations used in the last solve.
Definition: ISTLSolverTPSA.hpp:327
bool checkConvergence(const Dune::InverseOperatorResult &result) const
Check for linear solver convergence.
Definition: ISTLSolverTPSA.hpp:363
bool solve(Vector &x) override
Solve the system of equations Ax = b.
Definition: ISTLSolverTPSA.hpp:235
void extractParallelGridInformationToISTL(const Dune::CpGrid &, std::any &)
Extracts the information about the data decomposition from the grid for dune-istl.
Definition: ExtractParallelGridInformationToISTL.cpp:46
void prepare(const Matrix &M, Vector &b) override
Prepare the solver with the given matrix and right-hand side vector.
Definition: ISTLSolverTPSA.hpp:183
void initPrepare(const Matrix &M, Vector &b)
Prepare matix and rhs vector for linear solve.
Definition: ISTLSolverTPSA.hpp:151
void setMatrix(const SparseMatrixAdapter &) override
Set the matrix for the solver.
Definition: ISTLSolverTPSA.hpp:302
Matrix & getMatrix()
Get reference to system matrix object.
Definition: ISTLSolverTPSA.hpp:376
The Opm property system, traits with inheritance.
int numAvailableSolvers() const override
Get the number of available solvers.
Definition: ISTLSolverTPSA.hpp:288
Abstract interface for ISTL solvers.
Definition: AbstractISTLSolver.hpp:44
void getResidual(Vector &b) const override
Get the residual vector.
Definition: ISTLSolverTPSA.hpp:311
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:83
Hierarchical collection of key/value pairs.
Definition: PropertyTree.hpp:38
void setResidual(Vector &) override
Set the residual vector.
Definition: ISTLSolverTPSA.hpp:296
PropertyTree setupPropertyTree(FlowLinearSolverParameters p, bool linearSolverMaxIterSet, bool linearSolverReductionSet, bool tpsaSetup)
Set up a property tree intended for FlexibleSolver by either reading the tree from a JSON file or cre...
Definition: setupPropertyTree.cpp:182
void init()
Internalize runtime parameters.
Definition: TPSALinearSolverParameters.cpp:37
static void registerParameters()
Register TPSA linear solver runtime parameters.
Definition: TPSALinearSolverParameters.cpp:59