LocalInteraction.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 | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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 "LocalInteraction.H"
27 
28 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
29 
30 template<class CloudType>
32 (
33  const dictionary& dict,
35 )
36 :
38  patchData_(cloud.mesh(), this->coeffDict()),
39  nEscape_(patchData_.size(), 0),
40  massEscape_(patchData_.size(), 0.0),
41  nStick_(patchData_.size(), 0),
42  massStick_(patchData_.size(), 0.0),
43  writeFields_(this->coeffDict().lookupOrDefault("writeFields", false)),
44  massEscapePtr_(NULL),
45  massStickPtr_(NULL)
46 {
47  if (writeFields_)
48  {
49  word massEscapeName(this->owner().name() + ":massEscape");
50  word massStickName(this->owner().name() + ":massStick");
51  Info<< " Interaction fields will be written to " << massEscapeName
52  << " and " << massStickName << endl;
53 
54  (void)massEscape();
55  (void)massStick();
56  }
57  else
58  {
59  Info<< " Interaction fields will not be written" << endl;
60  }
61 
62  // check that interactions are valid/specified
63  forAll(patchData_, patchI)
64  {
65  const word& interactionTypeName =
66  patchData_[patchI].interactionTypeName();
68  this->wordToInteractionType(interactionTypeName);
69 
71  {
72  const word& patchName = patchData_[patchI].patchName();
74  << "Unknown patch interaction type "
75  << interactionTypeName << " for patch " << patchName
76  << ". Valid selections are:"
78  << nl << exit(FatalError);
79  }
80  }
81 }
82 
83 
84 template<class CloudType>
86 (
88 )
89 :
91  patchData_(pim.patchData_),
92  nEscape_(pim.nEscape_),
93  massEscape_(pim.massEscape_),
94  nStick_(pim.nStick_),
95  massStick_(pim.massStick_),
96  writeFields_(pim.writeFields_),
97  massEscapePtr_(NULL),
98  massStickPtr_(NULL)
99 {}
100 
101 
102 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
103 
104 template<class CloudType>
106 {}
107 
108 
109 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
110 
111 template<class CloudType>
113 {
114  if (!massEscapePtr_.valid())
115  {
116  const fvMesh& mesh = this->owner().mesh();
117 
118  massEscapePtr_.reset
119  (
120  new volScalarField
121  (
122  IOobject
123  (
124  this->owner().name() + ":massEscape",
125  mesh.time().timeName(),
126  mesh,
127  IOobject::READ_IF_PRESENT,
128  IOobject::AUTO_WRITE
129  ),
130  mesh,
131  dimensionedScalar("zero", dimMass, 0.0)
132  )
133  );
134  }
135 
136  return massEscapePtr_();
137 }
138 
139 
140 template<class CloudType>
142 {
143  if (!massStickPtr_.valid())
144  {
145  const fvMesh& mesh = this->owner().mesh();
146 
147  massStickPtr_.reset
148  (
149  new volScalarField
150  (
151  IOobject
152  (
153  this->owner().name() + ":massStick",
154  mesh.time().timeName(),
155  mesh,
156  IOobject::READ_IF_PRESENT,
157  IOobject::AUTO_WRITE
158  ),
159  mesh,
160  dimensionedScalar("zero", dimMass, 0.0)
161  )
162  );
163  }
164 
165  return massStickPtr_();
166 }
167 
168 
169 template<class CloudType>
171 (
172  typename CloudType::parcelType& p,
173  const polyPatch& pp,
174  bool& keepParticle,
175  const scalar trackFraction,
176  const tetIndices& tetIs
177 )
178 {
179  label patchI = patchData_.applyToPatch(pp.index());
180 
181  if (patchI >= 0)
182  {
183  vector& U = p.U();
184  bool& active = p.active();
185 
187  this->wordToInteractionType
188  (
189  patchData_[patchI].interactionTypeName()
190  );
191 
192  switch (it)
193  {
195  {
196  scalar dm = p.mass()*p.nParticle();
197 
198  keepParticle = false;
199  active = false;
200  U = vector::zero;
201  nEscape_[patchI]++;
202  massEscape_[patchI] += dm;
203  if (writeFields_)
204  {
205  label pI = pp.index();
206  label fI = pp.whichFace(p.face());
207  massEscape().boundaryField()[pI][fI] += dm;
208  }
209  break;
210  }
212  {
213  scalar dm = p.mass()*p.nParticle();
214 
215  keepParticle = true;
216  active = false;
217  U = vector::zero;
218  nStick_[patchI]++;
219  massStick_[patchI] += dm;
220  if (writeFields_)
221  {
222  label pI = pp.index();
223  label fI = pp.whichFace(p.face());
224  massStick().boundaryField()[pI][fI] += dm;
225  }
226  break;
227  }
229  {
230  keepParticle = true;
231  active = true;
232 
233  vector nw;
234  vector Up;
235 
236  this->owner().patchData(p, pp, trackFraction, tetIs, nw, Up);
237 
238  // Calculate motion relative to patch velocity
239  U -= Up;
240 
241  scalar Un = U & nw;
242  vector Ut = U - Un*nw;
243 
244  if (Un > 0)
245  {
246  U -= (1.0 + patchData_[patchI].e())*Un*nw;
247  }
248 
249  U -= patchData_[patchI].mu()*Ut;
250 
251  // Return velocity to global space
252  U += Up;
253 
254  break;
255  }
256  default:
257  {
259  << "Unknown interaction type "
260  << patchData_[patchI].interactionTypeName()
261  << "(" << it << ") for patch "
262  << patchData_[patchI].patchName()
263  << ". Valid selections are:" << this->interactionTypeNames_
264  << endl << abort(FatalError);
265  }
266  }
267 
268  return true;
269  }
270 
271  return false;
272 }
273 
274 
275 template<class CloudType>
277 {
279 
280  // retrieve any stored data
281  labelList npe0(patchData_.size(), 0);
282  this->getModelProperty("nEscape", npe0);
283 
284  scalarList mpe0(patchData_.size(), 0.0);
285  this->getModelProperty("massEscape", mpe0);
286 
287  labelList nps0(patchData_.size(), 0);
288  this->getModelProperty("nStick", nps0);
289 
290  scalarList mps0(patchData_.size(), 0.0);
291  this->getModelProperty("massStick", mps0);
292 
293  // accumulate current data
294  labelList npe(nEscape_);
295  Pstream::listCombineGather(npe, plusEqOp<label>());
296  npe = npe + npe0;
297 
298  scalarList mpe(massEscape_);
299  Pstream::listCombineGather(mpe, plusEqOp<scalar>());
300  mpe = mpe + mpe0;
301 
302  labelList nps(nStick_);
303  Pstream::listCombineGather(nps, plusEqOp<label>());
304  nps = nps + nps0;
305 
306  scalarList mps(massStick_);
307  Pstream::listCombineGather(mps, plusEqOp<scalar>());
308  mps = mps + mps0;
309 
310 
311  forAll(patchData_, i)
312  {
313  os << " Parcel fate: patch " << patchData_[i].patchName()
314  << " (number, mass)" << nl
315  << " - escape = " << npe[i]
316  << ", " << mpe[i] << nl
317  << " - stick = " << nps[i]
318  << ", " << mps[i] << nl;
319  }
320 
321  if (this->outputTime())
322  {
323  this->setModelProperty("nEscape", npe);
324  nEscape_ = 0;
325 
326  this->setModelProperty("massEscape", mpe);
327  massEscape_ = 0.0;
328 
329  this->setModelProperty("nStick", nps);
330  nStick_ = 0;
331 
332  this->setModelProperty("massStick", mps);
333  massStick_ = 0.0;
334  }
335 }
336 
337 
338 // ************************************************************************* //
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::LocalInteraction::patchData_
const patchInteractionDataList patchData_
List of participating patches.
Definition: LocalInteraction.H:54
p
p
Definition: pEqn.H:62
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::LocalInteraction::massStick_
List< scalar > massStick_
Mass of parcels stuck to patches.
Definition: LocalInteraction.H:69
Foam::LocalInteraction::nEscape_
List< label > nEscape_
Number of parcels escaped.
Definition: LocalInteraction.H:60
nw
label nw
Definition: createFields.H:25
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::LocalInteraction::LocalInteraction
LocalInteraction(const dictionary &dict, CloudType &owner)
Construct from dictionary.
Definition: LocalInteraction.C:32
Foam::LocalInteraction::writeFields_
Switch writeFields_
Flag to output data as fields.
Definition: LocalInteraction.H:73
U
U
Definition: pEqn.H:46
Foam::PatchInteractionModel< CloudType >
Foam::label
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
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
LocalInteraction.H
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::DSMCCloud
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:68
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::LocalInteraction::~LocalInteraction
virtual ~LocalInteraction()
Destructor.
Definition: LocalInteraction.C:105
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::LocalInteraction::info
virtual void info(Ostream &os)
Write patch interaction info to stream.
Definition: LocalInteraction.C:276
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::plusEqOp
Definition: ops.H:71
Foam::dimensioned
Generic dimensioned Type class.
Definition: dimensionedScalarFwd.H:41
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam::dimMass
const dimensionSet dimMass(1, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:49
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::LocalInteraction
Patch interaction specified on a patch-by-patch basis.
Definition: LocalInteraction.H:47
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::tetIndices
Storage and named access for the indices of a tet which is part of the decomposition of a cell.
Definition: tetIndices.H:73
Foam::cloud
A cloud is a collection of lagrangian particles.
Definition: cloud.H:51
Foam::LocalInteraction::correct
virtual bool correct(typename CloudType::parcelType &p, const polyPatch &pp, bool &keepParticle, const scalar trackFraction, const tetIndices &tetIs)
Apply velocity correction.
Definition: LocalInteraction.C:171
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::polyPatch::whichFace
label whichFace(const label l) const
Return label of face in patch from global face label.
Definition: polyPatch.H:389
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::DSMCCloud::parcelType
ParcelType parcelType
Type of parcel the cloud was instantiated for.
Definition: DSMCCloud.H:217
Foam::LocalInteraction::massEscape_
List< scalar > massEscape_
Mass of parcels escaped.
Definition: LocalInteraction.H:63
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::LocalInteraction::massEscape
volScalarField & massEscape()
Return access to the massEscape field.
Definition: LocalInteraction.C:112
Foam::patchIdentifier::index
label index() const
Return the index of this patch in the boundaryMesh.
Definition: patchIdentifier.H:133
Foam::LocalInteraction::massStick
volScalarField & massStick()
Return access to the massStick field.
Definition: LocalInteraction.C:141
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::LocalInteraction::nStick_
List< label > nStick_
Number of parcels stuck to patches.
Definition: LocalInteraction.H:66