rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
step10_plot_trajectories.m
Go to the documentation of this file.
1 % script generating a tikz graphic showing trajectories for certain
2 % selected parameters
3 %
4 % required variables that need to be set:
5 % - 'model'
6 % - 'detailed_data' (including RB information)
7 % - 'plot_params'
8 % - 'mu_set': a cell array of parameter vectors for which a trajectory
9 % shall be generated.
10 % - 'imsavepath': a string specifying the directory name, where to put
11 % the generated files to.
12 %
13 % optional variables that can be set:
14 % - 'colormap'
15 % - 'clim'
16 % - 'timeinstants': time instants to include into trajectory. Default is
17 % '[ 0, 1/3, 2/3, 1 ] * model.T'
18 % - 'filename': file name for the trajectory
19 % - 'width': width of single snapshot. Default is 5cm;
20 % - 'boxed_snapshots': if set to 'true' snapshots are surrounded by a box
21 
22 % optimize plot_params
23 npp = plot_params;
24 if ~isfield(npp, 'plot_type')
25  npp.plot_type = 'patch';
26 end
27 if isequal(npp.plot_type, 'contour')
28  npp.no_lines = 0;
29 end
30 npp.no_axes = 1;
31 npp.axes_equal = 1;
32 npp.transparent_background = 1;
33 npp.show_colorbar = 0;
34 if exist('colormap','var')
35  npp.colormap = colormap;
36 end
37 if exist('clim','var')
38  npp.clim = clim;
39 end
40 if ~exist('timeinstants','var')
41  timeinstants = [0, 1/3, 2/3, 1] * model.T;
42 end
43 tsteps = max(1,floor(timeinstants/model.T .* model.nt));
44 if ~exist('filename','var')
45  filename = ['trajectory_',model.name];
46 end
47 if ~exist('width','var')
48  width = 3;
49 end
50 
51 % generate reduced_data
52 reduced_data = gen_reduced_data(model, detailed_data);
53 model.N = size(detailed_data.RB,2);
54 model.M = cellfun(@(X)size(X,2), detailed_data.QM,'UniformOutput', true);
55 model.Mstrich = 0;
56 model.enable_error_estimator = 0;
57 reduced_data = extract_reduced_data_subset(model, reduced_data);
58 
59 subline = find(detailed_data.grid.CY > 0.6 ...
60  & detailed_data.grid.CY < 0.6+detailed_data.grid.hmin);
61 subline_title = {'X'};
62 subline_values = detailed_data.grid.CX(subline)';
63 
64 fp = fullfile(imsavepath, params.model_type);
65 if ~exist(fp, 'dir')
66  mkdir(fp);
67 end
68 
69 file = '\\pgfplotsset{width=6cm,compat=newest};';
70 xmulabel = -0.3;
71 xshift = width+0.2;
72 yshift = -width-0.2;
73 ymulabeloff = -0.45*yshift;
74 ytimelabel = -yshift+0.1;
75 xtimelabeloff = 0.4*xshift;
76 
77 for mi=1:length(mu_set)
78  newmodel = model.set_mu(model, mu_set{mi});
79  newmodel.newton_epsilon=1e-9;
80  rb_sim_data = rb_simulation(newmodel, reduced_data);
81  rb_sim_data = rb_reconstruction(newmodel, detailed_data, rb_sim_data);
82 
83  ymulabel = (mi-1)*yshift+ymulabeloff;
84  mu = mu_set{mi};
85  muname = num2str(mu(1));
86  for mni=2:length(mu);
87  muname = [muname, ', ', num2str(mu(mni))];
88  end
89 
90  file = [file, sprintf(['\n',...
91  '\\draw (%scm,%scm) node [rotate=90]',...
92  '{$\\scriptstyle \\boldsymbol \\mu = (%s)$};'], ...
93  num2str(xmulabel), num2str(ymulabel), muname)];
94 
95  for nt=1:length(tsteps)
96  if mi == 1
97  xtimelabel = (nt-1)*xshift+xtimelabeloff;
98  file = [file, sprintf(['\n',...
99  '\\draw (%scm,%scm) node {$\\scriptstyle t = %.3f$};'], ...
100  num2str(xtimelabel), num2str(ytimelabel), timeinstants(nt) )];
101  end
102  npp.plot(model_data.grid, rb_sim_data.U(:,tsteps(nt)), npp);
103  set(gca,'PlotBoxAspectRatio',[1 1 1]);
104 
105  mustring = strrep(strrep(strrep(strrep(mat2str(mu),' ', '_'),'[',''),']',''),'.','p');
106  fn = ['sample_mu_', mustring, '_tstep_', num2str(nt)];
107 
108  Uline = rb_sim_data.U(subline,tsteps(nt));
109  subline_title = [ subline_title, [mustring,'_t_',num2str(nt) ] ];
110  subline_values = [ subline_values; reshape(Uline, 1, length(Uline)) ];
111 
112  disp(['Processing ', fn, '...']);
113  tikzparams.filename = fn;
114  tikzparams.filepath = fp;
115  tikzparams.width = width;
116  tikzparams.print_axes = 0;
117  if(nt == 1 && (mi == 1 || ~exist('clim', 'var')))
118  tikzparams.save_colorbar = 1;
119  cbfn = [fn,'colorbar'];
120  else
121  tikzparams.save_colorbar = 0;
122  end
123  xcoord = (nt-1) * xshift;
124  ycoord = (mi-1) * yshift;
125 
126  file = [file, sprintf(['\n\n',...
127  '\\begin{scope}[xshift=%scm,yshift=%scm]\n',...
128  ' \\input{%s}\n'],...
129  num2str(xcoord), num2str(ycoord), [fn, '.tikz']),...
130  '\end{scope}'];
131 
132  tclim = plot_as_tikzfile(model, tikzparams);
133  close(gcf);
134  pause(1);
135  end
136 
137 end
138 
139 datafn = 'sublines.dat';
140 plot(subline_values');
141 print_datatable(fullfile(fp, datafn), subline_title, subline_values);
142 
143 % colorbar
144 ytstr = '';
145 ticks = 5;
146 for i = 1:ticks
147  ytstr = [ytstr, ...
148  sprintf('%.2fcm/%.1f', (-yshift) * (i-1)/(ticks-1),...
149  (tclim(2)-tclim(1))*(i-1)/(ticks-1) + tclim(1))];
150  if i ~= ticks
151  ytstr = [ytstr, ', '];
152  end
153 end
154 file = [file, sprintf(['\n',...
155  '\\begin{scope}[xshift=%scm,yshift=%scm]\n',...
156  ' \\pgfdeclareimage[width=%scm,height=%scm]{colorbar}{%s}\n',...
157  ' \\pgftext[at=\\pgfpoint{0}{0},left,base]{\\pgfuseimage{colorbar}};\n',...
158  ' \\foreach \\y/\\ytext in {%s}\n', ...
159  ' \\draw[shift={(0,\\y)}] (1pt,0pt) -- (-1pt,0pt) node[left] (coordsy) {${\\scriptscriptstyle \\ytext}$};\n', ...
160  '\\end{scope}\n']',...
161  num2str(nt*xshift+1), num2str((mi-1)/2*yshift),...
162  num2str(0.2),num2str(-yshift),cbfn,ytstr)];
163 disp(cbfn);
164 
165 tfn = fullfile(fp, [filename,'.tikz']);
166 fid = fopen(tfn, 'w+');
167 fwrite(fid,file);
168 fclose(fid);
169 
170 tfntex = fullfile(fp, [filename,'_out.tex']);
171 fid = fopen(tfntex, 'w+');
172 fprintf(fid, ['\\documentclass[a4paper,11pt]{article}\n',...
173  '\\usepackage[x11names,rgb]{xcolor}\n',...
174  '\\usepackage{tikz,pgfplots}\n',...
175  '\\pgfplotsset{plot coordinates/math parser=false}\n',...
176  '\\usepackage{amsfonts}\n',...
177  '\\usepackage{amsmath}\n',...
178  '\\usetikzlibrary{arrows,snakes,shapes,decorations.pathmorphing,backgrounds,fit}\n',...
179  '\\usepackage[active,tightpage]{preview}\n',...
180  '\\PreviewEnvironment{tikzpicture}\n',...
181  '\\oddsidemargin -10mm\n',...
182  '\\evensidemargin -10mm\n',...
183  '\\topmargin 5mm\n',...
184  '\\headheight 0mm\n',...
185  '\\headsep 0mm\n',...
186  '\\textheight 247mm\n',...
187  '\\textwidth 160mm\n',...
188  '\\begin{document}\n',...
189  ' \\begin{tikzpicture}[scale=0.5]\n',...
190  ' \\input{%s}\n',...
191  ' \\end{tikzpicture}\n',...
192  '\\end{document}\n'],tfn);
193 fclose(fid);
194 
195 
196 
function [ opt_data , model ] = optimize(model, model_data, detailed_data, reduced_data)
opt_data = optimize(model, model_data, detailed_data, reduced_data)
Definition: optimize.m:17