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-2022 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  executeCalls | list of calls on execute | yes |
67  writeCalls | list of calls on write | yes |
68  endCalls | list of calls on end | yes |
69  \endtable
70 
71  Note:
72  Since this function object executes system calls, there is a potential
73  security risk. In order to use the \c systemCall function object, the
74  \c allowSystemOperations must be set to '1'; otherwise, system calls
75  will not be allowed.
76 
77 See also
78  Foam::functionObject
79  Foam::functionObjects::timeControl
80 
81 SourceFiles
82  systemCall.C
83 
84 \*---------------------------------------------------------------------------*/
85 
86 #ifndef functionObjects_systemCall_H
87 #define functionObjects_systemCall_H
88 
89 #include "functionObject.H"
90 #include "stringList.H"
91 
92 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
93 
94 namespace Foam
95 {
96 namespace functionObjects
97 {
98 
99 /*---------------------------------------------------------------------------*\
100  Class systemCall Declaration
101 \*---------------------------------------------------------------------------*/
102 
103 class systemCall
104 :
105  public functionObject
106 {
107 protected:
108 
109  // Private Data
110 
111  //- List of calls to execute - every step
113 
114  //- List of calls to execute when exiting the time-loop
116 
117  //- List of calls to execute - write steps
119 
120 
121 public:
122 
123  //- Runtime type information
124  TypeName("systemCall");
125 
126 
127  // Constructors
128 
129  //- Construct from Time and dictionary
130  systemCall
131  (
132  const word& name,
133  const Time& runTime,
134  const dictionary& dict
135  );
136 
137  //- Disallow default bitwise copy construction
138  systemCall(const systemCall&) = delete;
139 
140 
141  //- Destructor
142  virtual ~systemCall();
143 
144 
145  // Member Functions
146 
147  //- Read the system calls
148  virtual bool read(const dictionary&);
149 
150  //- Return the list of fields required
151  virtual wordList fields() const
152  {
153  return wordList::null();
154  }
155 
156  //- Execute the "executeCalls" at each time-step
157  virtual bool execute();
158 
159  //- Execute the "endCalls" at the final time-loop
160  virtual bool end();
161 
162  //- Write, execute the "writeCalls"
163  virtual bool write();
164 
165 
166  // Member Operators
167 
168  //- Disallow default bitwise assignment
169  void operator=(const systemCall&) = delete;
170 };
171 
172 
173 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
174 
175 } // End namespace functionObjects
176 } // End namespace Foam
177 
178 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
179 
180 #endif
181 
182 // ************************************************************************* //
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:160
const word & name() const
Return the name of this functionObject.
Executes system calls, entered in the form of a string lists.
Definition: systemCall.H:130
virtual wordList fields() const
Return the list of fields required.
Definition: systemCall.H:175
stringList writeCalls_
List of calls to execute - write steps.
Definition: systemCall.H:142
TypeName("systemCall")
Runtime type information.
stringList executeCalls_
List of calls to execute - every step.
Definition: systemCall.H:136
virtual ~systemCall()
Destructor.
Definition: systemCall.C:70
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:139
virtual bool execute()
Execute the "executeCalls" at each time-step.
Definition: systemCall.C:109
virtual bool write()
Write, execute the "writeCalls".
Definition: systemCall.C:131
void operator=(const systemCall &)=delete
Disallow default bitwise assignment.
virtual bool end()
Execute the "endCalls" at the final time-loop.
Definition: systemCall.C:120
virtual bool read(const dictionary &)
Read the system calls.
Definition: systemCall.C:76
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