CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   how to program two independent time loops (http://www.cfd-online.com/Forums/openfoam-programming-development/112249-how-program-two-independent-time-loops.html)

ziemowitzima January 24, 2013 12:19

how to program two independent time loops
 
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

Cyp January 24, 2013 15:53

hi!

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

Regards,
Cyp

ngj January 25, 2013 05:36

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

JimKnopf January 25, 2013 05:56

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

akidess January 25, 2013 07:59

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 January 25, 2013 18:47

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

Hisham January 26, 2013 08:05

Quote:

Originally Posted by ziemowitzima (Post 404108)
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

ziemowitzima January 26, 2013 10:39

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


All times are GMT -4. The time now is 20:24.