How to show Edgelabels in PDE Toolbox of particular face only

45 ビュー (過去 30 日間)
Gobinda Debnath
Gobinda Debnath 2024 年 12 月 28 日 19:41
編集済み: Gobinda Debnath 2024 年 12 月 30 日 19:32
I have created 2D geometry with combining one rectangle and one triangle with code to solve a problem in matlab pdetoolbox
% geometry
topLayer = [3 4 0 2 2 0 0 0 1.5 1.5];
TriLayer = [2 3 1 1.5 0.5 0.7 1.5 1.5 0 0];
gdm = [topLayer;TriLayer]';
[d1,bt] = decsg(gdm,'R1+R4',['R1';'R4']');
figure
pdegplot(d1,"EdgeLabels","on", "FaceLabels","on")
now after running above code it shows 2 face with all edge labels, but my concerned is to show only F2 edgelabels, i.e., only triangle facelabels how to do that.
the reason to know this answer is because; after solving complete problem in matlab pde toolbox we get 2D solution plot using pdeplot function; now let say pressure distribution; now on that plot using "hold on", I want to highlight/plot the triangle (F2) edges as to see how the pressure distribution in F2 compared to F1.
i think i am clear with my problem; please let me know anything required

回答 (1 件)

Malay Agarwal
Malay Agarwal 2024 年 12 月 30 日 11:21
編集済み: Malay Agarwal 2024 年 12 月 30 日 11:24
While it is not possible to plot specific edges that belong to a face using pdeplot directly, you can highlight the edges with a different color.
The decomposed geometry matrix d1 is a matrix. The rows 2 to 5 of the matrix have the coordinates of the edges in each column, where:
  • 2nd row has the starting x-coordinate of the edge.
  • 3rd row has the ending x-coordinate of the edge.
  • 4th row has the starting y-coordinate of the edge.
  • 5th row has the ending y-coordinate of the edge.
If you can identify which edges belong to a particular face, you can use the plot() function to then plot those edges with a different color. To identify the edges which belong to a particular face, you can use the faceEdges() function. Since it expects a geometry, you will first have to convert the decomposed geometry matrix to a geometry using the geometryFromEdges() function.
The following code shows how to achieve this:
topLayer = [3 4 0 2 2 0 0 0 1.5 1.5];
TriLayer = [2 3 1 1.5 0.5 0.7 1.5 1.5 0 0];
gdm = [topLayer; TriLayer]';
[d1, bt] = decsg(gdm, 'R1+R4', ['R1'; 'R4']');
figure
pdegplot(d1,"FaceLabels","on", "EdgeLabels", "on") % Plot with face labels but no edge labels initially
% Convert the decomposed matrix to edges
gm = geometryFromEdges(d1);
% Change this to highlight different faces
face_num = 2;
% Obtain the indices of the edges that belong to the face
edges = faceEdges(gm, face_num);
% Obtain the coordinates of the edges from the decomposed matrix
faceEdgeCoords = d1(2:5, edges);
% Plot each edge with a thicker red line
hold on;
for i = 1 : size(faceEdgeCoords, 2)
plot(faceEdgeCoords(1:2, i), faceEdgeCoords(3:4, i), 'r-', 'LineWidth', 2);
end
hold off;
Refer to the following resources for more information:
Hope this helps!
  1 件のコメント
Gobinda Debnath
Gobinda Debnath 2024 年 12 月 30 日 19:28
編集済み: Gobinda Debnath 2024 年 12 月 30 日 19:32
Hello @Malay Agarwal sir,
I appreciate your answer, and yes it works fine when the edges are only straight lines and (inner face). but failed in curve edges and (outer kind of face).
see first curve edge problem:
% geometry
topLayer = [3 4 0 2 2 0 0 0 1.5 1.5];
C1=[1,1,1.2,0.3,0,0,0,0,0,0];
gdm = [topLayer;C1]';
[d1,bt] = decsg(gdm,'R1+C1',['R1';'C1']');
figure
pdegplot(d1,"EdgeLabels","on", "FaceLabels","on")
% Convert the decomposed matrix to edges
gm = geometryFromEdges(d1);
% Change this to highlight different faces
face_num = 2;
% Obtain the indices of the edges that belong to the face
edges = faceEdges(gm, face_num);
% Obtain the coordinates of the edges from the decomposed matrix
faceEdgeCoords = d1(2:5, edges);
% Plot each edge with a thicker red line
hold on;
for i = 1 : size(faceEdgeCoords, 2)
plot(faceEdgeCoords(1:2, i), faceEdgeCoords(3:4, i), 'r-', 'LineWidth', 2);
end
hold off;
this above code, colour the straight line between two points. But what to do when the edges of a face are in curve nature?
and i am sorry to tell you that when i tried to highlight the edges of face 1 (F1); it highlights both the face; and this is with all geometry; if we highlight outside face, it also highlights inside contained face (see fig A); or sometimes abnormal (see fig B)
Fig A generation:
% geometry
topLayer = [3 4 0 2 2 0 0 0 1.5 1.5];
C1=[1,1,1.2,0.3,0,0,0,0,0,0];
gdm = [topLayer;C1]';
[d1,bt] = decsg(gdm,'R1+C1',['R1';'C1']');
figure
pdegplot(d1,"EdgeLabels","on", "FaceLabels","on")
% Convert the decomposed matrix to edges
gm = geometryFromEdges(d1);
% Change this to highlight different faces
face_num = 1;
% Obtain the indices of the edges that belong to the face
edges = faceEdges(gm, face_num);
% Obtain the coordinates of the edges from the decomposed matrix
faceEdgeCoords = d1(2:5, edges);
% Plot each edge with a thicker red line
hold on;
for i = 1 : size(faceEdgeCoords, 2)
plot(faceEdgeCoords(1:2, i), faceEdgeCoords(3:4, i), 'r-', 'LineWidth', 2);
end
hold off;
Fig B generation:
topLayer = [3 4 0 2 2 0 0 0 1.5 1.5];
TriLayer = [2 3 1 1.5 0.5 0.7 1.5 1.5 0 0];
gdm = [topLayer; TriLayer]';
[d1, bt] = decsg(gdm, 'R1+R4', ['R1'; 'R4']');
figure
pdegplot(d1,"FaceLabels","on", "EdgeLabels", "on") % Plot with face labels but no edge labels initially
% Convert the decomposed matrix to edges
gm = geometryFromEdges(d1);
% Change this to highlight different faces
face_num = 1;
% Obtain the indices of the edges that belong to the face
edges = faceEdges(gm, face_num);
% Obtain the coordinates of the edges from the decomposed matrix
faceEdgeCoords = d1(2:5, edges);
% Plot each edge with a thicker red line
hold on;
for i = 1 : size(faceEdgeCoords, 2)
plot(faceEdgeCoords(1:2, i), faceEdgeCoords(3:4, i), 'r-', 'LineWidth', 2);
end
hold off;
Sir, please help in detailed!!

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

カテゴリ

Help Center および File ExchangeGeneral PDEs についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by