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-2019 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 // * * * * * * * * * * * * * * * * 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 
63 
64 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
65 
67 {}
68 
69 
70 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
71 
73 {
74  return true;
75 }
76 
77 
79 {
80  if (!calc())
81  {
82  Warning
83  << " functionObjects::" << type() << " " << name()
84  << " failed to execute." << endl;
85 
86  // Clear the result field from the objectRegistry if present
87  clear();
88 
89  return false;
90  }
91  else
92  {
93  return true;
94  }
95 }
96 
97 
99 {
100  return writeObject(resultName_);
101 }
102 
103 
105 {
106  return clearObject(resultName_);
107 }
108 
109 
110 // ************************************************************************* //
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:667
tUEqn clear()
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
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
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
fieldExpression(const word &name, const Time &runTime, const dictionary &dict, const word &functionName, const word &defaultFieldName=word::null)
Construct from Time and dictionary.
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:812