1 function plot_trajectories(rmodel, detailed_data, plot_params, mu_set, imsavepath, plot_name, opts)
2 %
function plot_trajectories(rmodel, detailed_data, plot_params, mu_set, imsavepath, plot_name, opts)
3 %
function generating a tikz graphic showing trajectories
for certain selected
7 % plot_params: a structure coming with a field
'plot' for plotting
8 % mu_set: a cell array of parameter vectors
for which a trajectory shall
10 % imsavepath: a
string specifying the directory name, where the generated
12 % plot_name: a
string naming
this plot.
13 % opts: optional settings.
15 % optional fields of opts:
16 %
'timeinstants': time instants to include into trajectory. Default is
17 %
'[ 0, 1/3, 2/3, 1 ] * model.T'
18 %
'width': width of single snapshot. Default is 5cm;
19 %
'subline_coord': coordinate at which a subline plot shall be created
20 %
'subline_dir': either
'x' or
'y' specifying the direction of the subline plot.
21 %
'sim_type': simulation type (either
'reduced' or
'detailed')
26 if ~isfield(plot_params,
'plot_type')
27 plot_params.plot_type = 'patch';
29 if isequal(plot_params.plot_type, 'contour')
30 plot_params.no_lines = 0;
32 plot_params.no_axes = 1;
33 plot_params.axes_equal = 1;
34 plot_params.transparent_background = 1;
35 plot_params.show_colorbar = 0;
36 if isfield(opts, 'timeinstants')
37 timeinstants = opts.timeinstants;
39 timeinstants = [0, 1/3, 2/3, 1] * rmodel.descr.T;
41 if ~isfield(opts, 'field')
42 opts.field = @(sim_data, model_data, t) sim_data.U(:,t);
45 if isfield(opts, 'sim_type')
46 sim_type = opts.sim_type;
51 tsteps = max(1,floor(timeinstants/rmodel.descr.T .* rmodel.nt));
53 if isfield(opts, 'width')
59 if isfield(opts, 'pic_scale')
60 picscale = opts.pic_scale;
65 if isfield(opts, 'subline_coord')
71 % generate reduced_data
72 reduced_data = gen_reduced_data(rmodel, detailed_data);
74 % disable error estimator
76 rmodel.enable_error_estimator = 0;
78 reduced_data = extract_reduced_data_subset(rmodel, reduced_data);
81 g = detailed_data.model_data.grid;
82 if isequal(opts.subline_dir, 'x')
83 subline = find(g.CY > opts.subline_coord ...
84 & g.CY < opts.subline_coord+g.hmin);
85 subline_title = {
'X'};
86 elseif isequal(opts.subline_dir,
'y')
87 subline = find(g.CY > opts.subline_coord ...
88 & g.CY < opts.subline_coord+g.hmin);
89 subline_title = {
'Y'};
91 subline_values = g.CX(subline)
';
94 if ~exist(imsavepath, 'dir
')
98 sample_dir_name = [plot_name, '_data
'];
99 sample_dir_path = fullfile(imsavepath, sample_dir_name);
100 if ~exist(sample_dir_path, 'dir
')
101 mkdir(sample_dir_path);
104 file = '\\pgfplotsset{width=6cm,compat=newest};
';
109 for mi=1:length(mu_set)
110 set_mu(rmodel, mu_set{mi});
111 set_mu(rmodel.detailed_model, mu_set{mi});
112 % newmodel.newton_epsilon = 1e-9;
114 if isequal(sim_type, 'reduced
')
115 rb_sim_data = rb_simulation(rmodel, reduced_data);
116 rb_sim_data = rb_reconstruction(rmodel, detailed_data, rb_sim_data);
118 rb_sim_data = detailed_simulation(rmodel.detailed_model, detailed_data.model_data);
123 mustring = strrep(strrep(strrep(strrep(mat2str(mu),' ', '_
'),'[
',''),']
',''),'.
','p
');
125 for nt=1:length(tsteps)
127 fn = [plot_name, '_mu_
', mustring, '_tstep_
', num2str(nt)];
129 disp(['Processing
', fn, '...
']);
131 file = add_to_tikzfile(file, plot_name, xshift, yshift, mi, mu, fn, nt, timeinstants(nt));
134 set(f, 'Visible
', 'off
');
135 U = opts.field(rb_sim_data, detailed_data.model_data, tsteps(nt));
136 plot_params.plot(detailed_data.model_data.grid, U, plot_params);
137 set(gca,'PlotBoxAspectRatio
',[1 1 1]);
141 subline_title = [ subline_title, [mustring,'_t_
',num2str(nt) ] ];
142 subline_values = [ subline_values; reshape(Uline, 1, length(Uline)) ];
145 tikzparams.filename = fn;
146 tikzparams.filepath = sample_dir_path;
147 tikzparams.relpath = fullfile(['\
', plot_name, 'TrajRelpath
'], [plot_name, '_data
']);
148 tikzparams.width = width;
149 tikzparams.print_axes = 0;
150 tikzparams.pic_scale = picscale;
151 if(nt == 1 && (mi == 1 || ~isfield(plot_params, 'clim
')))
152 tikzparams.save_colorbar = 1;
153 cbfn = [fn,'colorbar
'];
155 tikzparams.save_colorbar = 0;
159 tclim = Postprocess.plot_as_tikzfile(tikzparams);
161 if verLessThan('matlab
', '7.6.1
')
166 colorbar_xshift = nt*xshift+1;
167 colorbar_yshift = (mi-1)/2*yshift;
168 file = create_colorbar_file(file, plot_name, colorbar_xshift, colorbar_yshift, 0.2, width+0.2, 5, tclim, imsavepath, cbfn);
172 datafn = [plot_name, 'sublines.dat
'];
174 plot(subline_values(1,:), subline_values(2:end,:));
175 print_datatable(fullfile(imsavepath, datafn), subline_title, subline_values);
179 tfn = fullfile(imsavepath, [plot_name,'_illustration.tikz
']);
180 fid = fopen(tfn, 'w
');
184 relpathcmd = ['\
', plot_name, 'TrajRelpath
'];
185 tfntex = fullfile(imsavepath, [plot_name,'illustration_out.tex
']);
186 fid = fopen(tfntex, 'w
');
187 fprintf(fid, ['\\documentclass[a4paper,11pt]{article}\n
',...
188 '\\usepackage[x11names,rgb]{xcolor}\n
',...
189 '\\usepackage{tikz,pgfplots}\n
',...
190 '\\pgfplotsset{plot coordinates/math parser=
false}\n
',...
191 '\\usepackage{amsfonts}\n
',...
192 '\\usepackage{amsmath}\n
',...
193 '\\usetikzlibrary{arrows,snakes,shapes,decorations.pathmorphing,backgrounds,fit}\n
',...
194 '\\usepackage[active,tightpage]{preview}\n
',...
195 '\\PreviewEnvironment{tikzpicture}\n
',...
196 '\\oddsidemargin -10mm\n
',...
197 '\\evensidemargin -10mm\n
',...
198 '\\topmargin 5mm\n
',...
199 '\\headheight 0mm\n
',...
200 '\\headsep 0mm\n
',...
201 '\\textheight 247mm\n
',...
202 '\\textwidth 160mm\n
',...
203 '\\begin{document}\n
',...
204 ' \\newcommand{%s}{./}\n
', ...
205 ' \\begin{tikzpicture}[scale=0.5]\n
',...
207 ' \\end{tikzpicture}\n
',...
208 '\\end{document}\n
'],relpathcmd, tfn);
213 function file = create_colorbar_file(file, plot_name, xshift, yshift, cwidth, cheight, ticks, tclim, cbfp, cbfn)
217 sample_dir_name = [plot_name, '_data
'];
218 relpathcmd = ['\
', plot_name, 'TrajRelpath
'];
222 sprintf('%.2fcm/%.1f
', (cheight) * (i-1)/(ticks-1),...
223 (tclim(2)-tclim(1))*(i-1)/(ticks-1) + tclim(1))];
225 ytstr = [ytstr, ',
'];
229 cbfrel = fullfile(relpathcmd, sample_dir_name, cbfn);
230 outfrel = fullfile(sample_dir_name, [cbfn, '.tikz
']);
231 outfn = fullfile(cbfp, sample_dir_name, [cbfn, '.tikz
']);
233 cfid = fopen(outfn, 'w
');
234 fprintf(cfid, [' \\pgfdeclareimage[width=%scm,height=%scm]{colorbar}{%s}\n
',...
235 ' \\pgftext[at=\\pgfpoint{0}{0},left,base]{\\pgfuseimage{colorbar}};\n
',...
236 ' \\foreach \\y/\\ytext in {%s}\n
', ...
237 ' \\draw[shift={(0,\\y)}] (1pt,0pt) -- (-1pt,0pt) node[left] (coordsy) {${\\scriptscriptstyle \\ytext}$};\n
'], ...
238 num2str(cwidth), num2str(cheight), cbfrel, ytstr);
241 file = [file, sprintf(['\n
',...
242 '\\begin{scope}[xshift=%scm,yshift=%scm]\n
',...
244 '\\end{scope}\n
']',...
245 num2str(xshift), num2str(yshift), outfrel)] ;
248 function file = add_to_tikzfile(file, plot_name, xshift, yshift, mi, mu, mufn, nt, ti)
250 sample_dir_name = [plot_name, '_data'];
251 mufnrel = fullfile(sample_dir_name, mufn);
254 ymulabeloff = -0.45*yshift;
255 ytimelabel = -yshift+0.1;
256 xtimelabeloff = 0.4*xshift;
259 ymulabel = (mi-1)*yshift+ymulabeloff;
260 muname = num2str(mu(1));
261 for mni=2:length(mu);
262 muname = [muname, ', ', num2str(mu(mni))];
265 file = [file, sprintf(['\n',...
266 '\\draw (%scm,%scm) node [rotate=90]',...
267 '{$\\scriptstyle \\boldsymbol \\mu = (%s)$};
'], ...
268 num2str(xmulabel), num2str(ymulabel), muname)];
271 xtimelabel = (nt-1)*xshift+xtimelabeloff;
272 file = [file, sprintf(['\n
',...
273 '\\draw (%scm,%scm) node {$\\scriptstyle t = %.3f$};
'], ...
274 num2str(xtimelabel), num2str(ytimelabel), ti )];
277 xcoord = (nt-1) * xshift;
278 ycoord = (mi-1) * yshift;
280 file = [file, sprintf(['\n\n
',...
281 '\\begin{scope}[xshift=%scm,yshift=%scm]\n
',...
282 ' \\input{%s}\n
'],...
283 num2str(xcoord), num2str(ycoord), [mufnrel, '.tikz
']),...
function plot_trajectories(IReducedModel rmodel,IDetailedData detailed_data, plot_params, mu_set, imsavepath, plot_name, opts)
function generating a tikz graphic showing trajectories for certain selected parameters ...
function [ opt_data , model ] = optimize(model, model_data, detailed_data, reduced_data)
opt_data = optimize(model, model_data, detailed_data, reduced_data)