PatchInteractionModel.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-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "PatchInteractionModel.H"
30 #include "fvMesh.H"
31 #include "Time.H"
32 #include "volFields.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 template<class CloudType>
38 {
39  "rebound", "stick", "escape"
40 };
41 
42 
43 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
44 
45 template<class CloudType>
47 {
48  this->writeHeader(os, "Particle patch interaction");
49  this->writeHeaderValue(os, "Model", this->modelType());
50 
51  this->writeCommented(os, "Time");
52  this->writeTabbed(os, "escapedParcels");
53  this->writeTabbed(os, "escapedMass");
54 }
55 
56 
57 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
58 
59 template<class CloudType>
61 (
62  const interactionType& itEnum
63 )
64 {
65  word it = "other";
66 
67  switch (itEnum)
68  {
69  case itNone:
70  {
71  it = "none";
72  break;
73  }
74  case itRebound:
75  {
76  it = "rebound";
77  break;
78  }
79  case itStick:
80  {
81  it = "stick";
82  break;
83  }
84  case itEscape:
85  {
86  it = "escape";
87  break;
88  }
89  default:
90  {
91  }
92  }
93 
94  return it;
95 }
96 
97 
98 template<class CloudType>
101 (
102  const word& itWord
103 )
104 {
105  if (itWord == "none")
106  {
107  return itNone;
108  }
109  if (itWord == "rebound")
110  {
111  return itRebound;
112  }
113  else if (itWord == "stick")
114  {
115  return itStick;
116  }
117  else if (itWord == "escape")
118  {
119  return itEscape;
120  }
121  else
122  {
123  return itOther;
124  }
125 }
126 
127 
128 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
129 
130 template<class CloudType>
132 (
133  CloudType& owner
134 )
135 :
137  functionObjects::writeFile(owner, this->localPath(), typeName, false),
138  UName_("unknown_U"),
139  escapedParcels_(0),
140  escapedMass_(0.0),
141  Urmax_(1e-4)
142 {}
143 
144 
145 template<class CloudType>
147 (
148  const dictionary& dict,
149  CloudType& owner,
150  const word& type
151 )
152 :
153  CloudSubModelBase<CloudType>(owner, dict, typeName, type),
154  functionObjects::writeFile
155  (
156  owner,
157  this->localPath(),
158  type,
159  this->coeffDict(),
160  false // Do not write by default
161  ),
162  UName_(this->coeffDict().template getOrDefault<word>("U", "U")),
163  escapedParcels_(0),
164  escapedMass_(0.0),
165  Urmax_(this->coeffDict().template getOrDefault<scalar>("UrMax", 0))
166 {}
167 
168 
169 template<class CloudType>
171 (
173 )
174 :
176  functionObjects::writeFile(pim),
177  UName_(pim.UName_),
178  escapedParcels_(pim.escapedParcels_),
179  escapedMass_(pim.escapedMass_),
180  Urmax_(pim.Urmax_)
181 {}
182 
183 
184 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
185 
186 template<class CloudType>
188 {
189  return UName_;
190 }
191 
192 
193 template<class CloudType>
194 const Foam::scalar& Foam::PatchInteractionModel<CloudType>::Urmax() const
195 {
196  return Urmax_;
197 }
198 
199 
200 template<class CloudType>
202 (
203  const scalar mass
204 )
205 {
206  escapedMass_ += mass;
207  ++escapedParcels_;
208 }
209 
211 template<class CloudType>
213 {}
214 
215 
216 template<class CloudType>
218 {
220 
221  const label escapedParcels0 =
222  this->template getBaseProperty<label>("escapedParcels");
223  const label escapedParcelsTotal =
224  escapedParcels0 + returnReduce(escapedParcels_, sumOp<label>());
225 
226  const scalar escapedMass0 =
227  this->template getBaseProperty<scalar>("escapedMass");
228  const scalar escapedMassTotal =
229  escapedMass0 + returnReduce(escapedMass_, sumOp<scalar>());
230 
231  Log_<< " Parcel fate: system (number, mass)" << nl
232  << " - escape = " << escapedParcelsTotal
233  << ", " << escapedMassTotal << endl;
234 
235  if (!this->writtenHeader_)
236  {
237  this->writeFileHeader(this->file());
238  this->writtenHeader_ = true;
239  this->file() << endl;
240  }
241 
242  this->writeCurrentTime(this->file());
243  this->file()
244  << tab << escapedParcelsTotal << tab << escapedMassTotal;
245 
246 
247  if (this->writeTime())
248  {
249  this->setBaseProperty("escapedParcels", escapedParcelsTotal);
250  escapedParcels_ = 0;
251 
252  this->setBaseProperty("escapedMass", escapedMassTotal);
253  escapedMass_ = 0.0;
254  }
255 }
256 
257 
258 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
259 
261 
262 // ************************************************************************* //
PatchInteractionModel(CloudType &owner)
Construct null from owner.
dictionary dict
static word interactionTypeToWord(const interactionType &itEnum)
Convert interaction result to word.
type
Types of root.
Definition: Roots.H:52
static void writeHeader(Ostream &os, const word &fieldName)
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
constexpr char tab
The tab &#39;\t&#39; character(0x09)
Definition: Ostream.H:49
virtual void addToEscapedParcels(const scalar mass)
Add to escaped parcels.
Base class for cloud sub-models.
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
virtual void info()
Write patch interaction info.
Templated patch interaction model class.
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
#define Log_
Report write to Foam::Info if the class log switch is true.
A class for handling words, derived from Foam::string.
Definition: word.H:63
const scalar & Urmax() const
Return Urmax.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
const word & UName() const
Return name of velocity field.
virtual void writeFileHeader(Ostream &os)
Output file header information.
virtual void postEvolve()
Post-evolve hook.
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:67
static interactionType wordToInteractionType(const word &itWord)
Convert word to interaction result.