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-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 "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  read(dict);
63 }
64 
65 
66 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
67 
69 {}
70 
71 
72 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
73 
75 {
76  return wordList(fieldName_);
77 }
78 
79 
81 {
82  if (!calc())
83  {
84  Warning
85  << " functionObjects::" << type() << " " << name()
86  << " failed to execute." << endl;
87 
88  // Clear the result field from the objectRegistry if present
89  clear();
90 
91  return false;
92  }
93  else
94  {
95  return true;
96  }
97 }
98 
99 
101 {
102  return writeObject(resultName_);
103 }
104 
105 
107 {
108  return clearObject(resultName_);
109 }
110 
111 
112 // ************************************************************************* //
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:162
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...
virtual bool read(const dictionary &)
Read optional controls.
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:257
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