libMesh
parallel_conversion_utils.h
Go to the documentation of this file.
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_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 
49 #ifdef LIBMESH_ENABLE_DEPRECATED
50 template <typename KeyType>
51 inline
52 bool is_sorted (const std::vector<KeyType> & v)
53 {
54  libmesh_deprecated();
55  return std::is_sorted(v.begin(), v.end());
56 }
57 #endif // LIBMESH_ENABLE_DEPRECATED
58 
63 template <typename KeyType>
64 inline
65 double to_double (const KeyType & k)
66 {
67  return static_cast<double>(k);
68 }
69 
77 template <typename KeyType>
78 struct Convert {
79  inline static
80  KeyType to_key_type (const double f)
81  {
82  return static_cast<KeyType>(f);
83  }
84 };
85 
89 template <typename FirstKeyType, typename SecondKeyType>
90 struct Convert<std::pair<FirstKeyType, SecondKeyType>> {
91  inline static
92  std::pair<FirstKeyType,SecondKeyType> to_key_type (const double f)
93  {
94  return std::make_pair
95  (Convert<FirstKeyType>::to_key_type(f),SecondKeyType());
96  }
97 };
98 
99 
100 
105 template <typename FirstKeyType, typename SecondKeyType>
106 inline
107 double to_double (const std::pair<FirstKeyType,SecondKeyType> &k)
108 {
109  return to_double(k.first);
110 }
111 
112 
113 #ifdef LIBMESH_HAVE_LIBHILBERT
114 
115 template <>
116 inline
117 double to_double (const Hilbert::HilbertIndices & bvt)
118 {
119  return static_cast<double>(bvt.rack2);
120 }
121 
122 template <>
123 struct Convert<Hilbert::HilbertIndices> {
124  inline static
125  Hilbert::HilbertIndices
126  to_key_type (const double f)
127  {
128  Hilbert::HilbertIndices bvt;
129 
130  bvt.rack0 = 0;
131  bvt.rack1 = 0;
132  bvt.rack2 = static_cast<Hilbert::inttype>(f);
133 
134  return bvt;
135  }
136 };
137 #endif // LIBMESH_HAVE_LIBHILBERT
138 }
139 }
140 
141 } // namespace libMesh
142 
143 #endif // LIBMESH_PARALLEL_CONVERSION_UTILS_H
static Hilbert::HilbertIndices to_key_type(const double f)
The libMesh namespace provides an interface to certain functionality in the library.
bool is_sorted(const std::vector< KeyType > &v)
static std::pair< FirstKeyType, SecondKeyType > to_key_type(const double f)
A utility to convert a double to some sort of KeyType, for interpreting how histogram bounds relate t...
static KeyType to_key_type(const double f)
double to_double(const KeyType &k)
A utility function which converts whatever KeyType is to a double for the histogram bounds...