Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal 2D Grid generation based on Transfinite Interpolation #3

Merged
merged 6 commits into from
Oct 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions mole_MATLAB/gridGen.m
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
9 changes: 9 additions & 0 deletions mole_MATLAB/grids/chevron/bottom.m
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
5 changes: 5 additions & 0 deletions mole_MATLAB/grids/chevron/left.m
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
5 changes: 5 additions & 0 deletions mole_MATLAB/grids/chevron/right.m
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
9 changes: 9 additions & 0 deletions mole_MATLAB/grids/chevron/top.m
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
5 changes: 5 additions & 0 deletions mole_MATLAB/grids/horseshoe/bottom.m
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
5 changes: 5 additions & 0 deletions mole_MATLAB/grids/horseshoe/left.m
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
5 changes: 5 additions & 0 deletions mole_MATLAB/grids/horseshoe/right.m
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
5 changes: 5 additions & 0 deletions mole_MATLAB/grids/horseshoe/top.m
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
5 changes: 5 additions & 0 deletions mole_MATLAB/grids/swan/bottom.m
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
5 changes: 5 additions & 0 deletions mole_MATLAB/grids/swan/left.m
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
5 changes: 5 additions & 0 deletions mole_MATLAB/grids/swan/right.m
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
5 changes: 5 additions & 0 deletions mole_MATLAB/grids/swan/top.m
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