www.cemf.ir
boundaryReflective.cpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 -----------------------------------------------------------------------------*/
19 
20 #include "boundaryReflective.hpp"
21 #include "pointFields.hpp"
22 #include "dictionary.hpp"
23 #include "Time.hpp"
24 
26 (
27  const dictionary &dict,
28  const plane &bplane,
29  internalPoints &internal,
30  boundaryList &bndrs,
31  uint32 thisIndex
32 )
33 :
35  (
36  dict,
37  bplane,
38  internal,
39  bndrs,
40  thisIndex
41  )
42 {
43  restitution_ = dict.getValOrSet("restitution", restitution_);
44  velocityName_ = dict.getValOrSet("velocityName",velocityName_);
45  diameterName_ = dict.getValOrSet("diameterName", diameterName_);
46 }
47 
49  uint32 step,
50  const timeInfo& ti,
51  bool updateIter,
52  bool iterBeforeUpdate ,
53  bool& callAgain)
54 {
55  boundaryBase::beforeIteration(step, ti, updateIter, iterBeforeUpdate, callAgain);
56  callAgain = false;
57  return true;
58 }
59 
61 (
62  const timeInfo& ti
63 )
64 {
65  return true;
66 }
67 
69 (
70  const timeInfo& ti
71 )
72 {
73  if(empty())return true;
74 
75  uint32 s = size();
76  uint32Vector_D inContactFlags("inContactFlags",s+1, s+1, RESERVE());
77  inContactFlags.fill(0u);
78  auto inContactFlagsD = inContactFlags.deviceViewAll();
79 
80  auto points = thisPoints();
81 
82  auto p = boundaryPlane().infPlane();
83  const auto &diam = time().lookupObject<realPointField_D>(diameterName_);
84  auto diams = diam.BoundaryField(thisBoundaryIndex()).thisField();
85 
86  uint32 numInContact = 0;
87 
88  Kokkos::parallel_reduce
89  (
90  "pFlow::boundaryReflective::afterIteration",
91  deviceRPolicyStatic(0u,s),
92  LAMBDA_HD(uint32 i, uint32& nContactToUpdate)
93  {
94  if(p.inPositiveDistance(points(i), 0.5*diams(i)))
95  {
96  inContactFlagsD(i)=1;
97  nContactToUpdate++;
98  }
99  },
100  numInContact
101  );
102 
103  // no particle in contact
104  if(numInContact == 0 )
105  {
106  return true;
107  }
108 
109  uint32Vector_D inContactList("inContactList", numInContact);
110  const auto& inContactListD = inContactList.deviceViewAll();
111 
112  exclusiveScan(inContactFlagsD, 0u, s+1, inContactFlagsD, 0u);
113 
114  Kokkos::parallel_for
115  (
116  "pFlow::boundaryReflective::afterIteration",
117  deviceRPolicyStatic(0, s),
118  LAMBDA_HD(uint32 i)
119  {
120  if(inContactFlagsD(i)!= inContactFlagsD(i+1))
121  inContactListD(inContactFlagsD(i)) = points.index(i);
122  }
123  );
124  Kokkos::fence();
125 
126  const auto& velocity = time().lookupObject<realx3PointField_D>(velocityName_);
127  const auto& velocityD = velocity.deviceViewAll();
128 
129  const auto restitution = restitution_;
130 
131  Kokkos::parallel_for(
132  "pFlow::boundaryReflective::velocityChange",
133  deviceRPolicyStatic(0,numInContact),
134  LAMBDA_HD(uint32 i)
135  {
136  auto& vel = velocityD(inContactListD(i));
137  real vn = dot(p.normal(), vel);
138 
139  if(vn < 0)
140  {
141  realx3 vt = vel - vn*p.normal();
142  vel = restitution*(vt - vn*p.normal());
143  }
144  }
145  );
146  Kokkos::fence();
147 
148  // TODO: notify integration for changes in the velocity
149 
150  return true;
151 }
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