@@ -24,47 +24,78 @@ License
24
24
\*---------------------------------------------------------------------------*/
25
25
26
26
#include "pipeCalc.H"
27
-
27
+ #include "addToRunTimeSelectionTable.H"
28
28
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29
29
30
30
namespace Foam
31
31
{
32
- defineTypeNameAndDebug (pipeCalc , 0 );
32
+ namespace functionObjects
33
+ {
34
+ defineTypeNameAndDebug (pipeCalc , 0 );
35
+ addToRunTimeSelectionTable (functionObject , pipeCalc , dictionary );
36
+ }
33
37
}
34
38
35
39
// * * * * * * * * * * * * * * * * Protected members * * * * * * * * * * * * * * //
36
40
37
- // NOTE: this method first gets declared in functionObjectFile.H, from which this
38
- // class is derived. This method gets called automatically when the base object
39
- // function gets called too.
41
+ // NOTE: this returns a list of file names which match indices of the enum
42
+ // defined in the header of this class. These names are used to create matching
43
+ // files by the logFiles object.
44
+ Foam ::wordList Foam ::functionObjects ::pipeCalc ::createFileNames
45
+ (
46
+ const dictionary & dict
47
+ ) const
48
+ {
49
+ DynamicList < word > names (1 );
50
+
51
+ // use type of the utility as specified in the dict as the top-level dir name
52
+ const word objectType (dict .lookup ("type "));
53
+
54
+ // Name for file(MAIN_FILE=0)
55
+ names .append (objectType );
56
+
57
+ return names ;
58
+ }
59
+
60
+ // NOTE: this method first gets declared in logFiles.H, from which this
61
+ // class is derived. This method gets called automatically when the base object's
62
+ // write() function gets called too.
40
63
// The purpose of the function is to add the header to the output data file.
41
- void Foam ::pipeCalc ::writeFileHeader (const label i )
64
+ void Foam ::functionObjects :: pipeCalc ::writeFileHeader (const label i )
42
65
{
43
- writeHeader (file (), "Flow rate through face zone" );
44
- writeHeaderValue (file (), "Face zone name" , faceZoneName_ );
45
- writeCommented (file (), "Time [s] | Flow rate [m3s-1]" );
46
- file () << endl ;
66
+ // Find the correct file to write to from the enum defined in the header.
67
+ switch (fileID (i ))
68
+ {
69
+ case MAIN_FILE :
70
+ {
71
+ writeHeader (file (i ), "Flow rate through face zone" );
72
+ writeHeaderValue (file (i ), "Face zone name" , faceZoneName_ );
73
+ writeCommented (file (i ), "Time [s] | Flow rate [m3s-1]" );
74
+ file () << endl ;
75
+ break ; // exit the case structure
76
+ }
77
+ default :
78
+ {
79
+ FatalErrorInFunction
80
+ << "Unhandled file index: " << i
81
+ << abort (FatalError );
82
+ }
83
+ }
47
84
}
48
85
49
86
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50
- Foam ::pipeCalc ::pipeCalc
87
+ Foam ::functionObjects :: pipeCalc ::pipeCalc
51
88
(
52
89
const word & name ,
53
- const objectRegistry & obr ,
54
- const dictionary & dict ,
55
- const bool loadFromFiles
90
+ const Time & runTime ,
91
+ const dictionary & dict
56
92
)
57
93
:
58
94
// NOTE: call the base class constructor
59
- functionObjectFile (obr , name , type ()),
95
+ fvMeshFunctionObject (name , runTime , dict ),
96
+ logFiles (obr_ , name ),
97
+
60
98
name_ (name ),
61
- obr_ (obr ),
62
- // NOTE: the instance only gets given a reference to the object registry
63
- // automaitcally (this keeps track of what objects, such as fields or
64
- // meshes) are registered in the simulation. The following line casts
65
- // (converts) the reference to a const fvMesh reference, which allows
66
- // the grid to be accessed but not modified.
67
- mesh_ (refCast < const fvMesh > (obr_ )),
68
99
active_ (true),
69
100
UName_ ("U" ),
70
101
// NOTE: Read the face zone to integrate over. Get its name from the dict, find
@@ -73,27 +104,13 @@ Foam::pipeCalc::pipeCalc
73
104
faceZoneLabel_ ( mesh_ .faceZones ().findZoneID (faceZoneName_ ) ),
74
105
faces_ ( mesh_ .faceZones ()[faceZoneLabel_ ] )
75
106
{
76
- // Check if the available mesh is an fvMesh, otherwise deactivate
77
- if (!isA < fvMesh > (obr_ ))
78
- {
79
- active_ = false;
80
- WarningIn
81
- (
82
- "pipeCalc::pipeCalc"
83
- "("
84
- "const word&, "
85
- "const objectRegistry&, "
86
- "const dictionary&, "
87
- "const bool"
88
- ")"
89
- ) << "No fvMesh available, deactivating " << name_ << nl
90
- << endl ;
91
- }
92
-
93
107
// NOTE: calls the separate .read() method to import the controls from the dict.
94
108
// dict reference is passed automatically by the OpenFOAM runtime object manager.
95
109
read (dict );
96
110
111
+ // built-in logFiles method for creating file streams.
112
+ resetNames (createFileNames (dict ));
113
+
97
114
if (active_ )
98
115
{
99
116
// Any extra initialisation goes here, if necessary
@@ -106,40 +123,43 @@ Foam::pipeCalc::pipeCalc
106
123
107
124
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
108
125
109
- Foam ::pipeCalc ::~pipeCalc ()
126
+ Foam ::functionObjects :: pipeCalc ::~pipeCalc ()
110
127
{}
111
128
112
129
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
113
130
114
- void Foam ::pipeCalc ::read (const dictionary & dict )
131
+ bool Foam :: functionObjects ::pipeCalc ::read (const dictionary & dict )
115
132
{
116
133
if (active_ )
117
134
{
118
135
UName_ = dict .lookupOrDefault < word > ("UName" , "U" );
119
136
}
137
+ return true;
120
138
}
121
139
122
- void Foam ::pipeCalc ::execute ()
140
+ bool Foam :: functionObjects ::pipeCalc ::execute ()
123
141
{
124
142
if (active_ )
125
143
{
126
144
// This gets called before write, should put things on which other
127
145
// function objects might depend on here (for instance field calculations)
128
146
}
147
+ return true;
129
148
}
130
149
131
- void Foam ::pipeCalc ::end ()
150
+ bool Foam :: functionObjects ::pipeCalc ::end ()
132
151
{
133
152
if (active_ )
134
153
{
135
154
execute ();
136
155
}
156
+ return true;
137
157
}
138
158
139
- void Foam ::pipeCalc ::timeSet ()
159
+ void Foam ::functionObjects :: pipeCalc ::timeSet ()
140
160
{}
141
161
142
- void Foam ::pipeCalc ::write ()
162
+ bool Foam :: functionObjects ::pipeCalc ::write ()
143
163
{
144
164
if (active_ )
145
165
{
@@ -180,12 +200,13 @@ void Foam::pipeCalc::write()
180
200
// Call the base class method which checks if the output file exists
181
201
// and creates it, if necessary. That also calls the .writeFileHeader()
182
202
// method of the derived class.
183
- functionObjectFile ::write ();
203
+ logFiles ::write ();
184
204
185
205
// Add the entry for this time step that has just been computed.
186
- file () << obr_ .time ().value () << tab << flowRate << endl ;
206
+ file (MAIN_FILE ) << obr_ .time ().value () << tab << flowRate << endl ;
187
207
}
188
208
}
209
+ return true;
189
210
}
190
211
191
212
// ************************************************************************* //
0 commit comments