
February 14th, 2013, 04:36 PM
#1
Need Variable Time Step to Avert Unstable Numerical Integ. Exceeding Limits of Double
I need to avert permitting a type double variable from exceeding the range limits for that data type during a Gaussian, numerical integration.
I need some means of predicting that the variable is going to infinity due to a time step that is too large, and reducing the time step after some test to determine if the time step needs to be smaller, while expanding it again so the integration doesn't take forever in more stable regions. (Right now the variable simply goes to infinity. Simply reducing the time step would probably leave me in need of a supercomputer to run the entire numerical integration.)
I will ask here, and consult my numerical methods text as well, hoping for some useful insights relative to C++.
Thank you.

February 15th, 2013, 11:59 AM
#2
Re: Need Variable Time Step to Avert Unstable Numerical Integ. Exceeding Limits of Do
Originally Posted by Protocol
I need some means of predicting that the variable is going to infinity due to a time step that is too large, and reducing the time step after some test to determine if the time step needs to be smaller, while expanding it again so the integration doesn't take forever in more stable regions. (Right now the variable simply goes to infinity. Simply reducing the time step would probably leave me in need of a supercomputer to run the entire numerical integration.)
Can't you reduce the time step after the result goes to infinity and roll back the last computation, or redo the whole computation?
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it.  P. D. Ouspensky

February 15th, 2013, 01:29 PM
#3
Re: Need Variable Time Step to Avert Unstable Numerical Integ. Exceeding Limits of Do
The "explosion" somehow forces the logic of the software to drop out of the function performing the computation. The variable "blows up" in a function loop, and I need to identify how to detect a variable that has just gone to infinity based upon some characteristic of the variable.
Yes, I can test for an empty position in the output vector (a zero value), and if I find one, restart the loop with a smaller time step. My question here is a little more subtle than that. I'm seeking some deeper mathematical insight into how to avoid merely adjusting the time step down to something on the order of 10^ 10 seconds in a simulation over billions of years and waiting for the world to end before the computation is done.
I could detect the "blowup" via the output vector test, then adjust the timestep down by a factor of ten until the "blowup" doesn't occur, after resetting variables appropriately, then reset the timestep to the "normal" value if the loop completes without a problem.
Testing the products, numerators, and denominators might be a useful alternative in terms of the exponential terms, to see if they can add up to a problematic value. I could reduce the timestep if the exponents seem to present a problem.
I'm going to attempt a 4th order RungeKutta method first, since my initial Euler technique is known to produce errors, which could generate instability if the errors are large enough. (I was hoping for a quick and dirty solution that would work.)
Thanks.

February 15th, 2013, 02:33 PM
#4
Re: Need Variable Time Step to Avert Unstable Numerical Integ. Exceeding Limits of Do
I'm attempting to use a "trycatch" construct to try to compute a value and assign it to a variable, intending to "catch" any result that exceeds the defined magnitude limits of the variable. If I'm using a type "double" for the variable, could someone please provide some insight relative to how to detect a computation that exceeds the limits of a "double"? Thank you.

February 16th, 2013, 08:15 AM
#5
Re: Need Variable Time Step to Avert Unstable Numerical Integ. Exceeding Limits of Do
Originally Posted by Protocol
I'm attempting to use a "trycatch" construct to try to compute a value and assign it to a variable, intending to "catch" any result that exceeds the defined magnitude limits of the variable. If I'm using a type "double" for the variable, could someone please provide some insight relative to how to detect a computation that exceeds the limits of a "double"? Thank you.
Not with an exception, this is C++. Compare the value with std::numeric_limits<double>::infinity().
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it.  P. D. Ouspensky

February 16th, 2013, 10:51 AM
#6
Re: Need Variable Time Step to Avert Unstable Numerical Integ. Exceeding Limits of Do
Thanks!
I'm now thinking of attempting to use a Boolean test of all three equations that may blow up. If any one fails using the comparison you suggest, I'll call a function that halves the time step. On the next line of the "if" construct (within the brackets) I insert a "goto" statement that drops to the bottom of the "while" loop to initiate another test of the time step on the next loop through. Only when the "if" statement is false do I proceed through the loop normally. (I hate to use a "goto" statement in C++, but it seems the most straightforward solution.)

February 16th, 2013, 04:08 PM
#7
Re: Need Variable Time Step to Avert Unstable Numerical Integ. Exceeding Limits of Do
Originally Posted by Protocol
On the next line of the "if" construct (within the brackets) I insert a "goto" statement that drops to the bottom of the "while" loop to initiate another test of the time step on the next loop through. Only when the "if" statement is false do I proceed through the loop normally.
In C++, there is no situation in which using 'goto' makes code more readable. There's always a better alternative.
What you describe is exactly what the 'continue' keyword does. However, I find that makes code almost as unreadable as goto does and would avoid it. Why not just write an else clause?
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it.  P. D. Ouspensky
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.
Featured
