BrownianMotionForce.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "BrownianMotionForce.H"
27 #include "mathematicalConstants.H"
28 #include "demandDrivenData.H"
29 #include "turbulenceModel.H"
30 
31 using namespace Foam::constant;
32 
33 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
34 
35 template<class CloudType>
36 Foam::scalar Foam::BrownianMotionForce<CloudType>::erfInv(const scalar y) const
37 {
38  const scalar a = 0.147;
39  scalar k = 2.0/(mathematical::pi*a) + 0.5*log(1.0 - y*y);
40  scalar h = log(1.0 - y*y)/a;
41  scalar x = sqrt(-k + sqrt(k*k - h));
42 
43  if (y < 0.0)
44  {
45  return -x;
46  }
47  else
48  {
49  return x;
50  }
51 }
52 
53 
54 template<class CloudType>
57 {
58  const objectRegistry& obr = this->owner().mesh();
59  const word turbName =
61  (
63  this->owner().U().group()
64  );
65 
66  if (obr.foundObject<turbulenceModel>(turbName))
67  {
68  const turbulenceModel& model =
69  obr.lookupObject<turbulenceModel>(turbName);
70  return model.k();
71  }
72  else
73  {
75  << "Turbulence model not found in mesh database" << nl
76  << "Database objects include: " << obr.sortedToc()
77  << abort(FatalError);
78 
79  return tmp<volScalarField>(NULL);
80  }
81 }
82 
83 
84 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
85 
86 template<class CloudType>
88 (
89  CloudType& owner,
90  const fvMesh& mesh,
91  const dictionary& dict
92 )
93 :
94  ParticleForce<CloudType>(owner, mesh, dict, typeName, true),
95  rndGen_(owner.rndGen()),
96  lambda_(readScalar(this->coeffs().lookup("lambda"))),
97  turbulence_(readBool(this->coeffs().lookup("turbulence"))),
98  kPtr_(NULL),
99  ownK_(false)
100 {}
101 
102 
103 template<class CloudType>
105 (
106  const BrownianMotionForce& bmf
107 )
108 :
110  rndGen_(bmf.rndGen_),
111  lambda_(bmf.lambda_),
112  turbulence_(bmf.turbulence_),
113  kPtr_(NULL),
114  ownK_(false)
115 {}
116 
117 
118 // * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
119 
120 template<class CloudType>
122 {}
123 
124 
125 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
126 
127 template<class CloudType>
129 {
130  if (turbulence_)
131  {
132  if (store)
133  {
134  tmp<volScalarField> tk = kModel();
135  if (tk.isTmp())
136  {
137  kPtr_ = tk.ptr();
138  ownK_ = true;
139  }
140  else
141  {
142  kPtr_ = &tk();
143  ownK_ = false;
144  }
145  }
146  else
147  {
148  if (ownK_ && kPtr_)
149  {
150  deleteDemandDrivenData(kPtr_);
151  ownK_ = false;
152  }
153  }
154  }
155 }
156 
157 
158 template<class CloudType>
160 (
161  const typename CloudType::parcelType& p,
162  const scalar dt,
163  const scalar mass,
164  const scalar Re,
165  const scalar muc
166 ) const
167 {
168  forceSuSp value(Zero, 0.0);
169 
170  const scalar dp = p.d();
171  const scalar Tc = p.Tc();
172 
173  const scalar eta = rndGen_.sample01<scalar>();
174  const scalar alpha = 2.0*lambda_/dp;
175  const scalar cc = 1.0 + alpha*(1.257 + 0.4*exp(-1.1/alpha));
176 
177  const scalar sigma = physicoChemical::sigma.value();
178 
179  scalar f = 0.0;
180  if (turbulence_)
181  {
182  const label celli = p.cell();
183  const volScalarField& k = *kPtr_;
184  const scalar kc = k[celli];
185  const scalar Dp = sigma*Tc*cc/(3*mathematical::pi*muc*dp);
186  f = eta/mass*sqrt(2.0*sqr(kc)*sqr(Tc)/(Dp*dt));
187  }
188  else
189  {
190  const scalar s0 =
191  216*muc*sigma*Tc/(sqr(mathematical::pi)*pow5(dp)*sqr(p.rho())*cc);
192  f = eta*sqrt(mathematical::pi*s0/dt);
193  }
194 
195  const scalar sqrt2 = sqrt(2.0);
196  for (label i = 0; i < 3; i++)
197  {
198  const scalar x = rndGen_.sample01<scalar>();
199  const scalar eta = sqrt2*erfInv(2*x - 1.0);
200  value.Su()[i] = mass*f*eta;
201  }
202 
203  return value;
204 }
205 
206 
207 // ************************************************************************* //
Collection of constants.
const char *const group
Group name for atomic constants.
dictionary dict
U
Definition: pEqn.H:83
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
dimensionedScalar log(const dimensionedScalar &ds)
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
dimensionedSymmTensor sqr(const dimensionedVector &dv)
ThermalDiffusivity< CompressibleTurbulenceModel< fluidThermo > > turbulenceModel
dimensionedScalar sqrt(const dimensionedScalar &ds)
const dimensionedScalar sigma
Stefan-Boltzmann constant: default SI units: [W/m2/K4].
Abstract base class for particle forces.
Definition: ParticleForce.H:53
const vector & Su() const
Return const access to the explicit contribution [kg.m/s2].
Definition: forceSuSpI.H:56
const Type & value() const
Return const reference to value.
bool readBool(Istream &)
Definition: boolIO.C:60
const fvMesh & mesh() const
Return the mesh database.
dimensionedScalar pow5(const dimensionedScalar &ds)
Helper container for force Su and Sp terms.
Definition: forceSuSp.H:61
stressControl lookup("compactNormalStress") >> compactNormalStress
dynamicFvMesh & mesh
dimensionedScalar exp(const dimensionedScalar &ds)
static const word propertiesName
Default name of the turbulence properties dictionary.
static word groupName(Name name, const word &group)
static const zero Zero
Definition: zero.H:91
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
errorManip< error > abort(error &err)
Definition: errorManip.H:131
BrownianMotionForce(CloudType &owner, const fvMesh &mesh, const dictionary &dict)
Construct from mesh.
ParcelType parcelType
Type of parcel the cloud was instantiated for.
Definition: DSMCCloud.H:217
T * ptr() const
Return tmp pointer for reuse.
Definition: tmpI.H:198
static const char nl
Definition: Ostream.H:262
labelList f(nPoints)
virtual void cacheFields(const bool store)
Cache fields.
Template functions to aid in the implementation of demand driven data.
virtual forceSuSp calcCoupled(const typename CloudType::parcelType &p, const scalar dt, const scalar mass, const scalar Re, const scalar muc) const
Calculate the coupled force.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
bool isTmp() const
Return true if this is really a temporary object.
Definition: tmpI.H:146
virtual ~BrownianMotionForce()
Destructor.
A class for managing temporary objects.
Definition: PtrList.H:54
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
void deleteDemandDrivenData(DataPtr &dataPtr)
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:68
Calculates particle Brownian motion force.