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 | Copyright (C) 2011-2016 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 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
32 (
33  const fvMesh& mesh,
34  const dictionary& dict
35 )
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  coupled_(false),
46  cellValueSourceCorrection_(false),
47  maxTrackTime_(0.0),
48  resetSourcesOnStartup_(true),
49  schemes_()
50 {
51  if (active_)
52  {
53  read();
54  }
55 }
56 
57 
59 (
60  const cloudSolution& cs
61 )
62 :
63  mesh_(cs.mesh_),
64  dict_(cs.dict_),
65  active_(cs.active_),
66  transient_(cs.transient_),
67  calcFrequency_(cs.calcFrequency_),
68  maxCo_(cs.maxCo_),
69  iter_(cs.iter_),
70  trackTime_(cs.trackTime_),
71  coupled_(cs.coupled_),
72  cellValueSourceCorrection_(cs.cellValueSourceCorrection_),
73  maxTrackTime_(cs.maxTrackTime_),
74  resetSourcesOnStartup_(cs.resetSourcesOnStartup_),
75  schemes_(cs.schemes_)
76 {}
77 
78 
80 (
81  const fvMesh& mesh
82 )
83 :
84  mesh_(mesh),
85  dict_(dictionary::null),
86  active_(false),
87  transient_(false),
88  calcFrequency_(0),
89  maxCo_(GREAT),
90  iter_(0),
91  trackTime_(0.0),
92  coupled_(false),
93  cellValueSourceCorrection_(false),
94  maxTrackTime_(0.0),
95  resetSourcesOnStartup_(false),
96  schemes_()
97 {}
98 
99 
100 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
101 
103 {}
104 
105 
106 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
107 
109 {
110  dict_.lookup("transient") >> transient_;
111  dict_.lookup("coupled") >> coupled_;
112  dict_.lookup("cellValueSourceCorrection") >> cellValueSourceCorrection_;
113  dict_.readIfPresent("maxCo", maxCo_);
114 
115  if (steadyState())
116  {
117  dict_.lookup("calcFrequency") >> calcFrequency_;
118  dict_.lookup("maxTrackTime") >> maxTrackTime_;
119 
120  if (coupled_)
121  {
122  dict_.subDict("sourceTerms").lookup("resetOnStartup")
123  >> resetSourcesOnStartup_;
124  }
125  }
126 
127  if (coupled_)
128  {
129  const dictionary&
130  schemesDict(dict_.subDict("sourceTerms").subDict("schemes"));
131 
132  wordList vars(schemesDict.toc());
133  schemes_.setSize(vars.size());
134  forAll(vars, i)
135  {
136  // read solution variable name
137  schemes_[i].first() = vars[i];
138 
139  // set semi-implicit (1) explicit (0) flag
140  Istream& is = schemesDict.lookup(vars[i]);
141  const word scheme(is);
142  if (scheme == "semiImplicit")
143  {
144  schemes_[i].second().first() = true;
145  }
146  else if (scheme == "explicit")
147  {
148  schemes_[i].second().first() = false;
149  }
150  else
151  {
153  << "Invalid scheme " << scheme << ". Valid schemes are "
154  << "explicit and semiImplicit" << exit(FatalError);
155  }
156 
157  // read under-relaxation factor
158  is >> schemes_[i].second().second();
159  }
160  }
161 }
162 
163 
164 Foam::scalar Foam::cloudSolution::relaxCoeff(const word& fieldName) const
165 {
166  forAll(schemes_, i)
167  {
168  if (fieldName == schemes_[i].first())
169  {
170  return schemes_[i].second().second();
171  }
172  }
173 
175  << "Field name " << fieldName << " not found in schemes"
176  << abort(FatalError);
177 
178  return 1.0;
179 }
180 
181 
182 bool Foam::cloudSolution::semiImplicit(const word& fieldName) const
183 {
184  forAll(schemes_, i)
185  {
186  if (fieldName == schemes_[i].first())
187  {
188  return schemes_[i].second().first();
189  }
190  }
191 
193  << "Field name " << fieldName << " not found in schemes"
194  << abort(FatalError);
195 
196  return false;
197 }
198 
199 
201 {
202  return
203  active_
204  && (
205  mesh_.time().writeTime()
206  || (mesh_.time().timeIndex() % calcFrequency_ == 0)
207  );
208 }
209 
210 
212 {
213  if (transient_)
214  {
215  trackTime_ = mesh_.time().deltaTValue();
216  }
217  else
218  {
219  trackTime_ = maxTrackTime_;
220  }
221 
222  return solveThisStep();
223 }
224 
225 
227 {
228  return active_ && mesh_.time().writeTime();
229 }
230 
231 
232 // ************************************************************************* //
virtual ~cloudSolution()
Destructor.
label timeIndex() const
Return current time index.
Definition: TimeStateI.H:35
cloudSolution(const fvMesh &mesh)
Construct null from mesh reference.
Definition: cloudSolution.C:80
#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
#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
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:633
static tmp< surfaceInterpolationScheme< Type > > scheme(const surfaceScalarField &faceFlux, Istream &schemeData)
Return weighting factors for scheme given from Istream.
bool writeTime() const
Return true if this is a write time.
Definition: TimeStateI.H:65
scalar relaxCoeff(const word &fieldName) const
Return relaxation coefficient for field.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
A class for handling words, derived from string.
Definition: word.H:59
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
bool semiImplicit(const word &fieldName) const
Return semi-implicit flag coefficient for field.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
scalar deltaTValue() const
Return time step value.
Definition: TimeStateI.H:41
Stores all relevant solution info for cloud.
Definition: cloudSolution.H:51
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
bool solveThisStep() const
Returns true if performing a cloud iteration this calc step.
const Switch steadyState() const
Return const access to the steady flag.
bool output() const
Returns true if writing this step.
void read()
Read properties from dictionary.
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
bool canEvolve()
Returns true if possible to evolve the cloud and sets timestep.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:451