Debian Codegraph @

packages/rol/example/PDE-OPT/dynamic/navier-stokes/plotControl.m

raw
1
2 function plotControl(type)
3
4 if (type == 1)
5 %nt = numel(dir('control.*.txt')); %% determine number of time steps
6 %Z = zeros(nt,1);
7 %for i = 0:nt-1
8 % state = load(['control.',int2str(i),'.txt']);
9 % Z(i+1) = state(1);
10 %end
11 Z = load('control.txt');
12 nt = numel(Z);
13 T = linspace(0,1,nt);
14
15 axsize = 400;
16 figure('Position', [100 100 4*axsize 4*axsize]);
17 plot(T,Z,'linewidth',2)
18 axis('square','tight');
19 xlabel('t');
20 ylabel('z');
21 set(gca, 'FontSize', 16); set(gcf, 'Color', 'White');% tightfig;
22
23 print('-depsc2','control.eps');
24 else
25 adj = load('cell_to_node_quad.txt') + 1; %% load node adjacency, increment by 1 for 1-based indexing
26 nodes = load('nodes.txt'); %% load node coordinates
27 N = 3*length(nodes); %% determine number of nodes
28 nt = numel(dir('control.*.txt')); %% determine number of time steps
29
30 %% Read in state
31 Ux = cell(nt,1);
32 Uy = cell(nt,1);
33 for i = 0:nt-1
34 data_obj = importdata(['control.',int2str(i),'.txt'], ' ', 2); %% we need to skip the first two lines
35 state = data_obj.data;
36 data_obj = importdata(['map_control.',int2str(i),'.txt'], ' ', 9); %% we need to skip the first 9 lines
37 map_state = data_obj.data;
38 map_state = map_state(1:2:end)+1;
39 [tmp, state_permute] = sort(map_state);
40 state = state(state_permute); %% we need to permute the state according to parallel maps
41
42 Ux{i+1} = state(1:3:N); %% Extract x-velocity
43 Uy{i+1} = state(2:3:N); %% Extract y-velocity
44 end
45
46 axsize = 400;
47 figure('Position', [100 100 4*axsize 4*axsize]);
48 for i=1:nt-1
49 quiver(nodes(:,1), nodes(:,2), Ux{i+1}, Uy{i+1});
50 axis('equal','tight');
51 xlim([-5,-3]);
52 xlabel('x');
53 ylabel('y');
54 title(['Time/T = ',num2str(i/(nt-1))],'fontsize',16);
55 set(gca, 'FontSize', 16); set(gcf, 'Color', 'White');% tightfig;
56
57 drawnow
58 end
59 end