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

What is the trigger of the function objects??

Register Blogs Community New Posts Updated Threads Search

Like Tree7Likes
  • 1 Post By Sylv
  • 4 Post By floquation
  • 2 Post By salehi144

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 24, 2014, 04:58
Default What is the trigger of the function objects??
  #1
New Member
 
Marcel Vonlanthen
Join Date: Nov 2012
Location: Zurich, Switzerland
Posts: 28
Rep Power: 14
Sylv is on a distinguished road
Dear foamer,

In any solver, one can add some function objects in the controlDict. They are triggered at the end of each solver timestep. In the solvers, I guess that the triggering line of code is "runTime.write()". Is that true?

Is it possible to trigger a function object at a different location in the source code? For example, I want to extract the field average of a LES run just after the prediction loop of pimpleFoam (after UEqu.H). What kind of code can I add to trigger a funcObj call?

Best,
Marcel
zhulianhua likes this.
Sylv is offline   Reply With Quote

Old   November 26, 2014, 09:35
Default
  #2
Senior Member
 
floquation's Avatar
 
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 21
floquation will become famous soon enough
(Below I take v2.3.x as my version.)

As part of my internship, I duck into the lagrangian library for which I looked into both FunctionObjects and CloudFunctionObjects. Attached you'll find a qualitative UML diagram showing the calling sequence of methods. The top-left of the image is the execution of a FunctionObject.

Tracing FunctionObjects, one may find the following in "OpenFOAM-2.3.x / src / OpenFOAM / db / Time / Time.C."

Code:
bool Foam::Time::run() const
{
   ...
   if (timeIndex_ == startTimeIndex_)
   {
      functionObjects_.start();
   }
   else
   {
      functionObjects_.execute();
   }
   ...
}
So, functionObjects are executed via the runTime.run() command in a solver.

While I have never tried executing them elsewhere, I see that the Time class does have a getter for the functionObjects list, so you should be able to retrieve that list and thus execute functionObjects whenever you want.

So something like...
Code:
runTime.functionObjects().execute();
will execute all functionObjects at that time.

To only execute a specific functionObject, you need to do something like...
Code:
label id = runTime.functionObjects().findObjectID(name); //Warning: returns -1 if "name" does not exist.
runTime.functionobjects()[id].execute(forceWrite); //Warning: fatal error if id is out of bounds (e.g. -1)
which uses the methods from:
OpenFOAM-2.3.x / src / OpenFOAM / db / functionObjects / functionObjectList / functionObjectList.C
and "forceWrite" is an optional boolean with defaults 'false'.


Disclaimer: I did not test the above code (I don't have access to OF right now). I reasoned from the source code. Try it yourself.
Attached Images
File Type: png lpt_codeflow1.png (21.9 KB, 151 views)
floquation is offline   Reply With Quote

Old   September 3, 2016, 16:29
Default
  #3
New Member
 
Jose
Join Date: Nov 2015
Posts: 3
Rep Power: 11
hoseinr59 is on a distinguished road
Quote:
Originally Posted by floquation View Post
(Below I take v2.3.x as my version.)

As part of my internship, I duck into the lagrangian library for which I looked into both FunctionObjects and CloudFunctionObjects. Attached you'll find a qualitative UML diagram showing the calling sequence of methods. The top-left of the image is the execution of a FunctionObject.
.
.
.


Disclaimer: I did not test the above code (I don't have access to OF right now). I reasoned from the source code. Try it yourself.
I am trying to access the forceCoeffs inside the solver. The execute function triggers the OpenFOAM::forceCoeffs.write() which is a virtual boolean type function and I can not change the type to return the forceCoeffs value.

Is there any way I can access forces in the solver ?

Last edited by hoseinr59; September 4, 2016 at 02:40.
hoseinr59 is offline   Reply With Quote

Old   October 30, 2020, 10:17
Default
  #4
New Member
 
Saeed Salehi
Join Date: Aug 2010
Posts: 27
Rep Power: 16
salehi144 is on a distinguished road
Hi,

It is an old question, but for the people who might be interested (Based on OpenFOAM-v2007):

I can see that Kevin answered the question correctly. Just to put it in another way, the functionObjects are called inside the run() function from the time class. For example, let's consider the pimpleFoam solver. The solver loop starts with:

Code:
    while (runTime.run())
    {
        #include "readDyMControls.H"
        #include "CourantNo.H"
        #include "setDeltaT.H"

        ++runTime;
The runTime object inherits from Time class in which run() function is defined. If you look at the function somewhere this piece of code is called:
Code:
             if (timeIndex_ == startTimeIndex_)
             {
                 addProfiling(functionObjects, "functionObjects.start()");
                 functionObjects_.start();
             }
             else
             {
                 addProfiling(functionObjects, "functionObjects.execute()");
                 functionObjects_.execute();
             }

Therefore, the functionObjects are called at the beginning of each loop and not at the end. In this way, they are also called after the final time step.

The simpleFoam solver is also similar. But first the loop() function is called and the run() function is called inside the loop().

Best
Saeed
Farid and Marpole like this.
salehi144 is offline   Reply With Quote

Old   November 28, 2021, 22:54
Default
  #5
Senior Member
 
mohammad
Join Date: Sep 2015
Posts: 281
Rep Power: 12
mostanad is on a distinguished road
Quote:
Originally Posted by salehi144 View Post
Hi,

It is an old question, but for the people who might be interested (Based on OpenFOAM-v2007):

I can see that Kevin answered the question correctly. Just to put it in another way, the functionObjects are called inside the run() function from the time class. For example, let's consider the pimpleFoam solver. The solver loop starts with:

Code:
    while (runTime.run())
    {
        #include "readDyMControls.H"
        #include "CourantNo.H"
        #include "setDeltaT.H"

        ++runTime;
The runTime object inherits from Time class in which run() function is defined. If you look at the function somewhere this piece of code is called:
Code:
             if (timeIndex_ == startTimeIndex_)
             {
                 addProfiling(functionObjects, "functionObjects.start()");
                 functionObjects_.start();
             }
             else
             {
                 addProfiling(functionObjects, "functionObjects.execute()");
                 functionObjects_.execute();
             }
Therefore, the functionObjects are called at the beginning of each loop and not at the end. In this way, they are also called after the final time step.

The simpleFoam solver is also similar. But first the loop() function is called and the run() function is called inside the loop().

Best
Saeed

Hi Saeed,


I know this post belongs to some time ago, and now we know where functionObjects are triggered. However, this brings an important question about functionObjects.



The question is about how to have access to a function in a functionObject?


I have a "forces" functionObject which writes the postProcessing files at the end of time step and also within the terminal. I am using OF 5.x, which is showing me this function for output files in the forces.C:


Code:
bool Foam::functionObjects::forces::write()
{
    calcForcesMoment();

    if (Pstream::master())
    {
        logFiles::write();

        writeForces();

        writeBins();

        Log << endl;
    }
    return true;
}
However, it shows me another function which is my of interest as well: forceEff()

Code:
Foam::vector Foam::functionObjects::forces::forceEff() const
{
    return sum(force_[0]) + sum(force_[1]) + sum(force_[2]);
}
So the question is whether it is possible to call this function within my icoFoam solver?


Hint: I have seen its usage in rigidBodyMeshMotion.


Thank you for your help and consideration.

Last edited by mostanad; November 29, 2021 at 01:45.
mostanad is offline   Reply With Quote

Old   January 18, 2022, 08:20
Default
  #6
New Member
 
Junwei Ma
Join Date: Jan 2022
Posts: 1
Rep Power: 0
xiaoxiao is on a distinguished road
Hi there, I have the same question as you do. Have you successfully called this forceEff function? I really dont know how to do it
xiaoxiao is offline   Reply With Quote

Reply


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
[Other] Contribution a new utility: refine wall layer mesh based on yPlus field lakeat OpenFOAM Community Contributions 58 December 23, 2021 03:36
channelFoam for a 3D pipe AlmostSurelyRob OpenFOAM 3 June 24, 2011 14:06
latest OpenFOAM-1.6.x from git failed to compile phsieh2005 OpenFOAM Bugs 25 February 9, 2010 05:37
Version 15 on Mac OS X gschaider OpenFOAM Installation 113 December 2, 2009 11:23
Problem with compile the setParabolicInlet ivanyao OpenFOAM Running, Solving & CFD 6 September 5, 2008 21:50


All times are GMT -4. The time now is 02:45.