CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM (
-   -   Calling an external function beforeafter each time step (

alesch December 12, 2008 14:35

Hi everybody: I need to mak
Hi everybody:

I need to make a call to an external function before and after each time step of the solver.
This is to be able to interact with other software.

I've seen I can compile my own library (foamUser) so my new functions are available for all applications.

But I don't know where to go from here. Any pointers are appreciated.

Thanks in advance!

gschaider December 12, 2008 15:46

Hi Alex! What you're lookin
Hi Alex!

What you're looking for is called a functionObject. For an example of the usage of those look at $FOAM_TUTORIASL/oodles/pitzDaily/system/controlDict. For examples on the programming of those look at the doxygen or


alesch December 15, 2008 14:30

Thank you Bernhard for your an
Thank you Bernhard for your answer.

I've looked a bit into Contrib_simpleFunctionObjetcs but I don't get any smarter, =(

The README references the script, but I cannot find that script.
That script is needed for building simpleFunctionObjects, right?

I guess I need to create my own functionObject, and I could use your contributed module as a starting point, right?

In other words: HELP, I'm still lost!

Thank you for you time!

alesch December 15, 2008 15:26

Ok, let's see If I'm getting t
Ok, let's see If I'm getting this right:

1) I need to subclass functionObject or, even better, simpleFunctionObject.

2) Overriding the write() method I can (in some way) extract data after the solver is ready with a time step.

3) I could use the flush() method to block, and wait for my external function to return some value. Then OF could continue with the next time step.

God!, I'm making progress here, :-)

olesen December 16, 2008 03:41

Hi Alex, Since it would app
Hi Alex,

Since it would appear that you are trying to achieve a specific task, why not just reassemble your own solver? Take whichever existing solver, copy it under a new name and within the main time-loop just add in your external calls directly.

At a later stage you can rework it all to use functionObjects (if desired), but this would get you going very quickly and is a good bit easier to implement.

alesch December 16, 2008 08:27

Mark, thanks for your input!
Mark, thanks for your input!

The tool I'm trying to build should, ideally, work with minimal modifications to standard installs.
This tool should work for other people than me, and then I cannot tell which solver they will choose.

gschaider December 16, 2008 14:08

Hi Alex! That is definitely
Hi Alex!

That is definitely the definition of a functionObject. But (especially if it is your first FO) Mark's suggestion is good practise: make sure that the functionality works, then rework it into a function object. That way you'll know whether the problems you're experiencing are "functionObject problems" or "other problems"


alesch December 16, 2008 14:47

Thanks Bernhard! I was thin
Thanks Bernhard!

I was thinking on adding a functionObject to the cavity tutorial, to be sure that the application works.

What about the script
Where can I find it?


gschaider December 17, 2008 05:57

Hi Alex! You're on 1.5 aren
Hi Alex!

You're on 1.5 aren't you? You don't need it there. The README was not properly updated when that code was ported to 1.5 (the functionality it was needed for - surface-plots triggered by a function object - is now part of the distribution)

But I'll update the README. Thanks for the hint (and it's nice to know that somebody actually reads READMEs ;) )


All times are GMT -4. The time now is 14:58.