linearCF.hpp
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 
21 #ifndef __linearCF_hpp__
22 #define __linearCF_hpp__
23 
24 #include "types.hpp"
25 #include "symArrays.hpp"
26 
27 namespace pFlow::cfModels
28 {
29 
30 template<bool limited=true>
31 class linear
32 {
33 public:
34 
36  {
38  };
39 
41  {
42  real kn_ = 1000.0;
43  real kt_ = 800.0;
44  real ethan_ = 0.0;
45  real ethat_ = 0.0;
46  real mu_ = 0.00001;
47 
50 
52  linearProperties(real kn, real kt, real etha_n, real etha_t, real mu ):
53  kn_(kn), kt_(kt), ethan_(etha_n),ethat_(etha_t), mu_(mu)
54  {}
55 
57  linearProperties(const linearProperties&)=default;
58 
61 
63  ~linearProperties() = default;
64  };
65 
66 protected:
67 
69 
71 
73 
75 
76 
77 
78  bool readLinearDictionary(const dictionary& dict)
79  {
80  auto kn = dict.getVal<realVector>("kn");
81  auto kt = dict.getVal<realVector>("kt");
82  auto en = dict.getVal<realVector>("en");
83  auto et = dict.getVal<realVector>("et");
84  auto mu = dict.getVal<realVector>("mu");
85 
86  auto nElem = kn.size();
87 
88 
89  if(nElem != kt.size())
90  {
92  "sizes of kn("<<nElem<<") and kt("<<kt.size()<<") do not match.\n";
93  return false;
94  }
95 
96  if(nElem != en.size())
97  {
99  "sizes of kn("<<nElem<<") and en("<<en.size()<<") do not match.\n";
100  return false;
101  }
102 
103  if(nElem != et.size())
104  {
106  "sizes of kn("<<nElem<<") and et("<<et.size()<<") do not match.\n";
107  return false;
108  }
109 
110  if(nElem != mu.size())
111  {
113  "sizes of kn("<<nElem<<") and mu("<<mu.size()<<") do not match.\n";
114  return false;
115  }
116 
117 
118  // check if size of vector matchs a symetric array
119  uint32 nMat;
120  if( !LinearArrayType::getN(nElem, nMat) )
121  {
123  "sizes of properties do not match a symetric array with size ("<<
124  numMaterial_<<"x"<<numMaterial_<<").\n";
125  return false;
126  }
127  else if( numMaterial_ != nMat)
128  {
130  "size mismatch for porperties. \n"<<
131  "you supplied "<< numMaterial_<<" items in materials list and "<<
132  nMat << " for other properties.\n";
133  return false;
134  }
135 
136  realVector etha_n(nElem);
137  realVector etha_t(nElem);
138  ForAll(i , kn)
139  {
140  etha_n[i] = -2.0*log(en[i])*sqrt(kn[i])/
141  sqrt(pow(log(en[i]),2.0)+ pow(Pi,2.0));
142 
143  etha_t[i] = -2.0*log( et[i]*sqrt(kt[i]) )/
144  sqrt(pow(log(et[i]),2.0)+ pow(Pi,2.0));
145  }
146 
147  Vector<linearProperties> prop(nElem);
148  ForAll(i,kn)
149  {
150  prop[i] = {kn[i], kt[i], etha_n[i], etha_t[i], mu[i]};
151  }
152 
154 
155  return true;
156 
157  }
158 
159  static const char* modelName()
160  {
161  if constexpr (limited)
162  {
163  return "linearLimited";
164  }
165  else
166  {
167  return "linearNonLimited";
168  }
169  return "";
170  }
171 
172 public:
173 
174 
176 
178  linear(){}
179 
180  linear(int32 nMaterial, const ViewType1D<real>& rho, const dictionary& dict)
181  :
182  numMaterial_(nMaterial),
183  rho_("rho",nMaterial),
184  linearProperties_("linearProperties",nMaterial)
185  {
186 
187  Kokkos::deep_copy(rho_,rho);
188  if(!readLinearDictionary(dict))
189  {
190  fatalExit;
191  }
192  }
193 
195  linear(const linear&) = default;
196 
198  linear(linear&&) = default;
199 
201  linear& operator=(const linear&) = default;
202 
204  linear& operator=(linear&&) = default;
205 
206 
208  ~linear()=default;
209 
212  {
213  return numMaterial_;
214  }
215 
217 
219  void contactForce
220  (
221  const real dt,
222  const int32 i,
223  const int32 j,
224  const int32 propId_i,
225  const int32 propId_j,
226  const real Ri,
227  const real Rj,
228  const real ovrlp_n,
229  const realx3& Vr,
230  const realx3& Nij,
231  contactForceStorage& history,
232  realx3& FCn,
233  realx3& FCt
234  )const
235  {
236 
237  auto prop = linearProperties_(propId_i,propId_j);
238 
239 
240  real vrn = dot(Vr, Nij);
241  realx3 Vt = Vr - vrn*Nij;
242 
243  history.overlap_t_ += Vt*dt;
244 
245  real mi = 3*Pi/4*pow(Ri,3.0)*rho_[propId_i];
246  real mj = 3*Pi/4*pow(Rj,3.0)*rho_[propId_j];
247 
248  real sqrt_meff = sqrt((mi*mj)/(mi+mj));
249 
250  FCn = (-prop.kn_ * ovrlp_n - sqrt_meff * prop.ethan_ * vrn)*Nij;
251  FCt = -prop.kt_ * history.overlap_t_ - sqrt_meff * prop.ethat_*Vt;
252 
253  real ft = length(FCt);
254  real ft_fric = prop.mu_ * length(FCn);
255 
256  if(ft > ft_fric)
257  {
258  if( length(history.overlap_t_) >static_cast<real>(0.0))
259  {
260  if constexpr (limited)
261  {
262  FCt *= (ft_fric/ft);
263  history.overlap_t_ = - (FCt/prop.kt_);
264  }
265  else
266  {
267  FCt = (FCt/ft)*ft_fric;
268  }
269  //cout<<"friction is applied here \n";
270 
271  }
272  else
273  {
274  FCt = 0.0;
275  }
276  }
277 
278  }
279 
280 };
281 
282 } //pFlow::cfModels
283 
284 #endif
pFlow::cfModels::linear::TypeInfoNV
TypeInfoNV(modelName())
pFlow::cfModels::linear::numMaterial
INLINE_FUNCTION_HD int32 numMaterial() const
Definition: linearCF.hpp:211
pFlow::real
float real
Definition: builtinTypes.hpp:46
fatalExit
#define fatalExit
Definition: error.hpp:57
types.hpp
pFlow::cfModels::linear::linearProperties_
LinearArrayType linearProperties_
Definition: linearCF.hpp:74
pFlow::cfModels::linear::contactForce
INLINE_FUNCTION_HD void contactForce(const real dt, const int32 i, const int32 j, const int32 propId_i, const int32 propId_j, const real Ri, const real Rj, const real ovrlp_n, const realx3 &Vr, const realx3 &Nij, contactForceStorage &history, realx3 &FCn, realx3 &FCt) const
Definition: linearCF.hpp:220
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:59
pFlow::cfModels::linear::readLinearDictionary
bool readLinearDictionary(const dictionary &dict)
Definition: linearCF.hpp:78
pFlow::cfModels::linear::~linear
INLINE_FUNCTION_HD ~linear()=default
pFlow::Vector::size
auto size() const
Definition: Vector.hpp:299
pFlow::cfModels::linear::numMaterial_
int32 numMaterial_
Definition: linearCF.hpp:70
pFlow::log
INLINE_FUNCTION_HD real log(real x)
Definition: math.hpp:119
pFlow::symArray< linearProperties >::getN
static bool getN(uint32 nElem, uint32 &n)
Definition: symArrayHD.hpp:240
pFlow::cfModels::linear::linearProperties::ethan_
real ethan_
Definition: linearCF.hpp:44
dot
INLINE_FUNCTION_HD T dot(const quadruple< T > &oprnd1, const quadruple< T > &oprnd2)
pFlow::symArray::assign
bool assign(const Vector< T > src)
Definition: symArrayHD.hpp:177
pFlow::cfModels::linear::linearProperties::kt_
real kt_
Definition: linearCF.hpp:43
pFlow::cfModels::linear::linearProperties::ethat_
real ethat_
Definition: linearCF.hpp:45
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
length
INLINE_FUNCTION_HD T length(const triple< T > &v1)
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::cfModels::linear::linearProperties::mu_
real mu_
Definition: linearCF.hpp:46
pFlow::pow
Vector< T, Allocator > pow(const Vector< T, Allocator > &v, T e)
Definition: VectorMath.hpp:109
pFlow::cfModels::linear::linear
linear(int32 nMaterial, const ViewType1D< real > &rho, const dictionary &dict)
Definition: linearCF.hpp:180
pFlow::cfModels::linear::linearProperties::linearProperties
INLINE_FUNCTION_HD linearProperties()
Definition: linearCF.hpp:49
pFlow::cfModels::linear::contactForceStorage
Definition: linearCF.hpp:35
pFlow::cfModels::linear::linear
INLINE_FUNCTION_HD linear()
Definition: linearCF.hpp:178
pFlow::cfModels::linear::linearProperties::kn_
real kn_
Definition: linearCF.hpp:42
ForAll
#define ForAll(i, container)
Definition: pFlowMacros.hpp:71
pFlow::dictionary::getVal
T getVal(const word &keyword) const
Definition: dictionary.hpp:309
pFlow::cfModels::linear::linearProperties::~linearProperties
INLINE_FUNCTION_HD ~linearProperties()=default
pFlow::cfModels::linear::linearProperties
Definition: linearCF.hpp:40
pFlow::cfModels::linear::linearProperties::operator=
INLINE_FUNCTION_HD linearProperties & operator=(const linearProperties &)=default
pFlow::cfModels::linear::modelName
static const char * modelName()
Definition: linearCF.hpp:159
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
Definition: KokkosTypes.hpp:62
pFlow::cfModels::linear::linearProperties::linearProperties
INLINE_FUNCTION_HD linearProperties(real kn, real kt, real etha_n, real etha_t, real mu)
Definition: linearCF.hpp:52
pFlow::Pi
const real Pi
Definition: numericConstants.hpp:32
pFlow::cfModels
Definition: linearCF.hpp:27
pFlow::cfModels::linear::rho_
ViewType1D< real > rho_
Definition: linearCF.hpp:72
pFlow::cfModels::linear::contactForceStorage::overlap_t_
realx3 overlap_t_
Definition: linearCF.hpp:37
pFlow::sqrt
INLINE_FUNCTION_HD real sqrt(real x)
Definition: math.hpp:148
pFlow::cfModels::linear::operator=
INLINE_FUNCTION_HD linear & operator=(const linear &)=default
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
pFlow::triple< real >
pFlow::Vector< real >
pFlow::cfModels::linear
Definition: linearCF.hpp:31
pFlow::symArray< linearProperties >
pFlow::dictionary
Definition: dictionary.hpp:38
symArrays.hpp