CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Running, Solving & CFD (
-   -   Dlopen vs foamUser for 141 (

egp August 20, 2007 11:22

In the release notes of 1.4.1,
In the release notes of 1.4.1, there is a note about foamUser being replaced,

"foamUser and foamUtil libraries replaced by the more general dlopen method in which any libraries may be included at run-time using the optional 'libs' entry in the case controlDict, e.g. to replicate previous automatic inclusion of the foamUser and foamUtil libraries include libs ("" ""); in controlDict."

This is a bit too cryptic for me, and unfortunately, section 3.2.6 of the 1.4.1 userGuide (dated 1 Aug 2007) has not been updated to reflect this change.

As such, does anyone have an example of how to use dlopen to link in a user library? I looked on the wiki, and no luck. A nice example of a new boundary condition, or something similar, would be cool.

Thanks, Eric

mbeaudoin August 20, 2007 12:07

Hello Eric, There are two e
Hello Eric,

There are two examples in the tutorials directory that explicitly use the dlopen mechanism in the controlDict file:


I am still exploring this part of OF 1.4.1, so I cannot help you a whole lot more than this for now.

But since we are still using the foamUser trick for loading and using our own development with OF, I guess we will have to adjust as well ..


egp August 20, 2007 12:59

Hi Martin, I don't see the
Hi Martin,

I don't see the dlopen mechanism being used in either of these cases. For the simpleFoam/pitzDaily example, it looks unchanged from earlier versions. For oodles/pitzDaily, controlDict has been modified to use the probe interface of 1.4.1.

Am I missing something? I was expecting to see a "libs" entry in controlDict with options.


mattijs August 20, 2007 13:12

What happens if you add li
What happens if you add

libs ("");

to your controlDict?

where is your library. When it loads the libraries it (dlopen) will call any static constructors. This is the mechanism used in the OpenFOAM libraries for most user settings (turbulence models, discretisation schemes etc.) so if you stick to that framework it should work.

But then this all is no different from linking in libraries during link time.

gschaider August 20, 2007 13:25

Hi Eric! For a vanilla case
Hi Eric!

For a vanilla case, the libs-mechanism shouldn't make any difference (using only stock-turbulence-models etc).
Havn't any experience with this implementation, but it seems to me, that libs obsoletes
(in earlier versions of OF, if you wanted to introduce your own boundary conditions/turbulence models/etc to a unmodified solver you had to include them all in the sources of the foamUser-library, now you can mix and match with in earlier versions you had to include myPersonalBoundaryConditionsForSinkingShips.C and theCrazyTurbulenceModelHugoSentMe.C into the sources for and if they contradicted sigournysBoundaryConditionsForSinkingShips.C you were in deep trouble)

Anyway. This is mostly of interest for those who program (or use) run-time-selectable models (turbulence, boundary conditions) that are not part of the OF-distribution.


mbeaudoin August 20, 2007 13:37

Hi Eric, Sorry, my mistake
Hi Eric,

Sorry, my mistake about the simpleFoam/pitzDaily example, you are quite right.

But in $FOAM_TUTORIALS/oodles/pitzDaily/system/controlDict, there is an entry that looks like this in the probe interface:

functionObjectLibs ("");

I would think that this is the way to dynamically load the library at runtime with your simulation.

Now, what would be the proper syntax for simply loading your library instead, I don't know yet. Maybe someone from this forum could quickly provide you with a simple example?

As a side note, I sure hope that the usage of will remain as a default mechanism for loading libraries in OpenFOAM because otherwise, we will have to modify a lot of controlDict files in our different simulations in order to plug our code back in.


olesen August 20, 2007 16:59

Perhaps there might be a means
Perhaps there might be a means of tapping into the Debug mechanism with something like the following hand-waving:

dictionary& debug::controlDict()
if (!controlDictPtr_)
dlLibraryTable::readDlLibrary foo(*controlDictPtr_, "libs");

return *controlDictPtr_;

All times are GMT -4. The time now is 19:13.