diff --git a/dumux/common/pdesolver.hh b/dumux/common/pdesolver.hh index 12ae1f9dd130c927a879f2510590a8e824f83dfb..e06c5cc4c9ffd6dd1456e1e54a3ffaee71227fa4 100644 --- a/dumux/common/pdesolver.hh +++ b/dumux/common/pdesolver.hh @@ -26,6 +26,7 @@ #include <memory> +#include <dumux/common/typetraits/matrix.hh> #include <dumux/common/timeloop.hh> namespace Dumux { @@ -101,6 +102,29 @@ protected: LinearSolver& linearSolver() { return *linearSolver_; } + /*! + * \brief Helper function to assure the MultiTypeBlockMatrix's sub-blocks have the correct sizes. + */ + template<class M> + bool checkSizesOfSubMatrices(const M& A) const + { + static_assert(isMultiTypeBlockMatrix<M>::value, "This function can only be used with MultiTypeBlockMatrix"); + bool matrixHasCorrectSize = true; + using namespace Dune::Hybrid; + using namespace Dune::Indices; + forEach(A, [&matrixHasCorrectSize](const auto& rowOfMultiTypeBlockMatrix) + { + const auto numRowsLeftMostBlock = rowOfMultiTypeBlockMatrix[_0].N(); + + forEach(rowOfMultiTypeBlockMatrix, [&matrixHasCorrectSize, &numRowsLeftMostBlock](const auto& subBlock) + { + if (subBlock.N() != numRowsLeftMostBlock) + matrixHasCorrectSize = false; + }); + }); + return matrixHasCorrectSize; + } + private: std::shared_ptr<Assembler> assembler_; std::shared_ptr<LinearSolver> linearSolver_; diff --git a/dumux/linear/pdesolver.hh b/dumux/linear/pdesolver.hh index 8214d01ed689ca00162f3b0eaa49e02583e79678..dca3534564750aef506958e9e40d5404ccaa2ca3 100644 --- a/dumux/linear/pdesolver.hh +++ b/dumux/linear/pdesolver.hh @@ -269,8 +269,7 @@ private: SolutionVector& x, SolutionVector& b) { - // check matrix sizes - assert(checkMatrix_(A) && "Sub blocks of MultiType matrix have wrong sizes!"); + assert(this->checkSizesOfSubMatrices(A) && "Sub-blocks of MultiTypeBlockMatrix have wrong sizes!"); // TODO: automatically derive the precondBlockLevel return ls.template solve</*precondBlockLevel=*/2>(A, x, b); @@ -294,8 +293,7 @@ private: SolutionVector& x, SolutionVector& b) { - // check matrix sizes - assert(checkMatrix_(A) && "Sub blocks of MultiType matrix have wrong sizes!"); + assert(this->checkSizesOfSubMatrices(A) && "Sub-blocks of MultiTypeBlockMatrix have wrong sizes!"); // create the bcrs matrix the IterativeSolver backend can handle const auto M = MatrixConverter<JacobianMatrix>::multiTypeToBCRSMatrix(A); @@ -323,27 +321,6 @@ private: return converged; } - //! helper method to assure the MultiType matrix's sub blocks have the correct sizes - template<class M = JacobianMatrix> - typename std::enable_if_t<!isBCRSMatrix<M>(), bool> - checkMatrix_(const JacobianMatrix& A) - { - bool matrixHasCorrectSize = true; - using namespace Dune::Hybrid; - using namespace Dune::Indices; - forEach(A, [&matrixHasCorrectSize](const auto& rowOfMultiTypeMatrix) - { - const auto numRowsLeftMostBlock = rowOfMultiTypeMatrix[_0].N(); - - forEach(rowOfMultiTypeMatrix, [&matrixHasCorrectSize, &numRowsLeftMostBlock](const auto& subBlock) - { - if (subBlock.N() != numRowsLeftMostBlock) - matrixHasCorrectSize = false; - }); - }); - return matrixHasCorrectSize; - } - //! initialize the parameters by reading from the parameter tree void initParams_(const std::string& group = "") { diff --git a/dumux/nonlinear/newtonsolver.hh b/dumux/nonlinear/newtonsolver.hh index e938fdb372ec47154d205f8b5dd6d356f30a07cb..4d3c0f24468fa4e9e65fc95cfba71f7877239f7e 100644 --- a/dumux/nonlinear/newtonsolver.hh +++ b/dumux/nonlinear/newtonsolver.hh @@ -1095,8 +1095,7 @@ private: SolutionVector& x, SolutionVector& b) { - // check matrix sizes - assert(checkMatrix_(A) && "Sub blocks of MultiType matrix have wrong sizes!"); + assert(this->checkSizesOfSubMatrices(A) && "Sub-blocks of MultiTypeBlockMatrix have wrong sizes!"); // TODO: automatically derive the precondBlockLevel return ls.template solve</*precondBlockLevel=*/2>(A, x, b); @@ -1120,8 +1119,7 @@ private: SolutionVector& x, SolutionVector& b) { - // check matrix sizes - assert(checkMatrix_(A) && "Sub blocks of MultiType matrix have wrong sizes!"); + assert(this->checkSizesOfSubMatrices(A) && "Sub-blocks of MultiTypeBlockMatrix have wrong sizes!"); // create the bcrs matrix the IterativeSolver backend can handle const auto M = MatrixConverter<JacobianMatrix>::multiTypeToBCRSMatrix(A); @@ -1149,27 +1147,6 @@ private: return converged; } - //! helper method to assure the MultiType matrix's sub blocks have the correct sizes - template<class M = JacobianMatrix> - typename std::enable_if_t<!isBCRSMatrix<M>(), bool> - checkMatrix_(const JacobianMatrix& A) - { - bool matrixHasCorrectSize = true; - using namespace Dune::Hybrid; - using namespace Dune::Indices; - forEach(A, [&matrixHasCorrectSize](const auto& rowOfMultiTypeMatrix) - { - const auto numRowsLeftMostBlock = rowOfMultiTypeMatrix[_0].N(); - - forEach(rowOfMultiTypeMatrix, [&matrixHasCorrectSize, &numRowsLeftMostBlock](const auto& subBlock) - { - if (subBlock.N() != numRowsLeftMostBlock) - matrixHasCorrectSize = false; - }); - }); - return matrixHasCorrectSize; - } - //! initialize the parameters by reading from the parameter tree void initParams_(const std::string& group = "") {