diff --git a/dune/fufem/assemblers/operatorassembler.hh b/dune/fufem/assemblers/operatorassembler.hh index 3a4cdaafa5bc28df6b0a6f007c67dbb761605abd..3ac2a771654a5625e6ee5e19ee218b9f585968db 100644 --- a/dune/fufem/assemblers/operatorassembler.hh +++ b/dune/fufem/assemblers/operatorassembler.hh @@ -1,6 +1,9 @@ #ifndef OPERATOR_ASSEMBLER_HH #define OPERATOR_ASSEMBLER_HH +#include <dune/grid/common/rangegenerators.hh> +#include <dune/grid/common/partitionset.hh> + #include <dune/istl/matrix.hh> #include <dune/istl/matrixindexset.hh> @@ -8,8 +11,11 @@ #include "dune/fufem/functionspacebases/functionspacebasis.hh" -//! Generic global assembler for operators on a gridview -template <class TrialBasis, class AnsatzBasis> +/** \brief Generic global assembler for operators on a gridview + * + * \tparam PartitionSet For distributed grids: The subset of the grid elements to assemble on + */ +template <class TrialBasis, class AnsatzBasis, class PartitionSet=Dune::Partitions::All> class OperatorAssembler { private: @@ -67,24 +73,21 @@ class OperatorAssembler template <class LocalAssemblerType, bool lumping> void addIndicesStaticLumping(LocalAssemblerType& localAssembler, Dune::MatrixIndexSet& indices) const { - typedef typename GridView::template Codim<0>::Iterator ElementIterator; typedef typename LocalAssemblerType::BoolMatrix BoolMatrix; typedef typename TrialBasis::LinearCombination LinearCombination; - ElementIterator it = tBasis_.getGridView().template begin<0>(); - ElementIterator end = tBasis_.getGridView().template end<0>(); - for (; it != end; ++it) + for (const auto& element : Dune::elements(tBasis_.getGridView(), PartitionSet())) { // get shape functions - const typename TrialBasis::LocalFiniteElement& tFE = tBasis_.getLocalFiniteElement(*it); - const typename AnsatzBasis::LocalFiniteElement& aFE = aBasis_.getLocalFiniteElement(*it); + const typename TrialBasis::LocalFiniteElement& tFE = tBasis_.getLocalFiniteElement(element); + const typename AnsatzBasis::LocalFiniteElement& aFE = aBasis_.getLocalFiniteElement(element); BoolMatrix localIndices(tFE.localBasis().size(), aFE.localBasis().size()); - localAssembler.indices(*it, localIndices, tFE, aFE); + localAssembler.indices(element, localIndices, tFE, aFE); for (size_t i=0; i<tFE.localBasis().size(); ++i) { - int rowIndex = tBasis_.index(*it, i); + int rowIndex = tBasis_.index(element, i); const LinearCombination& rowConstraints = tBasis_.constraints(rowIndex); bool rowIsConstrained = tBasis_.isConstrained(rowIndex); for (size_t j=0; j<aFE.localBasis().size(); ++j) @@ -103,7 +106,7 @@ class OperatorAssembler } else { - int colIndex = aBasis_.index(*it, j); + int colIndex = aBasis_.index(element, j); const LinearCombination& colConstraints = aBasis_.constraints(colIndex); bool colIsConstrained = aBasis_.isConstrained(colIndex); if (rowIsConstrained and colIsConstrained) @@ -137,24 +140,21 @@ class OperatorAssembler template <class LocalAssemblerType, class GlobalMatrixType, bool lumping> void addEntriesStaticLumping(LocalAssemblerType& localAssembler, GlobalMatrixType& A) const { - typedef typename GridView::template Codim<0>::Iterator ElementIterator; typedef typename LocalAssemblerType::LocalMatrix LocalMatrix; typedef typename TrialBasis::LinearCombination LinearCombination; - ElementIterator it = tBasis_.getGridView().template begin<0>(); - ElementIterator end = tBasis_.getGridView().template end<0>(); - for (; it != end; ++it) + for (const auto& element : Dune::elements(tBasis_.getGridView(), PartitionSet())) { // get shape functions - const typename TrialBasis::LocalFiniteElement& tFE = tBasis_.getLocalFiniteElement(*it); - const typename AnsatzBasis::LocalFiniteElement& aFE = aBasis_.getLocalFiniteElement(*it); + const typename TrialBasis::LocalFiniteElement& tFE = tBasis_.getLocalFiniteElement(element); + const typename AnsatzBasis::LocalFiniteElement& aFE = aBasis_.getLocalFiniteElement(element); LocalMatrix localA(tFE.localBasis().size(), aFE.localBasis().size()); - localAssembler.assemble(*it, localA, tFE, aFE); + localAssembler.assemble(element, localA, tFE, aFE); for (size_t i=0; i<tFE.localBasis().size(); ++i) { - int rowIndex = tBasis_.index(*it, i); + int rowIndex = tBasis_.index(element, i); const LinearCombination& rowConstraints = tBasis_.constraints(rowIndex); bool rowIsConstrained = tBasis_.isConstrained(rowIndex); for (size_t j=0; j<aFE.localBasis().size(); ++j) @@ -174,7 +174,7 @@ class OperatorAssembler } else { - int colIndex = aBasis_.index(*it, j); + int colIndex = aBasis_.index(element, j); const LinearCombination& colConstraints = aBasis_.constraints(colIndex); bool colIsConstrained = aBasis_.isConstrained(colIndex); if (rowIsConstrained and colIsConstrained)