LCOV - code coverage report
Current view: top level - include/parallel - parallel_conversion_utils.h (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4476 (4beb67) with base a68cc6 Lines: 16 16 100.0 %
Date: 2026-06-03 20:22:46 Functions: 6 8 75.0 %
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_PARALLEL_CONVERSION_UTILS_H
      21             : #define LIBMESH_PARALLEL_CONVERSION_UTILS_H
      22             : 
      23             : // Local includes
      24             : #include "libmesh/libmesh_common.h"
      25             : #include "libmesh/int_range.h"
      26             : 
      27             : #ifdef LIBMESH_HAVE_LIBHILBERT
      28             : #include "hilbert.h"
      29             : #endif
      30             : 
      31             : // C++ includes
      32             : #include <vector>
      33             : 
      34             : namespace libMesh
      35             : {
      36             : 
      37             : 
      38             : 
      39             : //--------------------------------------------------------------------------
      40             : namespace Parallel {
      41             : namespace Utils {
      42             : 
      43             : /**
      44             :  * A utility function which converts whatever \p KeyType is to
      45             :  * a \p double for the histogram bounds
      46             :  */
      47             : template <typename KeyType>
      48             : inline
      49         208 : double to_double (const KeyType & k)
      50             : {
      51         342 :   return static_cast<double>(k);
      52             : }
      53             : 
      54             : /**
      55             :  * A utility to convert a \p double to some sort of \p KeyType, for
      56             :  * interpreting how histogram bounds relate to \p KeyType positions.
      57             :  *
      58             :  * This is a class to allow partial template specialization for the
      59             :  * std::pair case without adding a "dummy" variable.
      60             :  */
      61             : template <typename KeyType>
      62             : struct Convert {
      63             :   inline static
      64         202 :   KeyType to_key_type (const double f)
      65             :   {
      66       35172 :     return static_cast<KeyType>(f);
      67             :   }
      68             : };
      69             : 
      70             : /**
      71             :  * A pseudoinverse for converting bounds back to pairs of key types.
      72             :  */
      73             : template <typename FirstKeyType, typename SecondKeyType>
      74             : struct Convert<std::pair<FirstKeyType, SecondKeyType>> {
      75             :   inline static
      76     1673974 :   std::pair<FirstKeyType,SecondKeyType> to_key_type (const double f)
      77             :   {
      78             :     return std::make_pair
      79     1673974 :       (Convert<FirstKeyType>::to_key_type(f),SecondKeyType());
      80             :   }
      81             : };
      82             : 
      83             : 
      84             : 
      85             : /**
      86             :  * A utility function for pairs of key types.  When finding bounds,
      87             :  * the second entry of the pair is effectively "rounded away".
      88             :  */
      89             : template <typename FirstKeyType, typename SecondKeyType>
      90             : inline
      91     1723696 : double to_double (const std::pair<FirstKeyType,SecondKeyType> &k)
      92             : {
      93     1740270 :   return to_double(k.first);
      94             : }
      95             : 
      96             : 
      97             : #ifdef LIBMESH_HAVE_LIBHILBERT
      98             : 
      99             : template <>
     100             : inline
     101     1723696 : double to_double (const Hilbert::HilbertIndices & bvt)
     102             : {
     103     3227982 :   return static_cast<double>(bvt.rack2);
     104             : }
     105             : 
     106             : template <>
     107             : struct Convert<Hilbert::HilbertIndices> {
     108             :   inline static
     109             :   Hilbert::HilbertIndices
     110     1673974 :   to_key_type (const double f)
     111             :   {
     112     1673974 :     Hilbert::HilbertIndices bvt;
     113             : 
     114     1673974 :     bvt.rack0 = 0;
     115     1673974 :     bvt.rack1 = 0;
     116   403179996 :     bvt.rack2 = static_cast<Hilbert::inttype>(f);
     117             : 
     118     1673974 :     return bvt;
     119             :   }
     120             : };
     121             : #endif // LIBMESH_HAVE_LIBHILBERT
     122             : }
     123             : }
     124             : 
     125             : } // namespace libMesh
     126             : 
     127             : #endif // LIBMESH_PARALLEL_CONVERSION_UTILS_H

Generated by: LCOV version 1.14