fieldExpression.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) 2016-2022 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 "fieldExpression.H"
27 #include "dictionary.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 namespace functionObjects
34 {
36 }
37 }
38 
39 
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 
43 (
44  const word& name,
45  const Time& runTime,
46  const dictionary& dict,
47  const word& functionName,
48  const word& defaultFieldName
49 )
50 :
51  fvMeshFunctionObject(name, runTime, dict),
52  fieldName_(dict.lookupOrDefault("field", defaultFieldName)),
53  resultName_
54  (
55  dict.found("result")
56  ? dict.lookup("result")
57  : (defaultFieldName.empty() || fieldName_ != defaultFieldName)
58  ? word(functionName + '(' + fieldName_ + ')')
59  : functionName
60  )
61 {}
62 
63 
64 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
65 
67 {}
68 
69 
70 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
71 
73 {
74  return wordList(fieldName_);
75 }
76 
77 
79 {
80  if (!calc())
81  {
82  Warning
83  << " functionObjects::" << type() << " " << name()
84  << " failed to execute." << endl;
85 
86  // Clear the result field from the objectRegistry if present
87  clear();
88 
89  return false;
90  }
91  else
92  {
93  return true;
94  }
95 }
96 
97 
99 {
100  return writeObject(resultName_);
101 }
102 
103 
105 {
106  return clearObject(resultName_);
107 }
108 
109 
110 // ************************************************************************* //
bool found
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
A functionName is a word starting with '#'.
Definition: functionName.H:60
fieldExpression(const word &name, const Time &runTime, const dictionary &dict, const word &functionName, const word &defaultFieldName=word::null)
Construct from Time and dictionary.
virtual wordList fields() const
Return the field required.
virtual bool clear()
Clear the result field from the objectRegistry.
virtual bool execute()
Calculate the result field.
virtual bool write()
Write the result field.
Specialisation of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
A class for handling words, derived from string.
Definition: word.H:62
tUEqn clear()
defineTypeNameAndDebug(adjustTimeStepToCombustion, 0)
Namespace for OpenFOAM.
List< word > wordList
A List of words.
Definition: fileName.H:54
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
messageStream Warning
dictionary dict