ENH: runTimeControl - added option to trigger a fatal error on exit (#2042)

- useful when used in a batch process to trap the exit signal,
  e.g. stop the run when the velocity magnitude exceeds a given
  threshold:

    runTimeControl
    {
        type            runTimeControl;
        libs            ("libutilityFunctionObjects.so");
        nWriteStep      1;

        // Optional end 'action'
        satisfiedAction abort; // end; // setTrigger

        conditions
        {
            maxU
            {
                type            minMax;
                functionObject  MinMax;
                fields          ("max(mag(U))");
                value           1e6;
                mode            maximum;
            }
        }
    }
This commit is contained in:
Andrew Heather
2021-03-23 20:28:22 +00:00
parent cbfa9f685e
commit b3142ffb54
2 changed files with 14 additions and 4 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation Copyright (C) 2015 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd. Copyright (C) 2015-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -53,6 +53,7 @@ Foam::Enum
> >
Foam::functionObjects::runTimeControls::runTimeControl::satisfiedActionNames Foam::functionObjects::runTimeControls::runTimeControl::satisfiedActionNames
{ {
{ satisfiedAction::ABORT, "abort"},
{ satisfiedAction::END, "end"}, { satisfiedAction::END, "end"},
{ satisfiedAction::SET_TRIGGER, "setTrigger"}, { satisfiedAction::SET_TRIGGER, "setTrigger"},
}; };
@ -251,6 +252,7 @@ bool Foam::functionObjects::runTimeControls::runTimeControl::execute()
switch (satisfiedAction_) switch (satisfiedAction_)
{ {
case satisfiedAction::ABORT:
case satisfiedAction::END: case satisfiedAction::END:
{ {
// Set to write a data dump or finalise the calculation // Set to write a data dump or finalise the calculation
@ -284,6 +286,13 @@ bool Foam::functionObjects::runTimeControls::runTimeControl::execute()
// Trigger any function objects // Trigger any function objects
time.run(); time.run();
if (satisfiedAction_ == satisfiedAction::ABORT)
{
FatalErrorInFunction
<< "Abort triggered"
<< exit(FatalError);
}
} }
break; break;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2015-2016 OpenFOAM Foundation Copyright (C) 2015-2016 OpenFOAM Foundation
Copyright (C) 2016-2018 OpenCFD Ltd. Copyright (C) 2016-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -76,8 +76,9 @@ public:
enum class satisfiedAction enum class satisfiedAction
{ {
END, ABORT, //!< "abort" - write and emit a FatalError
SET_TRIGGER END, //!< "end" - write and exit cleanly
SET_TRIGGER //!< "setTrigger" - trigger another condition
}; };
static Enum<satisfiedAction> satisfiedActionNames; static Enum<satisfiedAction> satisfiedActionNames;