Error meshing 2D geometry in Matlab R2018a

13 ビュー (過去 30 日間)
Yoav Blau
Yoav Blau 2018 年 12 月 9 日
コメント済み: Konstantin Kovalev 2019 年 11 月 4 日
My model is a 2d geometry of an ellipse subtracted from a rectangle. Generating the mesh for the model fails in Matlab R2018a, but succeeds in previous version (tried on R2017a, R2015a).
Error:
Meshing failed due to invalid geometry. Each face must have a unique face ID.
Code to reproduce error (fails on last line - generateMesh):
model = createpde;
% rectangle parameters
w = 2;
h = 1;
% ellipse parameters
x_cent = 0;
y_cent = 0;
r1 = 0.6;
r2 = 0.4;
rot = pi/5;
% geometry
rect_model = zeros(12,4);
rect_geometry = [3; 4; w/2; -w/2; -w/2; w/2; h/2; h/2; -h/2; -h/2];
ellipse_geometry = [4; x_cent; y_cent; r1; r2; rot];
% model
rect_model(1:7,:) = decsg(rect_geometry);
ellipse_model = decsg(ellipse_geometry);
geometryFromEdges(model,[rect_model,ellipse_model]);
% mesh
generateMesh(model);
Image of geometry:
geometry.jpg

採用された回答

Alan Weiss
Alan Weiss 2018 年 12 月 10 日
I do not know what the commands you were using do. Seriously, I simply do not understand them. But I went through the doc topic 2-D Geometry Creation at Command Line and did the following:
model = createpde;
% rectangle parameters
w = 2;
h = 1;
% ellipse parameters
x_cent = 0;
y_cent = 0;
r1 = 0.6;
r2 = 0.4;
rot = pi/5;
% geometry
% rect_model = zeros(12,4);
rect_geometry = [3; 4; w/2; -w/2; -w/2; w/2; h/2; h/2; -h/2; -h/2];
ellipse_geometry = [4; x_cent; y_cent; r1; r2; rot;0;0;0;0];
%%
gd = [rect_geometry ellipse_geometry];
%%
ns = char('rect','ellip');
ns = ns';
%%
sf = 'rect-ellip';
%%
[dl,bt] = decsg(gd,sf,ns);
%%
% model
% rect_model(1:7,:) = decsg(rect_geometry);
% ellipse_model = decsg(ellipse_geometry);
geometryFromEdges(model,dl);
%%
% mesh
generateMesh(model);
%%
pdeplot(model)
pdemeshplot.png
I don't know what changed between previous versions and the current version, but the commands I gave work as documented.
Alan Weiss
MATLAB mathematical toolbox documentation
  1 件のコメント
Konstantin Kovalev
Konstantin Kovalev 2019 年 11 月 4 日
The original script uses decsg conceptually incorrectly. The entire geometry description must be passed to decsg, so it can properly compute all regions. The formula in Alan's answer is used to specify that only the region between rectangle and ellipse is needed. If formula is not used, decsg will return geometry with 2 regions.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGeometry and Mesh についてさらに検索

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by