comparison +noname/calculateErrors.m @ 797:5cf9fdf4c98f feature/poroelastic

Merge with feature/grids and bugfix bcSetup
author Martin Almquist <malmquist@stanford.edu>
date Thu, 26 Jul 2018 10:53:05 -0700
parents 1201eb16557e
children
comparison
equal deleted inserted replaced
796:aa1ed37a1b56 797:5cf9fdf4c98f
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)
9 %TODO: Ability to choose paralell or not
8 assertType(schemeFactory, 'function_handle'); 10 assertType(schemeFactory, 'function_handle');
9 assertNumberOfArguments(schemeFactory, 1); 11 assertNumberOfArguments(schemeFactory, 1);
10 assertScalar(T); 12 assertScalar(T);
11 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');
12 assertType(errorFun, 'function_handle'); 14 assertType(errorFun, 'function_handle');
13 assertNumberOfArguments(errorFun, 2);
14 default_arg('timeOpt');
15 15
16 e = []; 16 if ~ismember(nargin(errorFun), [2,3])
17 for i = 1:length(m) 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)
18 done = timeTask('m = %3d ', m(i)); 25 done = timeTask('m = %3d ', m(i));
19 26
20 [discr, trueSolution] = schemeFactory(m(i)); 27 [discr, trueSolution] = schemeFactory(m(i));
21 28
22 timeOpt.k = T/N(i); 29 timeOptTemp = timeOpt;
23 ts = discr.getTimestepper(timeOpt); 30 timeOptTemp.k = T/N(i);
31 ts = discr.getTimestepper(timeOptTemp);
24 ts.stepTo(N(i), true); 32 ts.stepTo(N(i), true);
25 approxSolution = discr.getTimeSnapshot(ts); 33 approxSolution = discr.getTimeSnapshot(ts);
26 34
27 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
28 41
29 fprintf('e = %.4e', e(i)) 42 fprintf('e = %.4e', e(i))
30 done() 43 done()
31 end 44 end
32 fprintf('\n') 45 fprintf('\n')