Mercurial > repos > public > sbplib
annotate +parametrization/old/curve_discretise.m @ 1031:2ef20d00b386 feature/advectionRV
For easier comparison, return both the first order and residual viscosity when evaluating the residual. Add the first order and residual viscosity to the state of the RungekuttaRV time steppers
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Thu, 17 Jan 2019 10:25:06 +0100 |
parents | 81e0ead29431 |
children |
rev | line source |
---|---|
0 | 1 % Discretises the curve g with the smallest number of points such that all segments |
2 % are shorter than h. If do_plot is true the points of the discretisation and | |
3 % the normals of the curve in those points are plotted. | |
4 % | |
5 % [t,p,d] = curve_discretise(g,h,do_plot) | |
6 % | |
7 % t is a vector of input values to g. | |
8 % p is a cector of points. | |
9 % d are the length of the segments. | |
10 function [t,p,d] = curve_discretise(g,h,do_plot) | |
11 default_arg('do_plot',false) | |
12 | |
13 n = 10; | |
14 | |
15 [t,p,d] = curve_discretise_n(g,n); | |
16 | |
17 % ni = 0; | |
18 while any(d>h) | |
19 [t,p,d] = curve_discretise_n(g,n); | |
20 n = ceil(n*d(1)/h); | |
21 % ni = ni+1; | |
22 end | |
23 | |
24 % nj = 0; | |
25 while all(d<h) | |
26 [t,p,d] = curve_discretise_n(g,n); | |
27 n = n-1; | |
28 % nj = nj+1; | |
29 end | |
30 [t,p,d] = curve_discretise_n(g,n+1); | |
31 | |
32 % fprintf('ni = %d, nj = %d\n',ni,nj); | |
33 | |
34 if do_plot | |
35 fprintf('n:%d max: %f min: %f\n', n, max(d),min(d)); | |
248
81e0ead29431
Fixed package names in +parametrization
Jonatan Werpers <jonatan@werpers.com>
parents:
151
diff
changeset
|
36 p = parametrization.map_curve(g,t); |
0 | 37 figure |
38 show(g,t,h); | |
39 end | |
40 | |
41 end | |
42 | |
43 function [t,p,d] = curve_discretise_n(g,n) | |
44 t = linspace(0,1,n); | |
45 t = equalize_d(g,t); | |
46 d = D(g,t); | |
248
81e0ead29431
Fixed package names in +parametrization
Jonatan Werpers <jonatan@werpers.com>
parents:
151
diff
changeset
|
47 p = parametrization.map_curve(g,t); |
0 | 48 end |
49 | |
50 function d = D(g,t) | |
248
81e0ead29431
Fixed package names in +parametrization
Jonatan Werpers <jonatan@werpers.com>
parents:
151
diff
changeset
|
51 p = parametrization.map_curve(g,t); |
0 | 52 |
53 d = zeros(1,length(t)-1); | |
54 for i = 1:length(d) | |
55 d(i) = norm(p(:,i) - p(:,i+1)); | |
56 end | |
57 end | |
58 | |
59 function t = equalize_d(g,t) | |
60 d = D(g,t); | |
61 v = d-mean(d); | |
62 while any(abs(v)>0.01*mean(d)) | |
63 dt = t(2:end)-t(1:end-1); | |
64 t(2:end) = t(2:end) - cumsum(dt.*v./d); | |
65 | |
66 t = t/t(end); | |
67 d = D(g,t); | |
68 v = d-mean(d); | |
69 end | |
70 end | |
71 | |
72 | |
73 function show(g,t,hh) | |
248
81e0ead29431
Fixed package names in +parametrization
Jonatan Werpers <jonatan@werpers.com>
parents:
151
diff
changeset
|
74 p = parametrization.map_curve(g,t); |
0 | 75 |
76 | |
77 | |
248
81e0ead29431
Fixed package names in +parametrization
Jonatan Werpers <jonatan@werpers.com>
parents:
151
diff
changeset
|
78 h = parametrization.plot_curve(g); |
0 | 79 h.LineWidth = 2; |
80 axis equal | |
81 hold on | |
82 h = plot(p(1,:),p(2,:),'.'); | |
83 h.Color = [0.8500 0.3250 0.0980]; | |
84 h.MarkerSize = 24; | |
85 hold off | |
86 | |
248
81e0ead29431
Fixed package names in +parametrization
Jonatan Werpers <jonatan@werpers.com>
parents:
151
diff
changeset
|
87 n = parametrization.curve_normals(g,t); |
0 | 88 hold on |
89 for i = 1:length(t) | |
90 p0 = p(:,i); | |
91 p1 = p0 + hh*n(:,i); | |
92 l = [p0, p1]; | |
93 h = plot(l(1,:),l(2,:)); | |
94 h.Color = [0.8500 0.3250 0.0980]; | |
95 end | |
96 | |
97 end |