changeset 658:1201eb16557e feature/grids

Allow the possibility to have discr as an input the an error function
author Jonatan Werpers <jonatan@werpers.com>
date Sat, 11 Nov 2017 13:02:57 -0800
parents b59345f905f0
children 11a39b274260
files +noname/calculateErrors.m
diffstat 1 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/+noname/calculateErrors.m	Tue Oct 24 16:32:00 2017 +0200
+++ b/+noname/calculateErrors.m	Sat Nov 11 13:02:57 2017 -0800
@@ -4,6 +4,7 @@
 % m are grid size parameters.
 % N are number of timesteps to use for each gird size
 % timeOpt are options for the timeStepper
+% errorFun is a function_handle taking 2 or 3 arguments, errorFun(trueSolution, approxSolution), errorFun(trueSolution, approxSolution, discr)
 function e = calculateErrors(schemeFactory, T, m, N, errorFun, timeOpt)
     %TODO: Ability to choose paralell or not
     assertType(schemeFactory, 'function_handle');
@@ -11,11 +12,15 @@
     assertScalar(T);
     assert(length(m) == length(N), 'Vectors m and N must have the same length');
     assertType(errorFun, 'function_handle');
-    assertNumberOfArguments(errorFun, 2);
+
+    if ~ismember(nargin(errorFun), [2,3])
+        error('sbplib:noname:calculateErrors:wrongNumberOfArguments', '"%s" must have 2 or 3, found %d', toString(errorFun), nargin(errorFun));
+    end
+
     default_arg('timeOpt', struct());
 
 
-    e = [];
+    e = zeros(1,length(m));
     parfor i = 1:length(m)
         done = timeTask('m = %3d ', m(i));
 
@@ -27,7 +32,12 @@
         ts.stepTo(N(i), true);
         approxSolution = discr.getTimeSnapshot(ts);
 
-        e(i) = errorFun(trueSolution, approxSolution);
+        switch nargin(errorFun)
+            case 2
+                e(i) = errorFun(trueSolution, approxSolution);
+            case 3
+                e(i) = errorFun(trueSolution, approxSolution, discr);
+        end
 
         fprintf('e = %.4e', e(i))
         done()