7
7
% Parameters
8
8
k = 2 ;
9
9
m = 20 ;
10
- n = 20 ;
10
+ n = 30 ;
11
11
12
12
% Grid
13
- r1 = 1 ; % Inner radius
13
+ r1 = 1 ; % Inner radius
14
14
r2 = 2 ; % Outer radius
15
15
nR = linspace(r1 , r2 , m ) ;
16
16
nT = linspace(0 , 2 * pi , n ) ;
17
17
[R , T ] = meshgrid(nR , nT ) ;
18
18
% Convert grid to cartesian coordinates
19
- X = R .* cos(T );
19
+ X = R .* cos(T );
20
20
Y = R .* sin(T );
21
21
22
22
% Test on another grid
44
44
Cy = (Uy(: , 1 : end - 1 ) + Uy(: , 2 : end ))/2 ;
45
45
scatter3(Cx(: ), Cy(: ), zeros(n * m , 1 ), ' .' , ' MarkerEdgeColor' , ' r' )
46
46
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
+
47
66
% Interpolate U values
48
67
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
+
51
71
% Interpolate V values
52
72
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
+
56
76
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 );
82
86
83
87
scatter3(Cx(: ), Cy(: ), zeros((m + 2 )*(n + 2 ), 1 ), ' o' , ' MarkerEdgeColor' , ' r' )
84
88
legend(' Nodal points' , ' u' , ' v' , ' Centers' , ' All centers' )
109
113
xlabel(' x' )
110
114
ylabel(' y' )
111
115
axis equal
112
- shading interp
116
+ shading interp
0 commit comments