diff --git a/dumux/discretization/cellcentered/mpfa/localassembler.hh b/dumux/discretization/cellcentered/mpfa/localassembler.hh index 1fdc7685944774b56997a1063f2cce915748db9a..2dc51bb868c07184fb32b79b6ae9f42a0511737e 100644 --- a/dumux/discretization/cellcentered/mpfa/localassembler.hh +++ b/dumux/discretization/cellcentered/mpfa/localassembler.hh @@ -26,8 +26,9 @@ #ifndef DUMUX_DISCRETIZATION_CC_MPFA_LOCAL_ASSEMBLER_HH #define DUMUX_DISCRETIZATION_CC_MPFA_LOCAL_ASSEMBLER_HH -#include <dune/common/exceptions.hh> +#include <type_traits> +#include <dune/common/exceptions.hh> #include <dumux/discretization/cellcentered/mpfa/methods.hh> namespace Dumux @@ -58,7 +59,34 @@ class InteractionVolumeAssemblerBase using FVElementGeometry = EG; using ElementVolumeVariables = EV; - public: + typedef std::true_type yes; + typedef std::false_type no; + + //! Determines whether or not a matrix has a resize() function + template<typename M> + struct matrix_has_resize_method + { + private: + // resize function is called with two indices for matrices + template<typename U> static auto test(int) -> decltype(std::declval<U>().resize(0, 0), yes()); + template<typename> static no test(...); + public: + static constexpr bool value = std::is_same<decltype(test<M>(0)), yes>::value; + }; + + //! determines whether or not a vector has a resize() function + template<typename V> + struct vector_has_resize_method + { + private: + // resize function is called with one index for vectors + template<typename U> static auto test(int) -> decltype(std::declval<U>().resize(0), yes()); + template<typename> static no test(...); + public: + static constexpr bool value = std::is_same<decltype(test<V>(0)), yes>::value; + }; + + public: /*! * \brief The constructor. * Sets pointers to the objects required for a subsequent call to assemble(). @@ -131,7 +159,40 @@ class InteractionVolumeAssemblerBase DUNE_THROW(Dune::NotImplemented, "Implementation does not provide a assembleGravity() function"); } - private: +protected: + //! resizes a matrix to the given sizes (specialization for dynamic matrix type) + template< class Matrix, + class size_type, + std::enable_if_t<matrix_has_resize_method<Matrix>::value, int> = 0 > + void resizeMatrix_(Matrix& M, size_type rows, size_type cols) + { + M.resize(rows, cols); + } + + //! resizes a matrix to the given sizes (specialization for static matrix type - do nothing) + template< class Matrix, + class size_type, + std::enable_if_t<!matrix_has_resize_method<Matrix>::value, int> = 0 > + void resizeMatrix_(Matrix& M, size_type rows, size_type cols) + {} + + //! resizes a vector to the given size (specialization for dynamic matrix type) + template< class Vector, + class size_type, + std::enable_if_t<vector_has_resize_method<Vector>::value, int> = 0 > + void resizeVector_(Vector& v, size_type size) + { + v.resize(size); + } + + //! resizes a vector to the given size (specialization for static vector type - do nothing) + template< class Vector, + class size_type, + std::enable_if_t<!vector_has_resize_method<Vector>::value, int> = 0 > + void resizeVector_(Vector& v, size_type rows) + {} + +private: // pointers to the data required for assembly const Problem* problemPtr_; const FVElementGeometry* fvGeometryPtr_; diff --git a/dumux/discretization/cellcentered/mpfa/omethod/interactionvolume.hh b/dumux/discretization/cellcentered/mpfa/omethod/interactionvolume.hh index 2dd239e6cbdf769fa18de84e35e46cbac02e13e9..ab52179d16cce2c1f3877cadc2dbce6e583f73c4 100644 --- a/dumux/discretization/cellcentered/mpfa/omethod/interactionvolume.hh +++ b/dumux/discretization/cellcentered/mpfa/omethod/interactionvolume.hh @@ -32,7 +32,6 @@ #include <dune/common/reservedvector.hh> #include <dumux/common/math.hh> -#include <dumux/common/matrixvectorhelper.hh> #include <dumux/discretization/cellcentered/mpfa/interactionvolumebase.hh> #include <dumux/discretization/cellcentered/mpfa/dualgridindexset.hh> diff --git a/dumux/discretization/cellcentered/mpfa/omethod/localassembler.hh b/dumux/discretization/cellcentered/mpfa/omethod/localassembler.hh index fd25271136fb8195b970f31d0ab32e60930d4fe5..ad77922b52cc3b5622a42408deb97072569e022b 100644 --- a/dumux/discretization/cellcentered/mpfa/omethod/localassembler.hh +++ b/dumux/discretization/cellcentered/mpfa/omethod/localassembler.hh @@ -26,7 +26,6 @@ #define DUMUX_DISCRETIZATION_CC_MPFA_O_LOCAL_ASSEMBLER_HH #include <dumux/common/math.hh> -#include <dumux/common/matrixvectorhelper.hh> #include <dumux/discretization/cellcentered/mpfa/methods.hh> #include <dumux/discretization/cellcentered/mpfa/localassembler.hh> @@ -97,7 +96,9 @@ public: const auto numOutsideFaces = curGlobalScvf.boundary() ? 0 : curGlobalScvf.numOutsideScvs(); // resize each face entry to the right number of outside faces tijOut[fIdx].resize(numOutsideFaces); - std::for_each(tijOut[fIdx].begin(), tijOut[fIdx].end(), [&iv](auto& v) { resizeVector(v, iv.numKnowns()); }); + std::for_each(tijOut[fIdx].begin(), + tijOut[fIdx].end(), + [&](auto& v) { this->resizeVector_(v, iv.numKnowns()); }); } // compute outside transmissibilities @@ -153,7 +154,7 @@ public: void assembleU(DataHandle& handle, const IV& iv, const GetU& getU) { auto& u = handle.uj(); - resizeVector(u, iv.numKnowns()); + this->resizeVector_(u, iv.numKnowns()); // put the cell unknowns first, then Dirichlet values typename IV::Traits::IndexSet::LocalIndexType i = 0; @@ -182,9 +183,9 @@ public: // resize the gravity vectors auto& g = handle.g(); auto& outsideG = handle.gOutside(); - resizeVector(g, iv.numFaces()); + this->resizeVector_(g, iv.numFaces()); if (isSurfaceGrid) - resizeVector(outsideG, iv.numFaces()); + this->resizeVector_(outsideG, iv.numFaces()); // we require the CA matrix to have the correct size already assert(CA.rows() == iv.numFaces() && CA.cols() == iv.numUnknowns()); @@ -219,7 +220,7 @@ public: if (isSurfaceGrid) { - resizeVector(outsideG[faceIdx], numOutsideFaces); + this->resizeVector_(outsideG[faceIdx], numOutsideFaces); std::fill(outsideG[faceIdx].begin(), outsideG[faceIdx].end(), 0.0); } @@ -279,7 +280,7 @@ public: { using FaceVector = typename IV::Traits::MatVecTraits::FaceVector; FaceVector AG; - resizeVector(AG, iv.numUnknowns()); + this->resizeVector_(AG, iv.numUnknowns()); handle.A().mv(sum_alphas, AG); // compute gravitational accelerations @@ -350,7 +351,7 @@ private: if (iv.numUnknowns() == 0) { // resize & reset D matrix - resizeMatrix(D, iv.numFaces(), iv.numKnowns()); D = 0.0; + this->resizeMatrix_(D, iv.numFaces(), iv.numKnowns()); D = 0.0; // Loop over all the faces, in this case these are all dirichlet boundaries for (LocalIndexType faceIdx = 0; faceIdx < iv.numFaces(); ++faceIdx) @@ -382,10 +383,10 @@ private: else { // resize & reset matrices - resizeMatrix(A, iv.numUnknowns(), iv.numUnknowns()); A = 0.0; - resizeMatrix(B, iv.numUnknowns(), iv.numKnowns()); B = 0.0; - resizeMatrix(C, iv.numFaces(), iv.numUnknowns()); C = 0.0; - resizeMatrix(D, iv.numFaces(), iv.numKnowns()); D = 0.0; + this->resizeMatrix_(A, iv.numUnknowns(), iv.numUnknowns()); A = 0.0; + this->resizeMatrix_(B, iv.numUnknowns(), iv.numKnowns()); B = 0.0; + this->resizeMatrix_(C, iv.numFaces(), iv.numUnknowns()); C = 0.0; + this->resizeMatrix_(D, iv.numFaces(), iv.numKnowns()); D = 0.0; auto& wijk = iv.omegas(); for (LocalIndexType faceIdx = 0; faceIdx < iv.numFaces(); ++faceIdx) diff --git a/dumux/discretization/cellcentered/mpfa/omethod/staticinteractionvolume.hh b/dumux/discretization/cellcentered/mpfa/omethod/staticinteractionvolume.hh index cfd6891edc52b9778bf5cc91eb28e6f1fe45c0cb..60f78d6d68929bc23be96354f1b866521aff8495 100644 --- a/dumux/discretization/cellcentered/mpfa/omethod/staticinteractionvolume.hh +++ b/dumux/discretization/cellcentered/mpfa/omethod/staticinteractionvolume.hh @@ -30,7 +30,6 @@ #include <dune/common/fvector.hh> #include <dumux/common/math.hh> -#include <dumux/common/matrixvectorhelper.hh> #include <dumux/discretization/cellcentered/mpfa/interactionvolumebase.hh> #include <dumux/discretization/cellcentered/mpfa/dualgridindexset.hh>