Skip to content

Commit

Permalink
functionObjects::/systemCall: Added optional parallel switch to execu…
Browse files Browse the repository at this point in the history
…te 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.
  • Loading branch information
Henry Weller committed Sep 14, 2023
1 parent fca802f commit 3e7ebe0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
24 changes: 18 additions & 6 deletions src/functionObjects/utilities/systemCall/systemCall.C
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Foam::functionObjects::systemCall::systemCall
)
:
functionObject(name, time),
parallel_(false),
executeCalls_(),
endCalls_(),
writeCalls_()
Expand All @@ -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_);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
26 changes: 15 additions & 11 deletions src/functionObjects/utilities/systemCall/systemCall.H
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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_;

Expand Down

0 comments on commit 3e7ebe0

Please sign in to comment.