Mercurial > repos > public > sbplib
comparison +noname/convergence.m @ 32:ddfb98209aa2
Fixed a bunch of problems regarding convergence and saving solutions
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 29 Sep 2015 09:22:22 +0200 |
parents | |
children | c6eb3af205c0 |
comparison
equal
deleted
inserted
replaced
31:d1f9dd55a2b0 | 32:ddfb98209aa2 |
---|---|
1 % Reference is either a key or a function handle | |
2 function [q, e, h] = convergence(filename, errorFunc, reference, method, order, m, T) | |
3 default_arg('errorFunc', @scheme.error1d); | |
4 | |
5 sf = SolutionFile(filename); | |
6 | |
7 analytical_ref = isa(reference,'function_handle'); | |
8 if ~analytical_ref | |
9 reference = sf.get(reference); | |
10 end | |
11 | |
12 | |
13 % Generate convergence, error, and efficiency plots for each search key with more than one entry. | |
14 for i = 1:length(m) | |
15 key.method = method; | |
16 key.order = order; | |
17 key.m = m(i); | |
18 key.T = T; | |
19 | |
20 entry = sf.get(key); | |
21 | |
22 [e(i),h(i)] = errorForEntry(key, entry, errorFunc, reference,T); | |
23 | |
24 end | |
25 q = convergence(e,h); | |
26 end | |
27 | |
28 function [e, h] = errorForEntry(key,entry, errorFunc, reference,T) | |
29 v_repr = entry.repr; | |
30 discr = entry.discr; | |
31 | |
32 % Get the solution to be compared | |
33 v = v_repr.v; | |
34 | |
35 % Get the reference solution vector | |
36 if isa(reference,'function_handle'); | |
37 x = v_repr.x; | |
38 v_ref = reference(x,T); | |
39 else | |
40 % Downsample the reference solution | |
41 x = v_repr.x; | |
42 x_ref = reference.x; | |
43 | |
44 [~,I] = ismember(x,x_ref,'rows'); | |
45 v_ref = reference.v(I); | |
46 end | |
47 | |
48 e = errorFunc(discr,v, v_ref); | |
49 h = discr.h; | |
50 end |