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 -------------------------------------------------------------------------------
11 License
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 Class
28  Foam::functionObjects::systemCall
29 
30 Group
31  grpUtilitiesFunctionObjects
32 
33 Description
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 
41 Usage
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 
76 Note
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 
85 See also
86  Foam::functionObject
87  Foam::functionObjects::timeControl
88 
89 SourceFiles
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 
102 namespace Foam
103 {
104 namespace functionObjects
105 {
106 
107 /*---------------------------------------------------------------------------*\
108  Class systemCall Declaration
109 \*---------------------------------------------------------------------------*/
110 
111 class systemCall
112 :
113  public functionObject
114 {
115 protected:
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 
144 public:
145 
146  //- Runtime type information
147  TypeName("systemCall");
148 
149 
150  // Constructors
151 
152  //- Construct from Time and dictionary
153  systemCall
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 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::functionObjects::systemCall::end
virtual bool end()
Execute the "endCalls" at the final time-loop.
Definition: systemCall.C:166
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::functionObjects::systemCall::TypeName
TypeName("systemCall")
Runtime type information.
Foam::functionObjects::systemCall::operator=
void operator=(const systemCall &)=delete
No copy assignment.
Foam::functionObjects::systemCall
Executes system calls, entered in the form of string lists.
Definition: systemCall.H:140
Foam::functionObjects::systemCall::writeCalls_
stringList writeCalls_
List of calls to execute - write steps.
Definition: systemCall.H:152
Foam::stringList
List< string > stringList
A List of strings.
Definition: stringList.H:58
Foam::functionObjects::systemCall::executeCalls_
stringList executeCalls_
List of calls to execute - every step.
Definition: systemCall.H:149
Foam::functionObject
Abstract base-class for Time/database function objects.
Definition: functionObject.H:332
Foam::functionObjects::systemCall::dispatch
label dispatch(const stringList &calls)
Dispatch specified calls.
Definition: systemCall.C:55
Foam::functionObjects::systemCall::~systemCall
virtual ~systemCall()=default
Destructor.
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::functionObjects::systemCall::systemCall
systemCall(const systemCall &)=delete
No copy construct.
Foam::functionObjects::systemCall::read
virtual bool read(const dictionary &dict)
Read the system calls.
Definition: systemCall.C:104
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObject::name
const word & name() const noexcept
Return the name of this functionObject.
Definition: functionObject.C:143
Foam::functionObjects::systemCall::write
virtual bool write()
Write, execute the "writeCalls".
Definition: systemCall.C:159
Foam::List< string >
Foam::functionObjects::systemCall::endCalls_
stringList endCalls_
List of calls to execute when exiting the time-loop.
Definition: systemCall.H:155
Foam::functionObjects::systemCall::execute
virtual bool execute()
Execute the "executeCalls" at each time-step.
Definition: systemCall.C:152
functionObject.H
Foam::functionObjects::systemCall::masterOnly_
bool masterOnly_
Perform system calls on the master only.
Definition: systemCall.H:158
stringList.H