jacobi.template
square_bb_4.m
Go to the documentation of this file.
1 % Square:
2 % flatpak run org.octave.Octave <filename>
3 % or
4 % octave --no-window-system --no-gui -qf <filename>
5 
6 clear all
7 clc
8 % %% L-shape
9 % g=[2 0 2 0 0 1 0; % #vertices,v_1x, v_2x, v_1y, v_2y, subdomain_left, subdomain_right
10 % 2 2 2 0 1 1 0;
11 % 2 2 1 1 0.5 1 0;
12 % 2 1 1 0.5 2 1 0;
13 % 2 1 0 2 2 1 0;
14 % 2 0 0 2 0 1 0]';
15 
16 %% square
17 % g=[2 0 1 0 0 1 0; % #vertices,v_1x, v_2x, v_1y, v_2y, subdomain_left, subdomain_right
18 % 2 1 1 0 1 1 0;
19 % 2 1 0 1 1 1 0;
20 % 2 0 0 1 0 1 0]';
21 
22 % %% 2 squares
23 % g=[2 0 1 0 0 1 0; % 1 #vertices,v_1x, v_2x, v_1y, v_2y, subdomain_left, subdomain_right
24 % 2 1 1 0 1 1 2;
25 % 2 1 0 1 1 1 0;
26 % 2 0 0 1 0 1 0;
27 % 2 1 2 0 0 2 0; % 2 #vertices,v_1x, v_2x, v_1y, v_2y, subdomain_left, subdomain_right
28 % 2 2 2 0 1 2 0;
29 % 2 2 1 1 1 2 0
30 % ]';
31 
32 %% 4 squares
33 g=[2 0 1 0 0 1 0; % 1 #vertices,v_1x, v_2x, v_1y, v_2y, subdomain_left, subdomain_right
34  2 1 1 0 1 1 2;
35  2 1 0 1 1 1 3;
36  2 0 0 1 0 1 0;
37  2 1 2 0 0 2 0; % 2 #vertices,v_1x, v_2x, v_1y, v_2y, subdomain_left, subdomain_right
38  2 2 2 0 1 2 0;
39  2 2 1 1 1 2 4;
40 % 2 1 1 1 0 2 1;
41 % 2 0 1 1 1 3 1; % 3 #vertices,v_1x, v_2x, v_1y, v_2y, subdomain_left, subdomain_right
42  2 1 1 1 2 3 4;
43  2 1 0 2 2 3 0;
44  2 0 0 2 1 3 0;
45 % 2 1 2 1 1 4 2; % 4 #vertices,v_1x, v_2x, v_1y, v_2y, subdomain_left, subdomain_right
46  2 2 2 1 2 4 0;
47  2 2 1 2 2 4 0
48 % 2 1 1 2 1 4 3
49  ]';
50 
51 %% Generate mesh from geometry
52 %
53 [p,e,t] = initmesh(g,'hmax',1); % works correctly
54 % p(1,15) = 1.51; %% angle in trangle > pi/2 ==> now the second refinement produces irregular meshes!
55 % p(1,15) = 1.7; %% angle in trangle > pi/2 ==> now the second refinement produces irregular meshes!
56 
57 % ??
58 % https://de.mathworks.com/help/pde/ug/mesh-data-pet-triples.html
59 % generateMesh(...)
60 % mesh2Pet(...)
61 %
62 % [p,e,t] = initmesh(g); % problems in solution after 2 refinements
63 % [p,e,t] = initmesh(g,'hmax',0.5); % problems in solution after 2 refinements (peaks with h=0.5, oscillations in (1,1) for h=0.1
64 % [p,e,t] = initmesh(g,'hmax',0.1/4); % no problems in solution with 0 refinemnet steps
65 
66 %% Show mesh
67 pdemesh(p,e,t)
68 % pdemesh(p,e,t,'NodeLabels','on')
69 
70 %% Improve mesh
71 % min(pdetriq(p,t))
72 % p = jigglemesh(p,e,t,'opt','minimum','iter',inf);
73 % min(pdetriq(p,t))
74 % pdemesh(p,e,t)
75 
76 %% Refine mesh, see comments in "Generate mesh from geometry"
77 %
78 % nrefine=8;
79 nrefine=2; %
80 for k=1:nrefine
81  [p,e,t] = refinemesh(g,p,e,t);
82 % p = jigglemesh(p,e,t,'opt','minimum','iter',inf); % improve mesh
83  min(pdetriq(p,t))
84  fprintf('refinement: %i nodes: %i triangles: %i \n', k, size(p,2), size(t,2))
85 end
86 % figure; pdemesh(p,e,t,'NodeLabels','on')
87 %
88 
89 %% GH
90 % output from <https://de.mathworks.com/help/pde/ug/initmesh.html initmesh>
91 %
92 % coordinates p: [2][nnode]
93 % connectivity t: [4][nelem] with t(4,:) are the subdomain numbers
94 % edges e: [7][nedges] boundary edges
95 % e([1,2],:) - start/end vertex of edge
96 % e([3,4],:) - start/end values
97 % e(5,:) - segment number
98 % e([6,7],:) - left/right subdomain
99 
100 ascii_write_mesh( p, t, e, mfilename);
101 
102 ascii_write_subdomains( p, t, e, mfilename);
103 
104 
105 % tmp=t(1:3,:)
106 
end
end
Definition: visualize_par_results.m:9
tmp
tmp(:,:).'
refinements
problems in solution after refinements[p, e, t]
Definition: square_bb_4.m:63
h
h
Definition: visualize_par_results.m:47
e
angle in trangle e
Definition: square_bb_4.m:62
p
works correctly p(1, 15)
ascii_write_subdomains
function ascii_write_subdomains(xc, ia, e, basename) % % Saves the 2D triangular mesh in the minimal way(only coordinates
pi
angle in trangle pi
Definition: square_bb_4.m:54
connectivity
function vertex connectivity
Definition: ascii_write_mesh.m:3
g
square g
Definition: square_bb_4.m:17
ascii_write_mesh
function ascii_write_mesh(xc, ia, e, basename) % % Saves the 2D triangular mesh in the minimal way(only coordinates
t
angle in trangle t
Definition: square_bb_4.m:62
fprintf
fprintf('Read file %s\n', fname) % Read mesh const ants nn
geometry
Generate mesh from geometry[p, e, t]
Definition: square_bb_4.m:53
size
e, 2 size()
nnode
function vertex minimal boundary edge info in an ASCII file Matlab indexing is stored(starts with 1). % % The output file format is compatible with Mesh_2d_3_matlab nnode
Definition: ascii_write_mesh.m:23
nelem
nelem
Definition: ascii_read_meshvector.m:24