CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Questions about the code (http://www.cfd-online.com/Forums/openfoam-programming-development/72119-questions-about-code.html)

Alicelin January 26, 2010 04:17

Questions about the code
 
Hi everyone,

I got some questions about the code...Can somebody explain what's the meaning of:
1. instantList Times = runTime.times();
2. runTime.setTime(Times[startTime], startTime); ?

Thanks!

Alice

olesen January 27, 2010 04:09

Quote:

Originally Posted by Alicelin (Post 243752)
Hi everyone,

I got some questions about the code...Can somebody explain what's the meaning of:
1. instantList Times = runTime.times();
2. runTime.setTime(Times[startTime], startTime); ?

The code states that it get the list of time instants and set the current time to be one of them from the list. What exactly is your question?

Alicelin January 28, 2010 01:59

Thanks for your reply...I want to know that in
Code:

runTime.setTime(Times[startTime], startTime);
, what's the meaning of the parameters in the blanket(i.e. Times[startTime] and startTime) ? Say if I put 0 or any other time instead of startTime for the second parameter in the blanket, what'll be the changes??

Alice

olesen January 28, 2010 03:42

Quote:

Originally Posted by Alicelin (Post 244000)
Thanks for your reply...I want to know that in
Code:

runTime.setTime(Times[startTime], startTime);
, what's the meaning of the parameters in the blanket(i.e. Times[startTime] and startTime) ? Say if I put 0 or any other time instead of startTime for the second parameter in the blanket, what'll be the changes??

If you have "Times[startTime]", that's a time 'instant' and you can see from the corresponding code (in Time.C) what happens:
Code:

void Foam::Time::setTime(const instant& inst, const label newIndex)
{
    value() = inst.value();
    dimensionedScalar::name() = inst.name();
    timeIndex_ = newIndex;

    IOdictionary timeDict
    (
        IOobject
        (
            "time",
            timeName(),
            "uniform",
            *this,
            IOobject::READ_IF_PRESENT,
            IOobject::NO_WRITE,
            false
        )
    );

    timeDict.readIfPresent("deltaT", deltaT_);
    timeDict.readIfPresent("deltaT0", deltaT0_);
    timeDict.readIfPresent("index", timeIndex_);
}

Thus if the specified time instant exists in your results and has the sub-dir with a uniform/time (eg, 0/uniform/time, or 100/uniform/time, etc.) the time index will be read from that file. Otherwise your specified time index will be used.

If you really want to bypass the read dictionary semantics, you could specifying the time value directly as a scalar. For example,
Code:

runTime.setTime(Times[startTime].value(), startTime);
But for most cases, I think that the normal behaviour (with the read dictionary semantics) probably does what you want. For example, suppose you had run a calculation from 0 to 1000 iterations with output every 100 iterations. Your time instantList would have 12 entries (constant, 0, 100 .. 1000). Specifying the following:
Code:

int someTime = 7;
runTime.setTime(Times[someTime], someTime);

This would select the time instance corresponding to '500' with an index of '7'. However, since the uniform/time entry exists, it will be read and the real time index will actually be set to 500. If you wished to continue calculating from here, this is exactly what you want.

Alicelin January 29, 2010 02:49

Dear olesen,

Thanks for your explanation. It helps:)

Alice


All times are GMT -4. The time now is 12:43.