How to generate a TFI (Transfinite Interpolation) based grid in MATLAB for a given analytical equation? (code provided)
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a code for a general equation, but I want the equations to be based on the following figure. I'm not able to get the function for the curve shown.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1079745/image.png)
clc
clear all ;
% number of discretizations along xi and eta axis
m = 10 ;
n = 10 ;
% discretize along xi and eta axis
xi = linspace(0.,1,m) ;
eta = linspace(0.,1.,n) ;
% Initialize matrices in x and y axis
X = zeros(m,n) ;
Y = zeros(m,n) ;
for i = 1:m
Xi = xi(i) ;
for j = 1:n
Eta = eta(j) ;
% Transfinite Interpolation
XY = (1-Eta)*Xb(Xi)+Eta*Xt(Xi)+(1-Xi)*Xl(Eta)+Xi*Xr(Eta)......
-(Xi*Eta*Xt(1)+Xi*(1-Eta)Xb(1)+Eta(1-Xi)Xt(0)+(1-Xi)(1-Eta)*Xb(0)) ;
X(i,j) = XY(1) ;
Y(i,j) = XY(2) ;
end
end
plotgrid(X,Y) ;
function xyb = Xb(s)
x = s ;
y = 0 ;
xyb = [x ; y] ;
end
function xyl = Xl(s)
x = 0 ;
y = s ;
xyl = [x ; y] ;
end
function xyr = Xr(s)
x = 1+2*s-2*s^2 ;
y = s ;
xyr = [x ; y] ;
end
function xyt = Xt(s)
x = s ;
y = 1-3*s+3*s^2 ;
xyt = [x ; y] ;
end
function plotgrid(X,Y)
% plotgrid: To plot structured grid.
%
% plotgrid(X,Y)
%
% INPUT:
% X (matrix) - matrix with x-coordinates of gridpoints
% Y (matrix) - matrix with y-coordinates of gridpoints
if any(size(X)~=size(Y))
error('Dimensions of X and Y must be equal');
end
[m,n]=size(X);
% Plot grid
figure
set(gcf,'color','w') ;
axis equal
axis off
box on
hold on
% Plot internal grid lines
for i=1:m
plot(X(i,:),Y(i,:),'b','linewidth',1);
end
for j=1:n
plot(X(:,j),Y(:,j),'b','linewidth',1);
end
hold off
end
0 commentaires
Réponses (1)
Sachin Lodhi
le 17 Nov 2023
Hi Chinmay,
From what I gather, you are facing error while generating a TFI (Transfinite Interpolation) based grid in MATLAB for an analytical equation.
The error is caused due to missing multiplication symbols in the syntax of analytical equation. After substituting the below line in the code, you can generate the TFI based grid.
XY = (1-Eta)*Xb(Xi)+Eta*Xt(Xi)+(1-Xi)*Xl(Eta)+Xi*Xr(Eta)-(Xi*Eta*Xt(1)+Xi*(1-Eta)*Xb(1)+Eta*(1-Xi)*Xt(0)+(1-Xi)*(1-Eta)*Xb(0));
I hope this helps.
Best Regards,
Sachin
0 commentaires
Voir également
Catégories
En savoir plus sur Computational Fluid Dynamics (CFD) dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!