在有限元网格中绘制 matlab 中的二维分段常数

计算科学 有限元 matlab 不连续-galerkin 八度
2021-12-05 04:14:06

我需要在matlab中生成一个不连续的图(在每个三角形中分段),比如:

不连续图,有限元法求解

这个情节来自http://www.alecjacobson.com/weblog/?p=3616,但我不明白如何生成它。


我有两个矩阵对应于域的三角形网格(典型的有限元方法,即没有重叠的三角形,所有三角形的并集等于域......):

coord=[x1,y1;x2,y2;...;xnod,ynod]      % vertices of the mesh
ele  =[n1,n2,n3;n1,n2,n3;...;n1,n2,n3] % mesh conectivity

例如:

coord(1,:)=[x1,y1] are the coordinates of vertex 1 of the mesh (vertex of some triangle)
coord(2,:)=[x2,y2] are the coordinates of vertex 2 of the mesh (vertex of some triangle)
etc,


ele(1,:)=[n1,n2,n3] is the number of the vertices of triangle 1
ele(2,:)=[n1,n2,n3] is the number of the vertices of triangle 2
etc.

这样,例如,

coord(ele(4,:),:)=[x1,y1;x2,y2;x3,y3]

是三角形 4 顶点的坐标 (x1,y1)、(x2,y2) 和 (x3,y3)。

我需要绘制的解是一个向量“u”,它的大小是网格的三角形数(=“elem”的行数),因为这个解在每个三角形上都是一个常数。

如何绘制这个不连续的解决方案?

1个回答

我通常使用以下方法。这个想法是制作一个新的网格,每个顶点都被复制,这样每个三角形都有自己的副本。然后您可以使用标准trisurf命令生成网格结构。

p=coord';
t=ele';
x=p(1,:);
y=p(2,:);
P=[x(t(:));y(t(:))];
T=reshape(1:size(P,2),[3 size(P,2)/3]);
% create random u for testing
u=rand(size(P,2)/3,1);
tmp=[u';u';u'];
trisurf(T',P(1,:),P(2,:),tmp(:))

在此处输入图像描述

如果你有 PDE 工具箱,还有一个内置的命令叫做pdesurf