-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChangeP1toP2Mesh.m
More file actions
50 lines (48 loc) · 1.2 KB
/
ChangeP1toP2Mesh.m
File metadata and controls
50 lines (48 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function [p,t] = ChangeP1toP2Mesh(p,t)
%
% Input: p: nodes
% t: index of node
% Each triangle is described by three points.
% Output: p: nodes
% t: index of node
% Each triangle is described by six points.
%
% y
% |
% |
% |
% 3
% |\
% | \
% 6 \5
% | \
% |________\ ________x
% 1 4 2
%
% ex:
% p = [0,0; 1,0; 0,1]';
% t = [1;2;3;1];
% p = [0,0; 1,0; 0,1; 1/2,0; 1/2,1/2; 0,1/2];
% t = [1;2;3;4;5;6];
%
np=size(p,2); % number of nodes
edges=Tri2Edge(p,t); % get element edge numbers
edges=edges+np; % change edges to new nodes
i=t(1,:); j=t(2,:); k=t(3,:);
e=edges(:,1);
p(1,e)=0.5*(p(1,j)+p(1,k));
p(2,e)=0.5*(p(2,j)+p(2,k));
e=edges(:,2);
p(1,e)=0.5*(p(1,i)+p(1,k));
p(2,e)=0.5*(p(2,i)+p(2,k));
e=edges(:,3);
% edge node coordinates
p(1,e)=0.5*(p(1,i)+p(1,j));
p(2,e)=0.5*(p(2,i)+p(2,j));
% t(7,:)=t(4,:); % move subdomain info, resize t
t(4:6,:)=edges'; % insert edge nodes into t
tt = t;
t(4,:) = tt(6,:);
t(5,:) = tt(4,:);
t(6,:) = tt(5,:);
end