mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: optionally limit systemCall function-object to master only (closes #729)
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -46,6 +46,36 @@ namespace functionObjects
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
Foam::label Foam::functionObjects::systemCall::dispatch(const stringList& calls)
|
||||
{
|
||||
if (calls.empty())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
label nCalls = 0;
|
||||
|
||||
if (!masterOnly_ || Pstream::master())
|
||||
{
|
||||
for (const string& call : calls)
|
||||
{
|
||||
Foam::system(call); // Handles empty command as a successful no-op.
|
||||
++nCalls;
|
||||
}
|
||||
}
|
||||
|
||||
// MPI barrier
|
||||
if (masterOnly_)
|
||||
{
|
||||
Pstream::scatter(nCalls);
|
||||
}
|
||||
|
||||
return nCalls;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::systemCall::systemCall
|
||||
@ -58,27 +88,27 @@ Foam::functionObjects::systemCall::systemCall
|
||||
functionObject(name),
|
||||
executeCalls_(),
|
||||
endCalls_(),
|
||||
writeCalls_()
|
||||
writeCalls_(),
|
||||
masterOnly_(false)
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::systemCall::~systemCall()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::systemCall::read(const dictionary& dict)
|
||||
{
|
||||
functionObject::read(dict);
|
||||
|
||||
executeCalls_.clear();
|
||||
writeCalls_.clear();
|
||||
endCalls_.clear();
|
||||
|
||||
dict.readIfPresent("executeCalls", executeCalls_);
|
||||
dict.readIfPresent("endCalls", endCalls_);
|
||||
dict.readIfPresent("writeCalls", writeCalls_);
|
||||
dict.readIfPresent("endCalls", endCalls_);
|
||||
masterOnly_ = dict.lookupOrDefault("master", false);
|
||||
|
||||
if (executeCalls_.empty() && endCalls_.empty() && writeCalls_.empty())
|
||||
{
|
||||
@ -89,8 +119,8 @@ bool Foam::functionObjects::systemCall::read(const dictionary& dict)
|
||||
else if (!dynamicCode::allowSystemOperations)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Executing user-supplied system calls is not enabled by "
|
||||
<< "default because of " << nl
|
||||
<< "Executing user-supplied system calls may not be enabled by "
|
||||
<< "default due to potential " << nl
|
||||
<< "security issues. If you trust the case you can enable this "
|
||||
<< "facility by " << nl
|
||||
<< "adding to the InfoSwitches setting in the system controlDict:"
|
||||
@ -109,33 +139,21 @@ bool Foam::functionObjects::systemCall::read(const dictionary& dict)
|
||||
|
||||
bool Foam::functionObjects::systemCall::execute()
|
||||
{
|
||||
forAll(executeCalls_, calli)
|
||||
{
|
||||
Foam::system(executeCalls_[calli]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::systemCall::end()
|
||||
{
|
||||
forAll(endCalls_, calli)
|
||||
{
|
||||
Foam::system(endCalls_[calli]);
|
||||
}
|
||||
|
||||
dispatch(executeCalls_);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::systemCall::write()
|
||||
{
|
||||
forAll(writeCalls_, calli)
|
||||
{
|
||||
Foam::system(writeCalls_[calli]);
|
||||
}
|
||||
dispatch(writeCalls_);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::systemCall::end()
|
||||
{
|
||||
dispatch(endCalls_);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user