fvSchemes.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-2024 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 "fvSchemes.H"
27 #include "Time.H"
28 #include "steadyStateDdtScheme.H"
29 #include "steadyStateD2dt2Scheme.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
36 }
37 
38 
39 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
40 
41 void Foam::fvSchemes::clear()
42 {
43  ddtSchemes_.clear();
44  defaultDdtScheme_.clear();
45  d2dt2Schemes_.clear();
46  defaultD2dt2Scheme_.clear();
47  interpolationSchemes_.clear();
48  defaultInterpolationScheme_.clear();
49  divSchemes_.clear();
50  defaultDivScheme_.clear();
51  gradSchemes_.clear();
52  defaultGradScheme_.clear();
53  snGradSchemes_.clear();
54  defaultSnGradScheme_.clear();
55  laplacianSchemes_.clear();
56  defaultLaplacianScheme_.clear();
57  // Do not clear fluxRequired settings
58 }
59 
60 
61 void Foam::fvSchemes::read(const dictionary& dict)
62 {
63  if (dict.found("ddtSchemes"))
64  {
65  ddtSchemes_ = dict.subDict("ddtSchemes");
66  }
67  else
68  {
69  ddtSchemes_.set("default", "none");
70  }
71 
72  if
73  (
74  ddtSchemes_.found("default")
75  && word(ddtSchemes_.lookup("default")) != "none"
76  )
77  {
78  defaultDdtScheme_ = ddtSchemes_.lookup("default");
79  steady_ =
80  (
81  word(defaultDdtScheme_)
82  == fv::steadyStateDdtScheme<scalar>::typeName
83  );
84  }
85 
86 
87  if (dict.found("d2dt2Schemes"))
88  {
89  d2dt2Schemes_ = dict.subDict("d2dt2Schemes");
90  }
91  else
92  {
93  d2dt2Schemes_.set("default", "none");
94  }
95 
96  if
97  (
98  d2dt2Schemes_.found("default")
99  && word(d2dt2Schemes_.lookup("default")) != "none"
100  )
101  {
102  defaultD2dt2Scheme_ = d2dt2Schemes_.lookup("default");
103  steady_ =
104  (
105  word(defaultD2dt2Scheme_)
106  == fv::steadyStateD2dt2Scheme<scalar>::typeName
107  );
108  }
109 
110 
111  if (dict.found("interpolationSchemes"))
112  {
113  interpolationSchemes_ = dict.subDict("interpolationSchemes");
114  }
115  else if (!interpolationSchemes_.found("default"))
116  {
117  interpolationSchemes_.add("default", "linear");
118  }
119 
120  if
121  (
122  interpolationSchemes_.found("default")
123  && word(interpolationSchemes_.lookup("default")) != "none"
124  )
125  {
126  defaultInterpolationScheme_ =
127  interpolationSchemes_.lookup("default");
128  }
129 
130 
131  divSchemes_ = dict.subDict("divSchemes");
132 
133  if
134  (
135  divSchemes_.found("default")
136  && word(divSchemes_.lookup("default")) != "none"
137  )
138  {
139  defaultDivScheme_ = divSchemes_.lookup("default");
140  }
141 
142 
143  gradSchemes_ = dict.subDict("gradSchemes");
144 
145  if
146  (
147  gradSchemes_.found("default")
148  && word(gradSchemes_.lookup("default")) != "none"
149  )
150  {
151  defaultGradScheme_ = gradSchemes_.lookup("default");
152  }
153 
154 
155  if (dict.found("snGradSchemes"))
156  {
157  snGradSchemes_ = dict.subDict("snGradSchemes");
158  }
159  else if (!snGradSchemes_.found("default"))
160  {
161  snGradSchemes_.add("default", "corrected");
162  }
163 
164  if
165  (
166  snGradSchemes_.found("default")
167  && word(snGradSchemes_.lookup("default")) != "none"
168  )
169  {
170  defaultSnGradScheme_ = snGradSchemes_.lookup("default");
171  }
172 
173 
174  laplacianSchemes_ = dict.subDict("laplacianSchemes");
175 
176  if
177  (
178  laplacianSchemes_.found("default")
179  && word(laplacianSchemes_.lookup("default")) != "none"
180  )
181  {
182  defaultLaplacianScheme_ = laplacianSchemes_.lookup("default");
183  }
184 
185 
186  if (dict.found("fluxRequired"))
187  {
188  fluxRequired_.merge(dict.subDict("fluxRequired"));
189 
190  if
191  (
192  fluxRequired_.found("default")
193  && word(fluxRequired_.lookup("default")) != "none"
194  )
195  {
196  defaultFluxRequired_ = Switch(fluxRequired_.lookup("default"));
197  }
198  }
199 }
200 
201 
202 Foam::word Foam::fvSchemes::filterGroup(const word& name) const
203 {
204  word filteredName(name);
205 
206  word::size_type n = 0;
207  word::iterator iter2 = filteredName.begin();
208 
209  bool found = false;
210 
211  for
212  (
213  word::const_iterator iter1 = filteredName.begin();
214  iter1 != filteredName.end();
215  ++iter1
216  )
217  {
218  const char c = *iter1;
219 
220  if (c == '.')
221  {
222  found = true;
223  }
224  else if (!found || !isalnum(c))
225  {
226  found = false;
227  *iter2++ = c;
228  n++;
229  }
230  }
231 
232  filteredName.resize(n);
233 
234  return filteredName;
235 }
236 
237 
238 Foam::ITstream& Foam::fvSchemes::lookupScheme
239 (
240  const word& name,
241  const dictionary& schemes,
242  const ITstream& defaultScheme
243 ) const
244 {
245  if (debug)
246  {
247  Info<< "Lookup scheme for " << name
248  << " in dictionary " << schemes.name().caseName() << endl;
249  }
250 
251  // Lookup scheme with optional wildcards
252  const entry* schemePtr = schemes.lookupEntryPtr(name, false, true);
253 
254  if (schemePtr)
255  {
256  return schemePtr->stream();
257  }
258  else
259  {
260  // If scheme not found check if it contains group names
261  bool filtered = (name.find('.') != word::npos);
262 
263  if (filtered)
264  {
265  // Filter-out the group names and lookup
266  const entry* schemePtr =
267  schemes.lookupEntryPtr(filterGroup(name), false, true);
268 
269  if (schemePtr)
270  {
271  return schemePtr->stream();
272  }
273  }
274 
275  // If scheme still not found check if a default scheme is provided
276  if (!defaultScheme.empty())
277  {
278  const_cast<ITstream&>(defaultScheme).rewind();
279  return const_cast<ITstream&>(defaultScheme);
280  }
281  else
282  {
283  // Cannot find scheme
284 
285  FatalIOErrorInFunction(schemes)
286  << "Cannot find scheme for " << name;
287 
288  if (filtered)
289  {
290  FatalIOError << " or " << filterGroup(name);
291  }
292 
294  << " in dictionary " << schemes.name().caseName()
295  << exit(FatalIOError);
296  return const_cast<ITstream&>(defaultScheme);
297  }
298  }
299 }
300 
301 
302 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
303 
305 :
307  (
308  IOobject
309  (
310  "fvSchemes",
311  obr.time().system(),
312  obr,
313  IOobject::MUST_READ_IF_MODIFIED,
314  IOobject::NO_WRITE
315  )
316  ),
317  ddtSchemes_("ddtSchemes", dict()),
318  defaultDdtScheme_
319  (
320  ddtSchemes_.name() + ".default",
321  tokenList()
322  ),
323  d2dt2Schemes_("d2dt2Schemes", dict()),
324  defaultD2dt2Scheme_
325  (
326  d2dt2Schemes_.name() + ".default",
327  tokenList()
328  ),
329  interpolationSchemes_("interpolationSchemes", dict()),
330  defaultInterpolationScheme_
331  (
332  interpolationSchemes_.name() + ".default",
333  tokenList()
334  ),
335  divSchemes_("divSchemes", dict()),
336  defaultDivScheme_
337  (
338  divSchemes_.name() + ".default",
339  tokenList()
340  ),
341  gradSchemes_("snGradSchemes", dict()),
342  defaultGradScheme_
343  (
344  gradSchemes_.name() + ".default",
345  tokenList()
346  ),
347  snGradSchemes_("snGradSchemes", dict()),
348  defaultSnGradScheme_
349  (
350  snGradSchemes_.name() + ".default",
351  tokenList()
352  ),
353  laplacianSchemes_("fluxRequired", dict()),
354  defaultLaplacianScheme_
355  (
356  laplacianSchemes_.name() + ".default",
357  tokenList()
358  ),
359  fluxRequired_("fluxRequired", dict()),
360  defaultFluxRequired_(false),
361  steady_(false)
362 {
363  read(dict());
364 }
365 
366 
367 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
368 
370 {
371  if (regIOobject::read())
372  {
373  // Clear current settings except fluxRequired
374  clear();
375 
376  read(dict());
377 
378  return true;
379  }
380  else
381  {
382  return false;
383  }
384 }
385 
386 
388 {
389  if (found("select"))
390  {
391  return subDict(word(lookup("select")));
392  }
393  else
394  {
395  return *this;
396  }
397 }
398 
399 
401 {
402  return lookupScheme(name, ddtSchemes_, defaultDdtScheme_);
403 }
404 
405 
407 {
408  return lookupScheme(name, d2dt2Schemes_, defaultD2dt2Scheme_);
409 }
410 
411 
413 {
414  return lookupScheme
415  (
416  name,
417  interpolationSchemes_,
418  defaultInterpolationScheme_
419  );
420 }
421 
422 
424 {
425  return lookupScheme(name, divSchemes_, defaultDivScheme_);
426 }
427 
428 
430 {
431  return lookupScheme(name, gradSchemes_, defaultGradScheme_);
432 }
433 
434 
436 {
437  return lookupScheme(name, snGradSchemes_, defaultSnGradScheme_);
438 }
439 
440 
442 {
443  return lookupScheme(name, laplacianSchemes_, defaultLaplacianScheme_);
444 }
445 
446 
448 {
449  if (debug)
450  {
451  Info<< "Setting fluxRequired for " << name << endl;
452  }
453 
454  fluxRequired_.add(name, true, true);
455 }
456 
457 
459 {
460  if (debug)
461  {
462  Info<< "Lookup fluxRequired for " << name << endl;
463  }
464 
465  if (fluxRequired_.found(name))
466  {
467  return true;
468  }
469  else
470  {
471  return defaultFluxRequired_;
472  }
473 }
474 
475 
476 // ************************************************************************* //
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
bool found
label n
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:57
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
Input token stream.
Definition: ITstream.H:53
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:125
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
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:740
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:849
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:1020
void clear()
Clear the dictionary.
Definition: dictionary.C:1359
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:539
Selector class for finite volume differencing schemes. fvMesh is derived from fvSchemes so that all f...
Definition: fvSchemes.H:53
void setFluxRequired(const word &name) const
Definition: fvSchemes.C:447
ITstream & interpolation(const word &name) const
Definition: fvSchemes.C:412
ITstream & snGrad(const word &name) const
Definition: fvSchemes.C:435
ITstream & grad(const word &name) const
Definition: fvSchemes.C:429
const dictionary & dict() const
Definition: fvSchemes.C:387
ITstream & ddt(const word &name) const
Definition: fvSchemes.C:400
fvSchemes(const objectRegistry &obr)
Construct for objectRegistry.
Definition: fvSchemes.C:304
ITstream & laplacian(const word &name) const
Definition: fvSchemes.C:441
ITstream & div(const word &name) const
Definition: fvSchemes.C:423
ITstream & d2dt2(const word &name) const
Definition: fvSchemes.C:406
bool read()
Read the fvSchemes.
Definition: fvSchemes.C:369
bool fluxRequired(const word &name) const
Definition: fvSchemes.C:458
Registry of regIOobjects.
virtual bool read()
Read object.
A class for handling words, derived from string.
Definition: word.H:62
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
tUEqn clear()
const dimensionedScalar c
Speed of light in a vacuum.
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
int system(const std::string &command)
Execute the specified command.
Definition: POSIX.C:1230
bool read(const char *, int32_t &)
Definition: int32IO.C:85
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
messageStream Info
defineTypeNameAndDebug(combustionModel, 0)
IOerror FatalIOError
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
dictionary dict