CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Programming & Development (
-   -   choose a specific time (

dav1dt January 4, 2011 21:10

choose a specific time
Hi All

My problem is: I want to choose a specific time in my post-processing code but I don't know how. I have seen a lot of loop with runtime where it chooses all the time-directories one after another but nothing about only the last time-directory for example.

You can find that code in postChannel:

// For each time step read all fields
forAll(timeDirs, timeI)
runTime.setTime(timeDirs[timeI], timeI);
Info<< "Collapsing fields for time " << runTime.timeName() << endl;

# include "readFields.H"
# include "calculateFields.H"

// Average fields over channel down to a line
# include "collapse.H"

But me I try to get (roughly) ----> //For last Time step read all field

I try several things but I'm not familiar with C++.

If someone could give me a hint, it will be great.



r08n January 7, 2011 11:46


Originally Posted by dav1dt (Post 289273)
Hi All

But me I try to get (roughly) ----> //For last Time step read all field

Do you want to select fields for the last time?

I have never done this myself, but just guessing: if you look at the 'postChannel' source (which you quote anyway), there is a reference to a 'timeSelector' class:


instantList timeDirs = timeSelector::select0(runTime, args);
Its description says:


The result program would receive -time, -latestTime, -constant and -noZero options. The -constant option explicitly includes the constant/ directory in the time list and the -noZero option explicitly excludes the 0/ directory from the time list.
So, I guess, you need to supply the option '-latestTime' in the 'args' before calling timeSelector::select0. The function 'timeSelector::addOptions' shows how to do it:


argList::validOptions.insert("latestTime", "");
Now, the 'timeDirs' will probably contain only the last time directory.

As I said, I haven't tested it, just a hint.

dav1dt January 10, 2011 12:19

Thank you

I'll give you feedback on this shortly.

dav1dt January 20, 2011 16:20


I didn't succeed the way you suggested. However I have been able to do what I wanted. I wrote my latestTime's number in a dictionary and asked openFoam to read and use it.


All times are GMT -4. The time now is 17:13.