Commit a2274d74 authored by David Moxey's avatar David Moxey

Fix rest of solvers, utilities and libraries, and add HashUtils to fix some...

Fix rest of solvers, utilities and libraries, and add HashUtils to fix some issues with C++11 unordered data structures
parent 5978e85b
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <vector> #include <vector>
#include <LibUtilities/BasicUtils/HashUtils.hpp>
#include <StdRegions/StdExpansion.h> #include <StdRegions/StdExpansion.h>
#include <SpatialDomains/Geometry.h> #include <SpatialDomains/Geometry.h>
#include <Collections/CollectionsDeclspec.h> #include <Collections/CollectionsDeclspec.h>
...@@ -49,15 +50,6 @@ ...@@ -49,15 +50,6 @@
namespace Nektar { namespace Nektar {
namespace Collections { namespace Collections {
struct EnumHash
{
template <typename T>
std::size_t operator()(T t) const
{
return static_cast<std::size_t>(t);
}
};
/** /**
* @brief Collection * @brief Collection
*/ */
......
...@@ -39,6 +39,7 @@ using namespace std; ...@@ -39,6 +39,7 @@ using namespace std;
#include "ProcessDisplacement.h" #include "ProcessDisplacement.h"
#include <LibUtilities/BasicUtils/HashUtils.hpp>
#include <LibUtilities/BasicUtils/ParseUtils.hpp> #include <LibUtilities/BasicUtils/ParseUtils.hpp>
#include <LibUtilities/BasicUtils/SharedArray.hpp> #include <LibUtilities/BasicUtils/SharedArray.hpp>
#include <LocalRegions/SegExp.h> #include <LocalRegions/SegExp.h>
...@@ -72,7 +73,7 @@ struct TriFaceHash : std::unary_function<TriFaceIDs, std::size_t> ...@@ -72,7 +73,7 @@ struct TriFaceHash : std::unary_function<TriFaceIDs, std::size_t>
ids[2] = p.c; ids[2] = p.c;
std::sort(ids.begin(), ids.end()); std::sort(ids.begin(), ids.end());
return boost::hash_range(ids.begin(), ids.end()); return hash_combine(ids[0], ids[1], ids[2]);
} }
}; };
......
///////////////////////////////////////////////////////////////////////////////
//
// File SessionReader.cpp
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Session reader
//
///////////////////////////////////////////////////////////////////////////////
#ifndef LIBUTILITIES_BASICUTILS_HASHUTILS
#define LIBUTILITIES_BASICUTILS_HASHUTILS
#include <functional>
namespace Nektar
{
inline void hash_combine(std::size_t& seed)
{
}
template <typename T, typename... Args>
inline void hash_combine(std::size_t& seed, const T& v, Args... args)
{
std::hash<T> hasher;
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
hash_combine(seed, args...);
}
template <typename T, typename... Args>
inline std::size_t hash_combine(const T& v, Args... args)
{
std::size_t seed;
hash_combine(seed, args...);
return seed;
}
template<typename Iter>
std::size_t hash_range(Iter first, Iter last)
{
std::size_t seed = 0;
for(; first != last; ++first)
{
hash_combine(seed, *first);
}
return seed;
}
template<typename Iter>
void hash_range(std::size_t &seed, Iter first, Iter last)
{
hash_combine(seed, hash_range(first, last));
}
struct EnumHash
{
template <typename T>
std::size_t operator()(T t) const
{
return static_cast<std::size_t>(t);
}
};
struct PairHash {
template <class T1, class T2>
std::size_t operator()(const std::pair<T1, T2> &p) const
{
std::size_t seed = 0;
auto h1 = std::hash<T1>{}(p.first);
auto h2 = std::hash<T2>{}(p.second);
hash_combine(seed, h1, h2);
return seed;
}
};
}
#endif
...@@ -16,6 +16,7 @@ SET(BasicUtilsHeaders ...@@ -16,6 +16,7 @@ SET(BasicUtilsHeaders
./BasicUtils/FieldIOXml.h ./BasicUtils/FieldIOXml.h
./BasicUtils/FileSystem.h ./BasicUtils/FileSystem.h
./BasicUtils/ErrorUtil.hpp ./BasicUtils/ErrorUtil.hpp
./BasicUtils/HashUtils.hpp
./BasicUtils/MeshEntities.hpp ./BasicUtils/MeshEntities.hpp
./BasicUtils/MeshPartition.h ./BasicUtils/MeshPartition.h
./BasicUtils/MeshPartitionMetis.h ./BasicUtils/MeshPartitionMetis.h
......
...@@ -183,36 +183,41 @@ namespace Nektar ...@@ -183,36 +183,41 @@ namespace Nektar
template<typename FuncPointerT, typename ObjectPointerT> template<typename FuncPointerT, typename ObjectPointerT>
void DefineOdeRhs(FuncPointerT func, ObjectPointerT obj) void DefineOdeRhs(FuncPointerT func, ObjectPointerT obj)
{ {
using namespace std::placeholders; m_functors1[0] = std::bind(
m_functors1[0] = std::bind(func, obj, _1, _2, _3); func, obj, std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3);
} }
template<typename FuncPointerT, typename ObjectPointerT> template<typename FuncPointerT, typename ObjectPointerT>
void DefineOdeExplicitRhs(FuncPointerT func, ObjectPointerT obj) void DefineOdeExplicitRhs(FuncPointerT func, ObjectPointerT obj)
{ {
using namespace std::placeholders; m_functors1[1] = std::bind(
m_functors1[1] = std::bind(func, obj, _1, _2, _3); func, obj, std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3);
} }
template<typename FuncPointerT, typename ObjectPointerT> template<typename FuncPointerT, typename ObjectPointerT>
void DefineOdeImplicitRhs(FuncPointerT func, ObjectPointerT obj) void DefineOdeImplicitRhs(FuncPointerT func, ObjectPointerT obj)
{ {
using namespace std::placeholders; m_functors1[2] = std::bind(
m_functors1[2] = std::bind(func, obj, _1, _2, _3); func, obj, std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3);
} }
template<typename FuncPointerT, typename ObjectPointerT> template<typename FuncPointerT, typename ObjectPointerT>
void DefineProjection(FuncPointerT func, ObjectPointerT obj) void DefineProjection(FuncPointerT func, ObjectPointerT obj)
{ {
using namespace std::placeholders; m_functors1[3] = std::bind(
m_functors1[3] = std::bind(func, obj, _1, _2, _3); func, obj, std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3);
} }
template<typename FuncPointerT, typename ObjectPointerT> template<typename FuncPointerT, typename ObjectPointerT>
void DefineImplicitSolve(FuncPointerT func, ObjectPointerT obj) void DefineImplicitSolve(FuncPointerT func, ObjectPointerT obj)
{ {
using namespace std::placeholders; m_functors2[0] = std::bind(
m_functors2[0] = std::bind(func, obj, _1, _2, _3, _4); func, obj, std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3, std::placeholders::_4);
} }
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
#include <LocalRegions/Expansion2D.h> #include <LocalRegions/Expansion2D.h>
#include <LocalRegions/Expansion3D.h> #include <LocalRegions/Expansion3D.h>
#include <LibUtilities/BasicUtils/ShapeType.hpp> #include <LibUtilities/BasicUtils/ShapeType.hpp>
#include <LibUtilities/BasicUtils/HashUtils.hpp>
#include <boost/config.hpp> #include <boost/config.hpp>
#include <boost/graph/adjacency_list.hpp> #include <boost/graph/adjacency_list.hpp>
...@@ -2033,8 +2033,8 @@ namespace Nektar ...@@ -2033,8 +2033,8 @@ namespace Nektar
} }
} }
m_hash = boost::hash_range(m_localToGlobalMap.begin(), m_hash = hash_range(m_localToGlobalMap.begin(),
m_localToGlobalMap.end()); m_localToGlobalMap.end());
// Add up hash values if parallel // Add up hash values if parallel
int hash = m_hash; int hash = m_hash;
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
// //
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#include <LibUtilities/BasicUtils/HashUtils.hpp>
#include <MultiRegions/AssemblyMap/AssemblyMapDG.h> #include <MultiRegions/AssemblyMap/AssemblyMapDG.h>
#include <MultiRegions/ExpList.h> #include <MultiRegions/ExpList.h>
#include <LocalRegions/SegExp.h> #include <LocalRegions/SegExp.h>
...@@ -518,8 +519,8 @@ namespace Nektar ...@@ -518,8 +519,8 @@ namespace Nektar
SetUpUniversalDGMap (locExp); SetUpUniversalDGMap (locExp);
SetUpUniversalTraceMap(locExp, tr, periodicTrace); SetUpUniversalTraceMap(locExp, tr, periodicTrace);
m_hash = boost::hash_range(m_localToGlobalBndMap.begin(), m_hash = hash_range(m_localToGlobalBndMap.begin(),
m_localToGlobalBndMap.end()); m_localToGlobalBndMap.end());
} }
/** /**
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#ifndef NEKMESHUTILS_MESHELEMENTS_EDGE #ifndef NEKMESHUTILS_MESHELEMENTS_EDGE
#define NEKMESHUTILS_MESHELEMENTS_EDGE #define NEKMESHUTILS_MESHELEMENTS_EDGE
#include <LibUtilities/BasicUtils/HashUtils.hpp>
#include <SpatialDomains/SegGeom.h> #include <SpatialDomains/SegGeom.h>
#include <NekMeshUtils/NekMeshUtilsDeclspec.h> #include <NekMeshUtils/NekMeshUtilsDeclspec.h>
...@@ -151,12 +152,9 @@ struct EdgeHash : std::unary_function<EdgeSharedPtr, std::size_t> ...@@ -151,12 +152,9 @@ struct EdgeHash : std::unary_function<EdgeSharedPtr, std::size_t>
{ {
std::size_t operator()(EdgeSharedPtr const &p) const std::size_t operator()(EdgeSharedPtr const &p) const
{ {
std::size_t seed = 0; const unsigned int id1 = p->m_n1->m_id;
unsigned int id1 = p->m_n1->m_id; const unsigned int id2 = p->m_n2->m_id;
unsigned int id2 = p->m_n2->m_id; return id1 < id2 ? hash_combine(id1, id2) : hash_combine(id2, id1);
boost::hash_combine(seed, id1 < id2 ? id1 : id2);
boost::hash_combine(seed, id2 < id1 ? id1 : id2);
return seed;
} }
}; };
typedef std::unordered_set<EdgeSharedPtr, EdgeHash> EdgeSet; typedef std::unordered_set<EdgeSharedPtr, EdgeHash> EdgeSet;
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#ifndef NEKMESHUTILS_MESHELEMENTS_FACE #ifndef NEKMESHUTILS_MESHELEMENTS_FACE
#define NEKMESHUTILS_MESHELEMENTS_FACE #define NEKMESHUTILS_MESHELEMENTS_FACE
#include <LibUtilities/BasicUtils/HashUtils.hpp>
#include <SpatialDomains/TriGeom.h> #include <SpatialDomains/TriGeom.h>
#include <SpatialDomains/QuadGeom.h> #include <SpatialDomains/QuadGeom.h>
...@@ -171,7 +172,7 @@ struct FaceHash : std::unary_function<FaceSharedPtr, std::size_t> ...@@ -171,7 +172,7 @@ struct FaceHash : std::unary_function<FaceSharedPtr, std::size_t>
} }
std::sort(ids.begin(), ids.end()); std::sort(ids.begin(), ids.end());
boost::hash_range(seed, ids.begin(), ids.end()); hash_range(seed, ids.begin(), ids.end());
return seed; return seed;
} }
......
...@@ -191,15 +191,9 @@ struct HOSurfHash : std::unary_function<HOSurfSharedPtr, std::size_t> ...@@ -191,15 +191,9 @@ struct HOSurfHash : std::unary_function<HOSurfSharedPtr, std::size_t>
*/ */
std::size_t operator()(HOSurfSharedPtr const &p) const std::size_t operator()(HOSurfSharedPtr const &p) const
{ {
std::size_t seed = 0;
std::vector<int> ids = p->vertId; std::vector<int> ids = p->vertId;
std::sort(ids.begin(), ids.end()); std::sort(ids.begin(), ids.end());
for (int i = 0; i < ids.size(); ++i) return hash_range(ids.begin(), ids.end());
{
boost::hash_combine(seed, ids[i]);
}
return seed;
} }
}; };
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#ifndef NEKMESHUTILS_MESHELEMENTS_NODE #ifndef NEKMESHUTILS_MESHELEMENTS_NODE
#define NEKMESHUTILS_MESHELEMENTS_NODE #define NEKMESHUTILS_MESHELEMENTS_NODE
#include <LibUtilities/BasicUtils/HashUtils.hpp>
#include <NekMeshUtils/NekMeshUtilsDeclspec.h> #include <NekMeshUtils/NekMeshUtilsDeclspec.h>
#include <iomanip> #include <iomanip>
...@@ -431,11 +432,7 @@ struct NodeHash : std::unary_function<NodeSharedPtr, std::size_t> ...@@ -431,11 +432,7 @@ struct NodeHash : std::unary_function<NodeSharedPtr, std::size_t>
{ {
std::size_t operator()(NodeSharedPtr const &p) const std::size_t operator()(NodeSharedPtr const &p) const
{ {
std::size_t seed = 0; return hash_combine(p->m_x, p->m_y, p->m_z);
boost::hash_combine(seed, p->m_x);
boost::hash_combine(seed, p->m_y);
boost::hash_combine(seed, p->m_z);
return seed;
} }
}; };
typedef std::unordered_set<NodeSharedPtr, NodeHash> NodeSet; typedef std::unordered_set<NodeSharedPtr, NodeHash> NodeSet;
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include <NekMeshUtils/MeshElements/Tetrahedron.h> #include <NekMeshUtils/MeshElements/Tetrahedron.h>
#include <NekMeshUtils/MeshElements/Triangle.h> #include <NekMeshUtils/MeshElements/Triangle.h>
#include <LibUtilities/BasicUtils/HashUtils.hpp>
#include <LibUtilities/Foundations/ManagerAccess.h> #include <LibUtilities/Foundations/ManagerAccess.h>
using namespace std; using namespace std;
...@@ -365,7 +366,7 @@ struct TetOrientHash : std::unary_function<struct TetOrient, std::size_t> ...@@ -365,7 +366,7 @@ struct TetOrientHash : std::unary_function<struct TetOrient, std::size_t>
{ {
std::size_t operator()(struct TetOrient const &p) const std::size_t operator()(struct TetOrient const &p) const
{ {
return boost::hash_range(p.nid.begin(), p.nid.end()); return hash_range(p.nid.begin(), p.nid.end());
} }
}; };
typedef std::unordered_set<struct TetOrient, TetOrientHash> TetOrientSet; typedef std::unordered_set<struct TetOrient, TetOrientHash> TetOrientSet;
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
#define NEKTAR_SOLVERUTILS_ADVECTION #define NEKTAR_SOLVERUTILS_ADVECTION
#include <string> #include <string>
#include <boost/function.hpp> #include <functional>
#include <LibUtilities/BasicUtils/NekFactory.hpp> #include <LibUtilities/BasicUtils/NekFactory.hpp>
#include <LibUtilities/BasicUtils/SharedArray.hpp> #include <LibUtilities/BasicUtils/SharedArray.hpp>
...@@ -53,7 +53,7 @@ namespace SolverUtils ...@@ -53,7 +53,7 @@ namespace SolverUtils
/// Defines a callback function which evaluates the flux vector \f$ F(u) /// Defines a callback function which evaluates the flux vector \f$ F(u)
/// \f$ in a conservative advection of the form \f$ \nabla\cdot F(u) /// \f$ in a conservative advection of the form \f$ \nabla\cdot F(u)
/// \f$. /// \f$.
typedef boost::function<void ( typedef std::function<void (
const Array<OneD, Array<OneD, NekDouble> >&, const Array<OneD, Array<OneD, NekDouble> >&,
Array<OneD, Array<OneD, Array<OneD, NekDouble> > >&)> Array<OneD, Array<OneD, Array<OneD, NekDouble> > >&)>
AdvectionFluxVecCB; AdvectionFluxVecCB;
...@@ -89,13 +89,14 @@ public: ...@@ -89,13 +89,14 @@ public:
* @brief Set the flux vector callback function. * @brief Set the flux vector callback function.
* *
* This routine is a utility function to avoid the explicit use of * This routine is a utility function to avoid the explicit use of
* boost::bind. A function and object can be passed to this function * std::bind. A function and object can be passed to this function
* instead. * instead.
*/ */
template<typename FuncPointerT, typename ObjectPointerT> template<typename FuncPointerT, typename ObjectPointerT>
void SetFluxVector(FuncPointerT func, ObjectPointerT obj) void SetFluxVector(FuncPointerT func, ObjectPointerT obj)
{ {
m_fluxVector = boost::bind(func, obj, _1, _2); m_fluxVector = std::bind(
func, obj, std::placeholders::_1, std::placeholders::_2);
} }
/** /**
...@@ -162,7 +163,7 @@ protected: ...@@ -162,7 +163,7 @@ protected:
}; };
/// A shared pointer to an Advection object. /// A shared pointer to an Advection object.
typedef boost::shared_ptr<Advection> AdvectionSharedPtr; typedef std::shared_ptr<Advection> AdvectionSharedPtr;
/// Datatype of the NekFactory used to instantiate classes derived /// Datatype of the NekFactory used to instantiate classes derived
/// from the Advection class. /// from the Advection class.
......
...@@ -120,14 +120,14 @@ namespace Nektar ...@@ -120,14 +120,14 @@ namespace Nektar
for (it1 = scalars.begin(); it1 != scalars.end(); ++it1) for (it1 = scalars.begin(); it1 != scalars.end(); ++it1)
{ {
boost::shared_ptr<HomoRSScalar> tmp = MemoryManager<HomoRSScalar> std::shared_ptr<HomoRSScalar> tmp = MemoryManager<HomoRSScalar>
::AllocateSharedPtr(it1->second, m_numPlanes); ::AllocateSharedPtr(it1->second, m_numPlanes);
m_riemann->SetScalar(it1->first, &HomoRSScalar::Exec, tmp);