Create mesh around more than one shape
이전 댓글 표시
I am trying to create an autonomous meshing code to create a 2D mesh around certain shapes that are created by the MATLAB contour function via the generateMesh function.
I am building the geometry from the contour coordinate data. This is used to create a polygon shape to be defined in the geometry description matrix, then the MATLAB decsg function is used.
I have succesfully got this working for a domain rectangle with one contour shape deducted from it. However, when I have more than one shape removed from the rectangle it fails, I get the following error displayed:
Output argument "dl1" (and maybe others) not assigned during call to "decsg".
If I instead try to add the domain and the contours together in the Set Formula, then again, it works for the domain plus one contour shape, but for multiple shapes I recieve the following error:
Meshing failed to create initial discretization.
Below is the algorithm I am using to build the geometry description matrix from the contour data:
% Domain rectangle
DR = [3,4,x_dom(1),x_dom(2),x_dom(2),x_dom(1),y_dom(2),y_dom(2),y_dom(1),y_dom(1)]';
S(1,:) = DR(:,1)';
% Contours from contour plot
for i = 1:n_contours
x = A{1,i}(1,:); % extract x data
y = A{1,i}(2,:); % extract y data
% Contour geometry description
S(i+1,1) = 2;
S(i+1,2) = numel(x(1,:));
k = 2;
for ii = 1:(numel(x(1,:)))
k = k+1;
S(i+1,k) = x(1,ii);
end
k = numel(x(1,:)) + 2;
for jj = 1:(numel(y(1,:)))
k = k+1;
S(i+1,k) = y(1,jj);
end
% Names each contour formula iteratively
cf_i(i,:) = ['S',num2str(i)];
end
gdm = S'; % geometry description matrix
where, n_contours is the total number of contours produced by the MATLAB contour function, and A is the cell array that hold all the contour data sets. See below the mesh successfully created for a domain with one contour.
Below is how I autonomously create a character string for the Set Formula and Name-Space matrix.
% Set formula
dr = 'R1';
sf = [dr,'-',cf_i(1,:)]; % set formula for when removing contours from domain
% sf = [dr,'+',cf_i(1,:)]; % set formula for when adding contours to domain
for i = 2:n_contours
sf = [sf,'-',cf_i(i,:)]; % set formula for when removing contours from domain
% sf = [sf,'+',cf_i(i,:)]; % set formula for when adding contours to domain
end
% Name geometry
ns = char([dr]);
for i = 1:n_contours
ns = char([ns;cf_i(i,:)]);
end
% Invoke decsg
g = decsg(gdm,sf,ns');
Below is an image of the meshed domain with one shape successfully removed (left) and the same domain and contour shape but added together (right):

Any insight to why this is not working for more than one shape is greatly appriciated.
Thank you.
Full code attached.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Geometry and Mesh에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!