fieldExpression.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2016 OpenFOAM Foundation
9  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "fieldExpression.H"
30 #include "dictionary.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace functionObjects
37 {
38  defineTypeNameAndDebug(fieldExpression, 0);
39 }
40 }
41 
42 
43 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
44 
46 (
47  const word& typeName,
48  const word& defaultArg
49 )
50 {
51  if (fieldName_.empty())
52  {
53  fieldName_ = defaultArg;
54  }
55 
56  if (resultName_.empty())
57  {
58  if (fieldName_ != defaultArg)
59  {
60  resultName_ = typeName + '(' + fieldName_ + ')';
61  }
62  else
63  {
64  resultName_ = typeName;
65  }
66  }
67 }
68 
69 
70 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
71 
73 (
74  const word& name,
75  const Time& runTime,
76  const dictionary& dict,
77  const word& fieldName,
78  const word& resultName
79 )
80 :
82  fieldName_(fieldName),
83  resultName_(resultName)
84 {
85  read(dict);
86 }
87 
88 
89 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
90 
92 {
94 
95  if (fieldName_.empty() || dict.found("field"))
96  {
97  dict.readEntry("field", fieldName_);
98  }
99 
100  dict.readIfPresent("result", resultName_);
101 
102  return true;
103 }
104 
105 
107 {
108  if (!calc())
109  {
110  Warning
111  << " functionObjects::" << type() << " " << name()
112  << " failed to execute." << endl;
113 
114  // Clear the result field from the objectRegistry if present
115  clear();
116 
117  return false;
118  }
119 
120  return true;
121 }
122 
123 
125 {
126  return writeObject(resultName_);
127 }
128 
129 
131 {
132  return clearObject(resultName_);
133 }
134 
135 
136 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::Warning
messageStream Warning
Foam::functionObjects::fieldExpression::read
virtual bool read(const dictionary &dict)
Read the fieldExpression data.
Definition: fieldExpression.C:91
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
Foam::functionObjects::fieldExpression::clear
virtual bool clear()
Clear the result field from the objectRegistry.
Definition: fieldExpression.C:130
Foam::functionObjects::fieldExpression::setResultName
void setResultName(const word &typeName, const word &defaultArg)
Set the name of result field.
Definition: fieldExpression.C:46
Foam::functionObjects::fieldExpression::fieldExpression
fieldExpression(const word &name, const Time &runTime, const dictionary &dict, const word &fieldName=word::null, const word &resultName=word::null)
Construct from Time and dictionary.
Definition: fieldExpression.C:73
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::blockMeshTools::read
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:33
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::functionObjects::fieldExpression::fieldName_
word fieldName_
Name of field to process.
Definition: fieldExpression.H:112
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Read optional controls.
Definition: regionFunctionObject.C:173
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
clear
patchWriters clear()
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
dictionary.H
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(ObukhovLength, 0)
fieldExpression.H
Foam::functionObjects::fieldExpression::write
virtual bool write()
Write the result field.
Definition: fieldExpression.C:124
Foam::functionObjects::fieldExpression::execute
virtual bool execute()
Calculate the result field.
Definition: fieldExpression.C:106
Foam::functionObjects::fieldExpression::resultName_
word resultName_
Name of result field.
Definition: fieldExpression.H:115