CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Reading forces from previous time step within solver (https://www.cfd-online.com/Forums/openfoam-programming-development/73677-reading-forces-previous-time-step-within-solver.html)

SD@TUB March 14, 2010 06:58

Reading forces from previous time step within solver
 
Hello FOAMers,

what would be the best way of reading forces from previous time step within solver code? I'm calculating some cases with OF 1.6 via simpleFoam.
I noticed the function objects where pressure and viscous forces/moments are integrated over given walls (using "libforces.so"). In forces.C the
data of interest accessed by:
Code:

...
fm.first().first() (pressure forces) or fm.first().second() (viscous forces)
fm.second().first() (moment of pressure forces) or fm.second().second() (moment of viscous forces)
...
return fm;
...
fm.write();

Now i tried to catch the values within solver code. I added my own header in simpleFoam.C where i calculate some additional stuff. Within this header i want to initialize variables with the summarized forces (under consideration of the listed headers in forces.C), but it doesn't work. I did something like:
Code:

scalar Fp = fm.first().first();
scalar Fv = fm.first().second();

According to the OF programmers guide, field data from previous time step are associated with geometricField<type>. In my understanding this isn't applicable for calculated forces, because they applied to pressure and shear stress on walls.
I'm not familiar with the code conventions of OF and new to object oriented programming in C++! Any advice is much appreciated...


/Stefan

federicabi May 25, 2016 03:00

Quote:

Originally Posted by SD@TUB (Post 249887)
Hello FOAMers,

what would be the best way of reading forces from previous time step within solver code? I'm calculating some cases with OF 1.6 via simpleFoam.
I noticed the function objects where pressure and viscous forces/moments are integrated over given walls (using "libforces.so"). In forces.C the
data of interest accessed by:
Code:

...
fm.first().first() (pressure forces) or fm.first().second() (viscous forces)
fm.second().first() (moment of pressure forces) or fm.second().second() (moment of viscous forces)
...
return fm;
...
fm.write();

Now i tried to catch the values within solver code. I added my own header in simpleFoam.C where i calculate some additional stuff. Within this header i want to initialize variables with the summarized forces (under consideration of the listed headers in forces.C), but it doesn't work. I did something like:
Code:

scalar Fp = fm.first().first();
scalar Fv = fm.first().second();

According to the OF programmers guide, field data from previous time step are associated with geometricField<type>. In my understanding this isn't applicable for calculated forces, because they applied to pressure and shear stress on walls.
I'm not familiar with the code conventions of OF and new to object oriented programming in C++! Any advice is much appreciated...


/Stefan

Hi!
I know that this is an old post but I'm very interested in it. Have you found a solution to that problem? I need to customize a restraint library inserting pressure and viscous forces calculated in the previous time step.
Do you have any suggestion?

Best regards

Federica

beluiz93 August 19, 2020 19:35

Any updates?
 
Hi all,

I'm also very interested in this problem. Has anyone managed to figure it out?

Thanks much!

Bernardo

quarkz March 4, 2022 01:42

Hi,

I also need to read the forces from the prev time step but I do not know how to do it.
Currently, what I did is:

1. I filter the forces output file to something simpler
2. read in that file to get the forces req

It works but it's slower.

mAlletto March 5, 2022 06:29

I don't know if it is useful but geometric fields have the member function oldTime() and prevIter() which gives back the value of the field at the previous time step and iterations, respectly.

Best

Michael

quarkz April 24, 2023 11:51

1 Attachment(s)
Hi all,

I have managed to get the forces and moments by directly calling from within OF.

I have attached the code, but some parts of my calculation are removed.

So anyone interested can just modify a bit to get it working for them. This is for OF v2206. Some ver may require removal of "s".


All times are GMT -4. The time now is 11:40.