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-2021 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// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34
36:
37 mesh_(mesh),
38 dict_(dict),
39 active_(dict.lookup("active")),
40 transient_(false),
41 calcFrequency_(1),
42 maxCo_(0.3),
43 iter_(1),
44 trackTime_(0.0),
45 deltaTMax_(GREAT),
46 coupled_(false),
47 cellValueSourceCorrection_(false),
48 maxTrackTime_(0.0),
49 resetSourcesOnStartup_(true),
50 schemes_()
51{
52 if (active_)
53 {
54 read();
55 }
56 else
57 {
58 // see if existing source terms should be reset
59 const dictionary sourceTerms(dict_.subOrEmptyDict("sourceTerms"));
60 sourceTerms.readIfPresent("resetOnStartup", resetSourcesOnStartup_);
61
62 if (resetSourcesOnStartup_)
63 {
64 Info<< "Cloud source terms will be reset" << endl;
65 }
66 else
67 {
68 Info<< "Cloud source terms will be held constant" << endl;
69 }
70
71 // transient default to false asks for extra massFlowRate
72 // in transient lagrangian
73 transient_ = true;
74 }
75}
76
77
79:
80 mesh_(cs.mesh_),
81 dict_(cs.dict_),
82 active_(cs.active_),
83 transient_(cs.transient_),
84 calcFrequency_(cs.calcFrequency_),
85 maxCo_(cs.maxCo_),
86 iter_(cs.iter_),
87 trackTime_(cs.trackTime_),
88 deltaTMax_(cs.deltaTMax_),
89 coupled_(cs.coupled_),
90 cellValueSourceCorrection_(cs.cellValueSourceCorrection_),
91 maxTrackTime_(cs.maxTrackTime_),
92 resetSourcesOnStartup_(cs.resetSourcesOnStartup_),
93 schemes_(cs.schemes_)
94{}
95
96
98:
99 mesh_(mesh),
100 dict_(),
101 active_(false),
102 transient_(false),
103 calcFrequency_(0),
104 maxCo_(GREAT),
105 iter_(0),
106 trackTime_(0.0),
107 deltaTMax_(GREAT),
108 coupled_(false),
109 cellValueSourceCorrection_(false),
110 maxTrackTime_(0.0),
111 resetSourcesOnStartup_(false),
112 schemes_()
113{}
114
115
116// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
117
119{}
120
121
122// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
123
125{
126 // For transient runs the Lagrangian tracking may be transient or steady
127 transient_ = dict_.getOrDefault("transient", false);
128
129 // For LTS and steady-state runs the Lagrangian tracking cannot be transient
130 if (transient_)
131 {
133 {
135 << "Transient tracking is not supported for LTS"
136 " simulations, switching to steady state tracking."
137 << endl;
138 transient_ = false;
139 }
140
141 if (mesh_.steady())
142 {
144 << "Transient tracking is not supported for steady-state"
145 " simulations, switching to steady state tracking."
146 << endl;
147 transient_ = false;
148 }
149 }
150
151 dict_.readEntry("coupled", coupled_);
152 dict_.readEntry("cellValueSourceCorrection", cellValueSourceCorrection_);
153 dict_.readIfPresent("maxCo", maxCo_);
154 dict_.readIfPresent("deltaTMax", deltaTMax_);
155
156 if (steadyState())
157 {
158 dict_.readEntry("calcFrequency", calcFrequency_);
159 dict_.readEntry("maxTrackTime", maxTrackTime_);
160
161 if (coupled_)
162 {
163 dict_.subDict("sourceTerms").lookup("resetOnStartup")
164 >> resetSourcesOnStartup_;
165 }
166 }
167
168 if (coupled_)
169 {
170 const dictionary&
171 schemesDict(dict_.subDict("sourceTerms").subDict("schemes"));
172
173 wordList vars(schemesDict.toc());
174 schemes_.setSize(vars.size());
175 forAll(vars, i)
176 {
177 // read solution variable name
178 schemes_[i].first() = vars[i];
179
180 // set semi-implicit (1) explicit (0) flag
181 ITstream& is = schemesDict.lookup(vars[i]);
182 const word scheme(is);
183 if (scheme == "semiImplicit")
184 {
185 schemes_[i].second().first() = true;
186 }
187 else if (scheme == "explicit")
188 {
189 schemes_[i].second().first() = false;
190 }
191 else
192 {
194 << "Invalid scheme " << scheme << ". Valid schemes are "
195 << "explicit and semiImplicit" << exit(FatalError);
196 }
197
198 // read under-relaxation factor
199 is >> schemes_[i].second().second();
200 }
201 }
202}
203
204
205Foam::scalar Foam::cloudSolution::relaxCoeff(const word& fieldName) const
206{
207 forAll(schemes_, i)
208 {
209 if (fieldName == schemes_[i].first())
210 {
211 return schemes_[i].second().second();
212 }
213 }
214
216 << "Field name " << fieldName << " not found in schemes"
217 << abort(FatalError);
218
219 return 1.0;
220}
221
222
223bool Foam::cloudSolution::semiImplicit(const word& fieldName) const
224{
225 forAll(schemes_, i)
226 {
227 if (fieldName == schemes_[i].first())
228 {
229 return schemes_[i].second().first();
230 }
231 }
232
234 << "Field name " << fieldName << " not found in schemes"
235 << abort(FatalError);
236
237 return false;
238}
239
240
242{
243 return
244 active_
245 && (
246 mesh_.time().writeTime()
247 || (mesh_.time().timeIndex() % calcFrequency_ == 0)
248 );
249}
250
251
253{
254 if (transient_)
255 {
256 trackTime_ = mesh_.time().deltaTValue();
257 }
258 else
259 {
260 trackTime_ = maxTrackTime_;
261 }
262
263 return solveThisStep();
264}
265
266
268{
269 return active_ && mesh_.time().writeTime();
270}
271
272
273Foam::scalar Foam::cloudSolution::deltaTMax(const scalar trackTime) const
274{
275 if (transient_)
276 {
277 return min(deltaTMax_, maxCo_*trackTime);
278 }
279 else
280 {
281 return min(deltaTMax_, trackTime);
282 }
283}
284
285
286Foam::scalar Foam::cloudSolution::deltaLMax(const scalar lRef) const
287{
288 return maxCo_*lRef;
289}
290
291
292// ************************************************************************* //
An input stream of tokens.
Definition: ITstream.H:56
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Stores all relevant solution info for cloud.
Definition: cloudSolution.H:54
virtual ~cloudSolution()
Destructor.
bool canEvolve()
Returns true if possible to evolve the cloud and sets timestep.
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.
scalar relaxCoeff(const word &fieldName) const
Return relaxation coefficient for field.
scalar deltaTMax() const
Return the maximum integration time step.
bool solveThisStep() const
Returns true if performing a cloud iteration this calc step.
virtual bool enabled() const
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
dictionary subOrEmptyDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX, const bool mandatory=false) const
Definition: dictionary.C:540
ITstream & lookup(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionary.C:386
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
wordList toc() const
Return the table of contents.
Definition: dictionary.C:602
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
Lookup type of boundary radiation properties.
Definition: lookup.H:66
A class for handling words, derived from Foam::string.
Definition: word.H:68
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333