Skip to content
Snippets Groups Projects
Commit b3142ffb authored by Andrew Heather's avatar Andrew Heather
Browse files

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;
            }
        }
    }
parent cbfa9f68
Branches
Tags
No related merge requests found
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd.
Copyright (C) 2015-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -53,6 +53,7 @@ Foam::Enum
>
Foam::functionObjects::runTimeControls::runTimeControl::satisfiedActionNames
{
{ satisfiedAction::ABORT, "abort"},
{ satisfiedAction::END, "end"},
{ satisfiedAction::SET_TRIGGER, "setTrigger"},
};
......@@ -251,6 +252,7 @@ bool Foam::functionObjects::runTimeControls::runTimeControl::execute()
switch (satisfiedAction_)
{
case satisfiedAction::ABORT:
case satisfiedAction::END:
{
// Set to write a data dump or finalise the calculation
......@@ -284,6 +286,13 @@ bool Foam::functionObjects::runTimeControls::runTimeControl::execute()
// Trigger any function objects
time.run();
if (satisfiedAction_ == satisfiedAction::ABORT)
{
FatalErrorInFunction
<< "Abort triggered"
<< exit(FatalError);
}
}
break;
}
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015-2016 OpenFOAM Foundation
Copyright (C) 2016-2018 OpenCFD Ltd.
Copyright (C) 2016-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -76,8 +76,9 @@ public:
enum class satisfiedAction
{
END,
SET_TRIGGER
ABORT, //!< "abort" - write and emit a FatalError
END, //!< "end" - write and exit cleanly
SET_TRIGGER //!< "setTrigger" - trigger another condition
};
static Enum<satisfiedAction> satisfiedActionNames;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment