CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

how to program two independent time loops

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree2Likes
  • 1 Post By Cyp
  • 1 Post By akidess

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 24, 2013, 12:19
Question how to program two independent time loops
  #1
Senior Member
 
Mieszko Młody
Join Date: Mar 2009
Location: POLAND, USA
Posts: 145
Rep Power: 17
ziemowitzima is on a distinguished road
Dear OpenFOAM users,

I am trying to implement two independent time loops in one solver.
More precisely one "main time loop" and "one nested loop" where some other iteration dependent equation is solved.

Something like that:

while(runTime.loop())
{
FIRST EQUATION
while (some_stop_condition)
{
SECOND EQUATION
}
}

If it is programmed like above, the second equation in the innerloop is not solved/updated...

Is it any way to have eg. two independent integration times in one solver ?

Thanks
ZMM
ziemowitzima is offline   Reply With Quote

Old   January 24, 2013, 15:53
Default
  #2
Cyp
Senior Member
 
Cyprien
Join Date: Feb 2010
Location: Stanford University
Posts: 299
Rep Power: 18
Cyp is on a distinguished road
hi!

you can look at interFoam and its subCycle.H used to perform sub timestep for the interface equation.

Regards,
Cyp
ngj likes this.
Cyp is offline   Reply With Quote

Old   January 25, 2013, 05:36
Default
  #3
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
Yes, Cyp points to the right part of the code.

One subtlety, which you might need at some point: The timeIndex, i.e. the integer index telling, which time step you have reached, is always incremented, so if the inner loop has say 9 sub-time steps, then the outer loop will only happen on timeIndices 0, 10, 20, 30, etc.

Kind regards,

Niels
ngj is offline   Reply With Quote

Old   January 25, 2013, 05:56
Default
  #4
Member
 
Jim Knopf
Join Date: Dec 2010
Posts: 60
Rep Power: 15
JimKnopf is on a distinguished road
You can do somethings like:

Code:
while(runTime.loop())

FIRST_EQUATION
// runs eqn 1 every time step
if (runTime.timeName() % N == 0)
{
 SECOND_EQUATION
}
// 2nd eqn only solved every Nth time step
Greets
Jim
JimKnopf is offline   Reply With Quote

Old   January 25, 2013, 07:59
Default
  #5
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 29
akidess will become famous soon enough
I've implemented something of the likes for interFoamSSF. Maybe it helps you to have a look at my code:
http://code.google.com/p/interfoamss...se/interFoam.C

- Anton
ziemowitzima likes this.
__________________
*On twitter @akidTwit
*Spend as much time formulating your questions as you expect people to spend on their answer.
akidess is offline   Reply With Quote

Old   January 25, 2013, 18:47
Default
  #6
Senior Member
 
Mieszko Młody
Join Date: Mar 2009
Location: POLAND, USA
Posts: 145
Rep Power: 17
ziemowitzima is on a distinguished road
Thanks all of you for your answers, they are really helpful.
Maybe you will have some hints how to deal with problem I encountered recently. Which is part of this algorithm.

I am trying to solve equation for y in rectangular (u,z) domain:
\frac{\partial y}{\partial t} + \frac{\partial  \psi}{\partial z}  = \frac{\partial^2 y}{\partial z^2} +  \left[ \frac{1+(\frac{\partial y}{\partial z})^2}{(\frac{\partial y}{\partial  u})^2}\right] \frac{\partial^2 y}{\partial u^2}
 - 2 \left[ \frac{\frac{\partial y}{\partial z}}{\frac{\partial y}{\partial u}}\right] \frac{\partial^2 y}{\partial z \partial u}

I decided to solve it as follows:

fvScalarMatrix yEqn
(
fvm::ddt(y)
- U.component(1)
- fvm::laplacian(nu + (A/C)*nu2, y)
+ D/C
);

where:
nu and nu2 are defined to act in z and u directions respectively
and
A = 1+(\frac{\partial y}{\partial z})^2
C = (\frac{\partial y}{\partial  u})^2
and
D = 2 \left[ \frac{\partial y}{\partial z}\frac{\partial y}{\partial u}\right] \frac{\partial^2 y}{\partial z \partial u}

where A, C and D are solved explicitly.
But solver had a problem with it, because C were getting too large.

So I decided to multiply above equation by C and get:

fvScalarMatrix yEqn
(
C*fvm::ddt(y)
- C*U.component(1)
- fvm::laplacian(C*nu + A*nu2, y)
+ D
);

Here I got solution, somehow similar to the one it should converge, but not exactly.
Problem seems to be in "C*fvm::ddt(y)" term, because it gives me the same answer if I have just "fvm::ddt(y)" ...

Any idea, what can be here wrong, or how to make it better ?

Thanks
ZMM
ziemowitzima is offline   Reply With Quote

Old   January 26, 2013, 08:05
Default
  #7
Senior Member
 
Hisham's Avatar
 
Hisham Elsafti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 257
Blog Entries: 10
Rep Power: 16
Hisham is on a distinguished road
Quote:
Originally Posted by ziemowitzima View Post
Thanks all of you for your answers, they are really helpful.
Maybe you will have some hints how to deal with problem I encountered recently. Which is part of this algorithm.

I am trying to solve equation for y in rectangular (u,z) domain:
\frac{\partial y}{\partial t} + \frac{\partial  \psi}{\partial z}  = \frac{\partial^2 y}{\partial z^2} +  \left[ \frac{1+(\frac{\partial y}{\partial z})^2}{(\frac{\partial y}{\partial  u})^2}\right] \frac{\partial^2 y}{\partial u^2}
 - 2 \left[ \frac{\frac{\partial y}{\partial z}}{\frac{\partial y}{\partial u}}\right] \frac{\partial^2 y}{\partial z \partial u}

I decided to solve it as follows:

fvScalarMatrix yEqn
(
fvm::ddt(y)
- U.component(1)
- fvm::laplacian(nu + (A/C)*nu2, y)
+ D/C
);

where:
nu and nu2 are defined to act in z and u directions respectively
and
A = 1+(\frac{\partial y}{\partial z})^2
C = (\frac{\partial y}{\partial  u})^2
and
D = 2 \left[ \frac{\partial y}{\partial z}\frac{\partial y}{\partial u}\right] \frac{\partial^2 y}{\partial z \partial u}

where A, C and D are solved explicitly.
But solver had a problem with it, because C were getting too large.

So I decided to multiply above equation by C and get:

fvScalarMatrix yEqn
(
C*fvm::ddt(y)
- C*U.component(1)
- fvm::laplacian(C*nu + A*nu2, y)
+ D
);

Here I got solution, somehow similar to the one it should converge, but not exactly.
Problem seems to be in "C*fvm::ddt(y)" term, because it gives me the same answer if I have just "fvm::ddt(y)" ...

Any idea, what can be here wrong, or how to make it better ?

Thanks
ZMM
Hi ZMM,

I think you don't need two time loops. You should keep one time loop for the yEqn and update the other relations inside the time loop without any local convergence iterations (they are still time dependent). This should, hopefully, enhance the results of your solver. Also, if you have very large numbers try to work with different units for your constants ... e.g. for mass instead of gm use kgm

Hope this helps!

Hisham
Hisham is offline   Reply With Quote

Old   January 26, 2013, 10:39
Default
  #8
Senior Member
 
Mieszko Młody
Join Date: Mar 2009
Location: POLAND, USA
Posts: 145
Rep Power: 17
ziemowitzima is on a distinguished road
Thanks Hisham for your thoughts.
But this is just one of three equations I need to solve.
In fact this one will run inside inner loop, and after convergence, it will be used for two others equations which run in outer loop.
In short, this equation need to be solved in every time step of outer/main loop.

Changing units here is not a solution, because I work with nondimensional equations.

Best
ZMM
ziemowitzima is offline   Reply With Quote

Reply

Tags
nested equations, nested integration, nested time loops, time levels, two time loops

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
TimeVaryingMappedFixedValue irishdave OpenFOAM Running, Solving & CFD 32 June 16, 2021 07:55
Multiple floating objects CKH OpenFOAM Running, Solving & CFD 14 February 20, 2019 10:08
pisoFoam with k-epsilon turb blows up - Some questions Heroic OpenFOAM Running, Solving & CFD 26 December 17, 2012 04:34
Convergence moving mesh lr103476 OpenFOAM Running, Solving & CFD 30 November 19, 2007 15:09
unsteady calcs in FLUENT Sanjay Padhiar Main CFD Forum 1 March 31, 1999 13:32


All times are GMT -4. The time now is 22:59.