ParticleTrap.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) 2012-2020 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 "ParticleTrap.H"
27 #include "fvcGrad.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class CloudType>
33 (
34  const dictionary& dict,
35  CloudType& owner,
36  const word& modelName
37 )
38 :
39  CloudFunctionObject<CloudType>(dict, owner, modelName, typeName),
40  alphaName_
41  (
42  this->coeffDict().template lookupOrDefault<word>("alpha", "alpha")
43  ),
44  alphaPtr_(nullptr),
45  gradAlphaPtr_(nullptr),
46  threshold_(this->coeffDict().template lookup<scalar>("threshold"))
47 {}
48 
49 
50 template<class CloudType>
52 (
53  const ParticleTrap<CloudType>& pt
54 )
55 :
57  alphaName_(pt.alphaName_),
58  alphaPtr_(pt.alphaPtr_),
59  gradAlphaPtr_(nullptr),
60  threshold_(pt.threshold_)
61 {}
62 
63 
64 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
65 
66 template<class CloudType>
68 {}
69 
70 
71 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
72 
73 template<class CloudType>
75 {
76  if (alphaPtr_ == nullptr)
77  {
78  const fvMesh& mesh = this->owner().mesh();
79  const volScalarField& alpha =
80  mesh.lookupObject<volScalarField>(alphaName_);
81 
82  alphaPtr_ = &alpha;
83  }
84 
85  if (gradAlphaPtr_.valid())
86  {
87  gradAlphaPtr_() == fvc::grad(*alphaPtr_);
88  }
89  else
90  {
91  gradAlphaPtr_.reset(new volVectorField(fvc::grad(*alphaPtr_)));
92  }
93 }
94 
95 
96 template<class CloudType>
98 {
99  gradAlphaPtr_.clear();
100 }
101 
102 
103 template<class CloudType>
105 (
106  parcelType& p,
107  const scalar,
108  const point&,
109  bool&
110 )
111 {
112  if (alphaPtr_->primitiveField()[p.cell()] < threshold_)
113  {
114  const vector& gradAlpha = gradAlphaPtr_()[p.cell()];
115  vector nHat = gradAlpha/mag(gradAlpha);
116  scalar nHatU = nHat & p.U();
117 
118  if (nHatU < 0)
119  {
120  p.U() -= 2*nHat*nHatU;
121  }
122  }
123 }
124 
125 
126 // ************************************************************************* //
virtual void preEvolve()
Pre-evolve hook.
Definition: ParticleTrap.C:74
dictionary dict
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcGrad.C:52
ParticleTrap(const dictionary &dict, CloudType &owner, const word &modelName)
Construct from dictionary.
Definition: ParticleTrap.C:33
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
volScalarField alpha(IOobject("alpha", runTime.timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
GeometricField< vector, fvPatchField, volMesh > volVectorField
Definition: volFieldsFwd.H:59
fvMesh & mesh
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
Calculate the gradient of the given field.
A class for handling words, derived from string.
Definition: word.H:59
virtual void postEvolve()
Post-evolve hook.
Definition: ParticleTrap.C:97
virtual ~ParticleTrap()
Destructor.
Definition: ParticleTrap.C:67
virtual void postMove(typename CloudType::parcelType &p, const scalar dt, const point &position0, bool &keepParticle)
Post-move hook.
Definition: ParticleTrap.C:105
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:95
dimensioned< scalar > mag(const dimensioned< Type > &)
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:75
Traps particles within a given phase fraction for multi-phase cases.
Definition: ParticleTrap.H:61
Templated cloud function object base class.