フィルターのクリア

Make a grid for a non-rectangular geometry

25 ビュー (過去 30 日間)
Ann St
Ann St 2015 年 4 月 25 日
コメント済み: Jeremy Ahner 2022 年 7 月 15 日
I have a code that makes a grid for a rectangular geometry. Then it solves equations at each grid point. I want to make the geometry a little more complex (like in the diagram attached--a tank with an outlet attached to it), but don't know how. There is probably information out there about this, but I am not experienced in using Matlab and probably am not using the right search terms. If someone could help, I would be very grateful.
Here is the code I have:
Nx = 20; Ny = Nx; % Number of nodes in x and y direction.
% Lx and Ly are the lengths of each side of the rectangle.
% Grid
x = linspace(0,Lx,Nx); y = linspace(0,Ly,Ny);
delta_x = Lx/(Nx-1); delta_y = Ly/(Ny-1); % Spacing between nodes
% Initial condition
psi = zeros(Nx,Ny); var_store = zeros(Nx,Ny); omega = zeros(Nx,Ny);
How can I modify this to make it appropriate for the shape I want?
  1 件のコメント
Khatereh Danaei
Khatereh Danaei 2018 年 11 月 8 日
Hi dear, I have a question exactly like you. do you find any answer? thank you.

サインインしてコメントする。

回答 (2 件)

KSSV
KSSV 2018 年 11 月 8 日
L = 10; % length
H1 = 5 ;
H2 = 7 ;
%
% Full rectangle
M = 500 ;
x1 = linspace(0,L,M)' ;
y1 = linspace(0,H1,M)' ;
[X1,Y1] = meshgrid(x1,y1) ;
%
N = nnz(x1>=4 & x1<=7);
% Create top notch rectangle from x = 4 t0 7
x2 = linspace(4,7,N)' ;
y2 = linspace(H1,H2,N)' ;
[X2,Y2] = meshgrid(x2,y2) ;
% Merge the double nodes present
idx = knnsearch([X1(end,:)' Y1(end,:)'],[X2(1,:)' Y2(1,:)']) ;
X2(1,:) = X1(end,idx) ;
Y2(1,:) = Y1(end,idx) ;
figure
hold on
plot(X1,Y1,'.r')
plot(X2,Y2,'.b')

Peter
Peter 2022 年 2 月 22 日
Another answer for this is to leave the nominal XY grid defining the mesh, but use NaN outside of the prefered geometry.
  1 件のコメント
Jeremy Ahner
Jeremy Ahner 2022 年 7 月 15 日
How would you go about assigning NaN values outside of the geometry?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by