# PhasicFlow: utilities/particlesPhasicFlow/positionRandom/positionRandom.cpp Source File
PhasicFlow is an open-source parallel DEM (discrete element method) package for simulating granular flow. It is developed in C++ and can be exectued on both GPU (like CUDA) and CPU.

positionRandom.cpp
Go to the documentation of this file.
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#include "positionRandom.hpp"
#include "collisionCheck.hpp"
bool pFlow::positionRandom::positionOnePass(collisionCheck& collCheck)
{
auto const& region = pRegion();
auto n = static_cast< uint32 >(position_.size());
for(uint32 iter = 0; iter<numPoints_; iter++)
{
realx3 p = region.peek();
if( collCheck.checkPoint(p, diameter_) )
{
position_.push_back(p);
diameters_.push_back(diameter_);
if(!collCheck.mapLastAddedParticle())
{
fatalErrorInFunction;
return false;
}
n++;
if(n == numPoints_) break;
}
}
return true;
}
bool pFlow::positionRandom::positionPointsRandom()
{
position_.clear();
diameters_.clear();
if(numPoints_ == 0)return true;
uint32 pass = 0;
collisionCheck collCheck(
box(pRegion().minPoint(), pRegion().maxPoint()),
diameter_,
position_,
diameters_);
while ( pass <maxIterations_)
{
if( !positionOnePass(collCheck) )
{
return false;
}
pass++;
REPORT(1)<<"Positioning "<< Green_Text("(Pass #"<< pass<<")")<<
": number of non-colliding spheres is "<<
Yellow_Text(position_.size())<<END_REPORT;
if( position_.size() == numPoints_ )
{
REPORT(0)<<END_REPORT;
return true;
}
}
fatalErrorInFunction<<
" Cannot position "<< numPoints_ << " in the domain in " <<
maxIterations_ << " iterations.\n" <<
" you may increase maxIterations for positioning points.\n";
return false;
}
pFlow::positionRandom::positionRandom
(
systemControl& control,
const dictionary& dict
)
:
positionParticles(control, dict),
prDict_
(
dict.subDict("randomInfo")
),
diameter_
(
prDict_.getVal<real>("diameter")
),
numPoints_
(
prDict_.getVal<uint32>("numPoints")
),
maxIterations_
(
prDict_.getValOrSet("maxIterations", 10u)
),
position_
(
"position",
maxNumberOfParticles(),
0,
RESERVE()
),
diameters_
(
"diameters",
maxNumberOfParticles(),
0,
RESERVE()
)
{
reportInterval_ = max(numPoints_/numReports_, static_cast< uint32 >(2));
if( !positionPointsRandom() )
{
fatalExit;
}
}
Green_Text
#define Green_Text(text)
Definition: iOstream.hpp:42
pFlow::real
float real
Definition: builtinTypes.hpp:45
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
REPORT
#define REPORT(n)
Definition: streams.hpp:39
pFlow::collisionCheck
Definition: collisionCheck.hpp:13
positionRandom.hpp
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::positionRandom::position_
realx3Vector position_
Definition: positionRandom.hpp:43
pFlow::positionRandom::positionOnePass
bool positionOnePass(collisionCheck &collCheck)
Definition: positionRandom.cpp:27
pFlow::systemControl
Definition: systemControl.hpp:41
pFlow::max
T max(const internalField< T, MemorySpace > &iField)
Definition: internalFieldAlgorithms.hpp:79
pFlow::Vector::size
auto size() const
Size of the vector.
Definition: Vector.hpp:265
pFlow::positionRandom::positionRandom
positionRandom(systemControl &control, const dictionary &dict)
Definition: positionRandom.cpp:100
Yellow_Text
#define Yellow_Text(text)
Definition: iOstream.hpp:40
pFlow::positionRandom::numPoints_
uint32 numPoints_
Definition: positionRandom.hpp:39
RESERVE
Definition: Vector.hpp:40
pFlow::positionParticles::pRegion
const auto & pRegion() const
Definition: positionParticles.hpp:55
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::positionRandom::positionPointsRandom
bool positionPointsRandom()
Definition: positionRandom.cpp:57
pFlow::collisionCheck::mapLastAddedParticle
bool mapLastAddedParticle()
Definition: collisionCheck.cpp:79
collisionCheck.hpp
pFlow::positionRandom::diameter_
real diameter_
Definition: positionRandom.hpp:37
pFlow::collisionCheck::checkPoint
bool checkPoint(const realx3 &p, const real d) const
Definition: collisionCheck.cpp:46
END_REPORT
#define END_REPORT
Definition: streams.hpp:40
pFlow::dictionary::subDict
dictionary & subDict(const word &keyword)
ref to a subdictioanry fatalExit if not found
Definition: dictionary.cpp:560
n
uint32 n
Definition: NBSLoop.hpp:24
pFlow::box
Definition: box.hpp:32
pFlow::positionRandom::diameters_
realVector diameters_
Definition: positionRandom.hpp:45
pFlow::positionParticles
Definition: positionParticles.hpp:35
pFlow::triple< real >
pFlow::dictionary
Dictionary holds a set of data entries or sub-dictionaries that are enclosed in a curely braces or ar...
Definition: dictionary.hpp:67