I’m pissed off. The f*ing Crank-Nicolson scheme for numerically solving diffusion equations isn’t stable. All of the textbooks state that it’s unconditionally stable. Liars. The fine print on this stability claim is that this unconditionality is for a constant diffusion coefficient. Large gradients in the diffusion coefficient can cause oscillations in the solution. Another issue is that there is a time and space step criterion on its stability. If the time step is too large relative to the spatial step, then oscillations appear. Another problem is that if the diffusion coefficient is too big, then the scheme tries to rearrange the result too much and again introduces oscillations. The net result is that the solution gives negative and/or very large values and the code crashes. I am now in search of another numerical scheme that can handle my large, spatially varying diffusion coefficients and nonuniform spatial grid. I have wasted nearly a week only to discover that my code was working perfectly and doing exactly what I was telling it to do: oscillate until it blows up.
Argh!
Ode to Bureaucracy
9 years ago
Dude. You gotta divide the thingy by the doohicky. Duh!
ReplyDelete-queso
(or, alternately, you could just set fire to your desk)
What a difference a day makes!
ReplyDeleteAll I had to do was switch to the fully implicit but less accurate numerical method instead of the fancier, more accurate but less stable method. I now have a check in the code to decide between the two methods based on the stability criterion. The code works. Life is good. Time to get drunk and set the desk on fire!
Crank-Nicolson sucks the butt. Really.
ReplyDelete