Skip to content

Instantly share code, notes, and snippets.

@robinknowles
Last active July 13, 2023 11:41
Show Gist options
  • Save robinknowles/385858f42f23100d16c1f65e86881fd2 to your computer and use it in GitHub Desktop.
Save robinknowles/385858f42f23100d16c1f65e86881fd2 to your computer and use it in GitHub Desktop.

Divergence detection in OpenFOAM using runTimeControls

Accompanies OnCFD Newsletter #148: "Divergence Detector"

Here's the copy-paste-able version of the function I use to detect (& end) simulations that are slowly diverging & taking up valuable cluster time.

minMaxU
{
    type        fieldMinMax;
    libs        (fieldFunctionObjects);

    mode        magnitude;
    fields      (U);
    location    true;
    log         false;
}

divergenceDetector
{
    type            runTimeControl;
    libs            (utilityFunctionObjects);
    conditions
    {
        condition0
        {
            type            minMax;
            functionObject  minMaxU;
            fields          (max(mag(U)));
            value           1000;
            mode            maximum;
            groupID         1;
        }
        condition1
        {
            type            equationMaxIter;
            fields          (p);
            threshold       100;
            groupID         1;
        }
    }
}

Save as system/divergenceDetector & reference it in the functions section of your controlDict

For more info - see the original article 👋

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment