Skip to content

Commit f406597

Browse files
committed
Use MOLE interpolators instead of scatterinterp, which is MATLAB specific. Added comments and madde none square to show U and V grid how to
1 parent 25a2358 commit f406597

File tree

1 file changed

+38
-34
lines changed

1 file changed

+38
-34
lines changed

examples_MATLAB/test_div2DCurv.m

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
% Parameters
88
k = 2;
99
m = 20;
10-
n = 20;
10+
n = 30;
1111

1212
% Grid
13-
r1 = 1; % Inner radius
13+
r1 = 1; % Inner radius
1414
r2 = 2; % Outer radius
1515
nR = linspace(r1, r2, m) ;
1616
nT = linspace(0, 2*pi, n) ;
1717
[R, T] = meshgrid(nR, nT) ;
1818
% Convert grid to cartesian coordinates
19-
X = R.*cos(T);
19+
X = R.*cos(T);
2020
Y = R.*sin(T);
2121

2222
% Test on another grid
@@ -44,41 +44,45 @@
4444
Cy = (Uy(:, 1:end-1) + Uy(:, 2:end))/2;
4545
scatter3(Cx(:), Cy(:), zeros(n*m, 1), '.', 'MarkerEdgeColor', 'r')
4646

47+
%% Interpolators
48+
% Some useful numbers
49+
num_nodes = (m+1)*(n+1);
50+
num_centers = (m+2)*(n+2);
51+
num_u = (m+1)*n;
52+
num_v = m*(n+1);
53+
54+
% MOLE Interpolator Matrices of 'k' order
55+
NtoC = interpolNodesToCenters2D(k, n, m);
56+
CtoF = interpolCentersToFacesD2D(k, n, m); % V is the top part!!
57+
58+
% Center to specific face, u or v
59+
CtoV = CtoF(1:(n+1)*m, 1:num_centers);
60+
CtoU = CtoF((n+1)*m+1:end, num_centers+1:end);
61+
62+
% Node to X interpolator is pre-multiplied
63+
NtoU = CtoU * NtoC;
64+
NtoV = CtoV * NtoC;
65+
4766
% Interpolate U values
4867
Ugiven = sin(X);
49-
interpolant = scatteredInterpolant([X(:) Y(:)], Ugiven(:));
50-
U = interpolant(Ux, Uy);
68+
U = NtoU * Ugiven(:);
69+
U = reshape(U,n,m+1);
70+
5171
% Interpolate V values
5272
Vgiven = cos(Y);
53-
interpolant = scatteredInterpolant([X(:) Y(:)], Vgiven(:));
54-
V = interpolant(Vx, Vy);
55-
% Interpolate C values
73+
V = NtoV * Vgiven(:);
74+
V = reshape(V,n+1,m);
75+
5676
Cgiven = cos(X)-sin(Y);
57-
interpolant = scatteredInterpolant([X(:) Y(:)], Cgiven(:));
58-
59-
% West-East sides
60-
Cx = [Ux(:, 1) Cx];
61-
Cy = [Uy(:, 1) Cy];
62-
Cx = [Cx Ux(:, end)];
63-
Cy = [Cy Uy(:, end)];
64-
65-
% South-North sides
66-
Cx = [[0 Vx(1, :) 0]; Cx];
67-
Cy = [[0 Vy(1, :) 0]; Cy];
68-
Cx = [Cx; [0 Vx(end, :) 0]];
69-
Cy = [Cy; [0 Vy(end, :) 0]];
70-
71-
% Corners
72-
Cx(1, 1) = X(1, 1);
73-
Cy(1, 1) = Y(1, 1);
74-
Cx(1, end) = X(1, end);
75-
Cy(1, end) = Y(1, end);
76-
Cx(end, 1) = X(end, 1);
77-
Cy(end, 1) = Y(end, 1);
78-
Cx(end, end) = X(end, end);
79-
Cy(end, end) = Y(end, end);
80-
81-
C = interpolant(Cx, Cy);
77+
C = NtoC * Cgiven(:);
78+
C = reshape(C,n+2,m+2);
79+
80+
% Interpolate Nodal grid to centered grid.
81+
Cx = NtoC * X(:);
82+
Cx = reshape(Cx,n+2,m+2);
83+
84+
Cy = NtoC * Y(:);
85+
Cy = reshape(Cy, n+2,m+2);
8286

8387
scatter3(Cx(:), Cy(:), zeros((m+2)*(n+2), 1), 'o', 'MarkerEdgeColor', 'r')
8488
legend('Nodal points', 'u', 'v', 'Centers', 'All centers')
@@ -109,4 +113,4 @@
109113
xlabel('x')
110114
ylabel('y')
111115
axis equal
112-
shading interp
116+
shading interp

0 commit comments

Comments
 (0)