Skip to content
Snippets Groups Projects
Select Git revision
  • releases/2.3-1
  • master default protected
  • fix/dune_deprecated_macro
  • use-keyword-signature-of-target_link_libraries
  • make-getiterationstep-return-shared-ptr
  • releases/2.6-1
  • flexible-loopsolver-max
  • releases/2.5-1
  • feature/incomplete-cholesky-rebased
  • feature/istl-preconditioners
  • feature/optional-ignore
  • generalized-blockgsstep-rebased
  • fix_linking_module
  • releases/2.4-1
  • feature/cmakelists-sources-target
  • new_interface
  • releases/2.2-1
  • releases/2.1-1
  • releases/2.0-1
  • subversion->git
20 results

nulloperator.hh

Blame
  • Forked from agnumpde / dune-solvers
    735 commits behind, 1 commit ahead of the upstream repository.
    Carsten Gräser's avatar
    graeser authored and graeser committed
    It is unclear where and if it is needed and it's very dangerous for the
    following reason: Suppose the that you have some class
    
    class C
    {
        C(const NullOperator<A>& a): a_(a) {}
        const NullOperator<A>& a_;
    };
    
    and make the not so unlikely error to call the constructor of C
    with a NullOperator<B>. Then the code will silently compile but the
    'a_' is a reference to an invalid temporary after the constructor call.
    
    [[Imported from SVN: r8227]]
    ab8abefc
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    nulloperator.hh 3.38 KiB
    #ifndef NULLOPERATOR_HH
    #define NULLOPERATOR_HH
    
    #include <cstddef>
    
    /** \brief Represents the null operator in the needed space
     *
     */
    template <class BlockType>
    class NullOperator
    {
        private:
            /** \brief A dummy class for the rows
             *
             *  Contains a zero block to refer to
             */
            class RowDummy
            {
                private:
                    BlockType zero_;
    
                public:
                    RowDummy(): zero_(0){}
    
                    const BlockType& operator[](size_t i) const
                    {
                        return zero_;
                    }
                    BlockType& operator[](size_t i)
                    {
                        return zero_;
                    }
            };
    
            //! a dummy row
            RowDummy rowDummy_;
    
        public:
            //! export the block type
            typedef BlockType block_type;
            //! export the field type
            typedef typename block_type::field_type field_type;
            //! export the size type
            typedef size_t size_type;
    
            //! Default constructor
            NullOperator(){}
    
            /** \brief constructor taking anything
             *
             *  This is here to allow for NullOperator as block_type (this is needed in the constructor of RowDummy)
             */
    //        template <class T>
    //        NullOperator(const T& t){}
    
            /** \brief Matrix-Vector multiplication
             *
             *  Implements b += Nx and hence does nothing (N=0 !)
             */
            template <class LVectorType, class RVectorType>
            void umv(const LVectorType& x, RVectorType& b) const
            {}
    
            /** \brief transposed Matrix-Vector multiplication
             *
             *  Implements b += N^tx and hence does nothing (N=0 !)
             */
            template <class LVectorType, class RVectorType>
            void umtv(const LVectorType& x, RVectorType& b) const
            {}
    
            /** \brief Matrix-Vector multiplication with scalar multiplication
             *
             *  Implements b += a*Nx and hence does nothing (N=0 !)
             */
            template <class LVectorType, class RVectorType>
            void usmv(const double a, const LVectorType& x, RVectorType& b) const
            {}
    
            /** \brief transposed Matrix-Vector multiplication with scalar multiplication
             *
             *  Implements b += a*N^tx and hence does nothing (N=0 !)
             */
            template <class LVectorType, class RVectorType>
            void usmtv(const double a, const LVectorType& x, RVectorType& b) const
            {}
    
            /** \brief Matrix-Vector multiplication
             *
             *  Implements b = Nx and hence does nothing but set b=0 (N=0 !)
             */
            template <class LVectorType, class RVectorType>
            void mv(const LVectorType& x, RVectorType& b) const
            {
                b = 0.0;
            }
    
            //! random access operator
            const RowDummy& operator[](size_t i) const
            {
                return rowDummy_;
            }
    
            //! random access operator
            RowDummy& operator[](size_t i)
            {
                return rowDummy_;
            }
    
            //! return j-th diagonal entry
            const block_type& diagonal(size_t i) const
            {
                return rowDummy_[0];
            }
    
            //! multiplication operator with scalar
            void operator*=(const field_type&)
            {}
    
            size_type M() const
            {
                return 0;
            }
    
            size_type N() const
            {
                return 0;
            }
    
    
    };
    
    #endif