mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: limit file checks in the abort function object to the master process
- do not recheck the abort after it has been triggered once. This reduces the output clutter and file checks.
This commit is contained in:
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -61,18 +61,42 @@ Foam::functionObjects::abort::actionNames_
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
void Foam::functionObjects::abort::removeFile() const
|
// file-scope
|
||||||
|
// Long description for the action name
|
||||||
|
namespace Foam
|
||||||
{
|
{
|
||||||
bool hasAbort = isFile(abortFile_);
|
static std::string longDescription(const Time::stopAtControls ctrl)
|
||||||
reduce(hasAbort, orOp<bool>());
|
{
|
||||||
|
switch (ctrl)
|
||||||
if (hasAbort && Pstream::master())
|
|
||||||
{
|
{
|
||||||
// Cleanup ABORT file (on master only)
|
case Foam::Time::saNoWriteNow :
|
||||||
rm(abortFile_);
|
{
|
||||||
|
return "stop without writing data";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case Time::saWriteNow :
|
||||||
|
{
|
||||||
|
return "stop and write data";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Time::saNextWrite :
|
||||||
|
{
|
||||||
|
return "stop after next data write";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
// Invalid choices already filtered out by Enum
|
||||||
|
return "abort";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -88,13 +112,17 @@ Foam::functionObjects::abort::abort
|
|||||||
functionObject(name),
|
functionObject(name),
|
||||||
time_(runTime),
|
time_(runTime),
|
||||||
abortFile_("$FOAM_CASE/" + name),
|
abortFile_("$FOAM_CASE/" + name),
|
||||||
action_(Time::stopAtControls::saNextWrite)
|
action_(Time::stopAtControls::saNextWrite),
|
||||||
|
triggered_(false)
|
||||||
{
|
{
|
||||||
abortFile_.expand();
|
abortFile_.expand();
|
||||||
read(dict);
|
read(dict);
|
||||||
|
|
||||||
// Remove any old files from previous runs
|
// Cleanup old files from previous runs
|
||||||
removeFile();
|
if (Pstream::master())
|
||||||
|
{
|
||||||
|
Foam::rm(abortFile_);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -110,6 +138,13 @@ bool Foam::functionObjects::abort::read(const dictionary& dict)
|
|||||||
{
|
{
|
||||||
functionObject::read(dict);
|
functionObject::read(dict);
|
||||||
|
|
||||||
|
if (dict.readIfPresent("file", abortFile_))
|
||||||
|
{
|
||||||
|
abortFile_.expand();
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto oldAction = action_;
|
||||||
|
|
||||||
action_ = actionNames_.lookupOrDefault
|
action_ = actionNames_.lookupOrDefault
|
||||||
(
|
(
|
||||||
"action",
|
"action",
|
||||||
@ -117,64 +152,42 @@ bool Foam::functionObjects::abort::read(const dictionary& dict)
|
|||||||
Time::stopAtControls::saNextWrite
|
Time::stopAtControls::saNextWrite
|
||||||
);
|
);
|
||||||
|
|
||||||
if (dict.readIfPresent("file", abortFile_))
|
// User can change action and re-trigger the abort.
|
||||||
|
// eg, they had nextWrite, but actually wanted writeNow.
|
||||||
|
if (oldAction != action_)
|
||||||
{
|
{
|
||||||
abortFile_.expand();
|
triggered_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Info<< type() << " activated ("
|
||||||
|
<< longDescription(action_).c_str() <<")" << nl
|
||||||
|
<< " File: " << abortFile_ << endl;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::functionObjects::abort::execute()
|
bool Foam::functionObjects::abort::execute()
|
||||||
{
|
{
|
||||||
bool hasAbort = isFile(abortFile_);
|
// If it has been triggered (eg, nextWrite) don't need to check it again
|
||||||
reduce(hasAbort, orOp<bool>());
|
if (!triggered_)
|
||||||
|
{
|
||||||
|
bool hasAbort = (Pstream::master() && isFile(abortFile_));
|
||||||
|
Pstream::scatter(hasAbort);
|
||||||
|
|
||||||
if (hasAbort)
|
if (hasAbort)
|
||||||
{
|
{
|
||||||
switch (action_)
|
triggered_ = time_.stopAt(action_);
|
||||||
{
|
|
||||||
case Time::saNoWriteNow :
|
if (triggered_)
|
||||||
{
|
|
||||||
if (time_.stopAt(action_))
|
|
||||||
{
|
{
|
||||||
Info<< "USER REQUESTED ABORT (timeIndex="
|
Info<< "USER REQUESTED ABORT (timeIndex="
|
||||||
<< time_.timeIndex()
|
<< time_.timeIndex()
|
||||||
<< "): stop without writing data"
|
<< "): " << longDescription(action_).c_str()
|
||||||
<< endl;
|
<< endl;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case Time::saWriteNow :
|
Pstream::scatter(triggered_);
|
||||||
{
|
|
||||||
if (time_.stopAt(action_))
|
|
||||||
{
|
|
||||||
Info<< "USER REQUESTED ABORT (timeIndex="
|
|
||||||
<< time_.timeIndex()
|
|
||||||
<< "): stop+write data"
|
|
||||||
<< endl;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case Time::saNextWrite :
|
|
||||||
{
|
|
||||||
if (time_.stopAt(action_))
|
|
||||||
{
|
|
||||||
Info<< "USER REQUESTED ABORT (timeIndex="
|
|
||||||
<< time_.timeIndex()
|
|
||||||
<< "): stop after next data write"
|
|
||||||
<< endl;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
// Invalid choices already filtered out by Enum
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,7 +203,12 @@ bool Foam::functionObjects::abort::write()
|
|||||||
|
|
||||||
bool Foam::functionObjects::abort::end()
|
bool Foam::functionObjects::abort::end()
|
||||||
{
|
{
|
||||||
removeFile();
|
// Cleanup ABORT file
|
||||||
|
if (Pstream::master())
|
||||||
|
{
|
||||||
|
Foam::rm(abortFile_);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -30,12 +30,21 @@ Group
|
|||||||
Description
|
Description
|
||||||
Watches for presence of the named file in the $FOAM_CASE directory
|
Watches for presence of the named file in the $FOAM_CASE directory
|
||||||
and aborts the calculation if it is present.
|
and aborts the calculation if it is present.
|
||||||
|
The presence of the abort file is only checked on the master process.
|
||||||
|
|
||||||
Currently the following action types are supported:
|
Currently the following action types are supported:
|
||||||
- noWriteNow
|
- noWriteNow
|
||||||
- writeNow
|
- writeNow
|
||||||
- nextWrite
|
- nextWrite
|
||||||
|
|
||||||
|
\heading Function object usage
|
||||||
|
\table
|
||||||
|
Property | Description | Required | Default value
|
||||||
|
type | Type name: abort | yes |
|
||||||
|
file | The abort filename | no | $FOAM_CASE/name
|
||||||
|
action | Abort action | no | nextWrite
|
||||||
|
\endtable
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
abort.C
|
abort.C
|
||||||
|
|
||||||
@ -76,12 +85,12 @@ class abort
|
|||||||
//- The type of action
|
//- The type of action
|
||||||
Time::stopAtControls action_;
|
Time::stopAtControls action_;
|
||||||
|
|
||||||
|
//- Only trigger action once
|
||||||
|
bool triggered_;
|
||||||
|
|
||||||
|
|
||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
|
|
||||||
//- Remove abort file.
|
|
||||||
void removeFile() const;
|
|
||||||
|
|
||||||
//- Disallow default bitwise copy construct
|
//- Disallow default bitwise copy construct
|
||||||
abort(const abort&) = delete;
|
abort(const abort&) = delete;
|
||||||
|
|
||||||
@ -102,7 +111,7 @@ public:
|
|||||||
(
|
(
|
||||||
const word& name,
|
const word& name,
|
||||||
const Time& runTime,
|
const Time& runTime,
|
||||||
const dictionary&
|
const dictionary& dict
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@ -115,13 +124,13 @@ public:
|
|||||||
//- Read the dictionary settings
|
//- Read the dictionary settings
|
||||||
virtual bool read(const dictionary& dict);
|
virtual bool read(const dictionary& dict);
|
||||||
|
|
||||||
//- Execute, check existence of abort file and take action
|
//- Check existence of abort file and take action
|
||||||
virtual bool execute();
|
virtual bool execute();
|
||||||
|
|
||||||
//- Execute, check existence of abort file and take action
|
//- No-op
|
||||||
virtual bool write();
|
virtual bool write();
|
||||||
|
|
||||||
//- Execute at the final time-loop, used for cleanup
|
//- Remove abort file after the final time-loop.
|
||||||
virtual bool end();
|
virtual bool end();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,13 @@
|
|||||||
|
// OpenFOAM dictionary -*- C++ -*-
|
||||||
|
|
||||||
|
ABORT
|
||||||
|
{
|
||||||
|
type abort;
|
||||||
|
libs ("libutilityFunctionObjects.so");
|
||||||
|
//file "$FOAM_CASE/ABORT"; // default name
|
||||||
|
// action writeNow;
|
||||||
|
action nextWrite;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -59,6 +59,7 @@ writeInterval 100;
|
|||||||
|
|
||||||
functions
|
functions
|
||||||
{
|
{
|
||||||
|
#include "abort"
|
||||||
#include "scalarTransport"
|
#include "scalarTransport"
|
||||||
#include "sampling"
|
#include "sampling"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user