CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Call external code (functionObject execute() like) within pimple.loop() (https://www.cfd-online.com/Forums/openfoam-programming-development/129097-call-external-code-functionobject-execute-like-within-pimple-loop.html)

jherb January 28, 2014 12:53

Call external code (functionObject execute() like) within pimple.loop()
 
Hello OpenFOAM colleagues,

I'm looking for a way to call code defined (as e.g. functionObject) in the controlDict (ideally a python function using pythonIntegration in swak4Foam) from within the pimple.loop() in a transient solver. Or in (hopefully) simple words: Call a function after each iteration of the outer corrector loop within one time step.

functionObjects or pythonIntegrationFunctionObjects are only called once per time step.

What is the easiest way to achieve this? Ideally I do not want to overwrite the pimpleControl class but add something (a call to functionObject.execute() ???) to the solver or even better use something already build in.

Thank you for any hints/help.

Joachim

jherb January 30, 2014 06:40

I found a way to do this: Add the following code to (within) the pimple.loop():
Code:

            functionObjectList& fol = runTime.functionObjects();
            fol.execute(false);

(you have to add #include "functionObjectList.H" at the beginning of your solver).

Add the following to your controlDict and the executeCode is called during each step of your pimple.loop:
Code:

functions {
    pythonSimple
    {
        type pythonIntegration;

        //        debugPythonWrapper 1; // switching on

        startCode "print 'Starting';a=0; print dir()";
        executeCode "a+=1; print 'a:',a";
        endCode "print 'Never been here'";
        //        tolerateExceptions true;
        parallelMasterOnly false;
        isParallelized true;
        useNumpy false;
        useIPython true;
    }
    pythonOutput
    {
        type pythonIntegration;

        startCode "";
        executeCode "print 'timeName :',timeName,'outputTime:',outputTime";
        endCode "print 'timeName :',timeName,'outputTime:',outputTime";
        //        tolerateExceptions true;
        parallelMasterOnly true;
        useNumpy false;
        useIPython true;
    }
}

libs (
    "libgroovyBC.so"
    "libswakPythonIntegration.so"
    "libswakFunctionObjects.so"
);


wyldckat January 30, 2014 17:01

Greetings Joachim,

I noticed your feature request on the bug tracker: http://www.openfoam.org/mantisbt/view.php?id=1145
Just to let you know that a very similar feature request was asked about back in August 2012: http://www.openfoam.org/mantisbt/view.php?id=641

Best regards,
Bruno

jherb January 30, 2014 17:24

Thank you for the information. Indeed the old bug looks somehow similar to what I would like to do. The final goal is to couple OpenFOAM with an external solver (for 1-d thermohydraulics). For the stability of the coupling it is necessary to exchange information on the boundaries more than once per time step.

wyldckat January 30, 2014 17:36

Have you checked the tutorial "./heatTransfer/buoyantSimpleFoam/externalCoupledCavity" in OpenFOAM 2.2, to see if it would work for you?

jherb January 31, 2014 09:21

Thank you for your hint. I would like to avoid the exchange via file system but yes, I was able to run this example and also the "hot room" of the buoyantPimpleFoam tutorials and the data are exchanged after each step of the outer corrector loop within a time step.

Quote:

Originally Posted by wyldckat (Post 472666)
Have you checked the tutorial "./heatTransfer/buoyantSimpleFoam/externalCoupledCavity" in OpenFOAM 2.2, to see if it would work for you?


wyldckat February 1, 2014 17:33

Hi Joachim,

Have a look into this thread: http://www.cfd-online.com/Forums/ope...lue-facei.html - the idea given there is that you can use that tutorial and the associated boundary condition as a basis for your connection between applications. In other words, you would have to copy-paste-modify the source code of the boundary condition to suit your needs.

Nonetheless, now I'm looking into the source code for the boundary condition, it does feel that the solution you're using with Python is somewhat easier to implement.

Best regards,
Bruno


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