# PhasicFlow: utilities/particlesPhasicFlow/positionParticles/positionParticles.cpp Source File

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 "box.hpp"
#include "cylinder.hpp"
#include "sphere.hpp"
#include "cells.hpp"
#include "contactSearchFunctions.hpp"
#include "streams.hpp"
pFlow::realx3Vector pFlow::positionParticles::sortByMortonCode(realx3Vector& position)const
{
struct indexMorton
{
size_t morton;
size_t index;
};
realx3 minP = min(position);
realx3 maxP = max(position);
real cellsize = maxDiameter();
cells<size_t> allCells( box(minP, maxP), cellsize);
Vector<indexMorton> indMor(position.size(),RESERVE());
indMor.clear();
size_t 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."<<endINFO;
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] );
}
return sortedPos;
}
pFlow::positionParticles::positionParticles
(
const dictionary& dict
)
{
maxNumberOfParticles_ = dict.getValOrSet("maxNumberOfParticles", static_cast<size_t>(10000));
mortonSorting_ = dict.getValOrSet("mortonSorting", Logical("Yes"));
if( dict.containsDictionay("box") )
{
region_ = makeUnique<region<box>>(dict.subDict("box"));
}
else if(dict.containsDictionay("cylinder"))
{
region_ = makeUnique<region<cylinder>>(dict.subDict("cylinder"));
}
else if(dict.containsDictionay("sphere"))
{
region_ = makeUnique<region<sphere>>(dict.subDict("sphere"));
}
}
pFlow::realx3Vector pFlow::positionParticles::getFinalPosition()
{
if(mortonSorting_)
{
return sortByMortonCode(position());
}
else
{
realx3Vector vec(position().capacity(), RESERVE());
vec.assign( position().begin(), position().end());
return std::move(vec);
}
}
pFlow::uniquePtr<pFlow::positionParticles>
pFlow::positionParticles::create(const dictionary & dict)
{
word method = dict.getVal<word>("method");
if( dictionaryvCtorSelector_.search(method) )
{
return dictionaryvCtorSelector_[method] (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
Definition: dictionary.hpp:325
pFlow::real
float real
Definition: builtinTypes.hpp:46
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::positionParticles::create
static uniquePtr< positionParticles > create(const dictionary &dict)
Definition: positionParticles.cpp:117
contactSearchFunctions.hpp
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
box.hpp
pFlow::printKeys
iOstream & printKeys(iOstream &os, const wordHashMap< T > &m)
pFlow::Vector::size
auto size() const
Definition: Vector.hpp:299
pFlow::dictionary::containsDictionay
bool containsDictionay(const word &name) const
Definition: dictionary.cpp:736
RESERVE
Definition: Vector.hpp:38
pFlow::positionParticles::positionParticles
positionParticles(const dictionary &dict)
Definition: positionParticles.cpp:78
pFlow::Vector::capacity
auto capacity() const
Definition: Vector.hpp:304
pFlow::positionParticles::position
virtual const realx3Vector & position() const =0
pFlow::positionParticles::maxDiameter
virtual real maxDiameter() const =0
cells.hpp
fatalError
#define fatalError
Definition: error.hpp:36
pFlow::dictionary::subDict
dictionary & subDict(const word &keyword)
Definition: dictionary.cpp:547
streams.hpp
sort
void sort(Vector< T, Allocator > &vec)
sphere.hpp
pFlow::max
T max(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:164
pFlow::dictionary::getVal
T getVal(const word &keyword) const
Definition: dictionary.hpp:309
pFlow::Vector::clear
auto clear()
Definition: Vector.hpp:248
pFlow::Logical
Definition: Logical.hpp:35
pFlow::box
Definition: box.hpp:32
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
pFlow::positionParticles::getFinalPosition
virtual realx3Vector getFinalPosition()
Definition: positionParticles.cpp:101
pFlow::positionParticles::sortByMortonCode
realx3Vector sortByMortonCode(realx3Vector &position) const
Definition: positionParticles.cpp:31
cylinder.hpp
pFlow::cells
Definition: cells.hpp:32
pFlow::triple< real >
pFlow::cells::pointIndex
INLINE_FUNCTION_HD CellType pointIndex(const realx3 &p) const
Definition: cells.hpp:158
pFlow::Vector< realx3 >
endINFO
#define endINFO
Definition: streams.hpp:38
positionParticles.hpp
pFlow::min
T min(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:138
pFlow::dictionary
Definition: dictionary.hpp:38
pFlow::xyzToMortonCode64
INLINE_FUNCTION_HD uint64_t xyzToMortonCode64(uint64_t x, uint64_t y, uint64_t z)
Definition: contactSearchFunctions.hpp:42
INFORMATION
#define INFORMATION
Definition: streams.hpp:37