Loading...
Searching...
No Matches
fixpointcriterion.hh
Go to the documentation of this file.
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*
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 2 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/>.
Consult the COPYING file in the top-level source directory of this
module for the precise wording of the license and the list of
copyright holders.
*/
#ifndef EWOMS_ISTL_FIXPOINT_CRITERION_HH
#define EWOMS_ISTL_FIXPOINT_CRITERION_HH
#include "convergencecriterion.hh"
namespace Opm {
namespace Linear {
template <class Vector, class CollectiveCommunication>
class FixPointCriterion : public ConvergenceCriterion<Vector>
{
using Scalar = typename Vector::field_type;
using BlockType = typename Vector::block_type;
public:
FixPointCriterion(const CollectiveCommunication& comm) : comm_(comm)
{}
FixPointCriterion(const CollectiveCommunication& comm,
const Vector& weightVec, Scalar reduction)
: comm_(comm), weightVec_(weightVec), tolerance_(reduction)
{}
void setWeight(const Vector& weightVec)
{ weightVec_ = weightVec; }
Scalar weight(int outerIdx, int innerIdx) const
{ return (weightVec_.size() == 0) ? 1.0 : weightVec_[outerIdx][innerIdx]; }
void setTolerance(Scalar tol)
{ tolerance_ = tol; }
Scalar tolerance() const
{ return tolerance_; }
void setInitial(const Vector& curSol, const Vector&) override
{
lastSol_ = curSol;
delta_ = 1000 * tolerance_;
}
void update(const Vector& curSol,
const Vector&,
const Vector&) override
{
assert(curSol.size() == lastSol_.size());
delta_ = 0.0;
for (size_t i = 0; i < curSol.size(); ++i) {
for (size_t j = 0; j < BlockType::dimension; ++j) {
delta_ =
std::max(delta_, weight(i, j)*std::abs(curSol[i][j] - lastSol_[i][j]));
}
}
delta_ = comm_.max(delta_);
lastSol_ = curSol;
}
bool converged() const override
{ return accuracy() < tolerance(); }
Scalar accuracy() const
{ return delta_; }
private:
const CollectiveCommunication& comm_;
Vector lastSol_; // solution of the last iteration
Vector weightVec_; // solution of the last iteration
Scalar delta_; // the maximum of the absolute weighted difference of the
// last two iterations
Scalar tolerance_; // the maximum allowed delta for the solution to be
// considered converged
};
}} // end namespace Linear, Opm
#endif
Opm::Linear::ConvergenceCriterion
Base class for all convergence criteria which only defines an virtual API.
Definition convergencecriterion.hh:56
Opm::Linear::FixPointCriterion::update
void update(const Vector &curSol, const Vector &, const Vector &) override
Update the internal members of the convergence criterion with the current solution.
Definition fixpointcriterion.hh:138
Opm::Linear::FixPointCriterion::weight
Scalar weight(int outerIdx, int innerIdx) const
Return the relative weight of a primary variable.
Definition fixpointcriterion.hh:105
Opm::Linear::FixPointCriterion::setTolerance
void setTolerance(Scalar tol)
Set the maximum allowed weighted maximum difference between two iterations.
Definition fixpointcriterion.hh:116
Opm::Linear::FixPointCriterion::tolerance
Scalar tolerance() const
Return the maximum allowed weighted difference between two iterations for the solution considered to ...
Definition fixpointcriterion.hh:123
Opm::Linear::FixPointCriterion::converged
bool converged() const override
Returns true if and only if the convergence criterion is met.
Definition fixpointcriterion.hh:159
Opm::Linear::FixPointCriterion::setWeight
void setWeight(const Vector &weightVec)
Sets the relative weight of a primary variable.
Definition fixpointcriterion.hh:86
Opm::Linear::FixPointCriterion::setInitial
void setInitial(const Vector &curSol, const Vector &) override
Set the initial solution of the linear system of equations.
Definition fixpointcriterion.hh:129
Opm::Linear::FixPointCriterion::accuracy
Scalar accuracy() const
Returns the accuracy of the solution at the last update.
Definition fixpointcriterion.hh:165
convergencecriterion.hh
Opm
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43