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 -------------------------------------------------------------------------------
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 "cloudSolution.H"
30 #include "Time.H"
31 #include "localEulerDdtScheme.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace 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 
86 Foam::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  {
136  if (fv::localEulerDdt::enabled(mesh_))
137  {
138  IOWarningInFunction(dict_)
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  {
147  IOWarningInFunction(dict_)
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 
211 Foam::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 
232 bool 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 
279 bool Foam::cloudSolution::log() const
280 {
281  return
282  active_
283  && (logFrequency_ > 0)
284  && (mesh_.time().timeIndex() % logFrequency_ == 0);
285 }
286 
288 bool Foam::cloudSolution::output() const
289 {
290  return active_ && mesh_.time().writeTime();
291 }
292 
293 
294 Foam::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 
307 Foam::scalar Foam::cloudSolution::deltaLMax(const scalar lRef) const
308 {
309  return maxCo_*lRef;
310 }
311 
312 
313 // ************************************************************************* //
dictionary dict
cloudSolution(const fvMesh &mesh)
Construct null from mesh reference.
Definition: cloudSolution.C:99
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
scalar relaxCoeff(const word &fieldName) const
Return relaxation coefficient for field.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
defineDebugSwitchWithName(pointMVCWeight, "pointMVCWeight", 0)
static tmp< edgeInterpolationScheme< Type > > scheme(const edgeScalarField &faceFlux, Istream &schemeData)
Return weighting factors for scheme given from Istream.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
scalar deltaLMax(const scalar lRef) const
Return the maximum integration length.
Lookup type of boundary radiation properties.
Definition: lookup.H:57
bool log() const
Returns true if possible to log this step.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
bool semiImplicit(const word &fieldName) const
Return semi-implicit flag coefficient for field.
void setSize(const label n)
Alias for resize()
Definition: List.H:316
dynamicFvMesh & mesh
static bool enabled(const fvMesh &mesh)
Return true if LTS is enabled.
Definition: localEulerDdt.C:32
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:26
bool solveThisStep() const
Returns true if performing a cloud iteration this calc step.
int debug
Static debugging option.
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
scalar deltaTMax() const
Return the maximum integration time step.
List< word > wordList
List of word.
Definition: fileName.H:59
Stores all relevant solution info for cloud.
Definition: cloudSolution.H:49
#define WarningInFunction
Report a warning using Foam::Warning.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
messageStream Info
Information stream (stdout output on master, null elsewhere)
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
void read()
Read properties from dictionary.
bool output() const
Returns true if writing this step.
Namespace for OpenFOAM.
bool canEvolve()
Returns true if possible to evolve the cloud and sets timestep parameters.