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  (
41  log,
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  (
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 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:61
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
Abstract base-class for Time/database functionObjects.
Switch log
Switch write log to Info.
word resultName_
Name of result field.
const word fieldName_
Name of field to process.
Calculates the natural logarithm of the specified scalar field.
Definition: log.H:106
virtual ~log()
Destructor.
Definition: log.C:110
virtual bool read(const dictionary &)
Read the randomise data.
Definition: log.C:116
bool store(const tmp< ObjectType > &tfield)
Store the given field in the objectRegistry.
A class for handling words, derived from string.
Definition: word.H:62
defineTypeNameAndDebug(adjustTimeStepToCombustion, 0)
addToRunTimeSelectionTable(functionObject, adjustTimeStepToCombustion, dictionary)
Namespace for OpenFOAM.
dimensionedScalar log(const dimensionedScalar &ds)
VolField< scalar > volScalarField
Definition: volFieldsFwd.H:61
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
dictionary dict