Loading...
Searching...
No Matches
cloudSolution.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-2017 OpenFOAM Foundation
9 Copyright (C) 2020-2023 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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 "cloudSolution.H"
30#include "Time.H"
31#include "localEulerDdtScheme.H"
32
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35namespace Foam
36{
37 defineDebugSwitchWithName(cloudSolution, "cloudSolution", 0);
38}
39
40// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41
43:
44 mesh_(mesh),
45 dict_(dict),
46 active_(dict.lookup("active")),
47 transient_(false),
48 calcFrequency_(1),
49 logFrequency_(1),
50 maxCo_(0.3),
51 iter_(1),
52 trackTime_(0.0),
53 deltaTMax_(GREAT),
54 coupled_(false),
55 cellValueSourceCorrection_(false),
56 maxTrackTime_(0.0),
57 resetSourcesOnStartup_(true),
58 schemes_()
59{
60 if (active_)
61 {
62 read();
63 }
64 else
65 {
66 // see if existing source terms should be reset
67 const dictionary sourceTerms(dict_.subOrEmptyDict("sourceTerms"));
68 sourceTerms.readIfPresent("resetOnStartup", resetSourcesOnStartup_);
69
70 if (resetSourcesOnStartup_)
71 {
72 Info<< "Cloud source terms will be reset" << endl;
73 }
74 else
75 {
76 Info<< "Cloud source terms will be held constant" << endl;
77 }
78
79 // transient default to false asks for extra massFlowRate
80 // in transient lagrangian
81 transient_ = true;
82 }
83}
84
85
86Foam::cloudSolution::cloudSolution(const cloudSolution& cs)
87:
88 mesh_(cs.mesh_),
89 dict_(cs.dict_),
90 active_(cs.active_),
91 transient_(cs.transient_),
92 calcFrequency_(cs.calcFrequency_),
93 logFrequency_(cs.logFrequency_),
94 maxCo_(cs.maxCo_),
95 iter_(cs.iter_),
96 trackTime_(cs.trackTime_),
97 deltaTMax_(cs.deltaTMax_),
98 coupled_(cs.coupled_),
99 cellValueSourceCorrection_(cs.cellValueSourceCorrection_),
100 maxTrackTime_(cs.maxTrackTime_),
101 resetSourcesOnStartup_(cs.resetSourcesOnStartup_),
102 schemes_(cs.schemes_)
103{}
104
105
107:
108 mesh_(mesh),
109 dict_(),
110 active_(false),
111 transient_(false),
112 calcFrequency_(0),
113 logFrequency_(0),
114 maxCo_(GREAT),
115 iter_(0),
116 trackTime_(0.0),
117 deltaTMax_(GREAT),
118 coupled_(false),
119 cellValueSourceCorrection_(false),
120 maxTrackTime_(0.0),
121 resetSourcesOnStartup_(false),
122 schemes_()
123{}
124
125
126// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
127
129{
130 // For transient runs the Lagrangian tracking may be transient or steady
131 transient_ = dict_.getOrDefault("transient", false);
132
133 // For LTS and steady-state runs the Lagrangian tracking cannot be transient
134 if (transient_)
135 {
137 {
139 << "Transient tracking is not supported for LTS"
140 " simulations, switching to steady state tracking."
141 << endl;
142 transient_ = false;
143 }
144
145 if (mesh_.steady())
146 {
148 << "Transient tracking is not supported for steady-state"
149 " simulations, switching to steady state tracking."
150 << endl;
151 transient_ = false;
152 }
153 }
154
155 dict_.readEntry("coupled", coupled_);
156 dict_.readEntry("cellValueSourceCorrection", cellValueSourceCorrection_);
157 dict_.readIfPresent("maxCo", maxCo_);
158 dict_.readIfPresent("deltaTMax", deltaTMax_);
159
160 dict_.readIfPresent("logFrequency", logFrequency_);
161
162 if (steadyState())
163 {
164 dict_.readEntry("calcFrequency", calcFrequency_);
165 dict_.readEntry("maxTrackTime", maxTrackTime_);
166
167 if (coupled_)
168 {
169 dict_.subDict("sourceTerms").lookup("resetOnStartup")
170 >> resetSourcesOnStartup_;
171 }
172 }
173
174 if (coupled_)
175 {
176 const dictionary&
177 schemesDict(dict_.subDict("sourceTerms").subDict("schemes"));
178
179 wordList vars(schemesDict.toc());
180 schemes_.setSize(vars.size());
181 forAll(vars, i)
182 {
183 // read solution variable name
184 schemes_[i].first() = vars[i];
185
186 // set semi-implicit (1) explicit (0) flag
187 ITstream& is = schemesDict.lookup(vars[i]);
188 const word scheme(is);
189 if (scheme == "semiImplicit")
190 {
191 schemes_[i].second().first() = true;
192 }
193 else if (scheme == "explicit")
194 {
195 schemes_[i].second().first() = false;
196 }
197 else
198 {
200 << "Invalid scheme " << scheme << ". Valid schemes are "
201 << "explicit and semiImplicit" << exit(FatalError);
202 }
203
204 // read under-relaxation factor
205 is >> schemes_[i].second().second();
206 }
207 }
208}
209
210
211Foam::scalar Foam::cloudSolution::relaxCoeff(const word& fieldName) const
212{
213 for (const auto& scheme : schemes_)
214 {
215 if (fieldName == scheme.first())
216 {
217 return scheme.second().second();
218 }
219 }
220
221 if (debug)
222 {
224 << "Field name " << fieldName << " not found in schemes. "
225 << "Setting relaxation factor to 1" << endl;
226 }
227
228 return 1.0;
229}
230
231
232bool Foam::cloudSolution::semiImplicit(const word& fieldName) const
233{
234 for (const auto& scheme : schemes_)
235 {
236 if (fieldName == scheme.first())
237 {
238 return scheme.second().first();
239 }
240 }
241
242 if (debug)
243 {
245 << "Field name " << fieldName << " not found in schemes. "
246 << "Setting relaxation factor to 1" << endl;
247 }
248
249 return false;
250}
251
252
254{
255 return
256 active_
257 && (
258 mesh_.time().writeTime()
259 || (mesh_.time().timeIndex() % calcFrequency_ == 0)
260 );
261}
262
263
265{
266 if (transient_)
267 {
268 trackTime_ = mesh_.time().deltaTValue();
269 }
270 else
271 {
272 trackTime_ = maxTrackTime_;
273 }
274
275 return solveThisStep();
276}
277
278
279bool Foam::cloudSolution::log() const
280{
281 return
282 active_
283 && (logFrequency_ > 0)
284 && (mesh_.time().timeIndex() % logFrequency_ == 0);
285}
286
289{
290 return active_ && mesh_.time().writeTime();
291}
292
293
294Foam::scalar Foam::cloudSolution::deltaTMax(const scalar trackTime) const
295{
296 if (transient_)
297 {
298 return min(deltaTMax_, maxCo_*trackTime);
299 }
300 else
301 {
302 return min(deltaTMax_, trackTime);
303 }
304}
305
306
307Foam::scalar Foam::cloudSolution::deltaLMax(const scalar lRef) const
308{
309 return maxCo_*lRef;
310}
311
312
313// ************************************************************************* //
An input stream of tokens.
Definition ITstream.H:56
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
Stores all relevant solution info for cloud.
const Switch steadyState() const
Return const access to the steady flag.
scalar trackTime() const
Return the particle track time.
bool canEvolve()
Returns true if possible to evolve the cloud and sets timestep parameters.
bool log() const
Returns true if possible to log this step.
bool semiImplicit(const word &fieldName) const
Return semi-implicit flag coefficient for field.
bool output() const
Returns true if writing this step.
void read()
Read properties from dictionary.
scalar deltaLMax(const scalar lRef) const
Return the maximum integration length.
const dictionary & dict() const
Return const access to the dictionary.
scalar relaxCoeff(const word &fieldName) const
Return relaxation coefficient for field.
static int debug
Debug switch.
const fvMesh & mesh() const
Return reference to the mesh.
scalar deltaTMax() const
Return the maximum integration time step.
cloudSolution(const fvMesh &mesh)
Construct null from mesh reference.
bool solveThisStep() const
Returns true if performing a cloud iteration this calc step.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
dictionary subOrEmptyDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX, const bool mandatory=false) const
Find and return a sub-dictionary as a copy, otherwise return an empty dictionary.
Definition dictionary.C:521
ITstream & lookup(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return an entry data stream. FatalIOError if not found, or not a stream.
Definition dictionary.C:367
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
wordList toc() const
Return the table of contents.
Definition dictionary.C:587
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
static bool enabled(const fvMesh &mesh)
Return true if LTS is enabled.
Lookup type of boundary radiation properties.
Definition lookup.H:60
A class for handling words, derived from Foam::string.
Definition word.H:66
dynamicFvMesh & mesh
#define defineDebugSwitchWithName(Type, Name, Value)
Define the debug information, lookup as Name.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for handling debugging switches.
Definition debug.C:45
Namespace for OpenFOAM.
List< word > wordList
List of word.
Definition fileName.H:60
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition hashSets.C:26
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299