How to create a non-uniform 2d grid?

Hi all, I have created a grid as shown in below image
But my aim is to create a grid in the following way
Can anyone help me in creating this type of mesh. Please find below code,
clear all
clc
L=1;
nx=50;
ny=50;
x1=linspace(0,0.4,10);
x2=linspace(0.42,1,40);
x=cat(2,x1,x2);
y1=linspace(0,0.4,10);
y2=linspace(0.42,1,40);
y=cat(2,y1,y2);
[X,Y]=meshgrid(x,y);
plot(X,Y,'k',Y,X,'k');
Thank you all.

Answers (2)

clear all; close all;
alx3 = 1.0; %LENGTH X
aly3 = 0.5; %LENGTH Y
nx = 50; %NODES X
ny = 50; %NODES Y
str3 = 1.2; %STRETCH
%HYPERBOLIC TANGENT-TYPE CLUSTERING
nxm=nx-1;
tstr3=tanh(str3);
xc(1)=0.0;
for kc=2:nx;
z2dp=(2*kc-nx-1)/(nxm);
xc(kc)=(1+tanh(str3*z2dp)/tstr3)*0.5*alx3;
end
nym=ny-1;
yc(1)=0.0;
for kc=2:ny;
z2dp=(2*kc-ny-1)/(nym);
yc(kc)=(1+tanh(str3*z2dp)/tstr3)*0.5*aly3;
end
[X,Y]=meshgrid(xc,yc);
hold on;
plot(X,Y,'k');
plot(X.',Y.','k');
axis equal;
xlim([0.0 alx3]);
ylim([0.0 aly3]);
You have an infinity different ways to difine how you will strach your mesh (uniform, HYPERBOLIC TANGENT-TYPE, CLIPPED CHEBYCHEV-TYPE and much more...), I picked up one method, because the trick is the last part of the code:
hold on;
plot(X,Y,'k'); %Creates the VERTICAL lines
plot(X.',Y.','k'); %Creates the Horizontal lines --> I am using the transpose matrices here
The code will give you the following mesh:
Hopefully it will help you
Hi Ganesh,
I understand that you are trying to create a Mesh(2nd image) with non-uniform width between the lines. My understanding is that you would like to change/increase the line width when compared to the first image. Please correct me if I am wrong.

7 Comments

Yes correct. Its like changing the spacing between the lines.
By using the LineWidth property in the Plot function you can change the size of the line drawn(make it thicker).
However if you want to decrease the spacing between the lines and make the 1st image look like the 2nd image then you have to tinker with the X and Y data. My observations would be that
  • Data along the y axis is gradually increasing in spacing while the data along the x axis is symmetric over some x value.
  • Due to this you have to use different sets on data in ploteg:- plot(X1,Y1,'k',X2,Y2,'k')
It would be very helpful if you could elaborate your application because if its related to Logrithmic functions then you can use the "loglog", "semilogx", etc functions for plotting these values.
Main application is to perform numerical analysis. I am interested to create prism layers near wall i.e slowly growing grid near wall. This is not just for visualization purpose.
Like I have mentioned before one of the possible way of creating the 2nd mesh image would be be play around with your X and Y data. But since you are more interested in Mesh Generation I have found some interesting links that could help you out.
https://www.mathworks.com/matlabcentral/answers/122114-how-to-make-a-grid-with-non-uniform-nodes
https://stackoverflow.com/questions/42045140/generating-a-non-uniform-1d-mesh-in-matlab
https://www.mathworks.com/matlabcentral/fileexchange/25555-mesh2d-delaunay-based-unstructured-mesh-generation
Thank you Venkata, your answer is very helpful!
How about for a non-uniform 3D mesh?
Do you have a picture?

Sign in to comment.

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!