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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "cloudSolution.H"
29 #include "Time.H"
30 #include "localEulerDdtScheme.H"
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
35 :
36  mesh_(mesh),
37  dict_(dict),
38  active_(dict.lookup("active")),
39  transient_(false),
40  calcFrequency_(1),
41  maxCo_(0.3),
42  iter_(1),
43  trackTime_(0.0),
44  deltaTMax_(GREAT),
45  coupled_(false),
46  cellValueSourceCorrection_(false),
47  maxTrackTime_(0.0),
48  resetSourcesOnStartup_(true),
49  schemes_()
50 {
51  if (active_)
52  {
53  read();
54  }
55  else
56  {
57  // see if existing source terms should be reset
58  const dictionary sourceTerms(dict_.subOrEmptyDict("sourceTerms"));
59  sourceTerms.readIfPresent("resetOnStartup", resetSourcesOnStartup_);
60 
61  if (resetSourcesOnStartup_)
62  {
63  Info<< "Cloud source terms will be reset" << endl;
64  }
65  else
66  {
67  Info<< "Cloud source terms will be held constant" << endl;
68  }
69 
70  // transient default to false asks for extra massFlowRate
71  // in transient lagrangian
72  transient_ = true;
73  }
74 }
75 
76 
78 :
79  mesh_(cs.mesh_),
80  dict_(cs.dict_),
81  active_(cs.active_),
82  transient_(cs.transient_),
83  calcFrequency_(cs.calcFrequency_),
84  maxCo_(cs.maxCo_),
85  iter_(cs.iter_),
86  trackTime_(cs.trackTime_),
87  deltaTMax_(cs.deltaTMax_),
88  coupled_(cs.coupled_),
89  cellValueSourceCorrection_(cs.cellValueSourceCorrection_),
90  maxTrackTime_(cs.maxTrackTime_),
91  resetSourcesOnStartup_(cs.resetSourcesOnStartup_),
92  schemes_(cs.schemes_)
93 {}
94 
95 
97 :
98  mesh_(mesh),
99  dict_(dictionary::null),
100  active_(false),
101  transient_(false),
102  calcFrequency_(0),
103  maxCo_(GREAT),
104  iter_(0),
105  trackTime_(0.0),
106  deltaTMax_(GREAT),
107  coupled_(false),
108  cellValueSourceCorrection_(false),
109  maxTrackTime_(0.0),
110  resetSourcesOnStartup_(false),
111  schemes_()
112 {}
113 
114 
115 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
116 
118 {}
119 
120 
121 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
122 
124 {
125  // For transient runs the Lagrangian tracking may be transient or steady
126  transient_ = dict_.lookupOrDefault("transient", false);
127 
128  // For LTS and steady-state runs the Lagrangian tracking cannot be transient
129  if (transient_)
130  {
131  if (fv::localEulerDdt::enabled(mesh_))
132  {
133  IOWarningInFunction(dict_)
134  << "Transient tracking is not supported for LTS"
135  " simulations, switching to steady state tracking."
136  << endl;
137  transient_ = false;
138  }
139 
140  if (mesh_.steady())
141  {
142  IOWarningInFunction(dict_)
143  << "Transient tracking is not supported for steady-state"
144  " simulations, switching to steady state tracking."
145  << endl;
146  transient_ = false;
147  }
148  }
149 
150  dict_.readEntry("coupled", coupled_);
151  dict_.readEntry("cellValueSourceCorrection", cellValueSourceCorrection_);
152  dict_.readIfPresent("maxCo", maxCo_);
153  dict_.readIfPresent("deltaTMax", deltaTMax_);
154 
155  if (steadyState())
156  {
157  dict_.readEntry("calcFrequency", calcFrequency_);
158  dict_.readEntry("maxTrackTime", maxTrackTime_);
159 
160  if (coupled_)
161  {
162  dict_.subDict("sourceTerms").lookup("resetOnStartup")
163  >> resetSourcesOnStartup_;
164  }
165  }
166 
167  if (coupled_)
168  {
169  const dictionary&
170  schemesDict(dict_.subDict("sourceTerms").subDict("schemes"));
171 
172  wordList vars(schemesDict.toc());
173  schemes_.setSize(vars.size());
174  forAll(vars, i)
175  {
176  // read solution variable name
177  schemes_[i].first() = vars[i];
178 
179  // set semi-implicit (1) explicit (0) flag
180  Istream& is = schemesDict.lookup(vars[i]);
181  const word scheme(is);
182  if (scheme == "semiImplicit")
183  {
184  schemes_[i].second().first() = true;
185  }
186  else if (scheme == "explicit")
187  {
188  schemes_[i].second().first() = false;
189  }
190  else
191  {
193  << "Invalid scheme " << scheme << ". Valid schemes are "
194  << "explicit and semiImplicit" << exit(FatalError);
195  }
196 
197  // read under-relaxation factor
198  is >> schemes_[i].second().second();
199  }
200  }
201 }
202 
203 
204 Foam::scalar Foam::cloudSolution::relaxCoeff(const word& fieldName) const
205 {
206  forAll(schemes_, i)
207  {
208  if (fieldName == schemes_[i].first())
209  {
210  return schemes_[i].second().second();
211  }
212  }
213 
215  << "Field name " << fieldName << " not found in schemes"
216  << abort(FatalError);
217 
218  return 1.0;
219 }
220 
221 
222 bool Foam::cloudSolution::semiImplicit(const word& fieldName) const
223 {
224  forAll(schemes_, i)
225  {
226  if (fieldName == schemes_[i].first())
227  {
228  return schemes_[i].second().first();
229  }
230  }
231 
233  << "Field name " << fieldName << " not found in schemes"
234  << abort(FatalError);
235 
236  return false;
237 }
238 
239 
241 {
242  return
243  active_
244  && (
245  mesh_.time().writeTime()
246  || (mesh_.time().timeIndex() % calcFrequency_ == 0)
247  );
248 }
249 
250 
252 {
253  if (transient_)
254  {
255  trackTime_ = mesh_.time().deltaTValue();
256  }
257  else
258  {
259  trackTime_ = maxTrackTime_;
260  }
261 
262  return solveThisStep();
263 }
264 
265 
267 {
268  return active_ && mesh_.time().writeTime();
269 }
270 
271 
272 Foam::scalar Foam::cloudSolution::deltaTMax(const scalar trackTime) const
273 {
274  if (transient_)
275  {
276  return min(deltaTMax_, maxCo_*trackTime);
277  }
278  else
279  {
280  return min(deltaTMax_, trackTime);
281  }
282 }
283 
284 
285 Foam::scalar Foam::cloudSolution::deltaLMax(const scalar lRef) const
286 {
287  return maxCo_*lRef;
288 }
289 
290 
291 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::cloudSolution::deltaTMax
scalar deltaTMax() const
Return the maximum integration time step.
Definition: cloudSolutionI.H:106
Foam::cloudSolution::canEvolve
bool canEvolve()
Returns true if possible to evolve the cloud and sets timestep.
Definition: cloudSolution.C:251
Foam::cloudSolution::deltaLMax
scalar deltaLMax(const scalar lRef) const
Return the maximum integration length.
Definition: cloudSolution.C:285
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::cloudSolution::output
bool output() const
Returns true if writing this step.
Definition: cloudSolution.C:266
Foam::fv::localEulerDdt::enabled
static bool enabled(const fvMesh &mesh)
Return true if LTS is enabled.
Definition: localEulerDdt.C:39
localEulerDdtScheme.H
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::cloudSolution::solveThisStep
bool solveThisStep() const
Returns true if performing a cloud iteration this calc step.
Definition: cloudSolution.C:240
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::cloudSolution
Stores all relevant solution info for cloud.
Definition: cloudSolution.H:53
Foam::radiation::lookup
Lookup type of boundary radiation properties.
Definition: lookup.H:63
Foam::cloudSolution::semiImplicit
bool semiImplicit(const word &fieldName) const
Return semi-implicit flag coefficient for field.
Definition: cloudSolution.C:222
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:84
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:137
Foam::dictionary::subOrEmptyDict
dictionary subOrEmptyDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX, const bool mandatory=false) const
Definition: dictionary.C:603
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Time.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
cloudSolution.H
Foam::cloudSolution::relaxCoeff
scalar relaxCoeff(const word &fieldName) const
Return relaxation coefficient for field.
Definition: cloudSolution.C:204
Foam::List< word >
Foam::cloudSolution::read
void read()
Read properties from dictionary.
Definition: cloudSolution.C:123
Foam::cloudSolution::cloudSolution
cloudSolution(const fvMesh &mesh)
Construct null from mesh reference.
Definition: cloudSolution.C:96
IOWarningInFunction
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
Definition: messageStream.H:306
Foam::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146
Foam::cloudSolution::~cloudSolution
virtual ~cloudSolution()
Destructor.
Definition: cloudSolution.C:117
Foam::fac::scheme
static tmp< edgeInterpolationScheme< Type > > scheme(const edgeScalarField &faceFlux, Istream &schemeData)
Return weighting factors for scheme given from Istream.
Foam::dictionary::readIfPresent
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:417