MixedDiffuseSpecular.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2024 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 "MixedDiffuseSpecular.H"
27 #include "standardNormal.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class CloudType>
33 (
34  const dictionary& dict,
36 )
37 :
39  diffuseFraction_
40  (
41  this->coeffDict().template lookup<scalar>("diffuseFraction")
42  )
43 {}
44 
45 
46 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
47 
48 template<class CloudType>
50 {}
51 
52 
53 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
54 
55 template<class CloudType>
57 (
58  typename CloudType::parcelType& p
59 )
60 {
61  const polyMesh& mesh = this->owner().mesh();
62 
63  vector& U = p.U();
64 
65  scalar& Ei = p.Ei();
66 
67  label typeId = p.typeId();
68 
69  const label wppIndex = p.patch(mesh);
70 
71  const polyPatch& wpp = mesh.boundaryMesh()[wppIndex];
72 
73  label wppLocalFace = wpp.whichFace(p.face());
74 
75  const vector nw = p.normal(mesh);
76 
77  // Normal velocity magnitude
78  scalar U_dot_nw = U & nw;
79 
80  CloudType& cloud(this->owner());
81 
82  randomGenerator& rndGen = cloud.rndGen();
83  distributions::standardNormal& stdNormal = cloud.stdNormal();
84 
85  if (diffuseFraction_ > rndGen.scalar01())
86  {
87  // Diffuse reflection
88 
89  // Wall tangential velocity (flow direction)
90  vector Ut = U - U_dot_nw*nw;
91 
92  while (mag(Ut) < small)
93  {
94  // If the incident velocity is parallel to the face normal, no
95  // tangential direction can be chosen. Add a perturbation to the
96  // incoming velocity and recalculate.
97 
98  U = vector
99  (
100  U.x()*(0.8 + 0.2*rndGen.scalar01()),
101  U.y()*(0.8 + 0.2*rndGen.scalar01()),
102  U.z()*(0.8 + 0.2*rndGen.scalar01())
103  );
104 
105  U_dot_nw = U & nw;
106 
107  Ut = U - U_dot_nw*nw;
108  }
109 
110  // Wall tangential unit vector
111  vector tw1 = Ut/mag(Ut);
112 
113  // Other tangential unit vector
114  vector tw2 = nw^tw1;
115 
116  scalar T = cloud.boundaryT().boundaryField()[wppIndex][wppLocalFace];
117 
118  scalar mass = cloud.constProps(typeId).mass();
119 
120  direction iDof = cloud.constProps(typeId).internalDegreesOfFreedom();
121 
122  U =
123  sqrt(physicoChemical::k.value()*T/mass)
124  *(
125  stdNormal.sample()*tw1
126  + stdNormal.sample()*tw2
127  - sqrt(-2.0*log(max(1 - rndGen.scalar01(), vSmall)))*nw
128  );
129 
130  U += cloud.boundaryU().boundaryField()[wppIndex][wppLocalFace];
131 
132  Ei = cloud.equipartitionInternalEnergy(T, iDof);
133  }
134  else
135  {
136  // Specular reflection
137 
138  if (U_dot_nw > 0.0)
139  {
140  U -= 2.0*U_dot_nw*nw;
141  }
142  }
143 
144 }
145 
146 
147 // ************************************************************************* //
label k
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:80
ParcelType parcelType
Type of parcel the cloud was instantiated for.
Definition: DSMCCloud.H:225
virtual ~MixedDiffuseSpecular()
Destructor.
virtual void correct(typename CloudType::parcelType &p)
Apply wall correction.
MixedDiffuseSpecular(const dictionary &dict, CloudType &cloud)
Construct from dictionary.
Templated wall interaction model class.
A cloud is a collection of lagrangian particles.
Definition: cloud.H:55
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Standard normal distribution. Not selectable.
virtual scalar sample() const
Sample the distribution.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:404
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:70
label whichFace(const label l) const
Return label of face in patch from global face label.
Definition: polyPatch.H:360
Random number generator.
scalar scalar01()
Return a scalar uniformly distributed between zero and one.
U
Definition: pEqn.H:72
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)
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< scalar > mag(const dimensioned< Type > &)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
uint8_t direction
Definition: direction.H:45
dictionary dict
randomGenerator rndGen(653213)
volScalarField & p