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 | Copyright (C) 2016 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 {
35  defineTypeNameAndDebug(fieldExpression, 0);
36 }
37 }
38 
39 
40 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
41 
43 {
45  return false;
46 }
47 
48 
50 (
51  const word& typeName,
52  const word& defaultArg
53 )
54 {
55  if (fieldName_.empty())
56  {
57  fieldName_ = defaultArg;
58  }
59 
60  if (resultName_.empty())
61  {
62  if (fieldName_ != defaultArg)
63  {
64  resultName_ = typeName + '(' + fieldName_ + ')';
65  }
66  else
67  {
68  resultName_ = typeName;
69  }
70  }
71 }
72 
73 
74 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
75 
76 Foam::functionObjects::fieldExpression::fieldExpression
77 (
78  const word& name,
79  const Time& runTime,
80  const dictionary& dict,
81  const word& fieldName,
82  const word& resultName
83 )
84 :
85  fvMeshFunctionObject(name, runTime, dict),
86  fieldName_(fieldName),
87  resultName_(resultName)
88 {
89  read(dict);
90 }
91 
92 
93 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
94 
96 {}
97 
98 
99 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
100 
102 {
104 
105  if (fieldName_.empty() || dict.found("field"))
106  {
107  dict.lookup("field") >> fieldName_;
108  }
109 
110  if (dict.found("result"))
111  {
112  dict.lookup("result") >> resultName_;
113  }
114 
115  return true;
116 }
117 
118 
120 {
121  if (!calc())
122  {
123  Warning
124  << "functionObject " << type() << ": Cannot find required field "
125  << fieldName_ << endl;
126 
127  // Clear the result field from the objectRegistry if present
128  clear();
129 
130  return false;
131  }
132  else
133  {
134  return true;
135  }
136 }
137 
138 
140 {
141  return writeObject(resultName_);
142 }
143 
144 
146 {
147  return clearObject(resultName_);
148 }
149 
150 
151 // ************************************************************************* //
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
tUEqn clear()
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
void setResultName(const word &typeName, const word &defaultArg)
virtual bool read(const dictionary &)
Read optional controls.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
A class for handling words, derived from string.
Definition: word.H:59
virtual bool write()
Write the result field.
virtual bool read(const dictionary &)
Read the fieldExpression data.
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:306
virtual bool execute()
Calculate the result field.
virtual bool clear()
Clear the result field from the objectRegistry.
messageStream Warning
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:461
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:366
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:451