LCOV - code coverage report
Current view: top level - include/numerics - dense_vector_base.h (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4229 (6a9aeb) with base 727f46 Lines: 5 15 33.3 %
Date: 2025-08-19 19:27:09 Functions: 6 27 22.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // The libMesh Finite Element Library.
       2             : // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
       3             : 
       4             : // This library is free software; you can redistribute it and/or
       5             : // modify it under the terms of the GNU Lesser General Public
       6             : // License as published by the Free Software Foundation; either
       7             : // version 2.1 of the License, or (at your option) any later version.
       8             : 
       9             : // This library is distributed in the hope that it will be useful,
      10             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12             : // Lesser General Public License for more details.
      13             : 
      14             : // You should have received a copy of the GNU Lesser General Public
      15             : // License along with this library; if not, write to the Free Software
      16             : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
      17             : 
      18             : 
      19             : 
      20             : #ifndef LIBMESH_DENSE_VECTOR_BASE_H
      21             : #define LIBMESH_DENSE_VECTOR_BASE_H
      22             : 
      23             : 
      24             : // Local Includes
      25             : #include "libmesh/libmesh_common.h"
      26             : #include "libmesh/int_range.h"
      27             : 
      28             : // C++ includes
      29             : 
      30             : namespace libMesh
      31             : {
      32             : 
      33             : /**
      34             :  * Defines an abstract dense vector base class for use in
      35             :  * Finite Element-type computations. Specialized dense vectors,
      36             :  * for example DenseSubVectors, can be derived from this class.
      37             :  *
      38             :  * \author John W. Peterson
      39             :  * \date 2003
      40             :  */
      41             : template<typename T>
      42     3358355 : class DenseVectorBase
      43             : {
      44             : public:
      45             :   /**
      46             :    * Constructor.
      47             :    */
      48      746823 :   DenseVectorBase() = default;
      49             : 
      50             :   /**
      51             :    * The 5 special functions can be defaulted for this class, as it
      52             :    * does not manage any memory itself.
      53             :    */
      54        9792 :   DenseVectorBase (DenseVectorBase &&) = default;
      55    23757994 :   DenseVectorBase (const DenseVectorBase &) = default;
      56             :   DenseVectorBase & operator= (const DenseVectorBase &) = default;
      57             :   DenseVectorBase & operator= (DenseVectorBase &&) = default;
      58      749845 :   virtual ~DenseVectorBase() = default;
      59             : 
      60             :   /**
      61             :    * Set every element in the vector to 0.  Needs to
      62             :    * be pure virtual since the storage method may
      63             :    * be different in derived classes.
      64             :    */
      65             :   virtual void zero() = 0;
      66             : 
      67             :   /**
      68             :    * \returns The \p (i) element of the vector.
      69             :    */
      70             :   virtual T el(const unsigned int i) const = 0;
      71             : 
      72             :   /**
      73             :    * \returns The \p (i) element of the vector as a writable reference.
      74             :    */
      75             :   virtual T & el(const unsigned int i) = 0;
      76             : 
      77             :   /**
      78             :    * \returns The size of the vector.
      79             :    */
      80             :   virtual unsigned int size() const = 0;
      81             : 
      82             :   /**
      83             :    * \returns \p true iff size() is 0.
      84             :    */
      85           0 :   virtual bool empty() const { return (this->size() == 0); }
      86             : 
      87             :   /**
      88             :    * Pretty-print the vector to \p stdout.
      89             :    */
      90             :   void print(std::ostream & os) const;
      91             : 
      92             :   /**
      93             :    * Same as above, but allows you to print using the
      94             :    * usual stream syntax.
      95             :    */
      96           0 :   friend std::ostream & operator << (std::ostream & os, const DenseVectorBase<T> & v)
      97             :   {
      98           0 :     v.print(os);
      99           0 :     return os;
     100             :   }
     101             : 
     102             :   /**
     103             :    * Prints the entries of the vector with additional
     104             :    * decimal places in scientific notation.
     105             :    */
     106             :   void print_scientific(std::ostream & os, unsigned precision=8) const;
     107             : };
     108             : 
     109             : template<typename T>
     110           0 : void DenseVectorBase<T>::print (std::ostream & os) const
     111             : {
     112           0 :   for (auto i : make_range(this->size()))
     113           0 :     os << std::setw(8)
     114           0 :        << this->el(i)
     115           0 :        << std::endl;
     116           0 : }
     117             : 
     118             : } // namespace libMesh
     119             : 
     120             : 
     121             : 
     122             : #endif // LIBMESH_DENSE_VECTOR_BASE_H

Generated by: LCOV version 1.14