Mercurial > repos > public > sbplib
diff +noname/calculateSolution.m @ 136:8298734b1938
Updated noname.calculateSolution to use the opt struct.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 09 Feb 2016 13:27:38 +0100 |
parents | 54d3ab296ba0 |
children | 2b133d833668 |
line wrap: on
line diff
--- a/+noname/calculateSolution.m Mon Feb 08 17:52:23 2016 +0100 +++ b/+noname/calculateSolution.m Tue Feb 09 13:27:38 2016 +0100 @@ -1,12 +1,13 @@ % Calculates the solution of discretization for a given set of ms ts and orders. % discrHand -- function handle to a Discretization constructor -% method -- time stepping method % m -- grid parameter % order -- order of accuracy of the approximtion % T -- time to calculate solution for +% tsOpt -- options for the time stepper creation. % input paramters m, t, order may all be vectors. -function [] = calculateSolution(filename, discrHand, method, m, T_in, order, force_flag) +function [] = calculateSolution(filename, name, discrHand, m, T_in, order, tsOpt, force_flag) default_arg('force_flag',false); + default_arg('tsOpt', []); if exist(filename,'file') && ~force_flag fprintf('File ''%s'' already exist.',filename); @@ -19,8 +20,6 @@ sf = SolutionFile(filename); - - orderWidth = findFieldWidth('%d',order); mWidth = findFieldWidth('%d',m); TWidth = findFieldWidth('%d',T_in); @@ -30,12 +29,12 @@ T = sort(T_in); % Make sure times are sorted discr = discrHand(m(j),order(i)); - k_max = discr.getTimestep(method); + k_max = discr.getTimestep(tsOpt); % Do we want to to save the initial conditions? if T(1) == 0 snapshot = discr.getTimeSnapshot(0); - saveToFile(sf, method, order(i), m(j),T(1), snapshot, NaN, NaN, discr); + saveToFile(sf, name, order(i), m(j),T(1), snapshot, NaN, NaN, discr); T(1) = []; end @@ -47,7 +46,8 @@ if is_int_multiples fprintf('Calculating time series in increments\n'); else - fprintf('Restarting for each time in timeseries\n'); + fprintf('RESTARTING for each time in timeseries\n'); + fprintf('If this is not what you want try giving T in integer multiples.\n'); end % T now contains all the times we need to step to, @@ -56,7 +56,7 @@ if is_int_multiples % Times are integer multiples, we can save time [k,N] = alignedTimestep(k_max,T(1)); - ts = discr.getTimestepper(method,k); + ts = discr.getTimestepper(tsOpt); runtime = 0; for l = 1:length(T) end_step = N * time_multiples(l); @@ -65,20 +65,20 @@ ts.stepN(end_step-ts.n,true); runtime = runtime + toc(clock_start); snapshot = discr.getTimeSnapshot(ts); - saveToFile(sf, method, order(i), m(j),T(l), snapshot, runtime, k, discr); + saveToFile(sf, name, order(i), m(j),T(l), snapshot, runtime, k, discr); fprintf('Done! (%.3fs)\n',runtime); end else % Times are not interger multiples, we have to start from 0 every time. for l = 1:length(T) [k,N] = alignedTimestep(k_max,T(l)); - ts = discr.getTimestepper(method,k); + ts = discr.getTimestepper(tsOpt); fprintf('[order = %-*d, m = %-*d, T = %-*d]: ',orderWidth,order(i),mWidth,m(j),TWidth,T(l)); clock_start = tic(); [v,t] = ts.stepN(N-ts.n,true); runtime = toc(clock_start); snapshot = discr.getTimeSnapshot(ts); - saveToFile(sf, method, order(i), m(j),T(l), snapshot, runtime, k, discr); + saveToFile(sf, name, order(i), m(j),T(l), snapshot, runtime, k, discr); fprintf('Done! (%.3fs)\n',runtime); end @@ -89,11 +89,11 @@ end -function saveToFile(sf, method, order, m, T, snapshot, runtime, k, discr) - key.method = method; - key.order = order; - key.m = m; - key.T = T; +function saveToFile(sf, name, order, m, T, snapshot, runtime, k, discr) + key.name = name; + key.order = order; + key.m = m; + key.T = T; entry.repr = snapshot; entry.runtime = runtime;