comparison +noname/calculateErrors.m @ 886:8894e9c49e40 feature/timesteppers

Merge with default for latest changes
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Thu, 15 Nov 2018 16:36:21 -0800
parents 1201eb16557e
children
comparison
equal deleted inserted replaced
816:b5e5b195da1e 886:8894e9c49e40
1 % [discr, trueSolution] = schemeFactory(m)
2 % where trueSolution should be a timeSnapshot of the true solution a time T
3 % T is the end time
4 % m are grid size parameters.
5 % N are number of timesteps to use for each gird size
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)
8 function e = calculateErrors(schemeFactory, T, m, N, errorFun, timeOpt)
9 %TODO: Ability to choose paralell or not
10 assertType(schemeFactory, 'function_handle');
11 assertNumberOfArguments(schemeFactory, 1);
12 assertScalar(T);
13 assert(length(m) == length(N), 'Vectors m and N must have the same length');
14 assertType(errorFun, 'function_handle');
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
20 default_arg('timeOpt', struct());
21
22
23 e = zeros(1,length(m));
24 parfor i = 1:length(m)
25 done = timeTask('m = %3d ', m(i));
26
27 [discr, trueSolution] = schemeFactory(m(i));
28
29 timeOptTemp = timeOpt;
30 timeOptTemp.k = T/N(i);
31 ts = discr.getTimestepper(timeOptTemp);
32 ts.stepTo(N(i), true);
33 approxSolution = discr.getTimeSnapshot(ts);
34
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
41
42 fprintf('e = %.4e', e(i))
43 done()
44 end
45 fprintf('\n')
46 end
47
48
49 %% Example error function
50 % u_true = grid.evalOn(dr.grid, @(x,y)trueSolution(T,x,y));
51 % err = u_true-u_false;
52 % e(i) = norm(err)/norm(u_true);
53 % % e(i) = sqrt(err'*d.H*d.J*err/(u_true'*d.H*d.J*u_true));