Loading...
Searching...
No Matches
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 Minimal example by using \c system/controlDict.functions:
43 \verbatim
44 systemCallFO
45 {
46 // Mandatory entries
47 type systemCall;
48 libs (utilityFunctionObjects);
49 ...
50
51 // Optional entries
52 executeCalls
53 (
54 "echo execute"
55 );
56 writeCalls
57 (
58 "echo === writing data ==="
59 );
60 endCalls
61 (
62 "echo === echoing .bashrc ==="
63 "cat ~/.bashrc"
64 "echo \*\*\* done \*\*\*"
65 );
66
67 // Inherited entries
68 ...
69 }
70 \endverbatim
71
72 where the entries mean:
73 \table
74 Property | Description | Type | Reqd | Deflt
75 type | Type name: systemCall | word | yes | -
76 libs | Library name: utilityFunctionObjects | word | yes | -
77 executeCalls | List of calls on execute | stringList | yes | -
78 writeCalls | List of calls on write | stringList | yes | -
79 endCalls | List of calls on end | stringList | yes | -
80 master | Execute on master only | bool | no | false
81 \endtable
82
83 The inherited entries are elaborated in:
84 - \link functionObject.H \endlink
85
86Note
87 Since this function object executes system calls, there is a potential
88 security risk. In order to use the \c systemCall function object, the
89 \c allowSystemOperations must be set to '1'; otherwise, system calls will
90 not be allowed.
91
92 Additionally, since the system commands are normally sent via the shell,
93 special shell character may require backslash escaping.
94
95SourceFiles
96 systemCall.C
97
98\*---------------------------------------------------------------------------*/
99
100#ifndef Foam_functionObjects_systemCall_H
101#define Foam_functionObjects_systemCall_H
102
103#include "functionObject.H"
104#include "stringList.H"
105
106// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
107
108namespace Foam
109{
110namespace functionObjects
111{
112
113/*---------------------------------------------------------------------------*\
114 Class systemCall Declaration
115\*---------------------------------------------------------------------------*/
116
117class systemCall
118:
119 public functionObject
120{
121protected:
122
123 // Protected Data
124
125 //- List of calls to execute - every step
127
128 //- List of calls to execute - write steps
130
131 //- List of calls to execute when exiting the time-loop
133
134 //- Perform system calls on the master only
135 bool masterOnly_;
136
137
138 // Protected Member Functions
139
140 //- Dispatch specified calls
141 label dispatch(const stringList& calls);
142
143 //- No copy construct
144 systemCall(const systemCall&) = delete;
145
146 //- No copy assignment
147 void operator=(const systemCall&) = delete;
148
149
150public:
151
152 //- Runtime type information
153 TypeName("systemCall");
155
156 // Constructors
157
158 //- Construct from name, Time and dictionary
160 (
161 const word& name,
162 const Time& runTime,
163 const dictionary& dict
164 );
166
167 //- Destructor
168 virtual ~systemCall() = default;
169
171 // Member Functions
172
173 //- Read the function-object dictionary
174 virtual bool read(const dictionary& dict);
176 //- Execute the function-object operations
177 // Execute the "executeCalls" at each time-step
178 virtual bool execute();
179
180 //- Write the function-object results
181 // Write, execute the "writeCalls"
182 virtual bool write();
183
184 //- Execute the "endCalls" at the final time-loop
185 virtual bool end();
186};
187
188
189// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190
191} // End namespace functionObjects
192} // End namespace Foam
194// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195
196#endif
197
198// ************************************************************************* //
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
const word & name() const noexcept
Return the name of this functionObject.
functionObject(const word &name, const bool withNamePrefix=defaultUseNamePrefix)
Construct from components.
Executes system calls, entered in the form of string lists.
Definition systemCall.H:157
label dispatch(const stringList &calls)
Dispatch specified calls.
Definition systemCall.C:48
bool masterOnly_
Perform system calls on the master only.
Definition systemCall.H:180
stringList writeCalls_
List of calls to execute - write steps.
Definition systemCall.H:170
systemCall(const systemCall &)=delete
No copy construct.
TypeName("systemCall")
Runtime type information.
stringList executeCalls_
List of calls to execute - every step.
Definition systemCall.H:165
virtual bool read(const dictionary &dict)
Read the function-object dictionary.
Definition systemCall.C:97
virtual ~systemCall()=default
Destructor.
stringList endCalls_
List of calls to execute when exiting the time-loop.
Definition systemCall.H:175
virtual bool execute()
Execute the function-object operations.
Definition systemCall.C:145
virtual bool write()
Write the function-object results.
Definition systemCall.C:152
void operator=(const systemCall &)=delete
No copy assignment.
virtual bool end()
Execute the "endCalls" at the final time-loop.
Definition systemCall.C:159
A class for handling words, derived from Foam::string.
Definition word.H:66
engineTime & runTime
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
Namespace for OpenFOAM.
List< string > stringList
List of string.
Definition stringList.H:32
dictionary dict
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68