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-2018 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 (
44  const word& typeName,
45  const word& defaultArg
46 )
47 {
48  if (fieldName_.empty())
49  {
50  fieldName_ = defaultArg;
51  }
52 
53  if (resultName_.empty())
54  {
55  if (fieldName_ != defaultArg)
56  {
57  resultName_ = typeName + '(' + fieldName_ + ')';
58  }
59  else
60  {
61  resultName_ = typeName;
62  }
63  }
64 }
65 
66 
67 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
68 
70 (
71  const word& name,
72  const Time& runTime,
73  const dictionary& dict,
74  const word& fieldName,
75  const word& resultName
76 )
77 :
78  fvMeshFunctionObject(name, runTime, dict),
79  fieldName_(fieldName),
80  resultName_(resultName)
81 {
82  read(dict);
83 }
84 
85 
86 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
87 
89 {}
90 
91 
92 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
93 
95 {
97 
98  if (fieldName_.empty() || dict.found("field"))
99  {
100  dict.lookup("field") >> fieldName_;
101  }
102 
103  if (dict.found("result"))
104  {
105  dict.lookup("result") >> resultName_;
106  }
107 
108  return true;
109 }
110 
111 
113 {
114  if (!calc())
115  {
116  Warning
117  << " functionObjects::" << type() << " " << name()
118  << " failed to execute." << endl;
119 
120  // Clear the result field from the objectRegistry if present
121  clear();
122 
123  return false;
124  }
125  else
126  {
127  return true;
128  }
129 }
130 
131 
133 {
134  return writeObject(resultName_);
135 }
136 
137 
139 {
140  return clearObject(resultName_);
141 }
142 
143 
144 // ************************************************************************* //
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.
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:438
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
tUEqn clear()
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
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.
virtual bool execute()
Calculate the result field.
virtual bool clear()
Clear the result field from the objectRegistry.
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
defineTypeNameAndDebug(Qdot, 0)
messageStream Warning
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:583