functionObjects::/systemCall: Added optional parallel switch to execute on all processors

When the parallel switch is set false (the default), the system call is executed
only on the master processor, if true it is executed on all processors.

Patch contributed by Stanislau Stasheuski, Aalto University.
This commit is contained in:
Henry Weller
2023-09-14 13:44:13 +01:00
parent fca802fa82
commit 3e7ebe0491
2 changed files with 33 additions and 17 deletions

View File

@ -57,6 +57,7 @@ Foam::functionObjects::systemCall::systemCall
)
:
functionObject(name, time),
parallel_(false),
executeCalls_(),
endCalls_(),
writeCalls_()
@ -75,6 +76,8 @@ Foam::functionObjects::systemCall::~systemCall()
bool Foam::functionObjects::systemCall::read(const dictionary& dict)
{
parallel_ = dict.lookupOrDefault("parallel", false);
dict.readIfPresent("executeCalls", executeCalls_);
dict.readIfPresent("endCalls", endCalls_);
dict.readIfPresent("writeCalls", writeCalls_);
@ -108,9 +111,12 @@ bool Foam::functionObjects::systemCall::read(const dictionary& dict)
bool Foam::functionObjects::systemCall::execute()
{
forAll(executeCalls_, callI)
if (Pstream::master() || parallel_)
{
Foam::system(executeCalls_[callI]);
forAll(executeCalls_, callI)
{
Foam::system(executeCalls_[callI]);
}
}
return true;
@ -119,9 +125,12 @@ bool Foam::functionObjects::systemCall::execute()
bool Foam::functionObjects::systemCall::end()
{
forAll(endCalls_, callI)
if (Pstream::master() || parallel_)
{
Foam::system(endCalls_[callI]);
forAll(endCalls_, callI)
{
Foam::system(endCalls_[callI]);
}
}
return true;
@ -130,9 +139,12 @@ bool Foam::functionObjects::systemCall::end()
bool Foam::functionObjects::systemCall::write()
{
forAll(writeCalls_, callI)
if (Pstream::master() || parallel_)
{
Foam::system(writeCalls_[callI]);
forAll(writeCalls_, callI)
{
Foam::system(writeCalls_[callI]);
}
}
return true;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -61,18 +61,19 @@ Description
Usage
\table
Property | Description | Required | Default value
type | type name: systemCall | yes |
executeCalls | list of calls on execute | yes |
writeCalls | list of calls on write | yes |
endCalls | list of calls on end | yes |
Property | Description | Required | Default value
type | type name: systemCall | yes |
parallel | execute on all processors | no | false
executeCalls | list of calls on execute | yes |
writeCalls | list of calls on write | yes |
endCalls | list of calls on end | yes |
\endtable
Note:
Since this function object executes system calls, there is a potential
security risk. In order to use the \c systemCall function object, the
\c allowSystemOperations must be set to '1'; otherwise, system calls
will not be allowed.
Note
Since this function object executes system calls, there is a potential
security risk. In order to use the \c systemCall function object, the \c
allowSystemOperations must be set to '1'; otherwise, system calls will not
be allowed.
See also
Foam::functionObject
@ -108,6 +109,9 @@ protected:
// Private Data
//- Perform the call by each processor or by the master only
bool parallel_;
//- List of calls to execute - every step
stringList executeCalls_;