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-2023 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_
318  (
319  ITstream
320  (
321  objectPath() + ".ddtSchemes",
322  tokenList()
323  )()
324  ),
325  defaultDdtScheme_
326  (
327  ddtSchemes_.name() + ".default",
328  tokenList()
329  ),
330  d2dt2Schemes_
331  (
332  ITstream
333  (
334  objectPath() + ".d2dt2Schemes",
335  tokenList()
336  )()
337  ),
338  defaultD2dt2Scheme_
339  (
340  d2dt2Schemes_.name() + ".default",
341  tokenList()
342  ),
343  interpolationSchemes_
344  (
345  ITstream
346  (
347  objectPath() + ".interpolationSchemes",
348  tokenList()
349  )()
350  ),
351  defaultInterpolationScheme_
352  (
353  interpolationSchemes_.name() + ".default",
354  tokenList()
355  ),
356  divSchemes_
357  (
358  ITstream
359  (
360  objectPath() + ".divSchemes",
361  tokenList()
362  )()
363  ),
364  defaultDivScheme_
365  (
366  divSchemes_.name() + ".default",
367  tokenList()
368  ),
369  gradSchemes_
370  (
371  ITstream
372  (
373  objectPath() + ".gradSchemes",
374  tokenList()
375  )()
376  ),
377  defaultGradScheme_
378  (
379  gradSchemes_.name() + ".default",
380  tokenList()
381  ),
382  snGradSchemes_
383  (
384  ITstream
385  (
386  objectPath() + ".snGradSchemes",
387  tokenList()
388  )()
389  ),
390  defaultSnGradScheme_
391  (
392  snGradSchemes_.name() + ".default",
393  tokenList()
394  ),
395  laplacianSchemes_
396  (
397  ITstream
398  (
399  objectPath() + ".laplacianSchemes",
400  tokenList()
401  )()
402  ),
403  defaultLaplacianScheme_
404  (
405  laplacianSchemes_.name() + ".default",
406  tokenList()
407  ),
408  fluxRequired_
409  (
410  ITstream
411  (
412  objectPath() + ".fluxRequired",
413  tokenList()
414  )()
415  ),
416  defaultFluxRequired_(false),
417  steady_(false)
418 {
419  read(dict());
420 }
421 
422 
423 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
424 
426 {
427  if (regIOobject::read())
428  {
429  // Clear current settings except fluxRequired
430  clear();
431 
432  read(dict());
433 
434  return true;
435  }
436  else
437  {
438  return false;
439  }
440 }
441 
442 
444 {
445  if (found("select"))
446  {
447  return subDict(word(lookup("select")));
448  }
449  else
450  {
451  return *this;
452  }
453 }
454 
455 
457 {
458  return lookupScheme(name, ddtSchemes_, defaultDdtScheme_);
459 }
460 
461 
463 {
464  return lookupScheme(name, d2dt2Schemes_, defaultD2dt2Scheme_);
465 }
466 
467 
469 {
470  return lookupScheme
471  (
472  name,
473  interpolationSchemes_,
474  defaultInterpolationScheme_
475  );
476 }
477 
478 
480 {
481  return lookupScheme(name, divSchemes_, defaultDivScheme_);
482 }
483 
484 
486 {
487  return lookupScheme(name, gradSchemes_, defaultGradScheme_);
488 }
489 
490 
492 {
493  return lookupScheme(name, snGradSchemes_, defaultSnGradScheme_);
494 }
495 
496 
498 {
499  return lookupScheme(name, laplacianSchemes_, defaultLaplacianScheme_);
500 }
501 
502 
504 {
505  if (debug)
506  {
507  Info<< "Setting fluxRequired for " << name << endl;
508  }
509 
510  fluxRequired_.add(name, true, true);
511 }
512 
513 
515 {
516  if (debug)
517  {
518  Info<< "Lookup fluxRequired for " << name << endl;
519  }
520 
521  if (fluxRequired_.found(name))
522  {
523  return true;
524  }
525  else
526  {
527  return defaultFluxRequired_;
528  }
529 }
530 
531 
532 // ************************************************************************* //
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 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
void set(entry *)
Assign a new entry, overwrite any existing entry.
Definition: dictionary.C:1152
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:843
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:1014
void clear()
Clear the dictionary.
Definition: dictionary.C:1344
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:509
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:503
ITstream & interpolation(const word &name) const
Definition: fvSchemes.C:468
ITstream & snGrad(const word &name) const
Definition: fvSchemes.C:491
ITstream & grad(const word &name) const
Definition: fvSchemes.C:485
const dictionary & dict() const
Definition: fvSchemes.C:443
ITstream & ddt(const word &name) const
Definition: fvSchemes.C:456
fvSchemes(const objectRegistry &obr)
Construct for objectRegistry.
Definition: fvSchemes.C:304
ITstream & laplacian(const word &name) const
Definition: fvSchemes.C:497
ITstream & div(const word &name) const
Definition: fvSchemes.C:479
ITstream & d2dt2(const word &name) const
Definition: fvSchemes.C:462
bool read()
Read the fvSchemes.
Definition: fvSchemes.C:425
bool fluxRequired(const word &name) const
Definition: fvSchemes.C:514
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:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
messageStream Info
defineTypeNameAndDebug(combustionModel, 0)
IOerror FatalIOError
dictionary dict