LCOV - code coverage report
Current view: top level - include/numerics - vector_value.h (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4451 (4263df) with base cc8438 Lines: 14 15 93.3 %
Date: 2026-06-09 23:12:55 Functions: 7 9 77.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // The libMesh Finite Element Library.
       2             : // Copyright (C) 2002-2026 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_VECTOR_VALUE_H
      21             : #define LIBMESH_VECTOR_VALUE_H
      22             : 
      23             : // Local includes
      24             : #include "libmesh/type_vector.h"
      25             : #include "libmesh/libmesh_device.h"
      26             : #include "libmesh/compare_types.h"
      27             : 
      28             : #ifdef LIBMESH_HAVE_METAPHYSICL
      29             : #include "metaphysicl/raw_type.h"
      30             : #include "metaphysicl/ct_types.h"
      31             : #endif
      32             : 
      33             : // C++ includes
      34             : 
      35             : namespace libMesh
      36             : {
      37             : 
      38             : /**
      39             :  * This class defines a vector in LIBMESH_DIM dimensional Real or Complex
      40             :  * space.  The typedef RealVectorValue always defines a real-valued vector,
      41             :  * and NumberVectorValue defines a real or complex-valued vector depending
      42             :  * on how the library was configured.
      43             :  *
      44             :  * \author Benjamin S. Kirk
      45             :  * \date 2003
      46             :  */
      47             : template <typename T>
      48           0 : class VectorValue : public TypeVector<T>
      49             : {
      50             : public:
      51             :   typedef T value_type;
      52             : 
      53             :   template <typename T2>
      54             :   struct rebind
      55             :   {
      56             :     typedef VectorValue<T2> other;
      57             :   };
      58             : 
      59             :   /**
      60             :    * Empty constructor.
      61             :    * Gives the vector 0 in \p LIBMESH_DIM dimensional T space.
      62             :    */
      63             :   VectorValue ();
      64             : 
      65             :   /**
      66             :    * Constructor-from-T.  By default sets higher dimensional
      67             :    * entries to 0.
      68             :    */
      69             :   VectorValue (const T & x,
      70             :                const T & y=0,
      71             :                const T & z=0);
      72             : 
      73             :   /**
      74             :    * Constructor-from-scalars.  By default sets higher dimensional
      75             :    * entries to 0.
      76             :    */
      77             :   template <typename Scalar1, typename Scalar2, typename Scalar3>
      78             :   VectorValue (typename
      79             :                std::enable_if<ScalarTraits<Scalar1>::value,
      80             :                const Scalar1>::type & x,
      81             :                typename
      82             :                std::enable_if<ScalarTraits<Scalar2>::value,
      83             :                const Scalar2>::type & y = 0,
      84             :                typename
      85             :                std::enable_if<ScalarTraits<Scalar3>::value,
      86             :                const Scalar3>::type & z = 0);
      87             : 
      88             : 
      89             :   /**
      90             :    * Constructor-from-scalar.  Sets higher dimensional entries to 0.
      91             :    * Necessary because for some reason the constructor-from-scalars
      92             :    * alone is insufficient to let the compiler figure out
      93             :    * VectorValue<Complex> v = 0;
      94             :    */
      95             :   template <typename Scalar>
      96             :   VectorValue (const Scalar & x,
      97             :                typename
      98             :                std::enable_if<ScalarTraits<Scalar>::value,
      99             :                const Scalar>::type * sfinae = nullptr);
     100             : 
     101             : 
     102             :   /**
     103             :    * Copy-constructor.
     104             :    */
     105             :   template <typename T2>
     106             :   VectorValue (const VectorValue<T2> & p);
     107             : 
     108             :   /**
     109             :    * Copy-constructor.
     110             :    */
     111             :   template <typename T2>
     112             :   VectorValue (const TypeVector<T2> & p);
     113             : 
     114             : #ifdef LIBMESH_USE_COMPLEX_NUMBERS
     115             :   /**
     116             :    * Constructor that takes two \p TypeVector<Real>
     117             :    * representing the real and imaginary part as
     118             :    * arguments.
     119             :    */
     120             :   VectorValue (const TypeVector<Real> & p_re,
     121             :                const TypeVector<Real> & p_im);
     122             : #endif
     123             : 
     124             :   /**
     125             :    * Assignment-from-scalar operator.  Used only to zero out vectors.
     126             :    */
     127             :   template <typename Scalar>
     128             :   LIBMESH_DEVICE_INLINE
     129             :   typename std::enable_if<
     130             :     ScalarTraits<Scalar>::value,
     131             :     VectorValue &>::type
     132    41408272 :   operator = (const Scalar & libmesh_dbg_var(p))
     133    41408272 :   { libmesh_assert_equal_to (p, Scalar(0)); this->zero(); return *this; }
     134             : };
     135             : 
     136             : /**
     137             :  * Useful typedefs to allow transparent switching
     138             :  * between Real and Complex data types.
     139             :  */
     140             : typedef VectorValue<Real>   RealVectorValue;
     141             : typedef VectorValue<Number> NumberVectorValue;
     142             : typedef RealVectorValue     RealGradient;
     143             : typedef NumberVectorValue   Gradient;
     144             : 
     145             : 
     146             : 
     147             : //------------------------------------------------------
     148             : // Inline functions
     149             : 
     150             : template <typename T>
     151             : LIBMESH_DEVICE_INLINE
     152     3790255 : VectorValue<T>::VectorValue () :
     153     3790255 :   TypeVector<T> ()
     154             : {
     155    50276771 : }
     156             : 
     157             : 
     158             : template <typename T>
     159             : LIBMESH_DEVICE_INLINE
     160      193860 : VectorValue<T>::VectorValue (const T & x,
     161             :                              const T & y,
     162             :                              const T & z) :
     163      193860 :   TypeVector<T> (x,y,z)
     164             : {
     165      193860 : }
     166             : 
     167             : 
     168             : 
     169             : template <typename T>
     170             : template <typename Scalar1, typename Scalar2, typename Scalar3>
     171             : LIBMESH_DEVICE_INLINE
     172             : VectorValue<T>::VectorValue (typename
     173             :                              std::enable_if<ScalarTraits<Scalar1>::value,
     174             :                              const Scalar1>::type & x,
     175             :                              typename
     176             :                              std::enable_if<ScalarTraits<Scalar2>::value,
     177             :                              const Scalar2>::type & y,
     178             :                              typename
     179             :                              std::enable_if<ScalarTraits<Scalar3>::value,
     180             :                              const Scalar3>::type & z) :
     181             :   TypeVector<T> (x,y,z)
     182             : {
     183             : }
     184             : 
     185             : 
     186             : template <typename T>
     187             : template <typename Scalar>
     188             : LIBMESH_DEVICE_INLINE
     189      768479 : VectorValue<T>::VectorValue (const Scalar & x,
     190             :                              typename
     191             :                              std::enable_if<ScalarTraits<Scalar>::value,
     192             :                              const Scalar>::type * /*sfinae*/) :
     193      768479 :   TypeVector<T> (x)
     194             : {
     195      768479 : }
     196             : 
     197             : template <typename T>
     198             : template <typename T2>
     199             : LIBMESH_DEVICE_INLINE
     200             : VectorValue<T>::VectorValue (const VectorValue<T2> & p) :
     201             :   TypeVector<T> (p)
     202             : {
     203             : }
     204             : 
     205             : 
     206             : 
     207             : template <typename T>
     208             : template <typename T2>
     209             : LIBMESH_DEVICE_INLINE
     210   238483470 : VectorValue<T>::VectorValue (const TypeVector<T2> & p) :
     211   240841482 :   TypeVector<T> (p)
     212             : {
     213     1837977 : }
     214             : 
     215             : #ifdef LIBMESH_USE_COMPLEX_NUMBERS
     216             : template <typename T>
     217             : LIBMESH_DEVICE_INLINE
     218             : VectorValue<T>::VectorValue (const TypeVector<Real> & p_re,
     219             :                              const TypeVector<Real> & p_im) :
     220             :   TypeVector<T> (Complex (p_re(0), p_im(0)),
     221             :                  Complex (p_re(1), p_im(1)),
     222             :                  Complex (p_re(2), p_im(2)))
     223             : {
     224             : }
     225             : #endif
     226             : 
     227             : template <typename T>
     228             : struct CompareTypes<VectorValue<T>, VectorValue<T>>
     229             : {
     230             :   typedef VectorValue<T> supertype;
     231             : };
     232             : 
     233             : template <typename T, typename T2>
     234             : struct CompareTypes<VectorValue<T>, VectorValue<T2>>
     235             : {
     236             :   typedef VectorValue<typename CompareTypes<T,T2>::supertype> supertype;
     237             : };
     238             : 
     239             : template <typename T, typename T2>
     240             : struct CompareTypes<VectorValue<T>, TypeVector<T2>>
     241             : {
     242             :   typedef VectorValue<typename CompareTypes<T,T2>::supertype> supertype;
     243             : };
     244             : 
     245             : template <typename T, typename T2>
     246             : struct CompareTypes<TypeVector<T>, VectorValue<T2>>
     247             : {
     248             :   typedef VectorValue<typename CompareTypes<T,T2>::supertype> supertype;
     249             : };
     250             : 
     251             : } // namespace libMesh
     252             : 
     253             : #ifdef LIBMESH_HAVE_METAPHYSICL
     254             : namespace MetaPhysicL
     255             : {
     256             : template <typename T>
     257             : struct RawType<libMesh::VectorValue<T>>
     258             : {
     259             :   typedef libMesh::VectorValue<typename RawType<T>::value_type> value_type;
     260             : 
     261             :   static value_type value (const libMesh::VectorValue<T> & in)
     262             :     {
     263             :       value_type ret;
     264             :       for (unsigned int i = 0; i < LIBMESH_DIM; ++i)
     265             :         ret(i) = raw_value(in(i));
     266             : 
     267             :       return ret;
     268             :     }
     269             : };
     270             : 
     271             : template <typename T, typename U>
     272             : struct ReplaceAlgebraicType<libMesh::VectorValue<T>, U>
     273             : {
     274             :   typedef U type;
     275             : };
     276             : }
     277             : #endif
     278             : 
     279             : #endif // LIBMESH_VECTOR_VALUE_H

Generated by: LCOV version 1.14