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
......@@ -27,8 +27,7 @@
#include "stencil/D3CornerStencil.h"
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_real.hpp>
#include <random>
using namespace walberla;
......@@ -112,7 +111,7 @@ void testNonEmptyAABB( const GenericAABB< T > & aabb )
WALBERLA_CHECK_FLOAT_EQUAL( tmpAABB.volume(), T(0) );
WALBERLA_CHECK_IDENTICAL( tmpAABB.volume(), aabb.intersectionVolume( intersectingBox ) );
boost::random::mt19937 urng;
std::mt19937 urng;
for( int i = 0; i < 100; ++i )
{
auto p = aabb.randomPoint( urng );
......@@ -530,9 +529,10 @@ void testConstructors( const T x0, const T y0, const T z0, const T x1, const T y
template< typename T >
void randomTest()
{
boost::mt11213b rng;
typedef std::mersenne_twister_engine< walberla::uint32_t, 32, 351, 175, 19, 0xccab8ee7, 11, 0xffffffff, 7, 0x31b6ab00, 15, 0xffe50000, 17, 0xa37d3c92 > mt11213b;
mt11213b rng;
boost::uniform_real<T> dist( -T(10), T(10) );
std::uniform_real_distribution<T> dist( -T(10), T(10) );
for( int i = 0; i < 1000; ++i )
{
......@@ -600,7 +600,7 @@ void testAABBDistancesRandom( const GenericAABB< T > & baseAABB )
{
static const uint_t NUM_BOXES = 100;
static const uint_t NUM_POINTS = 1000;
boost::random::mt19937 rng;
std::mt19937 rng;
for( uint_t i = 0; i < NUM_BOXES; ++i )
{
......
......@@ -25,9 +25,7 @@
#include "core/math/Vector3.h"
#include "core/mpi/Environment.h"
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/normal_distribution.hpp>
#include <boost/random/variate_generator.hpp>
#include <random>
#include <cmath>
#include <vector>
......@@ -39,9 +37,9 @@ template < typename scalar_t >
struct RandomPointGenerator
{
typedef walberla::Vector3<scalar_t> vector_t;
typedef boost::mt11213b RandomNumberEngine;
typedef boost::normal_distribution<scalar_t> NormalDistribution;
typedef boost::variate_generator< RandomNumberEngine, NormalDistribution > Generator;
typedef std::mersenne_twister_engine< walberla::uint32_t, 32, 351, 175, 19, 0xccab8ee7, 11, 0xffffffff, 7, 0x31b6ab00, 15, 0xffe50000, 17, 0xa37d3c92 > mt11213b;
typedef mt11213b RandomNumberEngine;
typedef std::normal_distribution<scalar_t> NormalDistribution;
RandomPointGenerator( const vector_t & mu, const vector_t & sigma )
{
......@@ -49,17 +47,19 @@ struct RandomPointGenerator
{
RandomNumberEngine rne;
rne.seed( numeric_cast< RandomNumberEngine::result_type >( i * 642573 ) );
normalDistributions.push_back( Generator( rne, NormalDistribution( mu[i], sigma[i] ) ) );
engines.push_back( rne );
normalDistributions.push_back( NormalDistribution( mu[i], sigma[i] ) );
}
}
vector_t operator()()
{
return vector_t( normalDistributions[0](), normalDistributions[1](), normalDistributions[2]() );
return vector_t( normalDistributions[0](engines[0]), normalDistributions[1](engines[1]), normalDistributions[2](engines[2]) );
}
private:
std::vector< Generator > normalDistributions;
std::vector< RandomNumberEngine > engines;
std::vector< NormalDistribution > normalDistributions;
};
void testIOStream( const Plane & p )
......
......@@ -27,8 +27,7 @@
#include "core/math/Primes.h"
#include "core/mpi/MPIManager.h"
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int.hpp>
#include <random>
#include <algorithm>
#include <numeric>
......@@ -85,8 +84,9 @@ int main(int argc, char * argv[])
runTests( n );
}
boost::mt11213b rng;
boost::uniform_int<uint_t> dist( 100, 10000 );
typedef std::mersenne_twister_engine< walberla::uint32_t, 32, 351, 175, 19, 0xccab8ee7, 11, 0xffffffff, 7, 0x31b6ab00, 15, 0xffe50000, 17, 0xa37d3c92 > mt11213b;
mt11213b rng;
std::uniform_int_distribution<uint_t> dist( 100, 10000 );
for(int i = 0; i < 100; ++i)
{
const uint_t n = dist(rng);
......
......@@ -26,9 +26,7 @@
#include "core/mpi/BufferSystem.h"
#include "core/mpi/Environment.h"
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int.hpp>
#include <boost/random/variate_generator.hpp>
#include <random>
#include <cmath>
#include <iostream>
......@@ -43,7 +41,7 @@ using namespace std::literals::chrono_literals;
typedef boost::mt19937 base_generator_type;
typedef std::mt19937 base_generator_type;
/**
* Utility function for sleeping a random time
......@@ -60,10 +58,9 @@ void randomSleep( int maxTimeInMs = 20 )
unsigned int seed = static_cast<unsigned int>(std::time(0)) + static_cast<unsigned int>(rank*1000) + counter;
generator.seed(seed);
boost::uniform_int<> uni_dist(0,maxTimeInMs);
boost::variate_generator<base_generator_type&, boost::uniform_int<> > uni(generator, uni_dist);
std::uniform_int_distribution<> uni_dist(0,maxTimeInMs);
int sleepTime = uni();
int sleepTime = uni_dist(generator);
std::this_thread::sleep_for( sleepTime * 1ms );
}
......
......@@ -36,8 +36,7 @@
#include "core/mpi/RecvBuffer.h"
#include "core/mpi/SendBuffer.h"
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int.hpp> // #include <boost/random/uniform_int_distribution.hpp>
#include <random>
#include <cstring>
#include <iostream>
......@@ -48,9 +47,9 @@ using namespace mpi;
template<typename T>
void initIntegerContainer( T & container )
{
static boost::mt19937 rng;
boost::uniform_int<typename T::value_type> dist;
boost::uniform_int<size_t> size_dist(10,1000);
static std::mt19937 rng;
std::uniform_int_distribution<typename T::value_type> dist;
std::uniform_int_distribution<size_t> size_dist(10,1000);
size_t size = size_dist(rng);
container.clear();
......@@ -61,9 +60,9 @@ void initIntegerContainer( T & container )
template<typename T>
void initIntegerAssocContainer( T & container )
{
static boost::mt19937 rng;
boost::uniform_int<typename T::value_type> dist;
boost::uniform_int<size_t> size_dist(10,1000);
static std::mt19937 rng;
std::uniform_int_distribution<typename T::value_type> dist;
std::uniform_int_distribution<size_t> size_dist(10,1000);
size_t size = size_dist(rng);
container.clear();
......@@ -74,9 +73,9 @@ void initIntegerAssocContainer( T & container )
void initVecBool( std::vector<bool> & vecBool )
{
static boost::mt19937 rng;
boost::uniform_int<walberla::uint32_t> dist;
boost::uniform_int<size_t> size_dist(10,1000);
static std::mt19937 rng;
std::uniform_int_distribution<walberla::uint32_t> dist;
std::uniform_int_distribution<size_t> size_dist(10,1000);
size_t size = size_dist(rng);
vecBool.clear();
......@@ -88,10 +87,10 @@ void initVecBool( std::vector<bool> & vecBool )
template<typename T>
void initIntegerMap( T & container )
{
static boost::mt19937 rng;
boost::uniform_int<typename T::mapped_type> mapped_dist;
boost::uniform_int<typename T::key_type> key_dist;
boost::uniform_int<size_t> size_dist(10,1000);
static std::mt19937 rng;
std::uniform_int_distribution<typename T::mapped_type> mapped_dist;
std::uniform_int_distribution<typename T::key_type> key_dist;
std::uniform_int_distribution<size_t> size_dist(10,1000);
size_t size = size_dist(rng);
container.clear();
......@@ -103,9 +102,9 @@ void initIntegerMap( T & container )
template<typename T>
void initCellContainer( T & container )
{
static boost::mt19937 rng;
boost::uniform_int<cell_idx_t> dist;
boost::uniform_int<size_t> size_dist(10,1000);
static std::mt19937 rng;
std::uniform_int_distribution<cell_idx_t> dist;
std::uniform_int_distribution<size_t> size_dist(10,1000);
size_t size = size_dist(rng);
container.clear();
......@@ -116,8 +115,8 @@ void initCellContainer( T & container )
template<typename T, std::size_t N>
void initBoostArray( boost::array< T, N > & array )
{
static boost::mt19937 rng;
boost::uniform_int<T> dist;
static std::mt19937 rng;
std::uniform_int_distribution<T> dist;
for( auto it = array.begin(); it != array.end(); ++it )
*it = dist( rng );
......
......@@ -131,7 +131,7 @@ int main( int argc, char ** argv )
BlockDataID asyncGPUFieldId = blocks->addStructuredBlockData< GPUFieldType >( &createGPUField,
"asyncGPUField" );
math::seedRandomGenerator( numeric_cast<boost::mt19937::result_type>( MPIManager::instance()->rank() ) );
math::seedRandomGenerator( numeric_cast<std::mt19937::result_type>( MPIManager::instance()->rank() ) );
// Initialize CPU field with random values
initFields( blocks, sourceFieldId );
......
......@@ -67,8 +67,8 @@ int main( int argc, char* argv[] )
real_t(1), // dx
uint_t( 2), uint_t( 1), uint_t( 2) ); // number of processes
//math::seedRandomGenerator( numeric_cast<boost::mt19937::result_type>( std::time(0) ) );
math::seedRandomGenerator( numeric_cast<boost::mt19937::result_type>( MPIManager::instance()->rank() ) );
//math::seedRandomGenerator( numeric_cast<std::mt19937::result_type>( std::time(0) ) );
math::seedRandomGenerator( numeric_cast<std::mt19937::result_type>( MPIManager::instance()->rank() ) );
auto sId = field::addToStorage< ScalarField_T >( blocks, "scalar field" );
auto vId = field::addToStorage< VectorField_T >( blocks, "vector field" );
......
......@@ -114,7 +114,7 @@ int main( int argc, char* argv[] )
auto originalFieldId = field::addToStorage< FieldType >( sbf, "OriginalField" );
auto readFieldId = field::addToStorage< FieldType >( sbf, "ReadField" );
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(); it != sbf->end(); ++it )
{
......
......@@ -33,9 +33,7 @@
#include "stencil/D3Q27.h"
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int_distribution.hpp>
#include <boost/random/uniform_real_distribution.hpp>
#include <random>
namespace mpi_datatypes_test {
......@@ -51,7 +49,7 @@ public:
template< typename T, uint_t fSize >
void operator()( Field< T, fSize > & field )
{
boost::random::uniform_real_distribution< T > distribution;
std::uniform_real_distribution< T > distribution;
for( auto it = field.begin(); it != field.end(); ++it )
{
......@@ -62,7 +60,7 @@ public:
template< typename T, uint_t fSize >
void operator()( GhostLayerField< T, fSize > & field )
{
boost::random::uniform_real_distribution< T > distribution;
std::uniform_real_distribution< T > distribution;
for( auto it = field.beginWithGhostLayer(); it != field.end(); ++it )
{
......@@ -71,7 +69,7 @@ public:
}
private:
boost::random::mt19937 generator_;
std::mt19937 generator_;
};
......
......@@ -23,9 +23,7 @@
#include "core/math/Vector3.h"
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/normal_distribution.hpp>
#include <boost/random/variate_generator.hpp>
#include <random>
#include <vector>
......@@ -33,21 +31,25 @@ template < typename scalar_t >
struct RandomPointGenerator
{
typedef walberla::Vector3<scalar_t> vector_t;
typedef boost::mt11213b RandomNumberEngine;
typedef boost::normal_distribution<scalar_t> NormalDistribution;
typedef boost::variate_generator< RandomNumberEngine, NormalDistribution > Generator;
typedef std::mersenne_twister_engine< walberla::uint32_t, 32, 351, 175, 19, 0xccab8ee7, 11, 0xffffffff, 7, 0x31b6ab00, 15, 0xffe50000, 17, 0xa37d3c92 > mt11213b;
typedef mt11213b RandomNumberEngine;
typedef std::normal_distribution<scalar_t> NormalDistribution;
RandomPointGenerator( const vector_t & mu, const vector_t & sigma )
{
for( walberla::uint_t i = 0; i < 3; ++i )
normalDistributions.push_back( Generator( RandomNumberEngine(), NormalDistribution( mu[i], sigma[i] ) ) );
{
engines.push_back( RandomNumberEngine() );
normalDistributions.push_back( NormalDistribution( mu[i], sigma[i] ) );
}
}
vector_t operator()()
{
return vector_t( normalDistributions[0](), normalDistributions[1](), normalDistributions[2]() );
return vector_t( normalDistributions[0](engines[0]), normalDistributions[1](engines[1]), normalDistributions[2](engines[2]) );
}
private:
std::vector< Generator > normalDistributions;
std::vector< RandomNumberEngine > engines;
std::vector< NormalDistribution > normalDistributions;
};
......@@ -54,8 +54,7 @@
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int.hpp>
#include <random>
#ifdef _MSC_VER
# pragma warning(push)
......@@ -69,15 +68,17 @@
# pragma warning(pop)
#endif //_MSC_VER
typedef std::mersenne_twister_engine< walberla::uint32_t, 32, 351, 175, 19, 0xccab8ee7, 11, 0xffffffff, 7, 0x31b6ab00, 15, 0xffe50000, 17, 0xa37d3c92 > mt11213b;
/// randomize the memory underlying the vector up the maximal size (== capacity)
template<typename T>
void randomizeVector( std::vector<T> & v )
{
//boost::random::mt11213b rng;
boost::mt11213b rng;
//boost::random::uniform_int_distribution<T> dist( std::numeric_limits<T>::min(), std::numeric_limits<T>::max() );
boost::uniform_int<T> dist( std::numeric_limits<T>::min(), std::numeric_limits<T>::max() );
static_assert(sizeof(T) > sizeof(char), "cannot use char");
mt11213b rng;
std::uniform_int_distribution<T> dist( std::numeric_limits<T>::min(), std::numeric_limits<T>::max() );
size_t oldSize = v.size();
v.resize( v.capacity() );
......@@ -86,18 +87,64 @@ void randomizeVector( std::vector<T> & v )
v.resize(oldSize);
}
template<>
void randomizeVector( std::vector<unsigned char> & v )
{
mt11213b rng;
std::uniform_int_distribution<walberla::int16_t> dist( std::numeric_limits<unsigned char>::min(), std::numeric_limits<unsigned char>::max() );
size_t oldSize = v.size();
v.resize( v.capacity() );
for(typename std::vector<unsigned char>::iterator it = v.begin(); it != v.end(); ++it)
*it = static_cast<unsigned char>( dist(rng) );
v.resize(oldSize);
}
template<>
void randomizeVector( std::vector<char> & v )
{
mt11213b rng;
std::uniform_int_distribution<int16_t> dist( std::numeric_limits<char>::min(), std::numeric_limits<char>::max() );
size_t oldSize = v.size();
v.resize( v.capacity() );
for(typename std::vector<char>::iterator it = v.begin(); it != v.end(); ++it)
*it = static_cast<char>( dist(rng) );
v.resize(oldSize);
}
template<typename T>
void makeRandomMultiArray( boost::multi_array<T, 3> & ma)
{
//boost::random::mt11213b rng;
boost::mt11213b rng;
//boost::random::uniform_int_distribution<T> dist( std::numeric_limits<T>::min(), std::numeric_limits<T>::max() );
boost::uniform_int<T> dist( std::numeric_limits<T>::min(), std::numeric_limits<T>::max() );
static_assert(sizeof(T) > sizeof(char), "cannot use char");
mt11213b rng;
std::uniform_int_distribution<T> dist( std::numeric_limits<T>::min(), std::numeric_limits<T>::max() );
for(T* it = ma.data(); it != ma.data() + ma.num_elements(); ++it)
*it = dist(rng);
}
template<>
void makeRandomMultiArray( boost::multi_array<unsigned char, 3> & ma)
{
mt11213b rng;
std::uniform_int_distribution<walberla::int16_t> dist( std::numeric_limits<unsigned char>::min(), std::numeric_limits<unsigned char>::max() );
for(unsigned char* it = ma.data(); it != ma.data() + ma.num_elements(); ++it)
*it = static_cast<unsigned char>( dist(rng) );
}
template<>
void makeRandomMultiArray( boost::multi_array<char, 3> & ma)
{
mt11213b rng;
std::uniform_int_distribution<int16_t> dist( std::numeric_limits<char>::min(), std::numeric_limits<char>::max() );
for(char* it = ma.data(); it != ma.data() + ma.num_elements(); ++it)
*it = static_cast<char>( dist(rng) );
}
template<typename T>
void runTests(const std::string & filename, size_t xSize, size_t ySize, size_t zSize);
......
......@@ -26,7 +26,7 @@
#include "geometry/bodies/Sphere.h"
#include "geometry/bodies/AABBBody.h"
#include <boost/random/mersenne_twister.hpp>
#include <random>
namespace walberla {
......@@ -77,7 +77,7 @@ void testAABB()
static const math::Vector3<real_t> UNIT( real_t( 1 ), real_t( 1 ), real_t( 1 ) );
static const real_t EPSILON = real_t(1e-4);
boost::random::mt19937 randomEngine;
std::mt19937 randomEngine;
std::vector<math::AABB> testAABBs;
testAABBs.push_back( math::AABB( -UNIT, UNIT ) );
......
......@@ -29,7 +29,7 @@
#include "mesh/DistanceComputations.h"
#include "mesh/TriangleMeshes.h"
#include <boost/random.hpp>
#include <random>
#include <boost/lexical_cast.hpp>
#include <vector>
......@@ -53,7 +53,7 @@ void runTests( const uint_t numAABBs )
WALBERLA_CHECK( isIntersecting( triDist, meshAABB, real_t(0) ) );
boost::random::mt19937 rng( uint32_t(42) );
std::mt19937 rng( uint32_t(42) );
for(uint_t i = 0; i < numAABBs; ++i)
{
......
......@@ -31,7 +31,7 @@
#include "mesh/MeshIO.h"
#include "mesh/MeshOperations.h"
#include <boost/random.hpp>
#include <random>
#include <boost/lexical_cast.hpp>
#include <algorithm>
......@@ -61,7 +61,7 @@ int main( int argc, char * argv[] )
auto aabb = computeAABB( *mesh );
boost::random::mt19937 rng;
std::mt19937 rng;
for( uint_t i = 0; i < numBoxes; ++i )
{
......
......@@ -35,7 +35,7 @@
#include "mesh/vtk/VTKMeshWriter.h"
#include "mesh/vtk/CommonDataSources.h"
#include <boost/random.hpp>
#include <random>
#include <vector>
#include <string>
......@@ -104,7 +104,7 @@ int main( int argc, char * argv[] )
if( writeVtk )
containmentOctree.writeVTKOutput( "containment_octree" );
boost::random::mt19937 rng;
std::mt19937 rng;
for( int i = 0; i < 10000; ++i )
{
......
......@@ -32,7 +32,7 @@
#include "mesh/DistanceComputations.h"
#include "mesh/MeshIO.h"
#include <boost/random.hpp>
#include <random>
#include <vector>
#include <string>
......@@ -54,7 +54,7 @@ void testAABBDistance( const Vector3<real_t> & translationVector = Vector3<real_
TriangleDistance<MeshType> triDist( mesh );
boost::random::mt19937 rng;
std::mt19937 rng;
for( int i = 0; i < 10000; ++i )
{
......
......@@ -32,7 +32,7 @@
#include "mesh/distance_octree/DistanceOctree.h"
#include "mesh/MeshIO.h"
#include <boost/random.hpp>
#include <random>
#include <vector>
#include <string>
......@@ -55,7 +55,7 @@ void test( const std::string & meshFile )
//distanceOctree.writeVTKOutput( "distance_octree" );
boost::random::mt19937 rng;
std::mt19937 rng;
for( int i = 0; i < 1000; ++i )
{
......
......@@ -45,7 +45,6 @@
#include "stencil/D3Q27.h"
#include <boost/lexical_cast.hpp>
#include <boost/random.hpp>
#include <vector>
#include <string>
......
......@@ -30,8 +30,6 @@
#include "mesh/vtk/CommonDataSources.h"
#include "mesh/vtk/CommonFilters.h"
#include <boost/random.hpp>
#include <vector>
#include <string>
......
......@@ -38,10 +38,11 @@
#include <core/logging/Logging.h>
#include <core/timing/TimingTree.h>
#include <core/waLBerlaBuildInfo.h>
#include <core/math/Utility.h>
#include <postprocessing/sqlite/SQLite.h>
#include <vtk/VTKOutput.h>
#include <boost/random.hpp>
#include <random>
using namespace walberla;
using namespace walberla::pe;
......@@ -86,15 +87,16 @@ std::vector<Vector3<real_t>> generatePointCloudDodecahedron()
template< typename RNG >
std::vector<Vector3<real_t>> generatPointCloudOnSphere( const real_t radius, const uint_t numPoints, RNG & rng )
{
boost::uniform_on_sphere<real_t> distribution(3);
std::uniform_real_distribution<real_t> distribution;
std::vector<Vector3<real_t>> pointCloud( numPoints );
for( auto & p : pointCloud )
{
auto v = distribution(rng);
p[0] = v[0] * radius;
p[1] = v[1] * radius;