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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "BrownianMotionForce.H"
29 #include "mathematicalConstants.H"
30 #include "fundamentalConstants.H"
31 #include "demandDrivenData.H"
32 #include "turbulenceModel.H"
33 
34 using namespace Foam::constant;
35 
36 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
37 
38 template<class CloudType>
39 Foam::scalar Foam::BrownianMotionForce<CloudType>::erfInv(const scalar y) const
40 {
41  const scalar a = 0.147;
42  scalar k = 2.0/(mathematical::pi*a) + 0.5*log(1.0 - y*y);
43  scalar h = log(1.0 - y*y)/a;
44  scalar x = sqrt(-k + sqrt(k*k - h));
45 
46  if (y < 0.0)
47  {
48  return -x;
49  }
50  else
51  {
52  return x;
53  }
54 }
55 
56 
57 template<class CloudType>
60 {
61  const objectRegistry& obr = this->owner().mesh();
62  const word turbName =
64  (
66  this->owner().U().group()
67  );
68 
69  const turbulenceModel* turb = obr.findObject<turbulenceModel>(turbName);
70 
71  if (turb)
72  {
73  return turb->k();
74  }
75 
77  << "Turbulence model not found in mesh database" << nl
78  << "Database objects include: " << obr.sortedToc()
79  << abort(FatalError);
80 
81  return nullptr;
82 }
83 
84 
85 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
86 
87 template<class CloudType>
89 (
90  CloudType& owner,
91  const fvMesh& mesh,
92  const dictionary& dict
93 )
94 :
95  ParticleForce<CloudType>(owner, mesh, dict, typeName, true),
96  rndGen_(owner.rndGen()),
97  lambda_(this->coeffs().getScalar("lambda")),
98  turbulence_(this->coeffs().getBool("turbulence")),
99  kPtr_(nullptr),
100  ownK_(false)
101 {}
102 
103 
104 template<class CloudType>
106 (
107  const BrownianMotionForce& bmf
108 )
109 :
111  rndGen_(bmf.rndGen_),
112  lambda_(bmf.lambda_),
113  turbulence_(bmf.turbulence_),
114  kPtr_(nullptr),
115  ownK_(false)
116 {}
117 
118 
119 // * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
120 
121 template<class CloudType>
123 {}
124 
125 
126 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
127 
128 template<class CloudType>
130 {
131  if (turbulence_)
132  {
133  if (store)
134  {
135  tmp<volScalarField> tk = kModel();
136  if (tk.isTmp())
137  {
138  kPtr_ = tk.ptr();
139  ownK_ = true;
140  }
141  else
142  {
143  kPtr_ = &tk();
144  ownK_ = false;
145  }
146  }
147  else
148  {
149  if (ownK_ && kPtr_)
150  {
151  deleteDemandDrivenData(kPtr_);
152  ownK_ = false;
153  }
154  }
155  }
156 }
157 
158 
159 template<class CloudType>
161 (
162  const typename CloudType::parcelType& p,
163  const typename CloudType::parcelType::trackingData& td,
164  const scalar dt,
165  const scalar mass,
166  const scalar Re,
167  const scalar muc
168 ) const
169 {
170  forceSuSp value(Zero);
171 
172  const scalar dp = p.d();
173  const scalar Tc = td.Tc();
174 
175  const scalar alpha = 2.0*lambda_/dp;
176  const scalar cc = 1.0 + alpha*(1.257 + 0.4*exp(-1.1/alpha));
177 
178  // Boltzmann constant
179  const scalar kb = physicoChemical::k.value();
180 
181  scalar f = 0;
182  if (turbulence_)
183  {
184  const label celli = p.cell();
185  const volScalarField& k = *kPtr_;
186  const scalar kc = k[celli];
187  const scalar Dp = kb*Tc*cc/(3*mathematical::pi*muc*dp);
188  f = sqrt(2.0*sqr(kc)*sqr(Tc)/(Dp*dt));
189  }
190  else
191  {
192  const scalar s0 =
193  216*muc*kb*Tc/(sqr(mathematical::pi)*pow5(dp)*sqr(p.rho())*cc);
194  f = mass*sqrt(mathematical::pi*s0/dt);
195  }
196 
197 
198  // To generate a cubic distribution (3 independent directions) :
199  // const scalar sqrt2 = sqrt(2.0);
200  // for (direction dir = 0; dir < vector::nComponents; dir++)
201  // {
202  // const scalar x = rndGen_.sample01<scalar>();
203  // const scalar eta = sqrt2*erfInv(2*x - 1.0);
204  // value.Su()[dir] = f*eta;
205  // }
206 
207 
208  // To generate a spherical distribution:
209 
210  Random& rnd = this->owner().rndGen();
211 
212  const scalar theta = rnd.sample01<scalar>()*twoPi;
213  const scalar u = 2*rnd.sample01<scalar>() - 1;
214 
215  const scalar a = sqrt(1 - sqr(u));
216  const vector dir(a*cos(theta), a*sin(theta), u);
217 
218  value.Su() = f*mag(rnd.GaussNormal<scalar>())*dir;
219 
220  return value;
221 }
222 
223 
224 // ************************************************************************* //
Foam::Random
Random number generator.
Definition: Random.H:59
mathematicalConstants.H
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::Random::GaussNormal
Type GaussNormal()
Definition: RandomTemplates.C:49
Foam::BrownianMotionForce::BrownianMotionForce
BrownianMotionForce(CloudType &owner, const fvMesh &mesh, const dictionary &dict)
Construct from mesh.
Definition: BrownianMotionForce.C:89
Foam::constant::atomic::group
constexpr const char *const group
Group name for atomic constants.
Definition: atomicConstants.H:52
Foam::constant::physicoChemical::k
const dimensionedScalar k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::BrownianMotionForce::calcCoupled
virtual forceSuSp calcCoupled(const typename CloudType::parcelType &p, const typename CloudType::parcelType::trackingData &td, const scalar dt, const scalar mass, const scalar Re, const scalar muc) const
Calculate the coupled force.
Definition: BrownianMotionForce.C:161
Foam::constant
Different types of constants.
Definition: atomicConstants.C:38
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::constant::atomic::alpha
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
Definition: readThermalProperties.H:212
Foam::sin
dimensionedScalar sin(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:264
Foam::BrownianMotionForce::~BrownianMotionForce
virtual ~BrownianMotionForce()
Destructor.
Definition: BrownianMotionForce.C:122
Foam::Random::sample01
Type sample01()
Return a sample whose components lie in the range [0,1].
Definition: RandomTemplates.C:36
Foam::turbulenceModel::propertiesName
static const word propertiesName
Default name of the turbulence properties dictionary.
Definition: turbulenceModel.H:100
Foam::BrownianMotionForce::cacheFields
virtual void cacheFields(const bool store)
Cache fields.
Definition: BrownianMotionForce.C:129
Foam::tmp::isTmp
bool isTmp() const noexcept
Identical to is_pointer()
Definition: tmp.H:181
Foam::dimensioned::value
const Type & value() const
Return const reference to value.
Definition: dimensionedType.C:434
Foam::exp
dimensionedScalar exp(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:261
Foam::forceSuSp::Su
const vector & Su() const
Return const access to the explicit contribution [kg.m/s2].
Definition: forceSuSpI.H:61
Foam::DSMCCloud::rndGen
Random & rndGen()
Return reference to the random object.
Definition: DSMCCloudI.H:124
Foam::deleteDemandDrivenData
void deleteDemandDrivenData(DataPtr &dataPtr)
Definition: demandDrivenData.H:42
Foam::compressible::turbulenceModel
ThermalDiffusivity< CompressibleTurbulenceModel< fluidThermo > > turbulenceModel
Definition: turbulentFluidThermoModel.H:63
Foam::constant::universal::h
const dimensionedScalar h
Planck constant.
Definition: setRegionSolidFields.H:33
Foam::DSMCCloud::mesh
const fvMesh & mesh() const
Return reference to the mesh.
Definition: DSMCCloudI.H:44
Foam::forceSuSp
Helper container for force Su and Sp terms.
Definition: forceSuSp.H:64
Foam::ParticleForce
Abstract base class for particle forces.
Definition: ParticleForce.H:59
Foam::DSMCCloud
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:71
Foam::constant::mathematical::twoPi
constexpr scalar twoPi(2 *M_PI)
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::pow5
dimensionedScalar pow5(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:111
Foam::log
dimensionedScalar log(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:262
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:83
Foam::tmp::ptr
T * ptr() const
Return managed pointer for reuse, or clone() the object reference.
Definition: tmpI.H:259
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::BrownianMotionForce
Calculates particle Brownian motion force.
Definition: BrownianMotionForce.H:62
U
U
Definition: pEqn.H:72
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::constant::mathematical::pi
constexpr scalar pi(M_PI)
Foam::nl
constexpr char nl
Definition: Ostream.H:385
f
labelList f(nPoints)
Foam::Vector< scalar >
fundamentalConstants.H
Fundamental dimensioned constants.
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:144
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
k
label k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
Foam::Re
scalarField Re(const UList< complex > &cf)
Extract real component.
Definition: complexField.C:159
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::DSMCCloud::parcelType
ParcelType parcelType
Type of parcel the cloud was instantiated for.
Definition: DSMCCloud.H:220
Foam::ParticleForce::mesh
const fvMesh & mesh() const
Return the mesh database.
Definition: ParticleForceI.H:45
Foam::IOobject::groupName
static word groupName(StringType base, const word &group)
Create dot-delimited name.group string.
kb
scalar kb
Definition: solveBulkSurfactant.H:7
Foam::GeometricField< scalar, fvPatchField, volMesh >
turb
compressible::turbulenceModel & turb
Definition: setRegionFluidFields.H:10
turbulenceModel.H
BrownianMotionForce.H
y
scalar y
Definition: LISASMDCalcMethod1.H:14
Foam::cos
dimensionedScalar cos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:265