Mercurial > repos > public > sbplib
comparison +noname/calculateErrors.m @ 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 |
comparison
equal
deleted
inserted
replaced
657:b59345f905f0 | 658:1201eb16557e |
---|---|
2 % where trueSolution should be a timeSnapshot of the true solution a time T | 2 % where trueSolution should be a timeSnapshot of the true solution a time T |
3 % T is the end time | 3 % T is the end time |
4 % m are grid size parameters. | 4 % m are grid size parameters. |
5 % N are number of timesteps to use for each gird size | 5 % N are number of timesteps to use for each gird size |
6 % timeOpt are options for the timeStepper | 6 % timeOpt are options for the timeStepper |
7 % errorFun is a function_handle taking 2 or 3 arguments, errorFun(trueSolution, approxSolution), errorFun(trueSolution, approxSolution, discr) | |
7 function e = calculateErrors(schemeFactory, T, m, N, errorFun, timeOpt) | 8 function e = calculateErrors(schemeFactory, T, m, N, errorFun, timeOpt) |
8 %TODO: Ability to choose paralell or not | 9 %TODO: Ability to choose paralell or not |
9 assertType(schemeFactory, 'function_handle'); | 10 assertType(schemeFactory, 'function_handle'); |
10 assertNumberOfArguments(schemeFactory, 1); | 11 assertNumberOfArguments(schemeFactory, 1); |
11 assertScalar(T); | 12 assertScalar(T); |
12 assert(length(m) == length(N), 'Vectors m and N must have the same length'); | 13 assert(length(m) == length(N), 'Vectors m and N must have the same length'); |
13 assertType(errorFun, 'function_handle'); | 14 assertType(errorFun, 'function_handle'); |
14 assertNumberOfArguments(errorFun, 2); | 15 |
16 if ~ismember(nargin(errorFun), [2,3]) | |
17 error('sbplib:noname:calculateErrors:wrongNumberOfArguments', '"%s" must have 2 or 3, found %d', toString(errorFun), nargin(errorFun)); | |
18 end | |
19 | |
15 default_arg('timeOpt', struct()); | 20 default_arg('timeOpt', struct()); |
16 | 21 |
17 | 22 |
18 e = []; | 23 e = zeros(1,length(m)); |
19 parfor i = 1:length(m) | 24 parfor i = 1:length(m) |
20 done = timeTask('m = %3d ', m(i)); | 25 done = timeTask('m = %3d ', m(i)); |
21 | 26 |
22 [discr, trueSolution] = schemeFactory(m(i)); | 27 [discr, trueSolution] = schemeFactory(m(i)); |
23 | 28 |
25 timeOptTemp.k = T/N(i); | 30 timeOptTemp.k = T/N(i); |
26 ts = discr.getTimestepper(timeOptTemp); | 31 ts = discr.getTimestepper(timeOptTemp); |
27 ts.stepTo(N(i), true); | 32 ts.stepTo(N(i), true); |
28 approxSolution = discr.getTimeSnapshot(ts); | 33 approxSolution = discr.getTimeSnapshot(ts); |
29 | 34 |
30 e(i) = errorFun(trueSolution, approxSolution); | 35 switch nargin(errorFun) |
36 case 2 | |
37 e(i) = errorFun(trueSolution, approxSolution); | |
38 case 3 | |
39 e(i) = errorFun(trueSolution, approxSolution, discr); | |
40 end | |
31 | 41 |
32 fprintf('e = %.4e', e(i)) | 42 fprintf('e = %.4e', e(i)) |
33 done() | 43 done() |
34 end | 44 end |
35 fprintf('\n') | 45 fprintf('\n') |