changeset 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 8979d81515ac
children 2b133d833668
files +noname/calculateSolution.m Dictionary.m SolutionFile.m
diffstat 3 files changed, 21 insertions(+), 17 deletions(-) [+]
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;
--- a/Dictionary.m	Mon Feb 08 17:52:23 2016 +0100
+++ b/Dictionary.m	Tue Feb 09 13:27:38 2016 +0100
@@ -72,7 +72,8 @@
                         end
                     end
                 otherwise
-                    error('Unsupported indexing operator: %s',S.type);
+                    B = builtin('subsref', obj, S);
+                    % error('Unsupported indexing operator: %s',S.type);
             end
         end
 
--- a/SolutionFile.m	Mon Feb 08 17:52:23 2016 +0100
+++ b/SolutionFile.m	Tue Feb 09 13:27:38 2016 +0100
@@ -34,15 +34,18 @@
         end
 
         function stupidSave(obj)
+            % Read file contents
             matObj = matfile(obj.filename,'Writable',true);
 
             keys = obj.matfile.keys;
             entries = obj.matfile.entries;
 
+            % Delete the file
             if exist(obj.filename,'file')
                 delete(obj.filename);
             end
 
+            % Rewrite the file
             matObj = matfile(obj.filename,'Writable',true);
             matObj.keys = keys;
             matObj.entries = entries;