3

When the absolute pressure becomes negative or $U$ exceeds the speed of light, things have pretty obviously gone wrong (be that bad boundary conditions, a too coarse mesh, a too large timestep etc.).

So, is there any way to have a simulation abort with an error message when values exceed definable non-physical ranges?

Tobias Kienzler
  • 321
  • 6
  • 22
  • I think this kind of question is better asked on the OpenFOAM MessageBoard as it is very program-specific – bgschaid Jul 05 '12 at 18:59
  • @bgschaid I did, I forgot to put a link here. But honestly, I prefer the SE format since anyone else having a similar question will directly see the accepted answer (yours in this case) instead of having to browse through a potential discussion leading to the solution followed by someone else asking a similar question with an actually different answer etc... – Tobias Kienzler Jul 06 '12 at 06:45

2 Answers2

7

This is basic C++ - just add whatever you are interested in to the code and recompile. For example, copy and paste the following code right before the runTime.write(); call (which is at the end of the main function of every solver) to execute the sanity check at the end of every time step:

// sanity check
if (min(p) < 0)
{
    FatalError
        << "Negative pressure" << nl
        << exit(FatalError);
}
akid
  • 719
  • 4
  • 15
  • This answer seems highly unlikely to be specific enough to OpenFOAM to work. Can you suggest where in OpenFOAM he should put this if it is? – Bill Barth Jun 30 '12 at 22:26
  • Thanks for your comment, I updated the answer. However, where to paste the snippet really depends on where you want to have the sanity check, e.g. at the end of each time step vs. every inner iteration of the pressure-velocity coupling. – akid Jul 01 '12 at 13:36
  • upvoted, though wouldn't it be a bit more idiomatic to raise a Foam Exception than to just return -1? Warning: fragile doxygen link to error.h in Foam source. – Aron Ahmadia Jul 01 '12 at 14:05
  • Thanks akid, I think having the check at every timestep (or even only at every writing timestep) is sufficient - anything that aborts the calculation sooner than "late" is welcome... But is there a possibility to achieve this in a way that does not require a modification of the respective solver used? Maybe some #codeStream magic in controlDict? – Tobias Kienzler Jul 02 '12 at 06:07
  • Aron, I updated the answer. – akid Jul 02 '12 at 07:49
  • Kar, I believe you can take the code above and enclose it in a codestream tag like this: http://www.openfoam.org/docs/user/basic-file-format.php. I will not update the answer because I can't test it. – akid Jul 02 '12 at 07:50
  • @Akid, thanks for the modification. I'll try to figure out a controlDict solution and comment on that here then. PS: If you want other users being notified about your reply, put an @ in front of their name (also, sorry for the lack of upvote, I'll do that as soon as my rep suffices) – Tobias Kienzler Jul 02 '12 at 08:29
  • Vote changed to up based on changes. Thanks @akid. – Bill Barth Jul 02 '12 at 16:46
  • @akid bgschaid's simpleFunctionObject solves this a bit easier for, but your answer is more flexible if needed. At least I can upvote you now... – Tobias Kienzler Jul 06 '12 at 06:52
4

If you don't want to write C++: In the simpleFunctionObjects there is a functionObject called panicDump. Something like

functions
{
    pressureOurOfRange {
        type panicDump;
        functionObjectLibs
        (
            "libsimpleFunctionObjects.so"
        );
        fieldName p;
        minimum 0;
        maximum 1e7;
    }
}

in system/controlDict would stop the simulation if the pressure blows up. Together with the expressionField-functionObject from swak4Foam you can also test for non-scalar fields.

Disclaimer: I'm the original developer of simpleFunctionObjects so this answer could be seen as advertisement

Tobias Kienzler
  • 321
  • 6
  • 22
bgschaid
  • 351
  • 1
  • 4