Why Does Increasing Final Run Time Cause Divergence in Finite Differencing?
Click For Summary
The discussion centers on the divergence observed in a forward time-centered space finite difference scheme when increasing the final run time (##tf##). The participants identify that the stability of the numerical method is influenced by the Courant-Friedrichs-Lewy (CFL) condition, which states that ##\frac{\Delta t}{\Delta z} < C## for stability. A von Neumann stability analysis is recommended to derive necessary conditions for stability, particularly for nonlinear equations. The conversation also touches on the importance of initial conditions and the potential for linearizing the problem to facilitate analysis.
PREREQUISITES- Understanding of finite difference methods for solving partial differential equations (PDEs)
- Familiarity with the Courant-Friedrichs-Lewy (CFL) stability condition
- Knowledge of von Neumann stability analysis
- Basic concepts of nonlinear PDEs and their linearization
- Study the application of von Neumann stability analysis to nonlinear PDEs
- Learn about the Courant-Friedrichs-Lewy (CFL) condition in detail
- Explore techniques for linearizing nonlinear PDEs for stability analysis
- Investigate finite difference methods for boundary conditions, including ghost nodes and backward space formulas
Researchers and practitioners in computational fluid dynamics, numerical analysis, and applied mathematics, particularly those working with finite difference methods and stability analysis of PDEs.
- 23,711
- 5,928
Not really. Just lots of experience.joshmccraney said:You're awesome!
- 23,711
- 5,928
Yes. I would lose 12 - 16.joshmccraney said:Ok, I think I corrected all the errors you pointed out. How does this attached version look?
As an aside, do we really need (12) through (16)? They seem to not really be used.
There's a typo in Eqn. 29: the y should be under the radical in the numerator.
Please show the derivation of Eqns. 30 and 34-36. I'm not able to follow in detail. I just want to make sure that it was done correctly. For example, I think there should be a 1/2 in Eqn. 30 instead of the factor of 2; and, in Eqn. 34, I feel like there should be a 4 in the denominator. Also, in Eqn. 36, there should be a ζ in the denominator rather than a ξ.
Chet
- 23,711
- 5,928
I found a couple of errors in the new version:joshmccraney said:How does this look?
I also got rid of zeta and xi.
Eqns. 17,19, 22,23,33,34,and 35 should have a 4 instead of a 2.
In Eqn. 32, you are missing an additional factor of 2 in the denominator of the first term in brackets. This is because ∂y/∂Z is evaluated numerically using a central difference over 2 grid intervals.
In Eqns. 33-34, you need to replace the j's with (j+1) and you need to replace the (j-1)'s with j. And in Eqn. 35, you need to replace the (j-1) with j (so you have j on both sides). As far as the Lj2 in the denominator of Eqn. 32 is concerned, you have already calculated that from the previous time step (Or, to the same degree of accuracy, you could also use Lj+12 or the average of the two).(23) is evaluated at ##t## and yet requires ##y## to be evaluated at ##t## as well. How would you deal with this?
How would I go about an error analysis though? It's non-linear so I don't think a von Neumann approach is valid since separation of variables doesn't work.
I'll start coding this too (in MatLab) and post a few pictures of what I'm getting in the .pdf for you're consideration.
- 23,711
- 5,928
Are you talking about error analysis, or are you talking about stability?joshmccraney said:Thanks for pointing these errors out. I agree with all of your corrections, and believe this is now error free. Thanks for all the help!
How would I go about an error analysis though? It's non-linear so I don't think a von Neumann approach is valid since separation of variables doesn't work.
I'll start coding this too (in MatLab) and post a few pictures of what I'm getting in the .pdf for you're consideration.
Chet
Chestermiller said:Are you talking about error analysis, or are you talking about stability?
Chet
Sorry, I'm talking about stability.
- 23,711
- 5,928
I don't know of any methods of analyzing the stability of time-dependent schemes in non-linear problems, but, experience has shown that stability is guaranteed if you go to fully implicit (e.g., Backward Euler). It is also possible to increase stability by going partially implicit (i.e., more implicit) by handling certain quantities implicitly, while treating others explicitly.joshmccraney said:Sorry, I'm talking about stability.
Solving the problem implicitly means that you have to solve a set of non-linear equations at each time step. The easiest method of solving a problem like this implicitly is to use the so-called "method of lines" in conjunction with a stiff ODE software package based on the C. W. Gear method. Such a package transparently solves the set on non-linear equations at each time step. The method of lines changes the non-linear PDE into a non-linear set of coupled ODEs, by finite differencing the spatial derivatives, but not the time derivative. So there is an ODE for each grid point. The stiff package automatically integrates these stiff ODEs.
A partially implicit method can be developed for your problem that requires a tri-diagonal set of linear equations to be solved at each time step. This can be done using a tri-diagonal matrix inversion routine. However, there will be some quantities in the difference equations that will have to be handled explicitly in this approach. Still, in my judgement, it would improve stability very substantially (and allow much larger time steps).
The first thing to do is to see whether the existing scheme gives you stability when small (but acceptable) time steps are used.
Chet
N = (tf/10)*M^2;## I can run for ##tf## values of 100 and more.
What is your take on this technique? Is this acceptable or should I go for an implicit scheme?
Also, for your curiosity, the percent change in volume was less than 1.5% for the code and pictures I posted. Changing line 9 as suggested and running for ##tf=100## produces a volume change of about 0.003%.
Attachments
- 23,711
- 5,928
I would say it looks pretty OK. I haven't checked the coding, but the solution looks like you expected, correct?joshmccraney said:Thanks a ton! So I just finished writing the code. It's at the end of the attached pdf. I put plots in the pdf for a time value of 14 (line 8 in the code) and it ran well. However, if I set ##tf = 15## I get some errors, specifically imaginary parts. My guess is from line 37/38, when the square root is introduced. I should say that if I change line 9 to ##
N = (tf/10)*M^2;## I can run for ##tf## values of 100 and more.
What is your take on this technique? Is this acceptable or should I go for an implicit scheme?
Also, for your curiosity, the percent change in volume was less than 1.5% for the code and pictures I posted. Changing line 9 as suggested and running for ##tf=100## produces a volume change of about 0.003%.
Regarding the need to go implicit, my question is "is computation time a problem?" If not, then I see no need to.
How come you are using such a large M. I would use a value of 20, and then check the accuracy of the solution by redoing the calculation at M = 40. But, I think 20 will be adequate. That should help tremendously with your stability.
What does L(t) look like?
Chet
Yes, the solution looks good.Chestermiller said:I haven't checked the coding, but the solution looks like you expected, correct?
Computation time is not an issue.Chestermiller said:Regarding the need to go implicit, my question is "is computation time a problem?" If not, then I see no need to.
I wanted a large M to reduce error. Having M=20 yields a final ##L## of about 8.4. Changing M=40 yields a final ##L## of about 8.75.Chestermiller said:How come you are using such a large M. I would use a value of 20, and then check the accuracy of the solution by redoing the calculation at M = 40. But, I think 20 will be adequate. That should help tremendously with your stability.
I'll attach a pdf.Chestermiller said:What does L(t) look like?
Chet
When changing M=20 and N=M^2 the maximum final run time before crashing is only 20. If I go to M=21 I get complex y values. However, if I let ##N=(tf/10)*M## I can go further in time. What are your thoughts here?
Attachments
- 23,711
- 5,928
Chet
Chestermiller said:To make this all easier to follow, you should calculate the value of ##\frac{t_fM^2}{(N-1)L^2}## for each case, and use this to try to map out the region where the solution is stable.
Chet
Why do you choose to use this value?
- 23,711
- 5,928
This is Δt/(Δz)2 which, aside from the diffusivity factor, is the standard stability parameter for a parabolic equation.joshmccraney said:Why do you choose to use this value?
Chet
As an aside, could you show me where are we actually conserving volume in the pdf? I ask because I was also going to try the same differential equation and the same tip boundary condition but instead of conserving volume apply the following integral constraint $$
-2 \int_0^{tf} \left.h^2 h_z\right|_{z=0} \,d t =\int_0^{L(tf)} \left. h^2 \right|_{t=tf} \, d z$$ I can discretize this for the new ##L##. What do you think? Won't this boundary condition affect the previous ##L## derived?
- 23,711
- 5,928
$$\frac{\partial h^2}{\partial t}=Z\left(\frac{\partial h^2}{\partial Z}\right)\frac{1}{L}\frac{dL}{dt}+\frac{2}{3L^2}\frac{\partial ^2h^3}{\partial Z^2}$$
If we multiply both sides by L, and re-express the first term on the right hand side using integration by parts, we obtain:
$$L\frac{\partial h^2}{\partial t}=\left[\frac{\partial (Zh^2)}{\partial Z}-h^2\right]\frac{dL}{dt}+\frac{2}{3L}\frac{\partial ^2h^3}{\partial Z^2}$$
If we next mover the second term in brackets to the left hand side of the equation, we obtain:
$$\frac{\partial (Lh^2)}{\partial t}=\frac{\partial (Zh^2)}{\partial Z}\frac{dL}{dt}+\frac{2}{3L}\frac{\partial ^2h^3}{\partial Z^2}$$
The finite difference form of this (that will automatically conserve volume) is:
##\frac{L(t+Δt)h^2(t+Δt,Z)-L(t)h^2(t,Z)}{Δt}=\frac{(Z+ΔZ)h^2(t,Z+ΔZ)-(Z-ΔZ)h^2(t,Z-ΔZ)}{2ΔZ}\frac{dL}{dt}+\frac{2}{3L}\frac{h^3(t,Z-ΔZ)-2h^3(t,Z)+h^3(t,Z+ΔZ)}{(ΔZ)^2}##
This yields:
##h^2(t+Δt,Z)=\frac{L(t)}{L(t+Δt)}h^2(t,Z)+[\frac{(Z+ΔZ)h^2(t,Z+ΔZ)-(Z-ΔZ)h^2(t,Z-ΔZ)}{4ΔZ}\frac{1}{L^2}\frac{dL^2}{dt}+\frac{2}{3L^2}\frac{h^3(t,Z-ΔZ)-2h^3(t,Z)+h^3(t,Z+ΔZ)}{(ΔZ)^2}]Δt##
If I did this right, it should give automatic conservation of volume.
Chet
Chestermiller said:If I did this right, it should give automatic conservation of volume.
I follow your math, but how does it now conserve volume? It seems like you have only written it differently, but have not introduced anything new. Am I missing something?
- 23,711
- 5,928
In my next-to-last equation, if you add the equations for all the grid points together, the right hand sides will cancel out. This will give you that the trapazoidal rule integration of h^2LdZ for the volume will have a time derivative of zero.joshmccraney said:I follow your math, but how does it now conserve volume? It seems like you have only written it differently, but have not introduced anything new. Am I missing something?
Chet
This is not immediately obvious to me. I'm happy to crunch the numbers, but I can't see the cancelation.Chestermiller said:In my next-to-last equation, if you add the equations for all the grid points together, the right hand sides will cancel out.
Chet
But h^2LdZ is not volume. Volume was h^2dZ.Chestermiller said:This will give you that the trapazoidal rule integration of h^2LdZ for the volume will have a time derivative of zero.
Chet
- 23,711
- 5,928
No way. h^2dz=h^2LdZ is volume.joshmccraney said:But h^2LdZ is not volume. Volume was h^2dZ.
Chet
- 23,711
- 5,928
It works kinda like this: (A-0) + (B-A) + (C-B) + (D-C) + (0 - D) = 0joshmccraney said:This is not immediately obvious to me. I'm happy to crunch the numbers, but I can't see the cancelation.
Aaaaaaand now I feel stupid. Thanks for clarifying; this makes perfect sense now!Chestermiller said:No way. h^2dz=h^2LdZ is volume.
Chet
I think there is a mistake. I'll begin where you didChestermiller said:##\frac{L(t+Δt)h^2(t+Δt,Z)-L(t)h^2(t,Z)}{Δt}=\frac{(Z+ΔZ)h^2(t,Z+ΔZ)-(Z-ΔZ)h^2(t,Z-ΔZ)}{2ΔZ}\frac{dL}{dt}+\frac{2}{3L}\frac{h^3(t,Z-ΔZ)-2h^3(t,Z)+h^3(t,Z+ΔZ)}{(ΔZ)^2}##
This yields:
##h^2(t+Δt,Z)=\frac{L(t)}{L(t+Δt)}h^2(t,Z)+[\frac{(Z+ΔZ)h^2(t,Z+ΔZ)-(Z-ΔZ)h^2(t,Z-ΔZ)}{4ΔZ}\frac{1}{L^2}\frac{dL^2}{dt}+\frac{2}{3L^2}\frac{h^3(t,Z-ΔZ)-2h^3(t,Z)+h^3(t,Z+ΔZ)}{(ΔZ)^2}]Δt##
If I did this right, it should give automatic conservation of volume.
##\frac{L(t+Δt)h^2(t+Δt,Z)-L(t)h^2(t,Z)}{Δt}=\frac{(Z+ΔZ)h^2(t,Z+ΔZ)-(Z-ΔZ)h^2(t,Z-ΔZ)}{2ΔZ}\frac{dL}{dt}+\frac{2}{3L}\frac{h^3(t,Z-ΔZ)-2h^3(t,Z)+h^3(t,Z+ΔZ)}{(ΔZ)^2} \implies##
##\frac{L(t+Δt)h^2(t+Δt,Z)-L(t)h^2(t,Z)}{L Δt}=\frac{(Z+ΔZ)h^2(t,Z+ΔZ)-(Z-ΔZ)h^2(t,Z-ΔZ)}{2ΔZ}\frac{1}{L}\frac{dL}{dt}+\frac{2}{3L^2}\frac{h^3(t,Z-ΔZ)-2h^3(t,Z)+h^3(t,Z+ΔZ)}{(ΔZ)^2} \implies##
##h^2(t+Δt,Z)=\frac{L(t)}{L(t+Δt)}h^2(t,Z)+[\frac{(Z+ΔZ)h^2(t,Z+ΔZ)-(Z-ΔZ)h^2(t,Z-ΔZ)}{4ΔZ}\frac{1}{L^2}\frac{dL^2}{dt}+\frac{2}{3L^2}\frac{h^3(t,Z-ΔZ)-2h^3(t,Z)+h^3(t,Z+ΔZ)}{(ΔZ)^2}]\frac{ΔtL}{L(t+Δt)}##
I checked back through the works but can't figure out if the ##L##'s are evaluated at ##t## or ##t+\Delta t##. I left it as simply ##L## since I am not sure. What do you think?
I now have the reflective boundary condition as $$y_{new}(1) = \frac{L_{old}}{L_{new}}y(1)+\left[ \frac{y(2)}{2 L^2}\frac{dL^2}{dt}-\frac{4 y^{3/2}(1)}{3 L^2 \Delta z^2}\right] \frac{L \Delta t}{L_{new}}$$ where 1 implies the first element of y. Do you agree with this? I should add that everywhere listed as simply ##L## I ran in the code as ##L(t+\Delta t)## yet volume isn't conserved. Any ideas?
- 23,711
- 5,928
Yes.joshmccraney said:I think there is a mistake. I'll begin where you did
##\frac{L(t+Δt)h^2(t+Δt,Z)-L(t)h^2(t,Z)}{Δt}=\frac{(Z+ΔZ)h^2(t,Z+ΔZ)-(Z-ΔZ)h^2(t,Z-ΔZ)}{2ΔZ}\frac{dL}{dt}+\frac{2}{3L}\frac{h^3(t,Z-ΔZ)-2h^3(t,Z)+h^3(t,Z+ΔZ)}{(ΔZ)^2} \implies##
##\frac{L(t+Δt)h^2(t+Δt,Z)-L(t)h^2(t,Z)}{L Δt}=\frac{(Z+ΔZ)h^2(t,Z+ΔZ)-(Z-ΔZ)h^2(t,Z-ΔZ)}{2ΔZ}\frac{1}{L}\frac{dL}{dt}+\frac{2}{3L^2}\frac{h^3(t,Z-ΔZ)-2h^3(t,Z)+h^3(t,Z+ΔZ)}{(ΔZ)^2} \implies##
##h^2(t+Δt,Z)=\frac{L(t)}{L(t+Δt)}h^2(t,Z)+[\frac{(Z+ΔZ)h^2(t,Z+ΔZ)-(Z-ΔZ)h^2(t,Z-ΔZ)}{4ΔZ}\frac{1}{L^2}\frac{dL^2}{dt}+\frac{2}{3L^2}\frac{h^3(t,Z-ΔZ)-2h^3(t,Z)+h^3(t,Z+ΔZ)}{(ΔZ)^2}]\frac{ΔtL}{L(t+Δt)}##
I checked back through the works but can't figure out if the ##L##'s are evaluated at ##t## or ##t+\Delta t##. I left it as simply ##L## since I am not sure. What do you think?
I now have the reflective boundary condition as $$y_{new}(1) = \frac{L_{old}}{L_{new}}y(1)+\left[ \frac{y(2)}{2 L^2}\frac{dL^2}{dt}-\frac{4 y^{3/2}(1)}{3 L^2 \Delta z^2}\right] \frac{L \Delta t}{L_{new}}$$ where 1 implies the first element of y. Do you agree with this? I should add that everywhere listed as simply ##L## I ran in the code as ##L(t+\Delta t)## yet volume isn't conserved. Any ideas?
It doesn't matter what we do with the L's, since each of the spatial terms on the right hand side have to integrate to zero individually. The reason that they didn't in your calculation is that I used a finite difference approximation in the first term on the right hand side doesn't integrate to zero (my mistake). The approximation I should have used was:
$$\frac{\partial (Zh^2)}{\partial Z}=\frac{(Z+\frac{ΔZ}{2})\frac{(h^2(Z+ΔZ)+h^2(Z))}{2}-(Z-\frac{ΔZ}{2})\frac{(h^2(Z-ΔZ)+h^2(Z))}{2}}{ΔZ}=\frac{(Z+\frac{ΔZ}{2})(h^2(Z+ΔZ)+h^2(Z))-(Z-\frac{ΔZ}{2})(h^2(Z-ΔZ)+h^2(Z))}{2ΔZ}$$
If you try it with this, I guarantee that volume will be conserved.
Chet
Chestermiller said:The approximation I should have used was:
$$\frac{\partial (Zh^2)}{\partial Z}=\frac{(Z+\frac{ΔZ}{2})\frac{(h^2(Z+ΔZ)+h^2(Z))}{2}-(Z-\frac{ΔZ}{2})\frac{(h^2(Z-ΔZ)+h^2(Z))}{2}}{ΔZ}=\frac{(Z+\frac{ΔZ}{2})(h^2(Z+ΔZ)+h^2(Z))-(Z-\frac{ΔZ}{2})(h^2(Z-ΔZ)+h^2(Z))}{2ΔZ}$$
If you try it with this, I guarantee that volume will be conserved.
Chet
I've redone the code with this expression and no luck. In fact, now the slope is not zero at Z=0. I've attached the code so you can see for yourself. Am I doing something terribly wrong here?
Attachments
- 23,711
- 5,928
I'm going to look over the code and get back with you.joshmccraney said:I've redone the code with this expression and no luck. In fact, now the slope is not zero at Z=0. I've attached the code so you can see for yourself. Am I doing something terribly wrong here?
Chet
- 23,711
- 5,928
ynew( 1 ) = Lold/Lnew*y ( 1 )+((y ( 2 )+y ( 1 ) ) /(4Lnew^2) * DL2+4/3*(y3( 2 )-y3 ( 1 )) /(Lnew^2 dz ^2) ) dt
My recommended corrections are in bold and italic.
Regarding line 44 (and maybe other lines), I definitely would not overwrite any of the y's until all the ynew's are calculated.
Regarding line 23, this is an incorrect application of the trapazoidal rule. The equation should read:
iv = iv+((h^2( i )+h^2( i+1) ) /2) dz
That's about all I checked so far.
Chet
Chestermiller said:Line 43 looks incorrect to me. I get:
ynew( 1 ) = Lold/Lnew*y ( 1 )+((y ( 2 )+y ( 1 ) ) /(4Lnew^2) * DL2+4/3*(y3( 2 )-y3 ( 1 )) /(Lnew^2 dz ^2) ) dt
My recommended corrections are in bold and italic.
Regarding line 44 (and maybe other lines), I definitely would not overwrite any of the y's until all the ynew's are calculated.
Regarding line 23, this is an incorrect application of the trapazoidal rule. The equation should read:
iv = iv+((h^2( i )+h^2( i+1) ) /2) dz
That's about all I checked so far.
Chet
Awesome! Not sure how I missed this but it looks great now, and conserves volume! You've been a huge help, Chet! I'll post a final pdf when I finish it so you can see how it all looks!
Similar threads
- · Replies 3 ·
- Replies
- 3
- Views
- 3K
- · Replies 1 ·
- Replies
- 1
- Views
- 3K
- · Replies 13 ·
- Replies
- 13
- Views
- 2K
- · Replies 3 ·
- Replies
- 3
- Views
- 2K
- · Replies 1 ·
- Replies
- 1
- Views
- 3K
- · Replies 8 ·
- Replies
- 8
- Views
- 5K
- · Replies 13 ·
- Replies
- 13
- Views
- 3K
- · Replies 2 ·
- Replies
- 2
- Views
- 949
- Replies
- 0
- Views
- 2K
- · Replies 2 ·
- Replies
- 2
- Views
- 2K