www.cemf.ir
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("etha_n", nElem);
137  realVector etha_t("etha_t", nElem);
138 
139  ForAll(i , kn)
140  {
141  etha_n[i] = -2.0*log(en[i])*sqrt(kn[i])/
142  sqrt(pow(log(en[i]),2.0)+ pow(Pi,2.0));
143 
144  etha_t[i] = -2.0*log( et[i]*sqrt(kt[i]) )/
145  sqrt(pow(log(et[i]),2.0)+ pow(Pi,2.0));
146  }
147 
148  Vector<linearProperties> prop("prop", nElem);
149  ForAll(i,kn)
150  {
151  prop[i] = {kn[i], kt[i], etha_n[i], etha_t[i], mu[i]};
152  }
153 
155 
156  return true;
157 
158  }
159 
160  static const char* modelName()
161  {
162  if constexpr (limited)
163  {
164  return "linearLimited";
165  }
166  else
167  {
168  return "linearNonLimited";
169  }
170  return "";
171  }
172 
173 public:
174 
175 
177 
179  linear(){}
180 
181  linear(int32 nMaterial, const ViewType1D<real>& rho, const dictionary& dict)
182  :
183  numMaterial_(nMaterial),
184  rho_("rho",nMaterial),
185  linearProperties_("linearProperties",nMaterial)
186  {
187 
188  Kokkos::deep_copy(rho_,rho);
189  if(!readLinearDictionary(dict))
190  {
191  fatalExit;
192  }
193  }
194 
196  linear(const linear&) = default;
197 
199  linear(linear&&) = default;
200 
202  linear& operator=(const linear&) = default;
203 
205  linear& operator=(linear&&) = default;
206 
207 
209  ~linear()=default;
210 
213  {
214  return numMaterial_;
215  }
216 
218 
220  void contactForce
221  (
222  const real dt,
223  const uint32 i,
224  const uint32 j,
225  const uint32 propId_i,
226  const uint32 propId_j,
227  const real Ri,
228  const real Rj,
229  const real ovrlp_n,
230  const realx3& Vr,
231  const realx3& Nij,
232  contactForceStorage& history,
233  realx3& FCn,
234  realx3& FCt
235  )const
236  {
237 
238  auto prop = linearProperties_(propId_i,propId_j);
239 
240 
241  real vrn = dot(Vr, Nij);
242  realx3 Vt = Vr - vrn*Nij;
243 
244  history.overlap_t_ += Vt*dt;
245 
246  real mi = 3*Pi/4*pow(Ri,3.0)*rho_[propId_i];
247  real mj = 3*Pi/4*pow(Rj,3.0)*rho_[propId_j];
248 
249  real sqrt_meff = sqrt((mi*mj)/(mi+mj));
250 
251  FCn = (-prop.kn_ * ovrlp_n - sqrt_meff * prop.ethan_ * vrn)*Nij;
252  FCt = -prop.kt_ * history.overlap_t_ - sqrt_meff * prop.ethat_*Vt;
253 
254  real ft = length(FCt);
255  real ft_fric = prop.mu_ * length(FCn);
256 
257  if(ft > ft_fric)
258  {
259  if( length(history.overlap_t_) >static_cast<real>(0.0))
260  {
261  if constexpr (limited)
262  {
263  FCt *= (ft_fric/ft);
264  history.overlap_t_ = - (FCt/prop.kt_);
265  }
266  else
267  {
268  FCt = (FCt/ft)*ft_fric;
269  }
270  //cout<<"friction is applied here \n";
271 
272  }
273  else
274  {
275  FCt = 0.0;
276  }
277  }
278 
279  }
280 
281 };
282 
283 } //pFlow::cfModels
284 
285 #endif
pFlow::cfModels::linear::TypeInfoNV
TypeInfoNV(modelName())
pFlow::cfModels::linear::numMaterial
INLINE_FUNCTION_HD int32 numMaterial() const
Definition: linearCF.hpp:212
pFlow::real
float real
Definition: builtinTypes.hpp:45
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::pow
Vector< T, Allocator > pow(const Vector< T, Allocator > &v1, const Vector< T, Allocator > &v2)
Definition: VectorMath.hpp:89
pFlow::sqrt
Vector< T, Allocator > sqrt(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:90
types.hpp
pFlow::cfModels::linear::linearProperties_
LinearArrayType linearProperties_
Definition: linearCF.hpp:74
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::cfModels::linear::contactForce
INLINE_FUNCTION_HD void contactForce(const real dt, const uint32 i, const uint32 j, const uint32 propId_i, const uint32 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:221
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
Size of the vector.
Definition: Vector.hpp:265
pFlow::cfModels::linear::numMaterial_
int32 numMaterial_
Definition: linearCF.hpp:70
pFlow::symArray< linearProperties >::getN
static bool getN(uint32 nElem, uint32 &n)
Definition: symArrayHD.hpp:238
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:175
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
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
length
INLINE_FUNCTION_HD T length(const triple< T > &v1)
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::cfModels::linear::linearProperties::mu_
real mu_
Definition: linearCF.hpp:46
pFlow::log
Vector< T, Allocator > log(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:87
pFlow::cfModels::linear::linear
linear(int32 nMaterial, const ViewType1D< real > &rho, const dictionary &dict)
Definition: linearCF.hpp:181
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:179
pFlow::cfModels::linear::linearProperties::kn_
real kn_
Definition: linearCF.hpp:42
ForAll
#define ForAll(i, container)
Definition: pFlowMacros.hpp:75
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
1D veiw as a vector
Definition: KokkosTypes.hpp:93
pFlow::dictionary::getVal
T getVal(const word &keyword) const
get the value of data entry
Definition: dictionary.hpp:379
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:160
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:30
pFlow::cfModels
Definition: cGAbsoluteLinearCF.hpp:34
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::cfModels::linear::operator=
INLINE_FUNCTION_HD linear & operator=(const linear &)=default
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:55
pFlow::triple< real >
pFlow::Vector< real >
pFlow::cfModels::linear
Definition: linearCF.hpp:31
pFlow::symArray< linearProperties >
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
symArrays.hpp