Commit 46d893d5 authored by Michael Kuron's avatar Michael Kuron
Browse files

Remove boost random, math::special_functions

Also remove some unneeded boost includes
parent fb43f673
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#include "mesh/distance_octree/DistanceOctree.h" #include "mesh/distance_octree/DistanceOctree.h"
#include "mesh/MeshIO.h" #include "mesh/MeshIO.h"
#include <boost/random.hpp> #include <random>
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
...@@ -64,7 +64,7 @@ void runBenchmark( const std::string & meshFile, const uint_t numPoints, const u ...@@ -64,7 +64,7 @@ void runBenchmark( const std::string & meshFile, const uint_t numPoints, const u
timer.end(); timer.end();
WALBERLA_LOG_INFO( "Mesh preparation took " << timer.last() << "s" ); WALBERLA_LOG_INFO( "Mesh preparation took " << timer.last() << "s" );
boost::random::mt19937 rng; std::mt19937 rng;
std::vector< typename MeshType::Point > points( numPoints ); std::vector< typename MeshType::Point > points( numPoints );
for(auto it = points.begin(); it != points.end(); ++it) for(auto it = points.begin(); it != points.end(); ++it)
......
...@@ -831,7 +831,7 @@ int main( int argc, char **argv ) ...@@ -831,7 +831,7 @@ int main( int argc, char **argv )
else if( int(Galileo) == 250 ) else if( int(Galileo) == 250 )
{ {
// add random perturbance for chaotic regime // add random perturbance for chaotic regime
walberla::math::seedRandomGenerator( boost::mt19937::result_type(std::time(0)) ); walberla::math::seedRandomGenerator( std::mt19937::result_type(std::time(0)) );
xParticle = real_c( xlength ) * real_t(0.5) + walberla::math::realRandom( real_t(-0.5), real_t(0.5) ); xParticle = real_c( xlength ) * real_t(0.5) + walberla::math::realRandom( real_t(-0.5), real_t(0.5) );
yParticle = real_c( ylength ) * real_t(0.5) + walberla::math::realRandom( real_t(-0.5), real_t(0.5) ); yParticle = real_c( ylength ) * real_t(0.5) + walberla::math::realRandom( real_t(-0.5), real_t(0.5) );
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include "core/math/Utility.h" #include "core/math/Utility.h"
#include "core/VectorTrait.h" #include "core/VectorTrait.h"
//#include <boost/math/special_functions/next.hpp>
#include <boost/type_traits/is_arithmetic.hpp> #include <boost/type_traits/is_arithmetic.hpp>
#include <boost/type_traits/is_floating_point.hpp> #include <boost/type_traits/is_floating_point.hpp>
#include <boost/type_traits/has_left_shift.hpp> #include <boost/type_traits/has_left_shift.hpp>
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include <boost/algorithm/string/replace.hpp> #include <boost/algorithm/string/replace.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/math/special_functions/pow.hpp>
...@@ -64,7 +63,10 @@ void DistributedSample::mpiAllGather() ...@@ -64,7 +63,10 @@ void DistributedSample::mpiAllGather()
variance_ = real_t(0); variance_ = real_t(0);
for( auto it = data_.begin(); it != data_.end(); ++it ) for( auto it = data_.begin(); it != data_.end(); ++it )
variance_ += boost::math::pow<2>( *it - mean_ ); {
real_t val = *it - mean_;
variance_ += val*val;
}
WALBERLA_MPI_SECTION() WALBERLA_MPI_SECTION()
{ {
...@@ -120,7 +122,10 @@ void DistributedSample::mpiGather( int rank ) ...@@ -120,7 +122,10 @@ void DistributedSample::mpiGather( int rank )
variance_ = real_t(0); variance_ = real_t(0);
for( auto it = data_.begin(); it != data_.end(); ++it ) for( auto it = data_.begin(); it != data_.end(); ++it )
variance_ += boost::math::pow<2>( *it - mean_ ); {
real_t val = *it - mean_;
variance_ += val*val;
}
WALBERLA_MPI_SECTION() WALBERLA_MPI_SECTION()
{ {
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#pragma once #pragma once
#include <boost/math/special_functions/fpclassify.hpp> #include <cmath>
namespace walberla { namespace walberla {
...@@ -39,7 +39,7 @@ namespace math { ...@@ -39,7 +39,7 @@ namespace math {
template<typename T> template<typename T>
inline bool isnan(T x) inline bool isnan(T x)
{ {
return (boost::math::isnan)(x); return (std::isnan)(x);
} }
...@@ -53,7 +53,7 @@ inline bool isnan(T x) ...@@ -53,7 +53,7 @@ inline bool isnan(T x)
template<typename T> template<typename T>
inline bool isinf(T x) inline bool isinf(T x)
{ {
return (boost::math::isinf)(x); return (std::isinf)(x);
} }
...@@ -67,7 +67,7 @@ inline bool isinf(T x) ...@@ -67,7 +67,7 @@ inline bool isinf(T x)
template<typename T> template<typename T>
bool finite(T x) bool finite(T x)
{ {
return (boost::math::isfinite)(x); return (std::isfinite)(x);
} }
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include <boost/array.hpp> #include <boost/array.hpp>
#include <boost/type_traits/is_floating_point.hpp> #include <boost/type_traits/is_floating_point.hpp>
#include <boost/random/uniform_real_distribution.hpp> #include <random>
namespace walberla { namespace walberla {
......
...@@ -1717,7 +1717,7 @@ void GenericAABB< T >::intersect( const GenericAABB & other ) ...@@ -1717,7 +1717,7 @@ void GenericAABB< T >::intersect( const GenericAABB & other )
* The point is in ( [ xMin(), xMax() ), [ yMin(), yMax() ), [ zMin(), zMax() ) ) * The point is in ( [ xMin(), xMax() ), [ yMin(), yMax() ), [ zMin(), zMax() ) )
* *
* \pre !empty() * \pre !empty()
* \param engine An Uniform Random Number Generator (e.g. boost::random::mt19937) * \param engine An Uniform Random Number Generator (e.g. std::mt19937)
* \returns Random point within *this * \returns Random point within *this
*/ */
template< typename T > template< typename T >
...@@ -1725,9 +1725,9 @@ template< typename Engine > ...@@ -1725,9 +1725,9 @@ template< typename Engine >
typename GenericAABB< T >::vector_type GenericAABB< T >::randomPoint( Engine & engine ) const typename GenericAABB< T >::vector_type GenericAABB< T >::randomPoint( Engine & engine ) const
{ {
WALBERLA_ASSERT( !empty() ); WALBERLA_ASSERT( !empty() );
boost::random::uniform_real_distribution< T > randX( xMin(), xMax() ); std::uniform_real_distribution< T > randX( xMin(), xMax() );
boost::random::uniform_real_distribution< T > randY( yMin(), yMax() ); std::uniform_real_distribution< T > randY( yMin(), yMax() );
boost::random::uniform_real_distribution< T > randZ( zMin(), zMax() ); std::uniform_real_distribution< T > randZ( zMin(), zMax() );
return vector_type( randX( engine ), randY( engine ), randZ( engine ) ); return vector_type( randX( engine ), randY( engine ), randZ( engine ) );
} }
......
...@@ -29,9 +29,9 @@ namespace math { ...@@ -29,9 +29,9 @@ namespace math {
namespace internal { namespace internal {
static boost::mt19937 generator; // static boost::random::mt19937_64 generator; static std::mt19937 generator; // static std::mt19937_64 generator;
boost::mt19937 & getGenerator() // boost::random::mt19937_64 std::mt19937 & getGenerator() // std::mt19937_64
{ {
return generator; return generator;
} }
...@@ -40,7 +40,7 @@ boost::mt19937 & getGenerator() // boost::random::mt19937_64 ...@@ -40,7 +40,7 @@ boost::mt19937 & getGenerator() // boost::random::mt19937_64
void seedRandomGenerator( const boost::mt19937::result_type & seed ) void seedRandomGenerator( const std::mt19937::result_type & seed )
{ {
#ifdef _OPENMP #ifdef _OPENMP
#pragma omp critical (random) #pragma omp critical (random)
......
...@@ -24,9 +24,7 @@ ...@@ -24,9 +24,7 @@
#include "core/DataTypes.h" #include "core/DataTypes.h"
#include "core/debug/Debug.h" #include "core/debug/Debug.h"
#include <boost/random/mersenne_twister.hpp> #include <random>
#include <boost/random/uniform_int.hpp> // #include <boost/random/uniform_int_distribution.hpp>
#include <boost/random/uniform_real.hpp> // #include <boost/random/uniform_real_distribution.hpp>
#include <limits> #include <limits>
...@@ -36,12 +34,12 @@ namespace math { ...@@ -36,12 +34,12 @@ namespace math {
namespace internal { namespace internal {
boost::mt19937 & getGenerator(); // boost::random::mt19937_64 std::mt19937 & getGenerator(); // std::mt19937_64
} }
void seedRandomGenerator( const boost::mt19937::result_type & seed ); // boost::random::mt19937_64 void seedRandomGenerator( const std::mt19937::result_type & seed ); // std::mt19937_64
...@@ -52,12 +50,13 @@ void seedRandomGenerator( const boost::mt19937::result_type & seed ); // boost:: ...@@ -52,12 +50,13 @@ void seedRandomGenerator( const boost::mt19937::result_type & seed ); // boost::
//********************************************************************************************************************** //**********************************************************************************************************************
template< typename INT > template< typename INT >
INT intRandom( const INT min = std::numeric_limits<INT>::min(), const INT max = std::numeric_limits<INT>::max(), INT intRandom( const INT min = std::numeric_limits<INT>::min(), const INT max = std::numeric_limits<INT>::max(),
boost::mt19937 & generator = internal::getGenerator() ) std::mt19937 & generator = internal::getGenerator() )
{ {
static_assert_int_t< INT >(); static_assert_int_t< INT >();
static_assert(sizeof(INT) > sizeof(char), "cannot use char");
WALBERLA_ASSERT_LESS_EQUAL( min, max ); WALBERLA_ASSERT_LESS_EQUAL( min, max );
boost::uniform_int< INT > distribution( min, max ); // boost::random::uniform_int_distribution< INT > distribution; std::uniform_int_distribution< INT > distribution( min, max );
INT value; INT value;
#ifdef _OPENMP #ifdef _OPENMP
...@@ -68,19 +67,70 @@ INT intRandom( const INT min = std::numeric_limits<INT>::min(), const INT max = ...@@ -68,19 +67,70 @@ INT intRandom( const INT min = std::numeric_limits<INT>::min(), const INT max =
return value; return value;
} }
template<>
inline char intRandom<char>( const char min, const char max, std::mt19937 & generator )
{
static_assert_int_t< char >();
WALBERLA_ASSERT_LESS_EQUAL( min, max );
std::uniform_int_distribution< int16_t > distribution( min, max );
char value;
#ifdef _OPENMP
#pragma omp critical (random)
#endif
{ value = static_cast<char>( distribution( generator ) ); }
return value;
}
template<>
inline unsigned char intRandom<unsigned char>( const unsigned char min, const unsigned char max, std::mt19937 & generator )
{
static_assert_int_t< unsigned char >();
WALBERLA_ASSERT_LESS_EQUAL( min, max );
std::uniform_int_distribution< int16_t > distribution( min, max );
unsigned char value;
#ifdef _OPENMP
#pragma omp critical (random)
#endif
{ value = static_cast<unsigned char>( distribution( generator ) ); }
return value;
}
template<>
inline signed char intRandom<signed char>( const signed char min, const signed char max, std::mt19937 & generator )
{
static_assert_int_t< signed char >();
WALBERLA_ASSERT_LESS_EQUAL( min, max );
std::uniform_int_distribution< int16_t > distribution( min, max );
signed char value;
#ifdef _OPENMP
#pragma omp critical (random)
#endif
{ value = static_cast<signed char>( distribution( generator ) ); }
return value;
}
template< typename INT > template< typename INT >
class IntRandom class IntRandom
{ {
public: public:
IntRandom( const boost::mt19937::result_type & seed = boost::mt19937::result_type() ) { generator_.seed( seed ); } IntRandom( const std::mt19937::result_type & seed = std::mt19937::result_type() ) { generator_.seed( seed ); }
INT operator()( const INT min = std::numeric_limits<INT>::min(), const INT max = std::numeric_limits<INT>::max() ) INT operator()( const INT min = std::numeric_limits<INT>::min(), const INT max = std::numeric_limits<INT>::max() )
{ {
return intRandom( min, max, generator_ ); return intRandom( min, max, generator_ );
} }
private: private:
boost::mt19937 generator_; std::mt19937 generator_;
}; };
...@@ -91,12 +141,12 @@ private: ...@@ -91,12 +141,12 @@ private:
*/ */
//********************************************************************************************************************** //**********************************************************************************************************************
template< typename REAL > template< typename REAL >
REAL realRandom( const REAL min = REAL(0), const REAL max = REAL(1), boost::mt19937 & generator = internal::getGenerator() ) REAL realRandom( const REAL min = REAL(0), const REAL max = REAL(1), std::mt19937 & generator = internal::getGenerator() )
{ {
static_assert( std::numeric_limits<REAL>::is_specialized && !std::numeric_limits<REAL>::is_integer, "Floating point type required/expected!" ); static_assert( std::numeric_limits<REAL>::is_specialized && !std::numeric_limits<REAL>::is_integer, "Floating point type required/expected!" );
WALBERLA_ASSERT_LESS( min, max ); WALBERLA_ASSERT_LESS( min, max );
boost::uniform_real< REAL > distribution( min, max ); // boost::uniform_real_distribution< REAL > distribution( min, max ); std::uniform_real_distribution< REAL > distribution( min, max );
REAL value; REAL value;
#ifdef _OPENMP #ifdef _OPENMP
...@@ -113,13 +163,13 @@ template< typename REAL > ...@@ -113,13 +163,13 @@ template< typename REAL >
class RealRandom class RealRandom
{ {
public: public:
RealRandom( const boost::mt19937::result_type & seed = boost::mt19937::result_type() ) { generator_.seed( seed ); } RealRandom( const std::mt19937::result_type & seed = std::mt19937::result_type() ) { generator_.seed( seed ); }
REAL operator()( const REAL min = REAL(0), const REAL max = REAL(1) ) REAL operator()( const REAL min = REAL(0), const REAL max = REAL(1) )
{ {
return realRandom( min, max, generator_ ); return realRandom( min, max, generator_ );
} }
private: private:
boost::mt19937 generator_; std::mt19937 generator_;
}; };
...@@ -133,10 +183,10 @@ inline bool boolRandom() { ///< Randomly returns 'true' or 'false' ...@@ -133,10 +183,10 @@ inline bool boolRandom() { ///< Randomly returns 'true' or 'false'
class BoolRandom class BoolRandom
{ {
public: public:
BoolRandom( const boost::mt19937::result_type & seed = boost::mt19937::result_type() ) { generator_.seed( seed ); } BoolRandom( const std::mt19937::result_type & seed = std::mt19937::result_type() ) { generator_.seed( seed ); }
bool operator()() { return boolRandom(); } bool operator()() { return boolRandom(); }
private: private:
boost::mt19937 generator_; std::mt19937 generator_;
}; };
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include <boost/algorithm/string/replace.hpp> #include <boost/algorithm/string/replace.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/math/special_functions/pow.hpp>
#include <functional> #include <functional>
#include <iterator> #include <iterator>
...@@ -128,7 +127,10 @@ real_t Sample::variance( real_t theMean ) const ...@@ -128,7 +127,10 @@ real_t Sample::variance( real_t theMean ) const
KahanAccumulator< real_t > acc; KahanAccumulator< real_t > acc;
for(auto it = begin(); it != end(); ++it) for(auto it = begin(); it != end(); ++it)
acc += boost::math::pow<2>(*it - theMean); {
real_t val = *it - theMean;
acc += val*val;
}
return acc.get() / real_c(size()); return acc.get() / real_c(size());
} }
......
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
#include "Operator.h" #include "Operator.h"
#include "Variable.h" #include "Variable.h"
#include <boost/math/special_functions/fpclassify.hpp> #include <cmath>
#include <algorithm>
namespace walberla { namespace walberla {
...@@ -128,10 +129,10 @@ namespace math { ...@@ -128,10 +129,10 @@ namespace math {
double left = root_->left_->compute(); double left = root_->left_->compute();
double right = root_->right_->compute(); double right = root_->right_->compute();
if ( boost::math::isnan(left) && boost::math::isnan(right) ){ if ( std::isnan(left) && std::isnan(right) ){
//WALBERLA_LOG_WARNING( "WARNING: Both values are NAN -> return true" ); //WALBERLA_LOG_WARNING( "WARNING: Both values are NAN -> return true" );
return true; return true;
} else if ( boost::math::isinf(left) && boost::math::isinf(right) ){ } else if ( std::isinf(left) && std::isinf(right) ){
//WALBERLA_LOG_WARNING( "WARNING: Both values are INF -> return true" ); //WALBERLA_LOG_WARNING( "WARNING: Both values are INF -> return true" );
return true; return true;
} }
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "Variable.h" #include "Variable.h"
#include <boost/math/special_functions/fpclassify.hpp> #include <cmath>
#include <sstream> #include <sstream>
...@@ -36,7 +36,7 @@ namespace math { ...@@ -36,7 +36,7 @@ namespace math {
void Var::setValue( const double value ){ void Var::setValue( const double value ){
value_ = value; value_ = value;
valid_ = !boost::math::isnan( value ); valid_ = !std::isnan( value );
} }
bool Var::operator==( const Var& var) const { bool Var::operator==( const Var& var) const {
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#include "core/math/AABB.h" #include "core/math/AABB.h"
#include "core/uid/SUID.h" #include "core/uid/SUID.h"
#include <boost/cast.hpp>
#include <typeinfo> #include <typeinfo>
#include <vector> #include <vector>
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
// //
//====================================================================================================================== //======================================================================================================================
#include "boost/lambda/bind.hpp"
#include "core/debug/Debug.h" #include "core/debug/Debug.h"
#include "core/logging/Logging.h" #include "core/logging/Logging.h"
#include "core/math/Parser.h" #include "core/math/Parser.h"
......
...@@ -91,7 +91,7 @@ int main( int argc, char* argv[] ) ...@@ -91,7 +91,7 @@ int main( int argc, char* argv[] )
auto dataHandling = make_shared< field::DefaultBlockDataHandling< FieldType > >( sbf, uint_t(3), 0.0, field::zyxf ); auto dataHandling = make_shared< field::DefaultBlockDataHandling< FieldType > >( sbf, uint_t(3), 0.0, field::zyxf );
auto originalFieldId = sbf->addBlockData( dataHandling, "OriginalField", None, Empty ); auto originalFieldId = sbf->addBlockData( dataHandling, "OriginalField", None, Empty );
math::seedRandomGenerator( numeric_cast<boost::mt19937::result_type>( MPIManager::instance()->rank() ) ); math::seedRandomGenerator( numeric_cast<std::mt19937::result_type>( MPIManager::instance()->rank() ) );
for( auto it = sbf->begin( None, Empty ); it != sbf->end(); ++it ) for( auto it = sbf->begin( None, Empty ); it != sbf->end(); ++it )
{ {
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include "core/debug/TestSubsystem.h" #include "core/debug/TestSubsystem.h"
#include "core/mpi/Environment.h" #include "core/mpi/Environment.h"
#include <boost/random/mersenne_twister.hpp> #include <random>
namespace walberla { namespace walberla {
namespace blockforest { namespace blockforest {
...@@ -418,7 +418,7 @@ static void test() { ...@@ -418,7 +418,7 @@ static void test() {
bb = *( block->getData< CellInterval >( bid ) ); bb = *( block->getData< CellInterval >( bid ) );
WALBERLA_CHECK_EQUAL( bb, CellInterval(Cell(150,180,210),Cell(199,239,279)) ); WALBERLA_CHECK_EQUAL( bb, CellInterval(Cell(150,180,210),Cell(199,239,279)) );
boost::random::mt19937 eng( 23 ); std::mt19937 eng( 23 );
for( int i = 0; i < 23; ++i ) for( int i = 0; i < 23; ++i )
{ {
const Vector3<real_t> globalPoint = forest.getDomain().getScaled( real_t(1.25) ).randomPoint( eng );