-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmeshToyProblem.m
More file actions
56 lines (49 loc) · 1.4 KB
/
meshToyProblem.m
File metadata and controls
56 lines (49 loc) · 1.4 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
51
52
53
54
55
56
clear; clc; close all;
addpath tests; % The ToyNode class is located here
bounds = [-1, 1, -1, 1];
templateNode = ToyNode();
%% Create the mesh and refine it
mapMesh = adaptiveMesh.Mesh();
mapMesh.setMinCellSize([1e-2, 1e-2]);
mapMesh.initMesh(bounds, templateNode);
mapMesh.refine();
%% Extract data
keys = fieldnames(mapMesh.nodeMap);
N = length(keys);
meshData = struct();
meshData.pos = zeros(N,2);
meshData.metric = zeros(N,1);
for r = 1:N
meshData.pos(r,:) = mapMesh.nodeMap.(keys{r}).state;
meshData.metric(r) = mapMesh.nodeMap.(keys{r}).getMetric();
end
%% Plot Results
colors = lines(length(unique(meshData.metric)));
hFig = figure(); hold on;
colormap(colors);
keys = fieldnames(mapMesh.cellMap);
for c = 1:length(keys)
% Plot cells
cell = mapMesh.cellMap.(keys{c});
if(~cell.isSubdivided)
rectangle('position', [cell.position, cell.size],...
'edgeColor', 'k', 'linewidth', 0.5);
end
end
% Plot the nodes, colored by their metric
scatter(meshData.pos(:,1), meshData.pos(:,2), 16, meshData.metric, 'filled');
hold off; grid on; axis equal;
xlabel('x');
ylabel('y');
hcb = colorbar;
caxis([-0.5, 1.5]);
set(hcb, 'ticks', [0, 1]);
%% Plot the mesh as an image
figure();
colormap(colors);
hcb = colorbar;
caxis([-0.5, 1.5]);
[xData, yData, CData] = mapMesh.toImage();
image(xData, yData, CData, 'CDataMapping', 'scaled');
axis equal;
set(gca, 'XDir', 'normal', 'YDir', 'normal');