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-2015 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  mesh_(mesh),
34  dict_(dict),
35  active_(dict.lookup("active")),
36  transient_(false),
37  calcFrequency_(1),
38  maxCo_(0.3),
39  iter_(1),
40  trackTime_(0.0),
41  deltaTMax_(GREAT),
42  coupled_(false),
43  cellValueSourceCorrection_(false),
44  maxTrackTime_(0.0),
45  resetSourcesOnStartup_(true),
46  schemes_()
47 {
48  if (active_)
49  {
50  read();
51  }
52  else
53  {
54  // see if existing source terms should be reset
55  const dictionary sourceTerms(dict_.subOrEmptyDict("sourceTerms"));
56  sourceTerms.readIfPresent("resetOnStartup", resetSourcesOnStartup_);
57 
59  {
60  Info<< "Cloud source terms will be reset" << endl;
61  }
62  else
63  {
64  Info<< "Cloud source terms will be held constant" << endl;
65  }
66  }
67 }
68 
69 
71 :
72  mesh_(cs.mesh_),
73  dict_(cs.dict_),
74  active_(cs.active_),
75  transient_(cs.transient_),
76  calcFrequency_(cs.calcFrequency_),
77  maxCo_(cs.maxCo_),
78  iter_(cs.iter_),
79  trackTime_(cs.trackTime_),
80  deltaTMax_(cs.deltaTMax_),
81  coupled_(cs.coupled_),
82  cellValueSourceCorrection_(cs.cellValueSourceCorrection_),
83  maxTrackTime_(cs.maxTrackTime_),
84  resetSourcesOnStartup_(cs.resetSourcesOnStartup_),
85  schemes_(cs.schemes_)
86 {}
87 
88 
90 :
91  mesh_(mesh),
92  dict_(dictionary::null),
93  active_(false),
94  transient_(false),
95  calcFrequency_(0),
96  maxCo_(GREAT),
97  iter_(0),
98  trackTime_(0.0),
99  deltaTMax_(GREAT),
100  coupled_(false),
101  cellValueSourceCorrection_(false),
102  maxTrackTime_(0.0),
103  resetSourcesOnStartup_(false),
104  schemes_()
105 {}
106 
107 
108 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
109 
111 {}
112 
113 
114 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
115 
117 {
118  dict_.lookup("transient") >> transient_;
119  dict_.lookup("coupled") >> coupled_;
120  dict_.lookup("cellValueSourceCorrection") >> cellValueSourceCorrection_;
121  dict_.readIfPresent("maxCo", maxCo_);
122  dict_.readIfPresent("deltaTMax", deltaTMax_);
123 
124  if (steadyState())
125  {
126  dict_.lookup("calcFrequency") >> calcFrequency_;
127  dict_.lookup("maxTrackTime") >> maxTrackTime_;
128 
129  if (coupled_)
130  {
131  dict_.subDict("sourceTerms").lookup("resetOnStartup")
132  >> resetSourcesOnStartup_;
133  }
134  }
135 
136  if (coupled_)
137  {
138  const dictionary&
139  schemesDict(dict_.subDict("sourceTerms").subDict("schemes"));
140 
141  wordList vars(schemesDict.toc());
142  schemes_.setSize(vars.size());
143  forAll(vars, i)
144  {
145  // read solution variable name
146  schemes_[i].first() = vars[i];
147 
148  // set semi-implicit (1) explicit (0) flag
149  Istream& is = schemesDict.lookup(vars[i]);
150  const word scheme(is);
151  if (scheme == "semiImplicit")
152  {
153  schemes_[i].second().first() = true;
154  }
155  else if (scheme == "explicit")
156  {
157  schemes_[i].second().first() = false;
158  }
159  else
160  {
162  << "Invalid scheme " << scheme << ". Valid schemes are "
163  << "explicit and semiImplicit" << exit(FatalError);
164  }
165 
166  // read under-relaxation factor
167  is >> schemes_[i].second().second();
168  }
169  }
170 }
171 
172 
173 Foam::scalar Foam::cloudSolution::relaxCoeff(const word& fieldName) const
174 {
175  forAll(schemes_, i)
176  {
177  if (fieldName == schemes_[i].first())
178  {
179  return schemes_[i].second().second();
180  }
181  }
182 
184  << "Field name " << fieldName << " not found in schemes"
185  << abort(FatalError);
186 
187  return 1.0;
188 }
189 
190 
191 bool Foam::cloudSolution::semiImplicit(const word& fieldName) const
192 {
193  forAll(schemes_, i)
194  {
195  if (fieldName == schemes_[i].first())
196  {
197  return schemes_[i].second().first();
198  }
199  }
200 
202  << "Field name " << fieldName << " not found in schemes"
203  << abort(FatalError);
204 
205  return false;
206 }
207 
208 
210 {
211  return
212  active_
213  && (
214  mesh_.time().outputTime()
215  || (mesh_.time().timeIndex() % calcFrequency_ == 0)
216  );
217 }
218 
219 
221 {
222  if (transient_)
223  {
224  trackTime_ = mesh_.time().deltaTValue();
225  }
226  else
227  {
228  trackTime_ = maxTrackTime_;
229  }
230 
231  return solveThisStep();
232 }
233 
234 
236 {
237  return active_ && mesh_.time().outputTime();
238 }
239 
240 
241 Foam::scalar Foam::cloudSolution::deltaTMax(const scalar trackTime) const
242 {
243  if (transient_)
244  {
245  return min(deltaTMax_, maxCo_*trackTime);
246  }
247  else
248  {
249  return min(deltaTMax_, trackTime);
250  }
251 }
252 
253 
254 Foam::scalar Foam::cloudSolution::deltaLMax(const scalar lRef) const
255 {
256  return maxCo_*lRef;
257 }
258 
259 
260 // ************************************************************************* //
Foam::cloudSolution::dict_
dictionary dict_
Dictionary used during construction.
Definition: cloudSolution.H:59
Foam::cloudSolution::resetSourcesOnStartup_
Switch resetSourcesOnStartup_
Flag to indicate whether coupling source terms should be.
Definition: cloudSolution.H:102
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::cloudSolution::deltaTMax
scalar deltaTMax() const
Return the maximum integation time step.
Definition: cloudSolutionI.H:104
Foam::dictionary::readIfPresent
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
Definition: dictionaryTemplates.C:94
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::cloudSolution::canEvolve
bool canEvolve()
Returns true if possible to evolve the cloud and sets timestep.
Definition: cloudSolution.C:220
Foam::cloudSolution::deltaLMax
scalar deltaLMax(const scalar lRef) const
Return the maximum integration length.
Definition: cloudSolution.C:254
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::cloudSolution::output
bool output() const
Returns true if writing this step.
Definition: cloudSolution.C:235
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::cloudSolution::solveThisStep
bool solveThisStep() const
Returns true if performing a cloud iteration this calc step.
Definition: cloudSolution.C:209
Foam::Info
messageStream Info
Foam::cloudSolution
Stores all relevant solution info for cloud.
Definition: cloudSolution.H:51
Foam::cloudSolution::semiImplicit
bool semiImplicit(const word &fieldName) const
Return semi-implicit flag coefficient for field.
Definition: cloudSolution.C:191
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
cloudSolution.H
Foam::cloudSolution::relaxCoeff
scalar relaxCoeff(const word &fieldName) const
Return relaxation coefficient for field.
Definition: cloudSolution.C:173
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::dictionary::subOrEmptyDict
dictionary subOrEmptyDict(const word &, const bool mustRead=false) const
Find and return a sub-dictionary as a copy, or.
Definition: dictionary.C:666
Foam::cloudSolution::read
void read()
Read properties from dictionary.
Definition: cloudSolution.C:116
Foam::cloudSolution::cloudSolution
cloudSolution(const fvMesh &mesh)
Construct null from mesh reference.
Definition: cloudSolution.C:89
Foam::dictionary::toc
wordList toc() const
Return the table of contents.
Definition: dictionary.C:697
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::fvc::scheme
tmp< surfaceInterpolationScheme< Type > > scheme(const surfaceScalarField &faceFlux, Istream &streamData)
Return weighting factors for scheme given from Istream.
Definition: surfaceInterpolate.C:43
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::cloudSolution::~cloudSolution
virtual ~cloudSolution()
Destructor.
Definition: cloudSolution.C:110
Foam::cloudSolution::active_
const Switch active_
Cloud active flag.
Definition: cloudSolution.H:62
lookup
stressControl lookup("compactNormalStress") >> compactNormalStress