# PhasicFlow: src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.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.

boundaryBase.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 "boundaryBase.hpp"
#include "boundaryList.hpp"
#include "dictionary.hpp"
#include "internalPoints.hpp"
#include "anyList.hpp"
#include "Time.hpp"
#include "pointStructure.hpp"
#include "boundaryBaseKernels.hpp"
void pFlow::boundaryBase::setSize(uint32 newSize)
{
indexList_.resize(newSize);
unSyncLists();
}
void pFlow::boundaryBase::setNewIndices
(
const uint32Vector_D& newIndices
)
{
indexList_.assign(newIndices, false);
unSyncLists();
}
bool pFlow::boundaryBase::appendNewIndices
(
const uint32Vector_D& newIndices
)
{
indexList_.append(newIndices);
unSyncLists();
message msg;
msg.add(message::BNDR_APPEND);
anyList varList;
varList.emplaceBack(
message::eventName(message::BNDR_APPEND),
newIndices);
if(!notify(
internal_.time().currentIter(),
internal_.time().currentTime(),
internal_.time().dt(),
msg,
varList))
{
fatalErrorInFunction;
return false;
}
return true;
}
bool pFlow::boundaryBase::removeIndices
(
uint32 numRemove,
const uint32Vector_D& removeMask
)
{
if(removeMask.size() != size()+1 )
{
fatalErrorInFunction<<"size mismatch"<<endl;
return false;
}
uint32Vector_D removeIndices("removeIndices");
uint32Vector_D keepIndices("keepIndices");
pFlow::boundaryBaseKernels::createRemoveKeepIndices
(
indexList_,
numRemove,
removeMask,
removeIndices,
keepIndices
);
if(!setRemoveKeepIndices(removeIndices, keepIndices))
{
return false;
}
anyList aList;
aList.emplaceBack(
message::eventName(message::BNDR_RESET),
std::move(keepIndices));
message msgBndry = message::BNDR_RESET;
uint32 iter = time().currentIter();
real t = time().currentTime();
real dt = time().dt();
if( !this->notify(iter, t, dt, msgBndry, aList) )
{
fatalErrorInFunction<<"Error in notify operation in boundary "<<
name_ <<endl;
return false;
}
return true;
}
bool pFlow::boundaryBase::setRemoveKeepIndices
(
const uint32Vector_D &removeIndices,
const uint32Vector_D &keepIndices
)
{
if(!internal_.deletePoints(removeIndices))
{
fatalErrorInFunction<<
"error in deleting points from boundary "<< name()<<endl;
return false;
}
setNewIndices(keepIndices);
return true;
}
bool pFlow::boundaryBase::transferPointsToMirror
(
uint32 numTransfer,
const uint32Vector_D& transferMask,
uint32 transferBoundaryIndex,
realx3 transferVector
)
{
if(transferMask.size() != size()+1 )
{
fatalErrorInFunction<<"size mismatch"<<endl;
return false;
}
uint32Vector_D transferIndices("transferIndices");
uint32Vector_D keepIndices("keepIndices");
pFlow::boundaryBaseKernels::createRemoveKeepIndices
(
indexList_,
numTransfer,
transferMask,
transferIndices,
keepIndices
);
// first, change the flags in the internalPoints
if( !internal_.changePointsFlagPosition(
transferIndices,
transferVector,
thisBoundaryIndex(),
transferBoundaryIndex) )
{
fatalErrorInFunction;
return false;
}
// second, remove the indices from this list
setNewIndices(keepIndices);
// third, add the indices to the mirror boundary
return mirrorBoundary().appendNewIndices(transferIndices);
}
pFlow::uint32 pFlow::boundaryBase::markInNegativeSide(const word &name, uint32Vector_D &markedIndices) const
{
uint32 s = size();
markedIndices.reallocate(s+1, s+1);
markedIndices.fill(0u);
const auto& markedIndicesD = markedIndices.deviceViewAll();
pointFieldAccessType points = thisPoints();
infinitePlane p = boundaryPlane().infPlane();
uint32 numMark = 0;
Kokkos::parallel_reduce
(
"boundaryProcessor::afterIteration",
deviceRPolicyStatic(0,s),
LAMBDA_HD(uint32 i, uint32& markToUpdate)
{
if(p.pointInNegativeSide(points(i)))
{
markedIndicesD(i)=1;
markToUpdate++;
}
},
numMark
);
return numMark;
}
pFlow::boundaryBase::boundaryBase(
const dictionary &dict,
const plane &bplane,
internalPoints &internal,
boundaryList &bndrs,
uint32 thisIndex)
: subscriber(dict.name()),
boundaryPlane_(bplane),
indexList_(groupNames("indexList", dict.name())),
indexListHost_(groupNames("hostIndexList", dict.name())),
neighborLength_(dict.getVal<real>("neighborLength")),
// updateInetrval_(dict.getVal<uint32>("updateInterval")),
boundaryExtntionLengthRatio_(dict.getVal<real>("boundaryExtntionLengthRatio")),
internal_(internal),
boundaries_(bndrs),
thisBoundaryIndex_(thisIndex),
neighborProcessorNo_(dict.getVal<int32>("neighborProcessorNo")),
isBoundaryMaster_(thisProcessorNo() >= neighborProcessorNo()),
name_(dict.name()),
type_(dict.getVal<word>("type"))
{
unSyncLists();
}
const pFlow::pointStructure &pFlow::boundaryBase::pStruct() const
{
return boundaries_.pStruct();
}
const pFlow::Time &pFlow::boundaryBase::time() const
{
return boundaries_.pStruct().time();
}
pFlow::boundaryBase &pFlow::boundaryBase::mirrorBoundary()
{
return boundaries_[mirrorBoundaryIndex()];
}
const pFlow::boundaryBase &pFlow::boundaryBase::mirrorBoundary() const
{
return boundaries_[mirrorBoundaryIndex()];
}
typename pFlow::boundaryBase::pointFieldAccessType
pFlow::boundaryBase::thisPoints()const
{
return pointFieldAccessType
(
indexList_.size(),
indexList_.deviceViewAll(),
internal_.pointPosition().deviceViewAll()
);
}
pFlow::realx3Vector_D& pFlow::boundaryBase::neighborProcPoints()
{
static realx3Vector_D dummyVector{"dummyVector"};
notImplementedFunction;
fatalExit;
return dummyVector;
}
const pFlow::realx3Vector_D&
pFlow::boundaryBase::neighborProcPoints()const
{
static realx3Vector_D dummyVector{"dummyVector"};
notImplementedFunction;
fatalExit;
return dummyVector;
}
pFlow::realx3 pFlow::boundaryBase::displacementVectroToMirror() const
{
const plane& thisP = boundaryPlane();
const plane& mirrorP = mirrorBoundary().boundaryPlane();
return thisP.normal()*(thisP.d() + mirrorP.d());
}
pFlow::uniquePtr<pFlow::boundaryBase> pFlow::boundaryBase::create
(
const dictionary &dict,
const plane &bplane,
internalPoints &internal,
boundaryList &bndrs,
uint32 thisIndex
)
{
word type = dict.getVal<word>("type");
word bType = angleBracketsNames("boundary", type);
if( dictionaryvCtorSelector_.search(bType) )
{
return dictionaryvCtorSelector_[bType] (dict, bplane, internal, bndrs, thisIndex);
}
else
{
printKeys
(
fatalError << "Ctor Selector "<< bType << " does not exist. \n"
<<"Avaiable ones are: \n\n"
,
dictionaryvCtorSelector_
);
fatalExit;
}
return nullptr;
}
anyList.hpp
notImplementedFunction
#define notImplementedFunction
Report that a function is yet not implemented.
Definition: error.hpp:84
pFlow::boundaryBase::pStruct
const pointStructure & pStruct() const
Definition: boundaryBase.cpp:249
pFlow::VectorSingle::fill
INLINE_FUNCTION_H void fill(const T &val)
Fill the range [0,size) with val.
Definition: VectorSingle.cpp:365
pFlow::internalPoints
Definition: internalPoints.hpp:38
pFlow::VectorSingle::resize
INLINE_FUNCTION_H void resize(uint32 n)
Resize the vector and preserve the content.
Definition: VectorSingle.cpp:344
pFlow::boundaryBase::displacementVectroToMirror
virtual realx3 displacementVectroToMirror() const
displacement vector that transfers points to a distance that is equal to the distance between this ...
Definition: boundaryBase.cpp:299
pFlow::infinitePlane::normal
const INLINE_FUNCTION_HD auto & normal() const
Definition: infinitePlane.hpp:155
pFlow::scatteredFieldAccess
Definition: scatteredFieldAccess.hpp:32
pFlow::message
Definition: message.hpp:33
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::infinitePlane::pointInNegativeSide
INLINE_FUNCTION_HD bool pointInNegativeSide(const realx3 &p) const
Definition: infinitePlane.hpp:107
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::plane
Definition: plane.hpp:30
pFlow::boundaryBase::transferPointsToMirror
bool transferPointsToMirror(uint32 numTransfer, const uint32Vector_D &transferMask, uint32 transferBoundaryIndex, realx3 transferVector)
Definition: boundaryBase.cpp:149
pFlow::boundaryBase::neighborProcPoints
virtual realx3Vector_D & neighborProcPoints()
Return a reference to point positions in the neighbor processor boundary.
Definition: boundaryBase.cpp:282
pFlow::boundaryBase::markInNegativeSide
uint32 markInNegativeSide(const word &name, uint32Vector_D &markedIndices) const
Definition: boundaryBase.cpp:193
pFlow::VectorSingle::reallocate
INLINE_FUNCTION_H void reallocate(uint32 cap)
Reallocate memory to new cap and set size to 0.
Definition: VectorSingle.cpp:326
boundaryBase.hpp
pFlow::infinitePlane
Definition: infinitePlane.hpp:32
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::printKeys
iOstream & printKeys(iOstream &os, const wordHashMap< T > &m)
pFlow::boundaryList
Definition: boundaryList.hpp:35
pFlow::boundaryBase::mirrorBoundary
boundaryBase & mirrorBoundary()
Definition: boundaryBase.cpp:259
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::subscriber
Definition: subscriber.hpp:37
pFlow::message::BNDR_APPEND
@ BNDR_APPEND
Definition: message.hpp:50
pFlow::boundaryBase::time
const Time & time() const
Definition: boundaryBase.cpp:254
pFlow::message::BNDR_RESET
@ BNDR_RESET
Definition: message.hpp:48
boundaryList.hpp
pFlow::pointStructure
Definition: pointStructure.hpp:34
pFlow::anyList
Definition: anyList.hpp:35
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::angleBracketsNames
word angleBracketsNames(const word &w1, const word &w2)
Output <w1,w2>
Definition: bTypesFunctions.cpp:156
boundaryBaseKernels.hpp
dictionary.hpp
Time.hpp
pFlow::boundaryBase
Definition: boundaryBase.hpp:42
pFlow::boundaryBase::setSize
virtual void setSize(uint32 newSize)
Set the size of indexList.
Definition: boundaryBase.cpp:30
pFlow::VectorSingle< uint32 >
pFlow::boundaryBaseKernels::createRemoveKeepIndices
void createRemoveKeepIndices(const uint32Vector_D &indices, uint32 numRemove, const uint32Vector_D &removeMask, uint32Vector_D &removeIndices, uint32Vector_D &keepIndices, bool exactCap=true)
Definition: boundaryBaseKernels.cpp:65
pFlow::boundaryBase::unSyncLists
void unSyncLists()
Definition: boundaryBase.hpp:127
fatalError
#define fatalError
Report a fatal error and exit the applicaiton.
Definition: error.hpp:70
pFlow::VectorSingle::deviceViewAll
INLINE_FUNCTION_H auto & deviceViewAll()
Device view range [0,capcity)
Definition: VectorSingle.cpp:249
pFlow::dictionary::getVal
T getVal(const word &keyword) const
get the value of data entry
Definition: dictionary.hpp:379
pFlow::infinitePlane::d
const INLINE_FUNCTION_HD auto & d() const
Definition: infinitePlane.hpp:161
pFlow::boundaryBase::indexList_
uint32Vector_D indexList_
list of particles indices on device
Definition: boundaryBase.hpp:59
pFlow::uniquePtr
Definition: uniquePtr.hpp:42
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:58
pFlow::deviceRPolicyStatic
Kokkos::RangePolicy< Kokkos::DefaultExecutionSpace, Kokkos::Schedule< Kokkos::Static >, Kokkos::IndexType< pFlow::uint32 > > deviceRPolicyStatic
Definition: KokkosTypes.hpp:66
pFlow::groupNames
word groupNames(const word &bw, const word &tw, char sep='.')
Group words and output bw.tw.
Definition: bTypesFunctions.cpp:179
pFlow::boundaryBase::setNewIndices
void setNewIndices(const uint32Vector_D &newIndices)
Definition: boundaryBase.cpp:37
pFlow::boundaryBase::boundaryBase
boundaryBase(const dictionary &dict, const plane &bplane, internalPoints &internal, boundaryList &bndrs, uint32 thisIndex)
Definition: boundaryBase.cpp:225
pFlow::boundaryBase::setRemoveKeepIndices
bool setRemoveKeepIndices(const uint32Vector_D &removeIndices, const uint32Vector_D &keepIndices)
Definition: boundaryBase.cpp:130
pFlow::boundaryBase::appendNewIndices
bool appendNewIndices(const uint32Vector_D &newIndices)
Definition: boundaryBase.cpp:47
pFlow::triple< real >
pointStructure.hpp
internalPoints.hpp
pFlow::anyList::emplaceBack
reference emplaceBack(const word &name, Args &&... args)
Create variable using constructor in-place.
Definition: anyList.hpp:84
pFlow::boundaryBase::thisPoints
pointFieldAccessType thisPoints() const
Definition: boundaryBase.cpp:270
pFlow::boundaryBase::create
static uniquePtr< boundaryBase > create(const dictionary &dict, const plane &bplane, internalPoints &internal, boundaryList &bndrs, uint32 thisIndex)
Definition: boundaryBase.cpp:308
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
pFlow::VectorSingle::size
INLINE_FUNCTION_H uint32 size() const
Size of the vector.
Definition: VectorSingle.cpp:297
pFlow::message::add
message & add(EVENT evnt)
Definition: message.hpp:113
pFlow::message::eventName
static const word & eventName(size_t event)
Definition: message.hpp:196
pFlow::Time
Definition: Time.hpp:37
pFlow::boundaryBase::removeIndices
bool removeIndices(uint32 numRemove, const uint32Vector_D &removeMask)
Definition: boundaryBase.cpp:79