log.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) 2018-2020 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 "log.H"
27 #include "volFields.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace functionObjects
35 {
37 
39  (
40  functionObject,
41  log,
42  dictionary
43  );
44 }
45 }
46 
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
50 bool Foam::functionObjects::log::calc()
51 {
52  if (foundObject<volScalarField>(fieldName_))
53  {
54  const volScalarField& x = lookupObject<volScalarField>(fieldName_);
55 
56  // Cache the current debug setting for dimensionSet
57  const bool dimensionSetDebug = dimensionSet::debug;
58 
59  // Switch-off dimension checking if requested
60  if (!checkDimensions_)
61  {
62  dimensionSet::debug = 0;
63  }
64 
65  bool stored = store
66  (
67  resultName_,
68  clip_ ? Foam::log(max(x, clipValue_)) : Foam::log(x)
69  );
70 
71  // Reinstate dimension checking
72  if (!checkDimensions_)
73  {
74  dimensionSet::debug = dimensionSetDebug;
75  }
76 
77  return stored;
78  }
79  else
80  {
81  cannotFindObject<volScalarField>(fieldName_);
82 
83  return false;
84  }
85 
86  return true;
87 }
88 
89 
90 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
91 
93 (
94  const word& name,
95  const Time& runTime,
96  const dictionary& dict
97 )
98 :
99  fieldExpression(name, runTime, dict, typeName),
100  clip_(false),
101  clipValue_(0),
102  checkDimensions_(true)
103 {
104  read(dict);
105 }
106 
107 
108 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
109 
111 {}
112 
113 
114 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
115 
117 {
118  if (dict.found("clip"))
119  {
120  clip_ = true;
121  dict.lookup("clip") >> clipValue_;
122  }
123 
124  checkDimensions_ = dict.lookupOrDefault<Switch>("checkDimensions", true);
125 
126  return true;
127 }
128 
129 
130 // ************************************************************************* //
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:643
dimensionedScalar log(const dimensionedScalar &ds)
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
addToRunTimeSelectionTable(functionObject, Qdot, dictionary)
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none/any.
Definition: Switch.H:60
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Macros for easy insertion into run-time selection tables.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
bool read(const char *, int32_t &)
Definition: int32IO.C:85
A class for handling words, derived from string.
Definition: word.H:59
virtual bool read(const dictionary &)
Read the randomise data.
Definition: log.C:116
defineTypeNameAndDebug(Qdot, 0)
log(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: log.C:93
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
virtual ~log()
Destructor.
Definition: log.C:110
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:844