comparison +noname/calculateSolution.m @ 20:c7efff913935

Decoupled plotting and timesteppers. Added possibility of different plot_types. Added functions for printing and plotting solution file content.
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 22 Sep 2015 17:35:58 +0200
parents 1644d000c304
children 791decafe6e4
comparison
equal deleted inserted replaced
19:1644d000c304 20:c7efff913935
41 discr = discrHand(m(j),order(i)); 41 discr = discrHand(m(j),order(i));
42 k_max = discr.getTimestep(method); 42 k_max = discr.getTimestep(method);
43 43
44 % Do we want to to save the initial conditions? 44 % Do we want to to save the initial conditions?
45 if T(1) == 0 45 if T(1) == 0
46 v = discr.v0; 46 snapshot = discr.getTimeSnapshot(0);
47 t = 0; 47 saveToFile(sf, method, order(i), m(j),T(1), snapshot, NaN, NaN, discrHand);
48 saveToFile(sf, method, order(i), m(j),T(1), v, t, NaN, NaN, discrHand);
49 T(1) = []; 48 T(1) = [];
50 end 49 end
51 50
52 % T now contains all the times we need to step to, 51 % T now contains all the times we need to step to,
53 % if T contained 0 it has now been removed. 52 % if T contained 0 it has now been removed.
59 runtime = 0; 58 runtime = 0;
60 for l = 1:length(T) 59 for l = 1:length(T)
61 end_step = N * time_multiples(l); 60 end_step = N * time_multiples(l);
62 fprintf('[order = %-*d, m = %-*d, T = %-*d]: ',orderWidth,order(i),mWidth,m(j),TWidth,T(l)); 61 fprintf('[order = %-*d, m = %-*d, T = %-*d]: ',orderWidth,order(i),mWidth,m(j),TWidth,T(l));
63 clock_start = tic(); 62 clock_start = tic();
64 [v,t] = ts.stepN(end_step-ts.n,true); 63 ts.stepN(end_step-ts.n,true);
65 runtime = runtime + toc(clock_start); 64 runtime = runtime + toc(clock_start);
66 saveToFile(sf, method, order(i), m(j),T(l), v, t, runtime, k, discrHand); 65 snapshot = discr.getTimeSnapshot(ts);
66 saveToFile(sf, method, order(i), m(j),T(l), snapshot, runtime, k, discrHand);
67 fprintf('Done! (%.3fs)\n',runtime); 67 fprintf('Done! (%.3fs)\n',runtime);
68 end 68 end
69 else 69 else
70 % Times are not interger multiples, we have to start from 0 every time. 70 % Times are not interger multiples, we have to start from 0 every time.
71 for l = 1:length(T) 71 for l = 1:length(T)
73 ts = discr.getTimestepper(method,k); 73 ts = discr.getTimestepper(method,k);
74 fprintf('[order = %-*d, m = %-*d, T = %-*d]: ',orderWidth,order(i),mWidth,m(j),TWidth,T(l)); 74 fprintf('[order = %-*d, m = %-*d, T = %-*d]: ',orderWidth,order(i),mWidth,m(j),TWidth,T(l));
75 clock_start = tic(); 75 clock_start = tic();
76 [v,t] = ts.stepN(N-ts.n,true); 76 [v,t] = ts.stepN(N-ts.n,true);
77 runtime = toc(clock_start); 77 runtime = toc(clock_start);
78 saveToFile(sf, method, order(i), m(j),T(l), v, t, runtime, k, discrHand); 78 snapshot = discr.getTimeSnapshot(ts);
79 saveToFile(sf, method, order(i), m(j),T(l), snapshot, runtime, k, discrHand);
79 fprintf('Done! (%.3fs)\n',runtime); 80 fprintf('Done! (%.3fs)\n',runtime);
80 end 81 end
81 82
82 end 83 end
83 84
84 end 85 end
85 end 86 end
86 end 87 end
87 88
88 89
89 function saveToFile(sf, method, order, m, T, v, t, runtime, k, discrHand) 90 function saveToFile(sf, method, order, m, T, snapshot, runtime, k, discrHand)
90 key.method = method; 91 key.method = method;
91 key.order = order; 92 key.order = order;
92 key.m = m; 93 key.m = m;
93 key.T = T; 94 key.T = T;
94 95
95 entry.v = v; 96 entry.repr = snapshot;
96 entry.t = t;
97 entry.runtime = runtime; 97 entry.runtime = runtime;
98 entry.k = k; 98 entry.k = k;
99 entry.discrHand = discrHand; 99 entry.discrHand = discrHand;
100 100
101 sf.store(key,entry); 101 sf.store(key,entry);