Mercurial > repos > public > sbplib
changeset 118:5046ff7d13b8
Fixed bug and made more robust.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 15 Dec 2015 16:38:02 +0100 |
parents | 8514c3d67201 |
children | c56437d097de |
files | +noname/testCfl.m |
diffstat | 1 files changed, 23 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/+noname/testCfl.m Mon Dec 14 19:15:01 2015 +0100 +++ b/+noname/testCfl.m Tue Dec 15 16:38:02 2015 +0100 @@ -6,9 +6,10 @@ default_arg('threshold',1e2); default_arg('silentFlag', false); - if T < alpha0(2) - error('Upper bound on alpha must be smaller than T'); - end + % TODO: + % Set threshold from the initial conditions of the pde? + % Take a set number of steps instead of evolving to a certain time? + % Stop evolving when it has blown up? testAlpha = getAlphaTester(discr, T, threshold, silentFlag, timestepper_method); @@ -29,13 +30,26 @@ % Use bisection to find sharp estimate while( (alpha0(2)-alpha0(1))/alpha0(1) > tol) alpha = mean(alpha0); - fprintf('[%.3e,%.3e]: ', alpha0(1), alpha0(2)); - ok = testAlpha(alpha); + + if ~silentFlag + fprintf('[%.3e,%.3e]: ', alpha0(1), alpha0(2)); + end + + [ok, n_step, maxVal] = testAlpha(alpha); + if ok alpha0(1) = alpha; else alpha0(2) = alpha; end + + if ~silentFlag + fprintf('a = %.3e, n_step=%d max = %.2e\n', alpha, n_step, maxVal); + end + end + + if silentFlag + fprintf('Last calculated: a = %.3e, n_step=%d max = %.2e\n', alpha, n_step, maxVal); end fprintf('T = %-3d dof = %-4d order = %d: clf = %.4e\n',T, discr.size(), discr.order, alpha0(1)); @@ -45,7 +59,7 @@ function f = getAlphaTester(discr, T, threshold, silentFlag, timestepper_method) % Returns true if cfl was ok - function ok = testAlpha(alpha) + function [ok, n_step, maxVal] = testAlpha(alpha) ts = discr.getTimestepper(struct('method', timestepper_method, 'cfl', alpha)); warning('off','all') @@ -55,16 +69,14 @@ [v,t] = ts.getV(); maxVal = max(v); - if isnan(maxVal) || maxVal == Inf || maxVal > threshold + if isnan(maxVal) || maxVal == Inf || abs(maxVal) > threshold ok = false; else ok = true; end - if ~silentFlag - fprintf('a = %.3e, max= %.2e\n', alpha, maxVal); - end + n_step = ts.n; end f = @testAlpha; -end \ No newline at end of file +end