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