How to show node/element numbers on the boundary ONLY?

조회 수: 8(최근 30일)
hmhuang
hmhuang 2021년 11월 30일
편집: Wan Ji 2021년 11월 30일
I have a function plotting the FE mesh with node numbers and element numbers displayed. An example with (meshx,meshy) = (30,15) shown on the figure below. How do I adpat the code so only node/element numbers on the boundary are displayed?
function plotGrid(meshx, meshy)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Plot FE mesh and diaplay node numbers as well as element numbers
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Initialization of figure object and variables
figure('Name', 'Finite Element Mesh', ...
'Numbertitle','off', ...
'Position', get(0, 'Screensize'));
nNodes = (meshx+1)*(meshy+1);
nElements = (meshx)*(meshy);
[X_nodes,Y_nodes] = meshgrid(0:meshx, 0:meshy);
[X_elements,Y_elements] = meshgrid(linspace(0.5, meshx-0.5, meshx), linspace(0.5, meshy-0.5, meshy));
% Plot the grid lines
plot(X_nodes, Y_nodes, 'k', X_nodes', Y_nodes', 'k');
title('Finite Element Mesh');
subtitle({sprintf('(meshx, meshy) = (%i, %i)', meshx, meshy), ''});
set(gca,'YDir','reverse');
set(gca,'XTick',[],'YTick',[],'XColor','None','YColor','None');
% Create the lists of node numbers and element numbers
nodeNumbers = mat2cell(num2str((1:nNodes)'), ones(nNodes,1));
elementNumbers = mat2cell(num2str((1:nElements)'), ones(nElements,1));
% Insert the labels for node numbers and element numbers
text(X_nodes(:), Y_nodes(:)+0.1, nodeNumbers, 'FontSize', 8, 'Color', 'k');
text(X_elements(:)-0.1, Y_elements(:), elementNumbers, 'FontSize', 10, 'FontWeight', 'bold', 'Color', 'r');
end

답변(1개)

Wan Ji
Wan Ji 2021년 11월 30일
편집: Wan Ji 2021년 11월 30일
Hi, friend,
Here are some tips for you.
Firstly, you can find those edges (an edge is generally denoted by two nodes) that are not shared by two elements, so these edges are the boundary edges.
Then collect all the nodes that are attacthed to the boundary edges mentioned above (hint: use unique is very convenient), these nodes are boundary nodes.
Finally, collect all the elements that the boundary nodes belong to, these elements are the boundary elements.
OK, I believe now you understand how to label the boundary nodes and boundary elements.
Do not forget to accept my answer if surely it helps you, thank you.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by