value of previous time step
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 |
did u try ?
fieldName.old(); |
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() |
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(); # |
Quote:
|
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.
|
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. |
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 |
Thanks for the help
I have tried the suggested: Code:
// Initialize 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:
... 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. |
> 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. |
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 I just do not know how to use them properly. Thanks in advance |
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. |
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 Luca |
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'. |
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]; Any idea?? |
You could use this constructor:
Code:
vectorField nameOfVectorField(sizeOfVectorField); |
I have been trying to use the vectorField without success. So I will keep my volVectorField.
Many thanks for your help!! |
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()) |
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 |
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(); |
All times are GMT -4. The time now is 19:02. |