$extrastylesheet
00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 00019 00020 #ifndef LIBMESH_PARALLEL_CONVERSION_UTILS_H 00021 #define LIBMESH_PARALLEL_CONVERSION_UTILS_H 00022 00023 // Local includes 00024 #include "libmesh/libmesh_common.h" 00025 00026 #ifdef LIBMESH_HAVE_LIBHILBERT 00027 #include "hilbert.h" 00028 #endif 00029 00030 // C++ includes 00031 #include <vector> 00032 00033 namespace libMesh 00034 { 00035 00036 00037 00038 //-------------------------------------------------------------------------- 00039 namespace Parallel { 00040 namespace Utils { 00041 00048 template <typename KeyType> 00049 inline 00050 bool is_sorted (const std::vector<KeyType>& v) 00051 { 00052 if (v.empty()) 00053 return true; 00054 00055 for (unsigned int i=1; i<v.size(); i++) 00056 if (v[i] < v[i-1]) 00057 return false; 00058 00059 return true; 00060 } 00061 00066 template <typename KeyType> 00067 inline 00068 double to_double (const KeyType &k) 00069 { 00070 return static_cast<double>(k); 00071 } 00072 00079 template <typename KeyType> 00080 inline 00081 KeyType to_key_type (const double f) 00082 { 00083 return static_cast<KeyType>(f); 00084 } 00085 00086 #ifdef LIBMESH_HAVE_LIBHILBERT 00087 00088 template <> 00089 inline 00090 double to_double (const Hilbert::HilbertIndices &bvt) 00091 { 00092 return static_cast<double>(bvt.rack2); 00093 } 00094 00095 template <> 00096 inline 00097 Hilbert::HilbertIndices 00098 to_key_type (const double f) 00099 { 00100 Hilbert::HilbertIndices bvt; 00101 00102 bvt.rack0 = 0; 00103 bvt.rack1 = 0; 00104 bvt.rack2 = static_cast<Hilbert::inttype>(f); 00105 00106 return bvt; 00107 } 00108 #endif // LIBMESH_HAVE_LIBHILBERT 00109 } 00110 } 00111 00112 } // namespace libMesh 00113 00114 #endif // LIBMESH_PARALLEL_CONVERSION_UTILS_H