cloudSolution.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 "cloudSolution.H"
27 #include "Time.H"
28 #include "localEulerDdtScheme.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
33 (
34  const fvMesh& mesh,
35  const dictionary& dict
36 )
37 :
38  mesh_(mesh),
39  dict_(dict),
40  transient_(false),
41  calcFrequency_(1),
42  maxCo_(0.3),
43  iter_(1),
44  trackTime_(0),
45  coupled_(false),
46  cellValueSourceCorrection_(false),
47  maxTrackTime_(0),
48  resetSourcesOnStartup_(true),
49  schemes_()
50 {
51  read();
52 }
53 
54 
56 (
57  const cloudSolution& cs
58 )
59 :
60  mesh_(cs.mesh_),
61  dict_(cs.dict_),
62  transient_(cs.transient_),
63  calcFrequency_(cs.calcFrequency_),
64  maxCo_(cs.maxCo_),
65  iter_(cs.iter_),
66  trackTime_(cs.trackTime_),
67  coupled_(cs.coupled_),
68  cellValueSourceCorrection_(cs.cellValueSourceCorrection_),
69  maxTrackTime_(cs.maxTrackTime_),
70  resetSourcesOnStartup_(cs.resetSourcesOnStartup_),
71  schemes_(cs.schemes_)
72 {}
73 
74 
76 (
77  const fvMesh& mesh
78 )
79 :
80  mesh_(mesh),
81  dict_(dictionary::null),
82  transient_(false),
83  calcFrequency_(0),
84  maxCo_(great),
85  iter_(0),
86  trackTime_(0),
87  coupled_(false),
88  cellValueSourceCorrection_(false),
89  maxTrackTime_(0),
90  resetSourcesOnStartup_(false),
91  schemes_()
92 {}
93 
94 
95 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
96 
98 {}
99 
100 
101 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
102 
104 {
105  // For transient runs the Lagrangian tracking may be transient or steady
106  transient_ = dict_.lookupOrDefault("transient", false);
107 
108  // For LTS and steady-state runs the Lagrangian tracking cannot be transient
109  if (transient_)
110  {
111  if (fv::localEulerDdt::enabled(mesh_))
112  {
113  IOWarningInFunction(dict_)
114  << "Transient tracking is not supported for LTS"
115  " simulations, switching to steady state tracking."
116  << endl;
117  transient_ = false;
118  }
119 
120  if (mesh_.schemes().steady())
121  {
122  IOWarningInFunction(dict_)
123  << "Transient tracking is not supported for steady-state"
124  " simulations, switching to steady state tracking."
125  << endl;
126  transient_ = false;
127  }
128  }
129 
130  dict_.lookup("coupled") >> coupled_;
131  dict_.lookup("cellValueSourceCorrection") >> cellValueSourceCorrection_;
132  dict_.readIfPresent("maxCo", maxCo_);
133 
134  if (steadyState())
135  {
136  dict_.lookup("calcFrequency") >> calcFrequency_;
137  dict_.lookup("maxTrackTime") >> maxTrackTime_;
138 
139  if (coupled_)
140  {
141  dict_.subDict("sourceTerms").lookup("resetOnStartup")
142  >> resetSourcesOnStartup_;
143  }
144  }
145 
146  if (coupled_)
147  {
148  const dictionary&
149  schemesDict(dict_.subDict("sourceTerms").subDict("schemes"));
150 
151  wordList vars(schemesDict.toc());
152  schemes_.setSize(vars.size());
153  forAll(vars, i)
154  {
155  // read solution variable name
156  schemes_[i].first() = vars[i];
157 
158  // set semi-implicit (1) explicit (0) flag
159  Istream& is = schemesDict.lookup(vars[i]);
160  const word scheme(is);
161  if (scheme == "semiImplicit")
162  {
163  schemes_[i].second().first() = true;
164  }
165  else if (scheme == "explicit")
166  {
167  schemes_[i].second().first() = false;
168  }
169  else
170  {
172  << "Invalid scheme " << scheme << ". Valid schemes are "
173  << "explicit and semiImplicit" << exit(FatalError);
174  }
175 
176  // read under-relaxation factor
177  is >> schemes_[i].second().second();
178  }
179  }
180 }
181 
182 
183 Foam::scalar Foam::cloudSolution::relaxCoeff(const word& fieldName) const
184 {
185  forAll(schemes_, i)
186  {
187  if (fieldName == schemes_[i].first())
188  {
189  return schemes_[i].second().second();
190  }
191  }
192 
194  << "Field name " << fieldName << " not found in schemes"
195  << abort(FatalError);
196 
197  return 1;
198 }
199 
200 
201 bool Foam::cloudSolution::semiImplicit(const word& fieldName) const
202 {
203  forAll(schemes_, i)
204  {
205  if (fieldName == schemes_[i].first())
206  {
207  return schemes_[i].second().first();
208  }
209  }
210 
212  << "Field name " << fieldName << " not found in schemes"
213  << abort(FatalError);
214 
215  return false;
216 }
217 
218 
220 {
221  return (mesh_.time().timeIndex() % calcFrequency_ == 0);
222 }
223 
224 
226 {
227  if (transient_)
228  {
229  trackTime_ = mesh_.time().deltaTValue();
230  }
231  else
232  {
233  trackTime_ = maxTrackTime_;
234  }
235 
236  return solveThisStep();
237 }
238 
239 
241 {
242  return mesh_.time().writeTime();
243 }
244 
245 
246 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Stores all relevant solution info for cloud.
Definition: cloudSolution.H:52
virtual ~cloudSolution()
Destructor.
Definition: cloudSolution.C:97
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 relaxCoeff(const word &fieldName) const
Return relaxation coefficient for field.
cloudSolution(const fvMesh &mesh)
Construct null from mesh reference.
Definition: cloudSolution.C:76
bool solveThisStep() const
Returns true if performing a cloud iteration this calc step.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:710
wordList toc() const
Return the table of contents.
Definition: dictionary.C:976
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:99
static bool enabled(const fvMesh &mesh)
Return true if LTS is enabled.
Definition: localEulerDdt.C:37
A class for handling words, derived from string.
Definition: word.H:62
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
static tmp< surfaceInterpolationScheme< Type > > scheme(const surfaceScalarField &faceFlux, Istream &schemeData)
Return weighting factors for scheme given from Istream.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
errorManip< error > abort(error &err)
Definition: errorManip.H:131
labelList first(const UList< labelPair > &p)
Definition: patchToPatch.C:39
error FatalError
dictionary dict