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-2026 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 
41 
42 
44 
45 
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 
49 (
50  const word& name,
51  const Time& runTime,
52  const dictionary& dict,
53  const word& functionName,
54  const word& defaultFieldName
55 )
56 :
57  fvMeshFunctionObject(name, runTime, dict),
58  fieldName_
59  (
60  &defaultFieldName == &noFieldName_ ? word::null
61  : &defaultFieldName == &noDefaultFieldName_ ? dict.lookup<word>("field")
62  : dict.lookupOrDefault("field", defaultFieldName)
63  ),
64  resultName_
65  (
66  dict.found("result") ? dict.lookup<word>("result")
67  : &defaultFieldName == &noFieldName_ ? functionName
68  : fieldName_ == defaultFieldName ? functionName
69  : word(functionName + '(' + fieldName_ + ')')
70  )
71 {
72  read(dict);
73 }
74 
75 
76 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
77 
79 {}
80 
81 
82 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
83 
85 {
86  return fieldName_ == word::null ? wordList() : wordList(fieldName_);
87 }
88 
89 
91 {
92  if (!calc())
93  {
94  Warning
95  << " functionObjects::" << type() << " " << name()
96  << " failed to execute." << endl;
97 
98  // Clear the result field from the objectRegistry if present
99  clear();
100 
101  return false;
102  }
103  else
104  {
105  return true;
106  }
107 }
108 
109 
111 {
112  return writeObject(resultName_);
113 }
114 
115 
117 {
118  return clearObject(resultName_);
119 }
120 
121 
122 // ************************************************************************* //
bool found
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
A functionName is a word starting with '#'.
Definition: functionName.H:60
static const word noFieldName_
Word indicating that this fieldExpression has no field name.
fieldExpression(const word &name, const Time &runTime, const dictionary &dict, const word &functionName, const word &defaultFieldName=noDefaultFieldName_)
Construct from Time and dictionary.
static const word noDefaultFieldName_
Word indicating that this fieldExpression has no default field.
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...
virtual bool read(const dictionary &)
Read optional controls.
A class for handling words, derived from string.
Definition: word.H:63
static const word null
An empty word.
Definition: word.H:78
tUEqn clear()
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
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:288
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
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