systemCall.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::functionObjects::systemCall
26 
27 Description
28  Executes system calls, entered in the form of a string lists.
29 
30  Calls can be made at the following points in the calculation:
31  - every time step
32  - every output time
33  - end of the calculation
34 
35  Example of function object specification:
36  \verbatim
37  systemCall1
38  {
39  type systemCall;
40 
41  libs ("libutilityFunctionObjects.so");
42 
43  executeCalls
44  (
45  "echo execute"
46  );
47 
48  writeCalls
49  (
50  "echo \*\*\* writing data \*\*\*"
51  );
52 
53  endCalls
54  (
55  "echo \*\*\* writing .bashrc \*\*\*"
56  "cat ~/.bashrc"
57  "echo \*\*\* done \*\*\*"
58  );
59  }
60  \endverbatim
61 
62 Usage
63  \table
64  Property | Description | Required | Default value
65  type | type name: systemCall | yes |
66  parallel | execute on all processors | no | false
67  executeCalls | list of calls on execute | yes |
68  writeCalls | list of calls on write | yes |
69  endCalls | list of calls on end | yes |
70  \endtable
71 
72 Note
73  Since this function object executes system calls, there is a potential
74  security risk. In order to use the \c systemCall function object, the \c
75  allowSystemOperations must be set to '1'; otherwise, system calls will not
76  be allowed.
77 
78 See also
79  Foam::functionObject
80  Foam::functionObjects::timeControl
81 
82 SourceFiles
83  systemCall.C
84 
85 \*---------------------------------------------------------------------------*/
86 
87 #ifndef functionObjects_systemCall_H
88 #define functionObjects_systemCall_H
89 
90 #include "functionObject.H"
91 #include "stringList.H"
92 
93 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
94 
95 namespace Foam
96 {
97 namespace functionObjects
98 {
99 
100 /*---------------------------------------------------------------------------*\
101  Class systemCall Declaration
102 \*---------------------------------------------------------------------------*/
103 
104 class systemCall
105 :
106  public functionObject
107 {
108 protected:
109 
110  // Private Data
111 
112  //- Perform the call by each processor or by the master only
113  bool parallel_;
114 
115  //- List of calls to execute - every step
117 
118  //- List of calls to execute when exiting the time-loop
120 
121  //- List of calls to execute - write steps
123 
124 
125 public:
126 
127  //- Runtime type information
128  TypeName("systemCall");
129 
130 
131  // Constructors
132 
133  //- Construct from Time and dictionary
134  systemCall
135  (
136  const word& name,
137  const Time& runTime,
138  const dictionary& dict
139  );
140 
141  //- Disallow default bitwise copy construction
142  systemCall(const systemCall&) = delete;
143 
144 
145  //- Destructor
146  virtual ~systemCall();
147 
148 
149  // Member Functions
150 
151  //- Read the system calls
152  virtual bool read(const dictionary&);
153 
154  //- Return the list of fields required
155  virtual wordList fields() const
156  {
157  return wordList::null();
158  }
159 
160  //- Execute the "executeCalls" at each time-step
161  virtual bool execute();
162 
163  //- Execute the "endCalls" at the final time-loop
164  virtual bool end();
165 
166  //- Write, execute the "writeCalls"
167  virtual bool write();
168 
169 
170  // Member Operators
171 
172  //- Disallow default bitwise assignment
173  void operator=(const systemCall&) = delete;
174 };
175 
176 
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178 
179 } // End namespace functionObjects
180 } // End namespace Foam
181 
182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183 
184 #endif
185 
186 // ************************************************************************* //
static const List< word > & null()
Return a null List.
Definition: ListI.H:118
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
const word & name() const
Return the name of this functionObject.
Executes system calls, entered in the form of a string lists.
Definition: systemCall.H:136
virtual wordList fields() const
Return the list of fields required.
Definition: systemCall.H:184
stringList writeCalls_
List of calls to execute - write steps.
Definition: systemCall.H:151
TypeName("systemCall")
Runtime type information.
bool parallel_
Perform the call by each processor or by the master only.
Definition: systemCall.H:142
stringList executeCalls_
List of calls to execute - every step.
Definition: systemCall.H:145
virtual ~systemCall()
Destructor.
Definition: systemCall.C:71
systemCall(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: systemCall.C:53
stringList endCalls_
List of calls to execute when exiting the time-loop.
Definition: systemCall.H:148
virtual bool execute()
Execute the "executeCalls" at each time-step.
Definition: systemCall.C:112
virtual bool write()
Write, execute the "writeCalls".
Definition: systemCall.C:140
void operator=(const systemCall &)=delete
Disallow default bitwise assignment.
virtual bool end()
Execute the "endCalls" at the final time-loop.
Definition: systemCall.C:126
virtual bool read(const dictionary &)
Read the system calls.
Definition: systemCall.C:77
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
List< string > stringList
A List of strings.
Definition: stringList.H:50
dictionary dict