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

Generated by: LCOV version 1.14