libMesh
Loading...
Searching...
No Matches
parallel_conversion_utils.h
Go to the documentation of this file.
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
34namespace libMesh
35{
36
37
38
39//--------------------------------------------------------------------------
40namespace Parallel {
41namespace Utils {
42
47template <typename KeyType>
48inline
49double to_double (const KeyType & k)
50{
51 return static_cast<double>(k);
52}
53
61template <typename KeyType>
62struct Convert {
63 inline static
64 KeyType to_key_type (const double f)
65 {
66 return static_cast<KeyType>(f);
67 }
68};
69
73template <typename FirstKeyType, typename SecondKeyType>
74struct Convert<std::pair<FirstKeyType, SecondKeyType>> {
75 inline static
76 std::pair<FirstKeyType,SecondKeyType> to_key_type (const double f)
77 {
78 return std::make_pair
79 (Convert<FirstKeyType>::to_key_type(f),SecondKeyType());
80 }
81};
82
83
84
89template <typename FirstKeyType, typename SecondKeyType>
90inline
91double to_double (const std::pair<FirstKeyType,SecondKeyType> &k)
92{
93 return to_double(k.first);
94}
95
96
97#ifdef LIBMESH_HAVE_LIBHILBERT
98
99template <>
100inline
101double to_double (const Hilbert::HilbertIndices & bvt)
102{
103 return static_cast<double>(bvt.rack2);
104}
105
106template <>
107struct Convert<Hilbert::HilbertIndices> {
108 inline static
109 Hilbert::HilbertIndices
110 to_key_type (const double f)
111 {
112 Hilbert::HilbertIndices bvt;
113
114 bvt.rack0 = 0;
115 bvt.rack1 = 0;
116 bvt.rack2 = static_cast<Hilbert::inttype>(f);
117
118 return bvt;
119 }
120};
121#endif // LIBMESH_HAVE_LIBHILBERT
122}
123}
124
125} // namespace libMesh
126
127#endif // LIBMESH_PARALLEL_CONVERSION_UTILS_H
double to_double(const KeyType &k)
A utility function which converts whatever KeyType is to a double for the histogram bounds.
The libMesh namespace provides an interface to certain functionality in the library.
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)