systemCall.H
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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2020 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
27Class
28 Foam::functionObjects::systemCall
29
30Group
31 grpUtilitiesFunctionObjects
32
33Description
34 Executes system calls, entered in the form of string lists.
35
36 Calls can be made at the following points in the calculation:
37 - every time step
38 - every output time
39 - end of the calculation
40
41Usage
42 Example of the function object specification:
43 \verbatim
44 systemCall1
45 {
46 type systemCall;
47 libs (utilityFunctionObjects);
48 ...
49 executeCalls
50 (
51 "echo execute"
52 );
53 writeCalls
54 (
55 "echo === writing data ==="
56 );
57 endCalls
58 (
59 "echo === echoing .bashrc ==="
60 "cat ~/.bashrc"
61 "echo \*\*\* done \*\*\*"
62 );
63 }
64 \endverbatim
65
66 Where the entries comprise:
67 \table
68 Property | Description | Required | Default value
69 type | type name: systemCall | yes |
70 executeCalls | list of calls on execute | yes |
71 writeCalls | list of calls on write | yes |
72 endCalls | list of calls on end | yes |
73 master | execute on master only | no | false
74 \endtable
75
76Note
77 Since this function object executes system calls, there is a potential
78 security risk. In order to use the \c systemCall function object, the
79 \c allowSystemOperations must be set to '1'; otherwise, system calls will
80 not be allowed.
81
82 Additionally, since the system commands are normally sent via the shell,
83 special shell character may require backslash escaping.
84
85See also
86 Foam::functionObject
87 Foam::functionObjects::timeControl
88
89SourceFiles
90 systemCall.C
91
92\*---------------------------------------------------------------------------*/
93
94#ifndef functionObjects_systemCall_H
95#define functionObjects_systemCall_H
96
97#include "functionObject.H"
98#include "stringList.H"
99
100// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
101
102namespace Foam
103{
104namespace functionObjects
105{
106
107/*---------------------------------------------------------------------------*\
108 Class systemCall Declaration
109\*---------------------------------------------------------------------------*/
110
111class systemCall
112:
113 public functionObject
114{
115protected:
116
117 // Private data
118
119 //- List of calls to execute - every step
121
122 //- List of calls to execute - write steps
124
125 //- List of calls to execute when exiting the time-loop
127
128 //- Perform system calls on the master only
129 bool masterOnly_;
130
131
132 // Protected Member Functions
133
134 //- Dispatch specified calls
135 label dispatch(const stringList& calls);
136
137 //- No copy construct
138 systemCall(const systemCall&) = delete;
139
140 //- No copy assignment
141 void operator=(const systemCall&) = delete;
142
143
144public:
145
146 //- Runtime type information
147 TypeName("systemCall");
148
150 // Constructors
151
152 //- Construct from Time and dictionary
154 (
155 const word& name,
156 const Time& runTime,
157 const dictionary& dict
158 );
159
160
161 //- Destructor
162 virtual ~systemCall() = default;
163
164
165 // Member Functions
166
167 //- Read the system calls
168 virtual bool read(const dictionary& dict);
169
170 //- Execute the "executeCalls" at each time-step
171 virtual bool execute();
172
173 //- Write, execute the "writeCalls"
174 virtual bool write();
175
176 //- Execute the "endCalls" at the final time-loop
177 virtual bool end();
178};
179
180
181// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182
183} // End namespace functionObjects
184} // End namespace Foam
185
186// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
187
188#endif
189
190// ************************************************************************* //
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Abstract base-class for Time/database function objects.
const word & name() const noexcept
Return the name of this functionObject.
Executes system calls, entered in the form of string lists.
Definition: systemCall.H:143
label dispatch(const stringList &calls)
Dispatch specified calls.
Definition: systemCall.C:55
bool masterOnly_
Perform system calls on the master only.
Definition: systemCall.H:158
stringList writeCalls_
List of calls to execute - write steps.
Definition: systemCall.H:152
systemCall(const systemCall &)=delete
No copy construct.
TypeName("systemCall")
Runtime type information.
stringList executeCalls_
List of calls to execute - every step.
Definition: systemCall.H:149
virtual bool read(const dictionary &dict)
Read the system calls.
Definition: systemCall.C:104
virtual ~systemCall()=default
Destructor.
stringList endCalls_
List of calls to execute when exiting the time-loop.
Definition: systemCall.H:155
virtual bool execute()
Execute the "executeCalls" at each time-step.
Definition: systemCall.C:152
virtual bool write()
Write, execute the "writeCalls".
Definition: systemCall.C:159
void operator=(const systemCall &)=delete
No copy assignment.
virtual bool end()
Execute the "endCalls" at the final time-loop.
Definition: systemCall.C:166
A class for handling words, derived from Foam::string.
Definition: word.H:68
engineTime & runTime
Namespace for OpenFOAM.
List< string > stringList
A List of strings.
Definition: stringList.H:58
dictionary dict
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73