Mercurial > repos > public > sbplib
comparison +noname/calculateErrors.m @ 657:b59345f905f0 feature/grids
Make noname.calculateErrors parallel
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 24 Oct 2017 16:32:00 +0200 |
parents | 818d52d4928f |
children | 1201eb16557e |
comparison
equal
deleted
inserted
replaced
656:38446922c32a | 657:b59345f905f0 |
---|---|
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 function e = calculateErrors(schemeFactory, T, m, N, errorFun, timeOpt) | 7 function e = calculateErrors(schemeFactory, T, m, N, errorFun, timeOpt) |
8 %TODO: Ability to choose paralell or not | |
8 assertType(schemeFactory, 'function_handle'); | 9 assertType(schemeFactory, 'function_handle'); |
9 assertNumberOfArguments(schemeFactory, 1); | 10 assertNumberOfArguments(schemeFactory, 1); |
10 assertScalar(T); | 11 assertScalar(T); |
11 assert(length(m) == length(N), 'Vectors m and N must have the same length'); | 12 assert(length(m) == length(N), 'Vectors m and N must have the same length'); |
12 assertType(errorFun, 'function_handle'); | 13 assertType(errorFun, 'function_handle'); |
13 assertNumberOfArguments(errorFun, 2); | 14 assertNumberOfArguments(errorFun, 2); |
14 default_arg('timeOpt'); | 15 default_arg('timeOpt', struct()); |
16 | |
15 | 17 |
16 e = []; | 18 e = []; |
17 for i = 1:length(m) | 19 parfor i = 1:length(m) |
18 done = timeTask('m = %3d ', m(i)); | 20 done = timeTask('m = %3d ', m(i)); |
19 | 21 |
20 [discr, trueSolution] = schemeFactory(m(i)); | 22 [discr, trueSolution] = schemeFactory(m(i)); |
21 | 23 |
22 timeOpt.k = T/N(i); | 24 timeOptTemp = timeOpt; |
23 ts = discr.getTimestepper(timeOpt); | 25 timeOptTemp.k = T/N(i); |
26 ts = discr.getTimestepper(timeOptTemp); | |
24 ts.stepTo(N(i), true); | 27 ts.stepTo(N(i), true); |
25 approxSolution = discr.getTimeSnapshot(ts); | 28 approxSolution = discr.getTimeSnapshot(ts); |
26 | 29 |
27 e(i) = errorFun(trueSolution, approxSolution); | 30 e(i) = errorFun(trueSolution, approxSolution); |
28 | 31 |