# PhasicFlow: src/Interaction/grainInteraction/grainInteraction/grainInteractionKernels.hpp 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.

grainInteractionKernels.hpp
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.
-----------------------------------------------------------------------------*/
#ifndef __grainInteractionKernels_hpp__
#define __grainInteractionKernels_hpp__
#include "grainTriSurfaceContact.hpp"
namespace pFlow::grainInteractionKernels
{
template<
typename ContactForceModel,
typename ContactListType>
struct ppInteractionFunctor
{
using PairType = typename ContactListType::PairType;
using ValueType = typename ContactListType::ValueType;
real dt_;
ContactForceModel forceModel_;
ContactListType tobeFilled_;
deviceViewType1D<real> diam_;
deviceViewType1D<real> coarseGrainFactor_;
deviceViewType1D<uint32> propId_;
deviceViewType1D<realx3> pos_;
deviceViewType1D<realx3> lVel_;
deviceViewType1D<realx3> rVel_;
deviceViewType1D<realx3> cForce_;
deviceViewType1D<realx3> cTorque_;
ppInteractionFunctor(
real dt,
ContactForceModel forceModel,
ContactListType tobeFilled,
deviceViewType1D<real> diam,
deviceViewType1D<real> coarseGrainFactor,
deviceViewType1D<uint32> propId,
deviceViewType1D<realx3> pos,
deviceViewType1D<realx3> lVel,
deviceViewType1D<realx3> rVel,
deviceViewType1D<realx3> cForce,
deviceViewType1D<realx3> cTorque )
:
dt_(dt),
forceModel_(forceModel),
tobeFilled_(tobeFilled),
diam_(diam),
coarseGrainFactor_(coarseGrainFactor),
propId_(propId),
pos_(pos),
lVel_(lVel),
rVel_(rVel),
cForce_(cForce), // this is converted to an atomic vector
cTorque_(cTorque) // this is converted to an atomic vector
{}
INLINE_FUNCTION_HD
void operator()(const uint32 n)const
{
if(!tobeFilled_.isValid(n))return;
auto [i,j] = tobeFilled_.getPair(n);
real Ri = 0.5*diam_[i];
real Rj = 0.5*diam_[j];
real cGFi = coarseGrainFactor_[j];
real cGFj = coarseGrainFactor_[j];
realx3 xi = pos_[i];
realx3 xj = pos_[j];
real dist = length(xj-xi);
real ovrlp = (Ri+Rj) - dist;
if( ovrlp >0.0 )
{
auto Vi = lVel_[i];
auto Vj = lVel_[j];
auto wi = rVel_[i];
auto wj = rVel_[j];
auto Nij = (xj-xi)/dist;
auto Vr = Vi - Vj + cross((Ri*wi+Rj*wj), Nij);
auto history = tobeFilled_.getValue(n);
int32 propId_i = propId_[i];
int32 propId_j = propId_[j];
realx3 FCn, FCt, Mri, Mrj, Mij, Mji;
// calculates contact force
forceModel_.contactForce(
dt_, i, j,
propId_i, propId_j,
Ri, Rj, cGFi , cGFj ,
ovrlp,
Vr, Nij,
history,
FCn, FCt
);
forceModel_.rollingFriction(
dt_, i, j,
propId_i, propId_j,
Ri, Rj, cGFi , cGFj ,
wi, wj,
Nij,
FCn,
Mri, Mrj
);
auto M = cross(Nij,FCt);
Mij = Ri*M+Mri;
Mji = Rj*M+Mrj;
auto FC = FCn + FCt;
Kokkos::atomic_add(&cForce_[i].x_,FC.x_);
Kokkos::atomic_add(&cForce_[i].y_,FC.y_);
Kokkos::atomic_add(&cForce_[i].z_,FC.z_);
Kokkos::atomic_add(&cForce_[j].x_,-FC.x_);
Kokkos::atomic_add(&cForce_[j].y_,-FC.y_);
Kokkos::atomic_add(&cForce_[j].z_,-FC.z_);
Kokkos::atomic_add(&cTorque_[i].x_, Mij.x_);
Kokkos::atomic_add(&cTorque_[i].y_, Mij.y_);
Kokkos::atomic_add(&cTorque_[i].z_, Mij.z_);
Kokkos::atomic_add(&cTorque_[j].x_, Mji.x_);
Kokkos::atomic_add(&cTorque_[j].y_, Mji.y_);
Kokkos::atomic_add(&cTorque_[j].z_, Mji.z_);
tobeFilled_.setValue(n,history);
}
else
{
tobeFilled_.setValue(n, ValueType());
}
}
};
template<
typename ContactForceModel,
typename ContactListType,
typename TraingleAccessor,
typename MotionModel>
struct pwInteractionFunctor
{
using PairType = typename ContactListType::PairType;
using ValueType = typename ContactListType::ValueType;
real dt_;
ContactForceModel forceModel_;
ContactListType tobeFilled_;
TraingleAccessor triangles_;
MotionModel motionModel_;
deviceViewType1D<real> diam_;
deviceViewType1D<real> coarseGrainFactor_;
deviceViewType1D<uint32> propId_;
deviceViewType1D<realx3> pos_;
deviceViewType1D<realx3> lVel_;
deviceViewType1D<realx3> rVel_;
deviceViewType1D<realx3> cForce_;
deviceViewType1D<realx3> cTorque_;
deviceViewType1D<uint32> wTriMotionIndex_;
deviceViewType1D<uint32> wPropId_;
deviceViewType1D<realx3> wCForce_;
pwInteractionFunctor(
real dt,
ContactForceModel forceModel,
ContactListType tobeFilled,
TraingleAccessor triangles,
MotionModel motionModel ,
deviceViewType1D<real> diam ,
deviceViewType1D<real> coarseGrainFactor,
deviceViewType1D<uint32> propId,
deviceViewType1D<realx3> pos ,
deviceViewType1D<realx3> lVel,
deviceViewType1D<realx3> rVel,
deviceViewType1D<realx3> cForce,
deviceViewType1D<realx3> cTorque ,
deviceViewType1D<uint32> wTriMotionIndex,
deviceViewType1D<uint32> wPropId,
deviceViewType1D<realx3> wCForce)
:
dt_(dt),
forceModel_(forceModel),
tobeFilled_(tobeFilled),
triangles_(triangles) ,
motionModel_(motionModel) ,
diam_(diam) ,
coarseGrainFactor_(coarseGrainFactor),
propId_(propId),
pos_(pos) ,
lVel_(lVel),
rVel_(rVel) ,
cForce_(cForce),
cTorque_(cTorque) ,
wTriMotionIndex_(wTriMotionIndex) ,
wPropId_(wPropId),
wCForce_(wCForce)
{}
INLINE_FUNCTION_HD
void operator()(const int32 n)const
{
if(!tobeFilled_.isValid(n))return;
auto [i,tj] = tobeFilled_.getPair(n);
real Ri = 0.5*diam_[i];
real Rj = 10000.0;
real cGFi = coarseGrainFactor_[i];
real cGFj = coarseGrainFactor_[i];
realx3 xi = pos_[i];
realx3x3 tri = triangles_(tj);
real ovrlp;
realx3 Nij, cp;
if( pFlow::grnTriInteraction::isGrainInContactBothSides(
tri, xi, Ri, ovrlp, Nij, cp) )
{
auto Vi = lVel_[i];
auto wi = rVel_[i];
int32 mInd = wTriMotionIndex_[tj];
auto Vw = motionModel_(mInd, cp);
//output<< "par-wall index "<< i<<" - "<< tj<<endl;
auto Vr = Vi - Vw + cross(Ri*wi, Nij);
auto history = tobeFilled_.getValue(n);
int32 propId_i = propId_[i];
int32 wPropId_j = wPropId_[tj];
realx3 FCn, FCt, Mri, Mrj, Mij;
//output<< "before "<<history.overlap_t_<<endl;
// calculates contact force
forceModel_.contactForce(
dt_, i, tj,
propId_i, wPropId_j,
Ri, Rj, cGFi , cGFj ,
ovrlp,
Vr, Nij,
history,
FCn, FCt
);
//output<< "after "<<history.overlap_t_<<endl;
forceModel_.rollingFriction(
dt_, i, tj,
propId_i, wPropId_j,
Ri, Rj, cGFi , cGFj ,
wi, 0.0,
Nij,
FCn,
Mri, Mrj
);
auto M = cross(Nij,FCt);
Mij = Ri*M+Mri;
//output<< "FCt = "<<FCt <<endl;
//output<< "FCn = "<<FCn <<endl;
//output<<"propId i, tj"<< propId_i << " "<<wPropId_j<<endl;
//output<<"par i , wj"<< i<<" "<< tj<<endl;
auto FC = FCn + FCt;
Kokkos::atomic_add(&cForce_[i].x_,FC.x_);
Kokkos::atomic_add(&cForce_[i].y_,FC.y_);
Kokkos::atomic_add(&cForce_[i].z_,FC.z_);
Kokkos::atomic_add(&wCForce_[tj].x_,-FC.x_);
Kokkos::atomic_add(&wCForce_[tj].y_,-FC.y_);
Kokkos::atomic_add(&wCForce_[tj].z_,-FC.z_);
Kokkos::atomic_add(&cTorque_[i].x_, Mij.x_);
Kokkos::atomic_add(&cTorque_[i].y_, Mij.y_);
Kokkos::atomic_add(&cTorque_[i].z_, Mij.z_);
tobeFilled_.setValue(n,history);
}
else
{
tobeFilled_.setValue(n,ValueType());
}
}
};
}
#endif //__grainInteractionKernels_hpp__
pFlow::grainInteractionKernels::ppInteractionFunctor::rVel_
deviceViewType1D< realx3 > rVel_
Definition: grainInteractionKernels.hpp:49
pFlow::grainInteractionKernels::pwInteractionFunctor::cTorque_
deviceViewType1D< realx3 > cTorque_
Definition: grainInteractionKernels.hpp:197
pFlow::grainInteractionKernels::ppInteractionFunctor::cTorque_
deviceViewType1D< realx3 > cTorque_
Definition: grainInteractionKernels.hpp:51
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::grainInteractionKernels::pwInteractionFunctor::tobeFilled_
ContactListType tobeFilled_
Definition: grainInteractionKernels.hpp:185
pFlow::grainInteractionKernels::pwInteractionFunctor::diam_
deviceViewType1D< real > diam_
Definition: grainInteractionKernels.hpp:190
pFlow::grainInteractionKernels::pwInteractionFunctor::coarseGrainFactor_
deviceViewType1D< real > coarseGrainFactor_
Definition: grainInteractionKernels.hpp:191
pFlow::grainInteractionKernels::ppInteractionFunctor::ValueType
typename ContactListType::ValueType ValueType
Definition: grainInteractionKernels.hpp:37
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::grainInteractionKernels::pwInteractionFunctor::PairType
typename ContactListType::PairType PairType
Definition: grainInteractionKernels.hpp:179
pFlow::grainInteractionKernels::pwInteractionFunctor::lVel_
deviceViewType1D< realx3 > lVel_
Definition: grainInteractionKernels.hpp:194
pFlow::grainInteractionKernels::pwInteractionFunctor::rVel_
deviceViewType1D< realx3 > rVel_
Definition: grainInteractionKernels.hpp:195
pFlow::deviceViewType1D
Kokkos::View< T * > deviceViewType1D
1D array (vector) with default device (memory space and execution space)
Definition: KokkosTypes.hpp:121
pFlow::grainInteractionKernels::pwInteractionFunctor::forceModel_
ContactForceModel forceModel_
Definition: grainInteractionKernels.hpp:184
pFlow::grainInteractionKernels::ppInteractionFunctor::propId_
deviceViewType1D< uint32 > propId_
Definition: grainInteractionKernels.hpp:46
pFlow::grainInteractionKernels::pwInteractionFunctor::wPropId_
deviceViewType1D< uint32 > wPropId_
Definition: grainInteractionKernels.hpp:199
pFlow::grainInteractionKernels::ppInteractionFunctor::pos_
deviceViewType1D< realx3 > pos_
Definition: grainInteractionKernels.hpp:47
cross
INLINE_FUNCTION_HD triple< T > cross(const triple< T > &v1, const triple< T > &v2)
pFlow::grainInteractionKernels::pwInteractionFunctor::dt_
real dt_
Definition: grainInteractionKernels.hpp:182
length
INLINE_FUNCTION_HD T length(const triple< T > &v1)
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::grainInteractionKernels::pwInteractionFunctor::triangles_
TraingleAccessor triangles_
Definition: grainInteractionKernels.hpp:187
pFlow::grainInteractionKernels::ppInteractionFunctor::dt_
real dt_
Definition: grainInteractionKernels.hpp:39
pFlow::grainInteractionKernels::pwInteractionFunctor::wTriMotionIndex_
deviceViewType1D< uint32 > wTriMotionIndex_
Definition: grainInteractionKernels.hpp:198
pFlow::grainInteractionKernels::ppInteractionFunctor::tobeFilled_
ContactListType tobeFilled_
Definition: grainInteractionKernels.hpp:42
pFlow::grainInteractionKernels::ppInteractionFunctor::coarseGrainFactor_
deviceViewType1D< real > coarseGrainFactor_
Definition: grainInteractionKernels.hpp:45
pFlow::grnTriInteraction::isGrainInContactBothSides
INLINE_FUNCTION_HD bool isGrainInContactBothSides(const realx3x3 &tri, const realx3 &cntr, real Rad, real &ovrlp, realx3 &norm, realx3 &cp)
Definition: grainTriSurfaceContact.hpp:172
pFlow::triple::x_
T x_
data members
Definition: triple.hpp:49
pFlow::grainInteractionKernels::pwInteractionFunctor::propId_
deviceViewType1D< uint32 > propId_
Definition: grainInteractionKernels.hpp:192
pFlow::grainInteractionKernels::ppInteractionFunctor::lVel_
deviceViewType1D< realx3 > lVel_
Definition: grainInteractionKernels.hpp:48
pFlow::grainInteractionKernels::pwInteractionFunctor::wCForce_
deviceViewType1D< realx3 > wCForce_
Definition: grainInteractionKernels.hpp:200
pFlow::grainInteractionKernels::pwInteractionFunctor::pwInteractionFunctor
pwInteractionFunctor(real dt, ContactForceModel forceModel, ContactListType tobeFilled, TraingleAccessor triangles, MotionModel motionModel, deviceViewType1D< real > diam, deviceViewType1D< real > coarseGrainFactor, deviceViewType1D< uint32 > propId, deviceViewType1D< realx3 > pos, deviceViewType1D< realx3 > lVel, deviceViewType1D< realx3 > rVel, deviceViewType1D< realx3 > cForce, deviceViewType1D< realx3 > cTorque, deviceViewType1D< uint32 > wTriMotionIndex, deviceViewType1D< uint32 > wPropId, deviceViewType1D< realx3 > wCForce)
Definition: grainInteractionKernels.hpp:203
pFlow::grainInteractionKernels::pwInteractionFunctor::cForce_
deviceViewType1D< realx3 > cForce_
Definition: grainInteractionKernels.hpp:196
pFlow::triple::y_
T y_
Definition: triple.hpp:50
pFlow::grainInteractionKernels::pwInteractionFunctor::ValueType
typename ContactListType::ValueType ValueType
Definition: grainInteractionKernels.hpp:180
pFlow::grainInteractionKernels::ppInteractionFunctor::forceModel_
ContactForceModel forceModel_
Definition: grainInteractionKernels.hpp:41
pFlow::triple::z_
T z_
Definition: triple.hpp:51
n
uint32 n
Definition: NBSLoop.hpp:24
pFlow::grainInteractionKernels::pwInteractionFunctor
Definition: grainInteractionKernels.hpp:177
pFlow::grainInteractionKernels::ppInteractionFunctor::operator()
INLINE_FUNCTION_HD void operator()(const uint32 n) const
Definition: grainInteractionKernels.hpp:81
pFlow::grainInteractionKernels::ppInteractionFunctor::cForce_
deviceViewType1D< realx3 > cForce_
Definition: grainInteractionKernels.hpp:50
pFlow::grainInteractionKernels::pwInteractionFunctor::operator()
INLINE_FUNCTION_HD void operator()(const int32 n) const
Definition: grainInteractionKernels.hpp:240
pFlow::grainInteractionKernels::ppInteractionFunctor::diam_
deviceViewType1D< real > diam_
Definition: grainInteractionKernels.hpp:44
pFlow::grainInteractionKernels::ppInteractionFunctor::PairType
typename ContactListType::PairType PairType
Definition: grainInteractionKernels.hpp:36
pFlow::MotionModel
Motion model abstract class (CRTP) for all the motion models.
Definition: MotionModel.hpp:39
pFlow::grainInteractionKernels::ppInteractionFunctor::ppInteractionFunctor
ppInteractionFunctor(real dt, ContactForceModel forceModel, ContactListType tobeFilled, deviceViewType1D< real > diam, deviceViewType1D< real > coarseGrainFactor, deviceViewType1D< uint32 > propId, deviceViewType1D< realx3 > pos, deviceViewType1D< realx3 > lVel, deviceViewType1D< realx3 > rVel, deviceViewType1D< realx3 > cForce, deviceViewType1D< realx3 > cTorque)
Definition: grainInteractionKernels.hpp:54
pFlow::grainInteractionKernels
Definition: grainInteractionKernels.hpp:27
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:55
pFlow::triple< real >
pFlow::grainInteractionKernels::ppInteractionFunctor
Definition: grainInteractionKernels.hpp:33
grainTriSurfaceContact.hpp
pFlow::grainInteractionKernels::pwInteractionFunctor::pos_
deviceViewType1D< realx3 > pos_
Definition: grainInteractionKernels.hpp:193
pFlow::grainInteractionKernels::pwInteractionFunctor::motionModel_
MotionModel motionModel_
Definition: grainInteractionKernels.hpp:188