Loading...
Searching...
No Matches
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-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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"
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
36namespace functionObjects
37{
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 {
65 }
66
68 }
69}
70
71
72// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
73
75(
76 const word& name,
77 const Time& runTime,
78 const dictionary& dict,
79 const word& fieldName,
80 const word& resultName
81)
82:
83 fvMeshFunctionObject(name, runTime, dict),
84 fieldName_(fieldName),
85 resultName_(resultName)
87 read(dict);
88}
89
90
91// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
92
94{
96 {
97 if (fieldName_.empty() || dict.found("field"))
98 {
99 dict.readEntry("field", fieldName_);
100 }
101
102 dict.readIfPresent("result", resultName_);
103
104 if (dict.found("cellZones"))
105 {
106 zoneSubSetPtr_.reset(new Detail::zoneSubSet(mesh_, dict));
107 }
108 else
109 {
110 zoneSubSetPtr_.reset(nullptr);
111 }
112
113 return true;
114 }
115
116 return false;
117}
118
119
121{
122 if (!calc())
123 {
124 Warning
125 << " functionObjects::" << type() << " " << name()
126 << " failed to execute." << endl;
127
128 // Clear the result field from the objectRegistry if present
129 clear();
130
131 return false;
132 }
133
134 return true;
135}
136
141}
142
143
145{
146 return clearObject(resultName_);
147}
148
149
150// ************************************************************************* //
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
word scopedName(const word &name) const
Return a scoped (prefixed) name.
Intermediate class for handling field expression function objects (e.g. blendingFactor etc....
virtual bool read(const dictionary &dict)
Read the function-object dictionary.
word resultName_
Name of result field.
word fieldName_
Name of field to process.
fieldExpression(const word &name, const Time &runTime, const dictionary &dict, const word &fieldName=word::null, const word &resultName=word::null)
Construct from name, Time and dictionary.
virtual bool clear()
Clear the result field from the objectRegistry.
virtual bool execute()
Execute the function-object operations.
autoPtr< Detail::zoneSubSet > zoneSubSetPtr_
Sub-set mesh.
virtual bool write()
Write the function-object results.
virtual bool calc()=0
Calculate the components of the field and return true if successful.
void setResultName(const word &typeName, const word &defaultArg)
Set the name of result field.
const fvMesh & mesh_
Reference to the fvMesh.
fvMeshFunctionObject(const fvMeshFunctionObject &)=delete
No copy construct.
bool writeObject(const word &fieldName)
Write field if present in the (sub) objectRegistry.
bool clearObject(const word &fieldName)
Clear field from the (sub) objectRegistry if present.
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
engineTime & runTime
auto & name
surface1 clear()
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
Namespace for OpenFOAM.
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition int32.H:127
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition POSIX.C:801
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
messageStream Warning
Warning stream (stdout output on master, null elsewhere), with additional 'FOAM Warning' header text.
dictionary dict