1 % script generating a tikz graphic showing trajectories
for certain
4 % required variables that need to be set:
6 % -
'detailed_data' (including RB information)
8 % -
'mu_set': a cell array of parameter vectors
for which a trajectory
10 % -
'imsavepath': a
string specifying the directory name, where to put
11 % the generated files to.
13 % optional variables that can be set:
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
24 if ~isfield(npp,
'plot_type')
25 npp.plot_type =
'patch';
27 if isequal(npp.plot_type,
'contour')
32 npp.transparent_background = 1;
33 npp.show_colorbar = 0;
34 if exist('colormap','var')
35 npp.colormap = colormap;
37 if exist('clim','var')
40 if ~exist('timeinstants','var')
41 timeinstants = [0, 1/3, 2/3, 1] * model.T;
43 tsteps = max(1,floor(timeinstants/model.T .* model.nt));
44 if ~exist('filename','var')
45 filename = ['trajectory_',model.name];
47 if ~exist('width','var')
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);
56 model.enable_error_estimator = 0;
57 reduced_data = extract_reduced_data_subset(model, reduced_data);
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)
';
64 fp = fullfile(imsavepath, params.model_type);
69 file = '\\pgfplotsset{width=6cm,compat=newest};
';
73 ymulabeloff = -0.45*yshift;
74 ytimelabel = -yshift+0.1;
75 xtimelabeloff = 0.4*xshift;
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);
83 ymulabel = (mi-1)*yshift+ymulabeloff;
85 muname = num2str(mu(1));
87 muname = [muname, ',
', num2str(mu(mni))];
90 file = [file, sprintf(['\n
',...
91 '\\draw (%scm,%scm) node [rotate=90]',...
92 '{$\\scriptstyle \\boldsymbol \\mu = (%s)$};
'], ...
93 num2str(xmulabel), num2str(ymulabel), muname)];
95 for nt=1:length(tsteps)
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) )];
102 npp.plot(model_data.grid, rb_sim_data.U(:,tsteps(nt)), npp);
103 set(gca,'PlotBoxAspectRatio
',[1 1 1]);
105 mustring = strrep(strrep(strrep(strrep(mat2str(mu),' ', '_
'),'[
',''),']
',''),'.
','p
');
106 fn = ['sample_mu_
', mustring, '_tstep_
', num2str(nt)];
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)) ];
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
'];
121 tikzparams.save_colorbar = 0;
123 xcoord = (nt-1) * xshift;
124 ycoord = (mi-1) * yshift;
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
']),...
132 tclim = plot_as_tikzfile(model, tikzparams);
139 datafn = 'sublines.dat
';
140 plot(subline_values');
141 print_datatable(fullfile(fp, datafn), subline_title, subline_values);
148 sprintf(
'%.2fcm/%.1f', (-yshift) * (i-1)/(ticks-1),...
149 (tclim(2)-tclim(1))*(i-1)/(ticks-1) + tclim(1))];
151 ytstr = [ytstr,
', '];
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)];
165 tfn = fullfile(fp, [filename,'.tikz
']);
166 fid = fopen(tfn, 'w+
');
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
',...
191 ' \\end{tikzpicture}\n
',...
192 '\\end{document}\n
'],tfn);
function [ opt_data , model ] = optimize(model, model_data, detailed_data, reduced_data)
opt_data = optimize(model, model_data, detailed_data, reduced_data)