Skip to content
Snippets Groups Projects
Commit c54f1047 authored by Elias Pipping's avatar Elias Pipping
Browse files

Add hasIgnore() to CanIgnore; use it

In particular, a CGStep will now, like a few other steps/solvers,
treat a missing ignore the same way as an ignore whose every entry is
false.
parent 317c4152
No related branches found
No related tags found
No related merge requests found
......@@ -47,6 +47,13 @@ public:
ignoreNodes_ = &i;
}
/**
* \brief Only if this returns true can ignore() safely be called.
*/
bool hasIgnore() const {
return ignoreNodes_ != nullptr;
}
/**
* \brief Const access to bit vector
*/
......
......@@ -24,7 +24,7 @@ template<class MatrixType, class DiscFuncType, class BitVectorType>
inline
void BlockGSStep<MatrixType, DiscFuncType, BitVectorType>::iterate()
{
assert(this->ignoreNodes_ != nullptr);
assert(this->hasIgnore());
if (gs_type_ != Direction::BACKWARD)
for (std::size_t i=0; i<this->x_->size(); i++)
......
......@@ -310,7 +310,7 @@ struct BlockGSStep : public LinearIterationStep<Matrix, Vector, BitVector> {
, direction_(direction) {}
void iterate() {
assert(this->ignoreNodes_ != nullptr);
assert(this->hasIgnore());
assert(this->mat_ != nullptr);
assert(this->x_ != nullptr);
assert(this->rhs_ != nullptr);
......
......@@ -4,8 +4,6 @@
template <class MatrixType, class VectorType>
void CGStep<MatrixType, VectorType>::check() const
{
if (this->ignoreNodes_ == nullptr)
DUNE_THROW(SolverError, "ignoreNodes_ member not set");
}
template <class MatrixType, class VectorType>
......@@ -13,9 +11,10 @@ void CGStep<MatrixType, VectorType>::preprocess()
{
// Compute the residual (r starts out as the rhs)
matrix_->mmv(*x_,r_);
for (size_t i=0; i < r_.size(); ++i)
if (this->ignore()[i].any())
r_[i] = 0;
if (this->hasIgnore())
for (size_t i=0; i < r_.size(); ++i)
if (this->ignore()[i].any())
r_[i] = 0;
if (preconditioner_) {
preconditioner_->setMatrix(*matrix_);
......@@ -36,9 +35,10 @@ void CGStep<MatrixType, VectorType>::iterate()
x_->axpy(alpha, p_); // x_1 = x_0 + alpha_0 p_0
r_.axpy(-alpha, q); // r_1 = r_0 - alpha_0 Ap_0
for (size_t i=0; i < r_.size(); ++i)
if (this->ignore()[i].any())
r_[i] = 0;
if (this->hasIgnore())
for (size_t i=0; i < r_.size(); ++i)
if (this->ignore()[i].any())
r_[i] = 0;
if (preconditioner_)
preconditioner_->apply(q, r_);
......
......@@ -13,7 +13,7 @@ void TrustRegionGSStep<MatrixType, VectorType>::iterate()
// Dirichlet nodes in this block
std::bitset<BlockSize> ignoreNodes(0);
if (this->ignoreNodes_ != nullptr)
if (this->hasIgnore())
ignoreNodes = this->ignore()[i];
if (ignoreNodes.all())
......
......@@ -70,7 +70,7 @@ public:
// We may use the original rhs, but ISTL modifies it, so we need a non-const type here
VectorType mutableRhs = *rhs_;
if (this->ignoreNodes_ == nullptr)
if (not this->hasIgnore())
{
/////////////////////////////////////////////////////////////////
// Solve the system
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment