DSMCParcel.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-2022 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 "DSMCParcel.H"
27 #include "meshTools.H"
28 
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 
31 template<class ParcelType>
32 template<class TrackCloudType>
34 (
35  TrackCloudType& cloud,
36  trackingData& td,
37  const scalar trackTime
38 )
39 {
40  typename TrackCloudType::parcelType& p =
41  static_cast<typename TrackCloudType::parcelType&>(*this);
42 
43  td.keepParticle = true;
44  td.sendToProc = -1;
45 
46  const polyMesh& mesh = cloud.pMesh();
47 
48  // For reduced-D cases, the velocity used to track needs to be
49  // constrained, but the actual U_ of the parcel must not be
50  // altered or used, as it is altered by patch interactions an
51  // needs to retain its 3D value for collision purposes.
52  vector Utracking = U_;
53 
54  while (td.keepParticle && td.sendToProc == -1 && p.stepFraction() < 1)
55  {
56  Utracking = U_;
57 
58  // Apply correction to velocity to constrain tracking for
59  // reduced-D cases
60  meshTools::constrainDirection(mesh, mesh.solutionD(), Utracking);
61 
62  // Deviation from the mesh centre for reduced-D cases
63  const vector d = p.deviationFromMeshCentre();
64 
65  const scalar f = 1 - p.stepFraction();
66  p.trackToAndHitFace(f*trackTime*Utracking - d, f, cloud, td);
67  }
68 
69  return td.keepParticle;
70 }
71 
72 
73 template<class ParcelType>
74 template<class TrackCloudType>
76 (
77  TrackCloudType& cloud,
79 )
80 {
81  const label wppIndex = this->patch();
82 
83  const wallPolyPatch& wpp =
84  static_cast<const wallPolyPatch&>
85  (
86  this->mesh().boundaryMesh()[wppIndex]
87  );
88 
89  const label wppLocalFace = wpp.whichFace(this->face());
90 
91  const scalar fA = wpp.magFaceAreas()[wppLocalFace];
92 
93  const scalar deltaT = cloud.pMesh().time().deltaTValue();
94 
95  const constantProperties& constProps(cloud.constProps(typeId_));
96 
97  scalar m = constProps.mass();
98 
99  vector nw = wpp.faceAreas()[wppLocalFace];
100  nw /= mag(nw);
101 
102  scalar U_dot_nw = U_ & nw;
103 
104  vector Ut = U_ - U_dot_nw*nw;
105 
106  scalar invMagUnfA = 1/max(mag(U_dot_nw)*fA, vSmall);
107 
108  cloud.rhoNBF()[wppIndex][wppLocalFace] += invMagUnfA;
109 
110  cloud.rhoMBF()[wppIndex][wppLocalFace] += m*invMagUnfA;
111 
112  cloud.linearKEBF()[wppIndex][wppLocalFace] +=
113  0.5*m*(U_ & U_)*invMagUnfA;
114 
115  cloud.internalEBF()[wppIndex][wppLocalFace] += Ei_*invMagUnfA;
116 
117  cloud.iDofBF()[wppIndex][wppLocalFace] +=
118  constProps.internalDegreesOfFreedom()*invMagUnfA;
119 
120  cloud.momentumBF()[wppIndex][wppLocalFace] += m*Ut*invMagUnfA;
121 
122  // pre-interaction energy
123  scalar preIE = 0.5*m*(U_ & U_) + Ei_;
124 
125  // pre-interaction momentum
126  vector preIMom = m*U_;
127 
128  cloud.wallInteraction().correct(*this);
129 
130  U_dot_nw = U_ & nw;
131 
132  Ut = U_ - U_dot_nw*nw;
133 
134  invMagUnfA = 1/max(mag(U_dot_nw)*fA, vSmall);
135 
136  cloud.rhoNBF()[wppIndex][wppLocalFace] += invMagUnfA;
137 
138  cloud.rhoMBF()[wppIndex][wppLocalFace] += m*invMagUnfA;
139 
140  cloud.linearKEBF()[wppIndex][wppLocalFace] +=
141  0.5*m*(U_ & U_)*invMagUnfA;
142 
143  cloud.internalEBF()[wppIndex][wppLocalFace] += Ei_*invMagUnfA;
144 
145  cloud.iDofBF()[wppIndex][wppLocalFace] +=
146  constProps.internalDegreesOfFreedom()*invMagUnfA;
147 
148  cloud.momentumBF()[wppIndex][wppLocalFace] += m*Ut*invMagUnfA;
149 
150  // post-interaction energy
151  scalar postIE = 0.5*m*(U_ & U_) + Ei_;
152 
153  // post-interaction momentum
154  vector postIMom = m*U_;
155 
156  scalar deltaQ = cloud.nParticle()*(preIE - postIE)/(deltaT*fA);
157 
158  vector deltaFD = cloud.nParticle()*(preIMom - postIMom)/(deltaT*fA);
159 
160  cloud.qBF()[wppIndex][wppLocalFace] += deltaQ;
161 
162  cloud.fDBF()[wppIndex][wppLocalFace] += deltaFD;
163 }
164 
165 
166 template<class ParcelType>
168 (
169  const transformer& transform
170 )
171 {
172  ParcelType::transformProperties(transform);
173  U_ = transform.transform(U_);
174 }
175 
176 
177 // * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * //
178 
179 #include "DSMCParcelIO.C"
180 
181 // ************************************************************************* //
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
Vector-tensor class used to perform translations, rotations and scaling operations in 3D space...
Definition: transformer.H:83
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
const Vector< label > & solutionD() const
Return the vector of solved-for directions in mesh.
Definition: polyMesh.C:911
fvMesh & mesh
void hitWallPatch(TrackCloudType &, trackingData &)
Overridable function to handle the particle hitting a wallPatch.
Definition: DSMCParcel.C:76
Class to hold DSMC particle constant properties.
Definition: DSMCParcel.H:80
Foam::wallPolyPatch.
Definition: wallPolyPatch.H:48
scalar mass() const
Return const access to the particle mass [kg].
Definition: DSMCParcelI.H:96
const vectorField::subField faceAreas() const
Return face areas.
Definition: polyPatch.C:309
labelList f(nPoints)
bool move(TrackCloudType &cloud, trackingData &td, const scalar trackTime)
Move the parcel.
Definition: DSMCParcel.C:34
const scalarField::subField magFaceAreas() const
Return face area magnitudes.
Definition: polyPatch.C:315
virtual void transformProperties(const transformer &)
Transform the physical properties of the particle.
Definition: DSMCParcel.C:168
ParcelType::trackingData trackingData
Use base tracking data.
Definition: DSMCParcel.H:130
dimensioned< scalar > mag(const dimensioned< Type > &)
Type transform(const Type &) const
Transform the given type.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
void constrainDirection(const polyMesh &mesh, const Vector< label > &dirs, vector &d)
Set the constrained components of directions/velocity to zero.
Definition: meshTools.C:671
volScalarField & p
label nw
Definition: createFields.H:12
label whichFace(const label l) const
Return label of face in patch from global face label.
Definition: polyPatch.H:386