Skip to content
Snippets Groups Projects
Select Git revision
  • 85bcbd04405b2b0cdf79cdac2e63f5899f35a7ff
  • master default
  • dune-tkr-article
  • p/lh188/test-assembler-bug
  • mention-makefunction
  • temp/test-CI-with-subgrid-enabled
  • releases/2.5-1
  • releases/2.4-2
  • improve_grid
  • experimental/test-core-ci
  • feature/dune-functions-assemblers
  • feature/DG-Transferoperator-Assembler
  • debug/functionspacebasistest
  • releases/2.4-1
  • feature/dune-functions-assembler-with-skeleton
  • feature/elastictensor-interface
  • releases/2.3-2
  • maxka/conformingbasis
  • releases/2.3-1
  • subgridassembler-rework
  • releases/2.2-1
  • dune-tkr-article-patched
  • dune-tkr-article-base
  • subversion->git
24 results

functionalassembler.hh

Blame
  • Forked from agnumpde / dune-fufem
    362 commits behind the upstream repository.
    user avatar
    Elias Pipping authored and pipping committed
    [[Imported from SVN: r8348]]
    ee555950
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    functionalassembler.hh 2.61 KiB
    #ifndef FUNCTIONAL_ASSEMBLER_HH
    #define FUNCTIONAL_ASSEMBLER_HH
    
    #include <dune/istl/bvector.hh>
    
    #include "dune/fufem/functionspacebases/functionspacebasis.hh"
    
    //! Generic global assembler for functionals on a gridview
    template <class TrialBasis>
    class FunctionalAssembler
    {
        private:
            typedef typename TrialBasis::GridView GridView;
    
        public:
            //! create assembler for gridview
            FunctionalAssembler(const TrialBasis& tBasis) :
                tBasis_(tBasis)
            {}
    
            /** \brief Assemble
             *
             * \param localAssembler local assembler
             * \param[out] b target vector
             * \param initializeVector If this is set the output vector is
             * set to the correct length and initialized to zero before
             * assembly. Otherwise the assembled values are just added to
             * the vector.
             */
            template <class LocalFunctionalAssemblerType, class GlobalVectorType>
            void assemble(LocalFunctionalAssemblerType& localAssembler, GlobalVectorType& b, bool initializeVector=true) const
            {
                typedef typename GridView::template Codim<0>::Iterator ElementIterator;
                typedef typename LocalFunctionalAssemblerType::LocalVector LocalVector;
                typedef typename TrialBasis::LinearCombination LinearCombination;
    
                int rows = tBasis_.size();
    
                if (initializeVector)
                {
                    b.resize(rows);
                    b=0.0;
                }
    
                ElementIterator it = tBasis_.getGridView().template begin<0>();
                ElementIterator end = tBasis_.getGridView().template end<0>();
                for (; it != end; ++it)
                {
                    // get shape functions
                    const typename TrialBasis::LocalFiniteElement& tFE = tBasis_.getLocalFiniteElement(*it);
    
                    LocalVector localB(tFE.localBasis().size());
                    localAssembler.assemble(*it, localB, tFE);
    
                    for (size_t i=0; i<tFE.localBasis().size(); ++i)
                    {
                        int idx = tBasis_.index(*it, i);
                        const LinearCombination& constraints = tBasis_.constraints(idx);
                        bool isConstrained = tBasis_.isConstrained(idx);
                        if (isConstrained)
                        {
                            for (size_t w=0; w<constraints.size(); ++w)
                                b[constraints[w].index].axpy(constraints[w].factor, localB[i]);
                        }
                        else
                            b[idx] += localB[i];
                    }
                }
                return;
            }
    
        private:
            const TrialBasis& tBasis_;
    };
    
    #endif