|
[Sponsors] |
September 30, 2011, 05:21 |
value of previous time step
|
#1 |
Member
luca
Join Date: Feb 2011
Posts: 34
Rep Power: 15 |
Hi
In OpenFoam is it possible to know the old time step value of any variable. I need to store a vectorField and use it in the next time step. I had a look in the forum and found the commands: fieldName.storeOldTime(); // to store an old time field fieldName.oldTime(); // to recover it I tried to compile these and got the error: # error: 'class Foam::vectorField' has no member named 'storeOldTime' error: 'class Foam::vectorField' has no member named 'storeOldTime' # My question is, how to handle with those? Luca |
|
September 30, 2011, 10:07 |
|
#3 | |
Senior Member
Ben K
Join Date: Feb 2010
Location: Ottawa, Canada
Posts: 140
Rep Power: 19 |
Quote:
Take a look at this post: http://www.cfd-online.com/Forums/ope...tml#post298878 If I remember correctly, the times are stored in an array and should be accessible through: Code:
runTime.times()[indexNumber].value() |
||
September 30, 2011, 10:14 |
|
#4 |
Member
luca
Join Date: Feb 2011
Posts: 34
Rep Power: 15 |
I still get the same kind of error.
I probably use a wrong sintax. If I wanted to store the vectorField a (for instance) for then using it in the next time step calculation, what should I write? I tried these and all gave errors: # a.old(); a.oldTime(); a.StoreOldTime(); # |
|
September 30, 2011, 10:18 |
|
#5 | |
Senior Member
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 22 |
Quote:
|
||
September 30, 2011, 10:36 |
|
#6 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
Use U.oldTime(). You don't need to tell it to store the old time... it figures that out on its own based on how many .oldTime() requests the GeometricField gets in a timestep. You can ask it how many old times it is storing: .nOldTimes() (I think). The first timestep, even if it is resuming in the middle of an old run, all the .oldTime() are the same.
__________________
~~~ Follow me on twitter @DavidGaden |
|
September 30, 2011, 11:22 |
|
#7 |
Member
luca
Join Date: Feb 2011
Posts: 34
Rep Power: 15 |
Thanks to all for replying
I tried U.oldTime() and it works but when I apply it to my vectorField 'myField' it gives: error: 'class Foam::vectorField' has no member named 'oldTime()' I am solving a system of equations by iteration and I want to give the current solution as first guess for the next time step. |
|
September 30, 2011, 11:29 |
|
#8 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
Oh, it's a vectorField, not a volVectorField? Yeah, vectorFields are just vectorLists with math. There's no fancy oldTime archiving. In that case, just create a vectorField like a temp variable.
Code:
// Initialize vectorField oldVectors(myVectors.size()); // Save old vectors: oldVectors = myVectors; // etc..
__________________
~~~ Follow me on twitter @DavidGaden |
|
October 3, 2011, 05:19 |
|
#9 |
Member
luca
Join Date: Feb 2011
Posts: 34
Rep Power: 15 |
Thanks for the help
I have tried the suggested: Code:
// Initialize vectorField oldVectors(myVectors.size()); // Save old vectors: oldVectors = myVectors; // etc.. I changed my vectorField to a volVectorField so that I could use fieldName.oldTime(). When I compile I do not know how to initialize my variable: Code:
... xn.oldTime(); for (int mm=0; mm < counter; mm++) // iteration process { xn = ... // in this loop the volVectorField xn is created by an iterative process } xn.storeOldTime(); ... error: 'xn' was not declared in this scope I want to use the results of the iteration as first guess for the next time step. |
|
October 4, 2011, 09:12 |
|
#10 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
> Had no success.
What was the error? Was it a compile error, or did it not hold the data. This is a simple vector field copy we're doing - it shouldn't be too hard. The constructors for volVectorField are listed in GeometricField.H.
__________________
~~~ Follow me on twitter @DavidGaden |
|
October 5, 2011, 05:49 |
|
#11 |
Member
luca
Join Date: Feb 2011
Posts: 34
Rep Power: 15 |
Hi.
The solver compiles whitout problems. What I can see is that every time step the volVectorField with the initial guesses is not updated. Code:
volVectorField xn //initialize the volVectorField with the initial guesses being 0,0,0 ( IOobject ( "xn", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh, dimensionedVector ( "xn", dimensionSet(0,0,0,0,0,0,0), vector::zero ) ); xn.oldTime(); // this should overwrite the xn with the results obtained in the previous step // I THINK THIS IS NOT WORKING!! for (int mm=0; mm < counter; mm++) // iteration process { xn = ... // in this loop the volVectorField xn is created by an iterative process } xn.storeOldTime(); // This should store the xn results to be used as initial guesses // for the next time step ... I just do not know how to use them properly. Thanks in advance |
|
October 5, 2011, 11:57 |
|
#12 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
Yes, oldTime works much simpler than you think. It is all totally automatic in the background. You never need to call storeOldTime()... and the xn.oldTime() immediately gives you the value from the previous timestep. runTime is clever enough to count how many .oldTime()'s you use, and automatically stores that many in its database.
I think you are probably using a local object. I was always confused as to why xn wouldn't *already* have the previous timestep's value at the start of the next timestep. If you are using a local object, it is erased and reconstructed at every timestep. In this case, oldTime() won't work, and neither would a simpler vectorField copy we talked about either. Where are you constructing your xn object? Will the program encounter the constructor once and only once throughout multiple timestep iterations? If not, move the constructor above your while(runTime.loop())... possibly even into createFields.H. If this is the problem, that's probably why it didn't work when you were using a standard vectorField. I'd recommend returning to the vectorField framework if possible.
__________________
~~~ Follow me on twitter @DavidGaden Last edited by marupio; October 5, 2011 at 11:58. Reason: "If so" changed to "If not" oops |
|
October 6, 2011, 18:03 |
|
#13 |
Member
luca
Join Date: Feb 2011
Posts: 34
Rep Power: 15 |
Hi
Thanks a lot!! I moved the volVectorField constructor in createFields.H and now the value at the next time step is overwritten correctly. Why do you suggest to return to the vectorField? I could do that but it will take me time due to my poor programming knowledge. How should the constructor for the vectorField in createFields.H? Code:
vectorField xn = vector::zero.boundaryField()[bottom_patch]; I tried also with the volVectorField but without success: Code:
volVectorField xn ( IOobject ( "xn", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh, dimensionedVector ( "xn", dimensionSet(0,0,0,0,0,0,0), //vector::zero // THIS WORKS BUT I DON'T WANT ZERO VECTORS uniform (0.05,0.001,0.001) // THIS IS NOT COMPILING ) ); Luca |
|
October 6, 2011, 19:23 |
|
#14 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
I don't think you even need to use the .oldTime because the previous values will still be in the vectorField at the start of the next timestep. I suggest using a vectorField if you are not doing any math on the boundary because you are carrying a lot of unnecessary extra memory in the boundary field, as well as performing unnecessary operations there. It's your perogative.
As for the compile error, that's probably because it doesn't know what a uniform is. Try replacing the word 'uniform' with the word 'vector'.
__________________
~~~ Follow me on twitter @DavidGaden |
|
October 7, 2011, 12:39 |
|
#15 |
Member
luca
Join Date: Feb 2011
Posts: 34
Rep Power: 15 |
Thanks
I undersatand the memory issue. So I am trying to use a vectorField. I want to define the vectorField in createFields.H. I tried different ways: Code:
vectorField xn = vector::zero.boundaryField()[bottom_patch]; vectorField xn ( IOobject ( "xn", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh.boundaryMesh().findPatchID(bottom_patch), ); vectorField xn ( IOobject ( "xn", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh.boundaryMesh()[bottom_patch], ); Any idea?? |
|
October 8, 2011, 12:25 |
|
#16 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
You could use this constructor:
Code:
vectorField nameOfVectorField(sizeOfVectorField); // or vectorField nameOfVectorField(sizeOfVectorField, initialValueForAllCells);
__________________
~~~ Follow me on twitter @DavidGaden |
|
October 14, 2011, 12:49 |
|
#17 |
Member
luca
Join Date: Feb 2011
Posts: 34
Rep Power: 15 |
I have been trying to use the vectorField without success. So I will keep my volVectorField.
Many thanks for your help!! |
|
February 7, 2013, 20:16 |
|
#18 |
Member
Martin
Join Date: Dec 2011
Location: Latvia
Posts: 54
Rep Power: 15 |
Greetings!
Sorry for bringing up such an old thread but the title is rather corresponding to my issue. I have a dependent variable like g=g(a). But my solution has really bad convergence and to improve it there is an idea to use weighted combination of values from different time steps. It should look something like this where k is iteration step. g(k+1)=g(a(k)+a(k-1)) How I can get these values in OF? Is something like this correct? I mean is a.oldTime value 'more previous' than simply value of a? Code:
g=g(a+a.oldTime()) |
|
May 21, 2013, 13:08 |
|
#19 |
New Member
Pietro Danilo Tomaselli
Join Date: Oct 2012
Location: Lyngby, DTU
Posts: 9
Rep Power: 14 |
Hi all!
I have to modify a solver and I'd like to do some calculations with values of U of all the previous time steps, not only the time step immediately earlier the current one. For instance, which is the way "to call" the value of U at (i-5) time step, if i is the current one (in run time)? Any hints to do this? Thanks in advance Danilo |
|
November 5, 2013, 05:47 |
|
#20 |
Member
Thomas Vossel
Join Date: Aug 2013
Location: Germany
Posts: 45
Rep Power: 13 |
Hi!
I tried the .oldTime() method but it didn't work for me - I always got the very same values for both my new volScalarField itself as well as for the fieldname.oldTime() expression... I once saw a .prevIter() method in one of OpenFoam's solvers so I tried it that way. The compiler then asked me to do a field.storePrevIter() command too and this actually worked. So maybe someone should clarify if the oldTime method got deprecated in the meantime or not. What works is this: Code:
fieldname.storePrevIter(); << DO THE CALCULATIONS / UPDATES ON YOUR FIELD AFTERWARDS >> fieldname.prevIter(); |
|
Tags |
field, store, time step |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Reading forces from previous time step within solver | SD@TUB | OpenFOAM Programming & Development | 5 | April 24, 2023 12:51 |
Time step size and max iterations per time step | pUl| | FLUENT | 31 | October 23, 2020 23:50 |
Superlinear speedup in OpenFOAM 13 | msrinath80 | OpenFOAM Running, Solving & CFD | 18 | March 3, 2015 06:36 |
UDF: Previous time step macros NOT working | jpapg | FLUENT | 0 | April 30, 2011 22:35 |
Convergence moving mesh | lr103476 | OpenFOAM Running, Solving & CFD | 30 | November 19, 2007 15:09 |