DispersionRASModel.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 "DispersionRASModel.H"
27 #include "demandDrivenData.H"
28 #include "momentumTransportModel.H"
29 
30 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
31 
32 template<class CloudType>
35 {
36  const objectRegistry& obr = this->owner().mesh();
37 
38  if (obr.foundType<momentumTransportModel>(this->owner().U().group()))
39  {
40  const momentumTransportModel& model =
41  obr.lookupType<momentumTransportModel>(this->owner().U().group());
42 
43  return model.k();
44  }
45  else
46  {
48  << "Turbulence model not found in mesh database" << nl
49  << "Database objects include: " << obr.sortedToc()
50  << abort(FatalError);
51 
52  return tmp<volScalarField>(nullptr);
53  }
54 }
55 
56 
57 template<class CloudType>
60 {
61  const objectRegistry& obr = this->owner().mesh();
62 
63  if (obr.foundType<momentumTransportModel>(this->owner().U().group()))
64  {
65  const momentumTransportModel& model =
66  obr.lookupType<momentumTransportModel>(this->owner().U().group());
67 
68  return model.epsilon();
69  }
70  else
71  {
73  << "Turbulence model not found in mesh database" << nl
74  << "Database objects include: " << obr.sortedToc()
75  << abort(FatalError);
76 
77  return tmp<volScalarField>(nullptr);
78  }
79 }
80 
81 
82 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
83 
84 template<class CloudType>
86 (
87  const dictionary&,
88  CloudType& owner
89 )
90 :
91  DispersionModel<CloudType>(owner),
92  kPtr_(nullptr),
93  ownK_(false),
94  epsilonPtr_(nullptr),
95  ownEpsilon_(false)
96 {}
97 
98 
99 template<class CloudType>
101 (
103 )
104 :
106  kPtr_(dm.kPtr_),
107  ownK_(dm.ownK_),
108  epsilonPtr_(dm.epsilonPtr_),
109  ownEpsilon_(dm.ownEpsilon_)
110 {
111  dm.ownK_ = false;
112  dm.ownEpsilon_ = false;
113 }
114 
115 
116 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
117 
118 template<class CloudType>
120 {
121  cacheFields(false);
122 }
123 
124 
125 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
126 
127 template<class CloudType>
129 {
130  if (store)
131  {
132  tmp<volScalarField> tk = this->kModel();
133  if (tk.isTmp())
134  {
135  kPtr_ = tk.ptr();
136  ownK_ = true;
137  }
138  else
139  {
140  kPtr_ = &tk();
141  ownK_ = false;
142  }
143 
144  tmp<volScalarField> tepsilon = this->epsilonModel();
145  if (tepsilon.isTmp())
146  {
147  epsilonPtr_ = tepsilon.ptr();
148  ownEpsilon_ = true;
149  }
150  else
151  {
152  epsilonPtr_ = &tepsilon();
153  ownEpsilon_ = false;
154  }
155  }
156  else
157  {
158  if (ownK_ && kPtr_)
159  {
160  deleteDemandDrivenData(kPtr_);
161  ownK_ = false;
162  }
163  if (ownEpsilon_ && epsilonPtr_)
164  {
165  deleteDemandDrivenData(epsilonPtr_);
166  ownEpsilon_ = false;
167  }
168  }
169 }
170 
171 
172 template<class CloudType>
174 {
176  writeEntry(os, "ownK", ownK_);
177  writeEntry(os, "ownEpsilon", ownEpsilon_);
178 }
179 
180 
181 // ************************************************************************* //
virtual void write(Ostream &os) const
Write.
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:79
Base class for particle dispersion models based on RAS turbulence.
tmp< volScalarField > kModel() const
Return the k field from the turbulence model.
virtual void cacheFields(const bool store)
Cache carrier fields.
virtual void write(Ostream &os) const
Write.
tmp< volScalarField > epsilonModel() const
Return the epsilon field from the turbulence model.
bool ownEpsilon_
Take ownership of the epsilon field.
DispersionRASModel(const dictionary &dict, CloudType &owner)
Construct from components.
virtual ~DispersionRASModel()
Destructor.
bool ownK_
Take ownership of the k field.
List< Key > sortedToc() const
Return the table of contents as a sorted list.
Definition: HashTable.C:217
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
Abstract base class for turbulence models (RAS, LES and laminar).
virtual tmp< volScalarField > k() const =0
Return the turbulence kinetic energy.
virtual tmp< volScalarField > epsilon() const =0
Return the turbulence kinetic energy dissipation rate.
Registry of regIOobjects.
bool foundType(const word &group=word::null) const
Is the Type in registry.
const Type & lookupType(const word &group=word::null) const
Lookup and return the object of the given Type.
A class for managing temporary objects.
Definition: tmp.H:55
bool isTmp() const
Return true if this is really a temporary object.
Definition: tmpI.H:153
T * ptr() const
Return tmp pointer for reuse.
Definition: tmpI.H:205
Template functions to aid in the implementation of demand driven data.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void deleteDemandDrivenData(DataPtr &dataPtr)
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
error FatalError
static const char nl
Definition: Ostream.H:260