-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minimal 2D Grid generation based on Transfinite Interpolation (#3)
- Loading branch information
Showing
13 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
% https://en.wikipedia.org/wiki/Transfinite_interpolation | ||
function [X, Y] = gridGen(grid_name, m, n, plot_grid) | ||
% Returns X and Y which are both m by n matrices that contains the physical | ||
% coordinates | ||
% | ||
% Parameters: | ||
% grid_name : String with the name of the grid folder | ||
% m : Number of nodes along the horizontal axis | ||
% n : Number of nodes along the vertical axis | ||
% plot_grid : If defined -> grid will be plotted | ||
|
||
assert(nargin == 4, 'Must specify all input arguments') | ||
assert(m > 4 && n > 4, 'm and n must be greater than 4') | ||
|
||
addpath(['grids/' grid_name]) | ||
|
||
% Logical grid | ||
Xl = linspace(0, 1, m); | ||
Yl = linspace(0, 1, n); | ||
|
||
% Allocate space for physical grid | ||
X = zeros(m, n); | ||
Y = zeros(m, n); | ||
|
||
for i = 1 : m | ||
u = Xl(i); | ||
for j = 1 : n | ||
v = Yl(j); | ||
% Transfinite interpolation | ||
XY = (1-v)*bottom(u)+v*top(u)+(1-u)*left(v)+u*right(v)-... | ||
(u*v*top(1)+u*(1-v)*bottom(1)+v*(1-u)*top(0)+(1-u)*(1-v)*bottom(0)); | ||
X(i, j) = XY(1); | ||
Y(i, j) = XY(2); | ||
end | ||
end | ||
|
||
if plot_grid | ||
figure | ||
mesh(X, Y, zeros(m, n), 'Marker', '.', 'MarkerSize', 10, 'EdgeColor', 'b') | ||
title(['Physical grid. m = ' num2str(m) ', n = ' num2str(n)]) | ||
set(gcf, 'color', 'w') | ||
axis equal | ||
axis off | ||
view([0 90]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function XY = bottom(s) | ||
X = s; | ||
if s <= 0.5 | ||
Y = -s; | ||
elseif s > 0.5 | ||
Y = s-1; | ||
end | ||
XY = [X Y]; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function XY = left(s) | ||
X = 0; | ||
Y = s; | ||
XY = [X Y]; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function XY = right(s) | ||
X = 1; | ||
Y = s; | ||
XY = [X Y]; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function XY = top(s) | ||
X = s; | ||
if s <= 0.5 | ||
Y = 1-s; | ||
elseif s > 0.5 | ||
Y = s; | ||
end | ||
XY = [X Y]; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function XY = bottom(s) | ||
X = 2*cos(pi/2*(1-2*s)); | ||
Y = sin(pi/2*(1-2*s)); | ||
XY = [X Y]; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function XY = left(s) | ||
X = 0; | ||
Y = 1+s; | ||
XY = [X Y]; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function XY = right(s) | ||
X = 0; | ||
Y = -1-s; | ||
XY = [X Y]; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function XY = top(s) | ||
X = 4*cos(pi/2*(1-2*s)); | ||
Y = 2*sin(pi/2*(1-2*s)); | ||
XY = [X Y]; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function XY = bottom(s) | ||
X = s; | ||
Y = 0; | ||
XY = [X Y]; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function XY = left(s) | ||
X = 0; | ||
Y = s; | ||
XY = [X Y]; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function XY = right(s) | ||
X = 1+2*s-2*s^2; | ||
Y = s; | ||
XY = [X Y]; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function XY = top(s) | ||
X = s; | ||
Y = 1-3*s+3*s^2; | ||
XY = [X Y]; | ||
end |