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

How to detect if PIMPLE has converged from inside fvOption?

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By wyldckat
  • 1 Post By wyldckat

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 1, 2015, 10:24
Default How to detect if PIMPLE has converged from inside fvOption?
  #1
Senior Member
 
Pete Bachant
Join Date: Jun 2012
Location: Boston, MA
Posts: 173
Rep Power: 14
pbachant is on a distinguished road
I am writing an fvOption that needs to write some data to CSV, but only when PIMPLE has converged. Is there a clever use of OpenFOAM's Time with which I can detect this? Right now I can detect when the time value has changed, but not when it's about to change.

Source code for reference
__________________
Home | Twitter | GitHub
pbachant is offline   Reply With Quote

Old   February 1, 2015, 10:59
Default
  #2
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 Pete,

Well, if you only wanted to know when it's an iteration in which the solver will save the fields, then you can rely on the method "outputTime()":
Code:
if(time_.outputTime())
{
  // do stuff here whenever it's a time step where the solver will save
}
The downside is that this means that it will write the CSV file whenever a time snapshot is saved.

As for knowing when it has converged... that's a tricky one. Wait, you want only when it's the last PIMPLE loop. Mmm... this requires access to the PIMPLE object... technically, access to the instance of the class "pimpleControl".
OK, let's see:
  1. The class "pimpleControl" derives from "solutionControl", which in turn derives from "IOobject", which means that we can access the registry looking for the respective object... named "solutionControl", because "PIMPLE" is only the algorithm name.
  2. I went savaging a bit for how to access said way of access and re-found this post: http://www.cfd-online.com/Forums/ope...tml#post426135 - see posts #14 and #15
  3. Now, once you have a local access instance to the "pimpleControl" object that is created by the solver, then you should be able to do this:
    Code:
    if (pimple.finalNonOrthogonalIter())
    {
      //the pertinent code to be done only in the last iteration
    }
But there's now a particularly big problem: will your "fvOption" actually be called in that last iteration of the PIMPLE loop?
I took a look and rhoPimpleFoam does call fvOption in the "pEqn.H", but pimpleFoam does not. Therefore, you need to be careful about this.


Sorry for not providing the actual piece of code that does the access to the registered object, but I would need to test it first and I've got a lot I would like to take care of today...

Best regards,
Bruno
sharonyue likes this.
__________________
wyldckat is offline   Reply With Quote

Old   February 1, 2015, 11:12
Default
  #3
Senior Member
 
Pete Bachant
Join Date: Jun 2012
Location: Boston, MA
Posts: 173
Rep Power: 14
pbachant is on a distinguished road
Bruno,

Thanks for your reply. As you guessed, I don't want to wait until a time when fields are written--I want to write every timestep. What I want to do is very similar to what the forces function object does, but now I'm wondering if forces are written on the first PIMPLE loop in that...

The numbers are very close to each other in my case, so it's not a big problem so far, but I am just trying to be as correct as possible.
__________________
Home | Twitter | GitHub
pbachant is offline   Reply With Quote

Old   February 1, 2015, 12:00
Default
  #4
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
Quote:
Originally Posted by pbachant View Post
What I want to do is very similar to what the forces function object does, but now I'm wondering if forces are written on the first PIMPLE loop in that...
Quick answer: Have a look into the method "Foam::Time::run()" in the file "src/OpenFOAM/db/Time/Time.C" and you'll see when the methods for the function objects are called.
As for the "run()" method, that is called whenever it's called directly be the solver or indirectly by the "simpleControl"/"pimpleControl", e.g.:
Code:
while (simple.loop())
{
  //....
}
wyldckat is offline   Reply With Quote

Old   May 6, 2015, 14:25
Default
  #5
Senior Member
 
Pete Bachant
Join Date: Jun 2012
Location: Boston, MA
Posts: 173
Rep Power: 14
pbachant is on a distinguished road
I have been trying to access the pimple object with

Code:
    // Write performance data if last PIMPLE iteration
    const solutionControl& pimple = mesh_.lookupObject<solutionControl>("pimple");
    if (pimple.finalNonOrthogonalIter() and Pstream::master())
    {
        writePerf();
    }
but I get the error

Code:
--> FOAM FATAL ERROR: 

    request for solutionControl pimple from objectRegistry region0 failed
    available objects of type solutionControl are
0()

    From function objectRegistry::lookupObject<Type>(const word&) const
    in file /home/pete/OpenFOAM/OpenFOAM-2.3.x/src/OpenFOAM/lnInclude/objectRegistryTemplates.C at line 198.
Is there somewhere else I should be trying to look up the solutionControl?
__________________
Home | Twitter | GitHub
pbachant is offline   Reply With Quote

Old   September 21, 2015, 18:34
Default
  #6
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 Pete,

I had this on my to-do list and only today did I manage to look into this.

The problem is that the "solutionControl" class derives from "IOobject" and not from "regIOobject", which is why it's not possible to get an instance of this object through the object database.

As far as I can figure out, there are roughly only two major solutions:
  1. To use a global/static C++ object that is made public in your custom library that has the "fvOption" and that the solver links and accesses to directly.
  2. Or to create a new class that derives from "regIOobject". The class structure would also have to be shared between the two (library and solver) and the access to the "solutionControl" would then be up to you.

As for making "solutionControl" class derive from "regIOobject" in OpenFOAM itself, I don't know if this makes much sense, since this is only useful in a few situations.

Best regards,
Bruno
SailorLiu likes this.
__________________
wyldckat is offline   Reply With Quote

Old   September 24, 2015, 20:49
Default
  #7
Senior Member
 
Pete Bachant
Join Date: Jun 2012
Location: Boston, MA
Posts: 173
Rep Power: 14
pbachant is on a distinguished road
Hi Bruno,

Thanks for your tireless efforts as usual!

Both solutions seem over my head, and may not be desirable, since I want to be compatible with the standard OpenFOAM. For now, I am writing every loop, and taking the last value in post-processing, which is quite easy with the Python Pandas library anyway.
__________________
Home | Twitter | GitHub
pbachant 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
Help for the small implementation in turbulence model shipman OpenFOAM Programming & Development 25 March 19, 2014 11:08
New sixDoFRigidBody BC working with laplaceFaceDecomposition Ya_Squall2010 OpenFOAM Running, Solving & CFD 13 April 17, 2013 03:04
OpenFOAM on MinGW crosscompiler hosted on Linux allenzhao OpenFOAM Installation 127 January 30, 2009 20:08
Modelling the Heat flow inside the curing oven Marios Vlad CFX 1 February 6, 2008 08:11
meshing F1 front wing Steve FLUENT 0 April 17, 2003 13:37


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