# PhasicFlow: utilities/particlesPhasicFlow/positionParticles/positionParticles.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.

positionParticles.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 "positionParticles.hpp"
#include "vocabs.hpp"
#include "dictionary.hpp"
#include "systemControl.hpp"
pFlow::realx3Vector pFlow::positionParticles::sortByMortonCode(
const realx3Vector& position)const
{
struct indexMorton
{
uint64 morton;
uint64 index;
};
/*realx3 minP = min(position);
realx3 maxP = max(position);
real cellsize = maxDiameter();
cells<uint64> allCells( box(minP, maxP), cellsize);
Vector<indexMorton> indMor(position.size(),RESERVE());
indMor.clear();
uint64 ind=0;
for(const auto& p:position)
{
auto cellInd = allCells.pointIndex(p);
indMor.push_back(
{ xyzToMortonCode64(cellInd.x(), cellInd.y(), cellInd.z()),
ind++});
}
INFORMATION<<"Performing morton sorting."<<END_INFO;
std::sort(
indMor.begin(),
indMor.end(),
[]( const indexMorton &lhs, const indexMorton &rhs){
return lhs.morton < rhs.morton; } );
realx3Vector sortedPos(position.capacity(), RESERVE());
sortedPos.clear();
for(auto& ind:indMor)
{
sortedPos.push_back( position[ind.index] );
}*/
WARNING<<"Morton sorting is inactive!"<<END_WARNING;
return position;
}
pFlow::positionParticles::positionParticles
(
systemControl& control,
const dictionary& dict
)
:
regionType_(dict.getValOrSet<word>("regionType", "domain")),
maxNumberOfParticles_(dict.getValOrSet(
"maxNumberOfParticles",
static_cast< uint32 >(10000))),
mortonSorting_(dict.getValOrSet("mortonSorting", Logical("Yes")))
{
if( regionType_ != "domain" )
{
pRegion_ = peakableRegion::create(
regionType_,
dict.subDict(regionType_+"Info"));
}
else
{
fileDictionary domainDict
(
objectFile
{
domainFile__,
"",
objectFile::READ_ALWAYS,
objectFile::WRITE_NEVER
},
&control.settings()
);
pRegion_ = peakableRegion::create(regionType_,domainDict.subDict("globalBox"));
}
}
pFlow::realx3Vector pFlow::positionParticles::getFinalPosition()
{
if(mortonSorting_)
{
return sortByMortonCode(position());
}
else
{
realx3Vector vec("final position",position().capacity(), 0 , RESERVE());
vec.assign( position().begin(), position().end());
return vec;
}
}
pFlow::uniquePtr<pFlow::positionParticles>
pFlow::positionParticles::create
(
systemControl& control,
const dictionary & dict
)
{
word method = dict.getVal<word>("method");
if( dictionaryvCtorSelector_.search(method) )
{
return dictionaryvCtorSelector_[method] (control, dict);
}
else
{
printKeys
(
fatalError << "Ctor Selector "<< method << " dose not exist. \n"
<<"Avaiable ones are: \n\n"
,
dictionaryvCtorSelector_
);
fatalExit;
}
return nullptr;
}
pFlow::dictionary::getValOrSet
T getValOrSet(const word &keyword, const T &setVal) const
get the value of data entry or if not found, set the value to setVal
Definition: dictionary.hpp:415
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::positionParticles::positionParticles
positionParticles(systemControl &control, const dictionary &dict)
Definition: positionParticles.cpp:75
systemControl.hpp
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::systemControl
Definition: systemControl.hpp:41
pFlow::printKeys
iOstream & printKeys(iOstream &os, const wordHashMap< T > &m)
pFlow::indexMorton
Definition: mortonIndexing.hpp:77
pFlow::objectFile::WRITE_NEVER
@ WRITE_NEVER
Definition: objectFile.hpp:44
RESERVE
Definition: Vector.hpp:40
END_WARNING
#define END_WARNING
Definition: streams.hpp:44
dictionary.hpp
pFlow::objectFile::READ_ALWAYS
@ READ_ALWAYS
Definition: objectFile.hpp:36
pFlow::positionParticles::position
virtual const realx3Vector & position() const =0
pFlow::positionParticles::sortByMortonCode
realx3Vector sortByMortonCode(const realx3Vector &position) const
Definition: positionParticles.cpp:26
pFlow::peakableRegion::create
static uniquePtr< peakableRegion > create(const word &type, const dictionary &dict)
Definition: peakableRegion.cpp:36
pFlow::systemControl::settings
const repository & settings() const
Definition: systemControl.hpp:105
pFlow::objectFile
Definition: objectFile.hpp:30
fatalError
#define fatalError
Report a fatal error and exit the applicaiton.
Definition: error.hpp:70
pFlow::dictionary::subDict
dictionary & subDict(const word &keyword)
ref to a subdictioanry fatalExit if not found
Definition: dictionary.cpp:560
pFlow::dictionary::getVal
T getVal(const word &keyword) const
get the value of data entry
Definition: dictionary.hpp:379
pFlow::positionParticles::create
static uniquePtr< positionParticles > create(systemControl &control, const dictionary &dict)
Definition: positionParticles.cpp:128
pFlow::Logical
Holds a bool value and converts strings to bool.
Definition: Logical.hpp:39
pFlow::fileDictionary
Definition: fileDictionary.hpp:29
pFlow::uniquePtr
Definition: uniquePtr.hpp:42
pFlow::positionParticles::getFinalPosition
virtual realx3Vector getFinalPosition()
Definition: positionParticles.cpp:112
pFlow::uint64
unsigned long long int uint64
Definition: builtinTypes.hpp:58
vocabs.hpp
pFlow::Vector< realx3 >
positionParticles.hpp
pFlow::domainFile__
const char *const domainFile__
Definition: vocabs.hpp:39
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
WARNING
#define WARNING
Definition: streams.hpp:43