diff --git a/dune/solvers/transferoperators/truncatedcompressedmgtransfer.cc b/dune/solvers/transferoperators/truncatedcompressedmgtransfer.cc index a53c7d929436c5f88dc1f9f8802b86eead210b73..bcf06918b58557ae8f142291eacc870267b17a0f 100644 --- a/dune/solvers/transferoperators/truncatedcompressedmgtransfer.cc +++ b/dune/solvers/transferoperators/truncatedcompressedmgtransfer.cc @@ -1,7 +1,14 @@ template<class VectorType, class BitVectorType, class MatrixType> -void TruncatedCompressedMGTransfer<VectorType, BitVectorType, MatrixType>::prolong(const VectorType& f, VectorType& t, - const BitVectorType& critical) const +void TruncatedCompressedMGTransfer<VectorType, BitVectorType, MatrixType>::prolong(const VectorType& f, VectorType& t) const { + // If the critical bitfield is not set, call the base class method + if (this->critical_ == nullptr) { + Base::prolong(f,t); + return; + } + + const BitVectorType& critical = *this->critical_; + if (f.size() != this->matrix_->M()) DUNE_THROW(Dune::Exception, "Number of entries in the coarse grid vector is not equal " << "to the number of columns of the prolongation matrix!"); @@ -42,9 +49,16 @@ void TruncatedCompressedMGTransfer<VectorType, BitVectorType, MatrixType>::prolo } template<class VectorType, class BitVectorType, class MatrixType> -void TruncatedCompressedMGTransfer<VectorType, BitVectorType, MatrixType>::restrict(const VectorType& f, VectorType& t, - const BitVectorType& critical) const +void TruncatedCompressedMGTransfer<VectorType, BitVectorType, MatrixType>::restrict(const VectorType& f, VectorType& t) const { + // If the critical bitfield is not set, call the base class method + if (this->critical_ == nullptr) { + Base::restrict(f,t); + return; + } + + const BitVectorType& critical = *this->critical_; + if (f.size() != this->matrix_->N()) DUNE_THROW(Dune::Exception, "Fine grid vector has " << f.size() << " entries " << "but the interpolation matrix has " << this->matrix_->N() << " rows!"); @@ -83,10 +97,15 @@ void TruncatedCompressedMGTransfer<VectorType, BitVectorType, MatrixType>::restr template<class VectorType, class BitVectorType, class MatrixType> void TruncatedCompressedMGTransfer<VectorType, BitVectorType, MatrixType>:: -galerkinRestrict(const MatrixType& fineMat, MatrixType& coarseMat, - const BitVectorType& critical) const +galerkinRestrict(const MatrixType& fineMat, MatrixType& coarseMat) const { - if (this->recompute_ != NULL && this->recompute_->size() != (unsigned int)this->matrix_->M()) + // If the critical bitfield is not set, call the base class method + if (this->recompute_ == nullptr && this->critical_ == nullptr) { + Base::galerkinRestrict(fineMat, coarseMat); + return; + } + + if (this->recompute_ != nullptr && this->recompute_->size() != (unsigned int)this->matrix_->M()) DUNE_THROW(Dune::Exception, "The size of the recompute_-bitfield doesn't match the " << "size of the coarse grid space!"); @@ -100,7 +119,7 @@ galerkinRestrict(const MatrixType& fineMat, MatrixType& coarseMat, typedef typename TransferOperatorType::row_type::ConstIterator TransferConstColumnIterator; // Clear coarse matrix - if (this->recompute_ == NULL) + if (this->recompute_ == nullptr) coarseMat = 0; else { for (size_t i=0; i<coarseMat.N(); i++) { @@ -159,7 +178,7 @@ galerkinRestrict(const MatrixType& fineMat, MatrixType& coarseMat, // Truncated Multigrid: Omit coupling if at least // one of the two vectors is critical - if (!critical[v][i] && !critical[w][j]) + if (this->critical_==nullptr || (!((*this->critical_)[v][i]) && !((*this->critical_)[w][j]))) cm[i][j] += (*im)[0][0] * (*m)[i][j] * (*jm)[0][0]; } } diff --git a/dune/solvers/transferoperators/truncatedcompressedmgtransfer.hh b/dune/solvers/transferoperators/truncatedcompressedmgtransfer.hh index 8fc17d5569dd84b1daa6ec0d8b08dd8e7a115ffa..cb1d2aad847313dfce42110774799a0108d282df 100644 --- a/dune/solvers/transferoperators/truncatedcompressedmgtransfer.hh +++ b/dune/solvers/transferoperators/truncatedcompressedmgtransfer.hh @@ -34,46 +34,25 @@ class TruncatedCompressedMGTransfer : enum {blocksize = VectorType::block_type::dimension}; typedef typename VectorType::field_type field_type; + typedef CompressedMultigridTransfer<VectorType, BitVectorType, MatrixType> Base; public: - typedef typename CompressedMultigridTransfer<VectorType, BitVectorType, MatrixType>::TransferOperatorType TransferOperatorType; + typedef typename Base::TransferOperatorType TransferOperatorType; /** \brief Default constructor */ TruncatedCompressedMGTransfer() {} - /** \brief Restrict level fL of f and store the result in level cL of t - * - * \param critical Has to contain an entry for each degree of freedom. - * Those dofs with a set bit are treated as critical. - */ - void restrict(const VectorType& f, VectorType &t, const BitVectorType& critical) const; + /** \brief Restrict level fL of f and store the result in level cL of t */ + void restrict(const VectorType& f, VectorType &t) const; - /** \brief Restriction of MultiGridTransfer*/ - using CompressedMultigridTransfer< VectorType, BitVectorType, MatrixType >::restrict; - - /** \brief Prolong level cL of f and store the result in level fL of t - * - * \param critical Has to contain an entry for each degree of freedom. - * Those dofs with a set bit are treated as critical. - */ - void prolong(const VectorType& f, VectorType &t, const BitVectorType& critical) const; - - /** \brief Prolongation of MultiGridTransfer*/ - using CompressedMultigridTransfer< VectorType, BitVectorType, MatrixType >::prolong; - - /** \brief Galerkin assemble a coarse stiffness matrix - * - * \param critical Has to contain an entry for each degree of freedom. - * Those dofs with a set bit are treated as critical. - */ - void galerkinRestrict(const MatrixType& fineMat, MatrixType& coarseMat, const BitVectorType& critical) const; - - /** \brief Galerkin restriction of MultiGridTransfer*/ - using CompressedMultigridTransfer< VectorType, BitVectorType, MatrixType >::galerkinRestrict; + /** \brief Prolong level cL of f and store the result in level fL of t */ + void prolong(const VectorType& f, VectorType &t) const; + /** \brief Galerkin assemble a coarse stiffness matrix */ + void galerkinRestrict(const MatrixType& fineMat, MatrixType& coarseMat) const; }; diff --git a/dune/solvers/transferoperators/truncateddensemgtransfer.cc b/dune/solvers/transferoperators/truncateddensemgtransfer.cc index cb13c026b5e9bbe51048174819119dc7e893fd2a..9ee7326614ddfdb767a187df07468c3c8b562702 100644 --- a/dune/solvers/transferoperators/truncateddensemgtransfer.cc +++ b/dune/solvers/transferoperators/truncateddensemgtransfer.cc @@ -1,9 +1,16 @@ template<class DiscFuncType, class BitVectorType, class OperatorType> -void TruncatedDenseMGTransfer<DiscFuncType, BitVectorType, OperatorType>::prolong(const DiscFuncType& f, DiscFuncType& t, - const BitVectorType& critical) const +void TruncatedDenseMGTransfer<DiscFuncType, BitVectorType, OperatorType>::prolong(const DiscFuncType& f, DiscFuncType& t) const { + // If the critical bitfield is not set, call the base class method + if (this->critical_ == nullptr) { + Base::prolong(f,t); + return; + } + + const BitVectorType& critical = *this->critical_; + if (f.size() != this->matrix_.M()) DUNE_THROW(Dune::Exception, "Number of entries in the coarse grid vector is not equal " << "to the number of columns of the prolongation matrix!"); @@ -23,8 +30,6 @@ void TruncatedDenseMGTransfer<DiscFuncType, BitVectorType, OperatorType>::prolon Iterator tIt = t.begin(); ConstIterator fIt = f.begin(); - - for(size_t rowIdx=0; rowIdx<this->matrix_.N(); rowIdx++) { const RowType& row = this->matrix_[rowIdx]; @@ -56,9 +61,17 @@ void TruncatedDenseMGTransfer<DiscFuncType, BitVectorType, OperatorType>::prolon } template<class DiscFuncType, class BitVectorType, class OperatorType> -void TruncatedDenseMGTransfer<DiscFuncType, BitVectorType, OperatorType>::restrict(const DiscFuncType& f, DiscFuncType& t, - const BitVectorType& critical) const +void TruncatedDenseMGTransfer<DiscFuncType, BitVectorType, OperatorType>::restrict(const DiscFuncType& f, DiscFuncType& t) const { + + // If the critical bitfield is not set, call the base class method + if (this->critical_ == nullptr) { + Base::restrict(f,t); + return; + } + + const BitVectorType& critical = *this->critical_; + if (f.size() != this->matrix_.N()) DUNE_THROW(Dune::Exception, "Fine grid vector has " << f.size() << " entries " << "but the interpolation matrix has " << this->matrix_.N() << " rows!"); @@ -112,11 +125,16 @@ void TruncatedDenseMGTransfer<DiscFuncType, BitVectorType, OperatorType>::restri template<class DiscFuncType, class BitVectorType, class OperatorType> void TruncatedDenseMGTransfer<DiscFuncType, BitVectorType, OperatorType>:: -galerkinRestrict(const OperatorType& fineMat, OperatorType& coarseMat, - const BitVectorType& critical) const +galerkinRestrict(const OperatorType& fineMat, OperatorType& coarseMat) const { - if (this->recompute_ != NULL && this->recompute_->size() != (unsigned int)this->matrix_.M()) + // If the critical bitfield is not set, call the base class method + if (this->recompute_ == nullptr && this->critical_ == nullptr) { + Base::galerkinRestrict(fineMat, coarseMat); + return; + } + + if (this->recompute_ != nullptr && this->recompute_->size() != (unsigned int)this->matrix_.M()) DUNE_THROW(Dune::Exception, "The size of the recompute_-bitfield doesn't match the " << "size of the coarse grid space!"); @@ -128,7 +146,7 @@ galerkinRestrict(const OperatorType& fineMat, OperatorType& coarseMat, typedef typename RowType::ConstIterator ConstColumnIterator; // Clear coarse matrix - if (this->recompute_ == NULL) + if (this->recompute_ == nullptr) coarseMat = 0; else { for (size_t i=0; i<coarseMat.N(); i++) { @@ -195,7 +213,7 @@ galerkinRestrict(const OperatorType& fineMat, OperatorType& coarseMat, for (int l=0; l<blocksize; l++) { // Truncated Multigrid: Omit coupling if at least // one of the two vectors is critical - if (!critical[v][k] && !critical[w][l]) { + if (this->critical_==nullptr || (!((*this->critical_)[v][k]) && !((*this->critical_)[w][l]))) { sum += (*im)[k][i] * (*m)[k][l] * (*jm)[l][j]; } diff --git a/dune/solvers/transferoperators/truncateddensemgtransfer.hh b/dune/solvers/transferoperators/truncateddensemgtransfer.hh index 2159caa381eaa8fc157ac849056709dd31a4b753..5b4206581c775fe594474bacedafdf937f392ba3 100644 --- a/dune/solvers/transferoperators/truncateddensemgtransfer.hh +++ b/dune/solvers/transferoperators/truncateddensemgtransfer.hh @@ -33,9 +33,9 @@ class TruncatedDenseMGTransfer : enum {blocksize = VectorType::block_type::dimension}; typedef typename VectorType::field_type field_type; - + typedef DenseMultigridTransfer<VectorType, BitVectorType, MatrixType> Base; public: - + using Base::restrictScalarBitField; typedef MatrixType OperatorType; typedef Dune::BCRSMatrix< Dune::FieldMatrix< field_type, blocksize, blocksize > > TransferOperatorType; @@ -44,36 +44,15 @@ public: TruncatedDenseMGTransfer() {} - /** \brief Restrict level fL of f and store the result in level cL of t - * - * \param critical Has to contain an entry for each degree of freedom. - * Those dofs with a set bit are treated as critical. - */ - void restrict(const VectorType& f, VectorType &t, const BitVectorType& critical) const; - - /** \brief Restriction of MultiGridTransfer*/ - using DenseMultigridTransfer< VectorType, BitVectorType, MatrixType >::restrict; - - /** \brief Prolong level cL of f and store the result in level fL of t - * - * \param critical Has to contain an entry for each degree of freedom. - * Those dofs with a set bit are treated as critical. - */ - void prolong(const VectorType& f, VectorType &t, const BitVectorType& critical) const; - - /** \brief Prolongation of MultiGridTransfer*/ - using DenseMultigridTransfer< VectorType, BitVectorType, MatrixType >::prolong; + /** \brief Restrict level fL of f and store the result in level cL of t */ + void restrict(const VectorType& f, VectorType &t) const; - /** \brief Galerkin assemble a coarse stiffness matrix - * - * \param critical Has to contain an entry for each degree of freedom. - * Those dofs with a set bit are treated as critical. - */ - void galerkinRestrict(const MatrixType& fineMat, MatrixType& coarseMat, const BitVectorType& critical) const; - /** \brief Galerkin restriction of MultiGridTransfer*/ - using DenseMultigridTransfer< VectorType, BitVectorType, MatrixType >::galerkinRestrict; + /** \brief Prolong level cL of f and store the result in level fL of t */ + void prolong(const VectorType& f, VectorType &t) const; + /** \brief Galerkin assemble a coarse stiffness matrix */ + void galerkinRestrict(const MatrixType& fineMat, MatrixType& coarseMat) const; };