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

boundaryReflective.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 "boundaryReflective.hpp"
#include "pointFields.hpp"
#include "dictionary.hpp"
#include "Time.hpp"
pFlow::boundaryReflective::boundaryReflective
(
const dictionary &dict,
const plane &bplane,
internalPoints &internal,
boundaryList &bndrs,
uint32 thisIndex
)
:
boundaryBase
(
dict,
bplane,
internal,
bndrs,
thisIndex
)
{
restitution_ = dict.getValOrSet("restitution", restitution_);
velocityName_ = dict.getValOrSet("velocityName",velocityName_);
diameterName_ = dict.getValOrSet("diameterName", diameterName_);
}
bool pFlow::boundaryReflective::beforeIteration(
uint32 step,
const timeInfo& ti,
bool updateIter,
bool iterBeforeUpdate ,
bool& callAgain)
{
boundaryBase::beforeIteration(step, ti, updateIter, iterBeforeUpdate, callAgain);
callAgain = false;
return true;
}
bool pFlow::boundaryReflective::iterate
(
const timeInfo& ti
)
{
return true;
}
bool pFlow::boundaryReflective::afterIteration
(
const timeInfo& ti
)
{
if(empty())return true;
uint32 s = size();
uint32Vector_D inContactFlags("inContactFlags",s+1, s+1, RESERVE());
inContactFlags.fill(0u);
auto inContactFlagsD = inContactFlags.deviceViewAll();
auto points = thisPoints();
auto p = boundaryPlane().infPlane();
const auto &diam = time().lookupObject<realPointField_D>(diameterName_);
auto diams = diam.BoundaryField(thisBoundaryIndex()).thisField();
uint32 numInContact = 0;
Kokkos::parallel_reduce
(
"pFlow::boundaryReflective::afterIteration",
deviceRPolicyStatic(0u,s),
LAMBDA_HD(uint32 i, uint32& nContactToUpdate)
{
if(p.inPositiveDistance(points(i), 0.5*diams(i)))
{
inContactFlagsD(i)=1;
nContactToUpdate++;
}
},
numInContact
);
// no particle in contact
if(numInContact == 0 )
{
return true;
}
uint32Vector_D inContactList("inContactList", numInContact);
const auto& inContactListD = inContactList.deviceViewAll();
exclusiveScan(inContactFlagsD, 0u, s+1, inContactFlagsD, 0u);
Kokkos::parallel_for
(
"pFlow::boundaryReflective::afterIteration",
deviceRPolicyStatic(0, s),
LAMBDA_HD(uint32 i)
{
if(inContactFlagsD(i)!= inContactFlagsD(i+1))
inContactListD(inContactFlagsD(i)) = points.index(i);
}
);
Kokkos::fence();
const auto& velocity = time().lookupObject<realx3PointField_D>(velocityName_);
const auto& velocityD = velocity.deviceViewAll();
const auto restitution = restitution_;
Kokkos::parallel_for(
"pFlow::boundaryReflective::velocityChange",
deviceRPolicyStatic(0,numInContact),
LAMBDA_HD(uint32 i)
{
auto& vel = velocityD(inContactListD(i));
real vn = dot(p.normal(), vel);
if(vn < 0)
{
realx3 vt = vel - vn*p.normal();
vel = restitution*(vt - vn*p.normal());
}
}
);
Kokkos::fence();
// TODO: notify integration for changes in the velocity
return true;
}
pFlow::VectorSingle::fill
INLINE_FUNCTION_H void fill(const T &val)
Fill the range [0,size) with val.
Definition: VectorSingle.cpp:365
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
pFlow::internalPoints
Definition: internalPoints.hpp:38
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::plane
Definition: plane.hpp:30
pFlow::empty
Definition: empty.hpp:30
pFlow::internalField::deviceViewAll
const auto & deviceViewAll() const
Definition: internalField.hpp:92
boundaryReflective.hpp
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pointFields.hpp
pFlow::boundaryList
Definition: boundaryList.hpp:35
pFlow::pointField::BoundaryField
const auto & BoundaryField(uint32 i) const
Definition: pointField.hpp:128
pFlow::boundaryBase::beforeIteration
virtual bool beforeIteration(uint32 step, const timeInfo &ti, bool updateIter, bool iterBeforeUpdate, bool &callAgain)
Definition: boundaryBase.hpp:359
pFlow::timeInfo
Definition: timeInfo.hpp:28
RESERVE
Definition: Vector.hpp:40
pFlow::pointField
Definition: pointField.hpp:33
dot
INLINE_FUNCTION_HD T dot(const quadruple< T > &oprnd1, const quadruple< T > &oprnd2)
pFlow::boundaryReflective::afterIteration
bool afterIteration(const timeInfo &ti) final
Definition: boundaryReflective.cpp:69
dictionary.hpp
Time.hpp
pFlow::boundaryBase
Definition: boundaryBase.hpp:42
pFlow::VectorSingle< uint32 >
pFlow::VectorSingle::deviceViewAll
INLINE_FUNCTION_H auto & deviceViewAll()
Device view range [0,capcity)
Definition: VectorSingle.cpp:249
pFlow::boundaryReflective::iterate
bool iterate(const timeInfo &ti) final
Definition: boundaryReflective.cpp:61
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::triple< real >
pFlow::boundaryReflective::beforeIteration
bool beforeIteration(uint32 step, const timeInfo &ti, bool updateIter, bool iterBeforeUpdate, bool &callAgain) final
Definition: boundaryReflective.cpp:48
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::boundaryReflective::boundaryReflective
boundaryReflective(const dictionary &dict, const plane &bplane, internalPoints &internal, boundaryList &bndrs, uint32 thisIndex)
Definition: boundaryReflective.cpp:26
pFlow::exclusiveScan
void exclusiveScan(const ViewType1D< Type, properties... > &view, uint32 start, uint32 end, ViewType1D< Type, dProperties... > &dView, uint32 dStart)
Definition: ViewAlgorithms.hpp:439