# how to program two independent time loops

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

 January 24, 2013, 12:19 how to program two independent time loops #1 Senior Member   Mieszko Młody Join Date: Mar 2009 Location: POLAND, USA Posts: 142 Rep Power: 10 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

 January 24, 2013, 15:53 #2 Senior Member   Cyprien Join Date: Feb 2010 Location: Stanford University Posts: 262 Rep Power: 11 hi! you can look at interFoam and its subCycle.H used to perform sub timestep for the interface equation. Regards, Cyp ngj likes this.

 January 25, 2013, 05:36 #3 Senior Member   Niels Gjoel Jacobsen Join Date: Mar 2009 Location: Deltares, Delft, The Netherlands Posts: 1,759 Rep Power: 29 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

 January 25, 2013, 05:56 #4 Member   Jim Knopf Join Date: Dec 2010 Posts: 60 Rep Power: 9 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

 January 25, 2013, 07:59 #5 Senior Member     Anton Kidess Join Date: May 2009 Location: Germany Posts: 1,274 Rep Power: 23 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.

 January 25, 2013, 18:47 #6 Senior Member   Mieszko Młody Join Date: Mar 2009 Location: POLAND, USA Posts: 142 Rep Power: 10 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 in rectangular domain: 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 and 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

January 26, 2013, 08:05
#7
Senior Member

Hisham Elsafti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 253
Blog Entries: 10
Rep Power: 10
Quote:
 Originally Posted by ziemowitzima 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 in rectangular domain: 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 and 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

 January 26, 2013, 10:39 #8 Senior Member   Mieszko Młody Join Date: Mar 2009 Location: POLAND, USA Posts: 142 Rep Power: 10 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

 Thread Tools Display Modes Linear Mode

 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 OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post irishdave OpenFOAM Running, Solving & CFD 30 September 19, 2017 12:38 CKH OpenFOAM Running, Solving & CFD 12 March 21, 2016 14:05 Heroic OpenFOAM Running, Solving & CFD 26 December 17, 2012 04:34 lr103476 OpenFOAM Running, Solving & CFD 30 November 19, 2007 15:09 Sanjay Padhiar Main CFD Forum 1 March 31, 1999 12:32

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