parallel_conversion_utils.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 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 
26 #ifdef LIBMESH_HAVE_LIBHILBERT
27 #include "hilbert.h"
28 #endif
29 
30 // C++ includes
31 #include <vector>
32 
33 namespace libMesh
34 {
35 
36 
37 
38 //--------------------------------------------------------------------------
39 namespace Parallel {
40  namespace Utils {
41 
48  template <typename KeyType>
49  inline
50  bool is_sorted (const std::vector<KeyType>& v)
51  {
52  if (v.empty())
53  return true;
54 
55  for (unsigned int i=1; i<v.size(); i++)
56  if (v[i] < v[i-1])
57  return false;
58 
59  return true;
60  }
61 
66  template <typename KeyType>
67  inline
68  double to_double (const KeyType &k)
69  {
70  return static_cast<double>(k);
71  }
72 
79  template <typename KeyType>
80  inline
81  KeyType to_key_type (const double f)
82  {
83  return static_cast<KeyType>(f);
84  }
85 
86 #ifdef LIBMESH_HAVE_LIBHILBERT
87 
88  template <>
89  inline
90  double to_double (const Hilbert::HilbertIndices &bvt)
91  {
92  return static_cast<double>(bvt.rack2);
93  }
94 
95  template <>
96  inline
97  Hilbert::HilbertIndices
98  to_key_type (const double f)
99  {
100  Hilbert::HilbertIndices bvt;
101 
102  bvt.rack0 = 0;
103  bvt.rack1 = 0;
104  bvt.rack2 = static_cast<Hilbert::inttype>(f);
105 
106  return bvt;
107  }
108 #endif // LIBMESH_HAVE_LIBHILBERT
109  }
110 }
111 
112 } // namespace libMesh
113 
114 #endif // LIBMESH_PARALLEL_CONVERSION_UTILS_H

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:06 UTC

Hosted By:
SourceForge.net Logo