CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Call external code (functionObject execute() like) within pimple.loop()

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 2 Post By jherb

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 28, 2014, 13:53
Default Call external code (functionObject execute() like) within pimple.loop()
  #1
Senior Member
 
Joachim Herb
Join Date: Sep 2010
Posts: 650
Rep Power: 22
jherb is on a distinguished road
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

Last edited by jherb; January 28, 2014 at 18:27.
jherb is offline   Reply With Quote

Old   January 30, 2014, 07:40
Default
  #2
Senior Member
 
Joachim Herb
Join Date: Sep 2010
Posts: 650
Rep Power: 22
jherb is on a distinguished road
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 and kamakura117 like this.
jherb is offline   Reply With Quote

Old   January 30, 2014, 18:01
Default
  #3
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
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
wyldckat is offline   Reply With Quote

Old   January 30, 2014, 18:24
Default
  #4
Senior Member
 
Joachim Herb
Join Date: Sep 2010
Posts: 650
Rep Power: 22
jherb is on a distinguished road
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.
jherb is offline   Reply With Quote

Old   January 30, 2014, 18:36
Default
  #5
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Have you checked the tutorial "./heatTransfer/buoyantSimpleFoam/externalCoupledCavity" in OpenFOAM 2.2, to see if it would work for you?
wyldckat is offline   Reply With Quote

Old   January 31, 2014, 10:21
Default
  #6
Senior Member
 
Joachim Herb
Join Date: Sep 2010
Posts: 650
Rep Power: 22
jherb is on a distinguished road
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 View Post
Have you checked the tutorial "./heatTransfer/buoyantSimpleFoam/externalCoupledCavity" in OpenFOAM 2.2, to see if it would work for you?
jherb is offline   Reply With Quote

Old   February 1, 2014, 18:33
Default
  #7
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
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
wyldckat is offline   Reply With Quote

Reply

Tags
functionobjects, pimple, swak4foam


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the Better Way to Do CFD? John C. Chien Main CFD Forum 54 April 23, 2001 09:10
Open source CFD code development, possible? Dr. Yazid Bindar Main CFD Forum 27 July 18, 2000 01:18
State of the art in CFD technology Juan Carlos GARCIA SALAS Main CFD Forum 39 November 1, 1999 15:34
Who's ok for an Open Source CFD project ? Viet Main CFD Forum 16 July 26, 1999 16:57
What kind of Cmmercial CFD code you feel well? Lans Main CFD Forum 13 October 27, 1998 11:20


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