|
[Sponsors] |
What is the trigger of the function objects?? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
November 24, 2014, 04:58 |
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 |
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 |
|
November 26, 2014, 09:35 |
|
#2 |
Senior Member
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 21 |
(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(); } ... } 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(); 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) 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. |
|
September 3, 2016, 16:29 |
|
#3 | |
New Member
Jose
Join Date: Nov 2015
Posts: 3
Rep Power: 11 |
Quote:
Is there any way I can access forces in the solver ? Last edited by hoseinr59; September 4, 2016 at 02:40. |
||
October 30, 2020, 10:17 |
|
#4 |
New Member
Saeed Salehi
Join Date: Aug 2010
Posts: 27
Rep Power: 16 |
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; 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 |
|
November 28, 2021, 22:54 |
|
#5 | |
Senior Member
mohammad
Join Date: Sep 2015
Posts: 281
Rep Power: 12 |
Quote:
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; } Code:
Foam::vector Foam::functionObjects::forces::forceEff() const { return sum(force_[0]) + sum(force_[1]) + sum(force_[2]); } 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. |
||
January 18, 2022, 08:20 |
|
#6 |
New Member
Junwei Ma
Join Date: Jan 2022
Posts: 1
Rep Power: 0 |
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
|
|
|
|
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 |