2 %
function dune_demo_rb_gui(model,detailed_data,[reduced_data],plot_params[,title, callbackfigure, cbhandle])
3 % reduced basis demo with sliders
for a remotely running DUNE-rb server
7 % Martin Drohmann 08.02.2012
8 % Bernard Haasdonk 20.7.2006
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 if nargin < 6 % no callback,open
new figure
17 error([
'no arguments passed, cannot load a reduced basis']);
27 list{5} =
'Dune RB Demo GUI';
31 ud.descr = ud.model.descr;
32 if isa(list{2},
'IDetailedData')
33 ud.detailed_data = list{2};
36 %
if ud.model.crb_enabled
37 % ud.model.set_Mratio(ud.detailed_data, 0.5);
40 if ~isfield(ud.descr,
'is_stationary')
41 ud.descr.is_stationary = 0; % for evolution problems
44 ud.plot_params = list{4};
45 if isempty(ud.plot_params)
46 % copy some fields from model
47 if isfield(ud.descr,
'yscale_uicontrols')
48 ud.plot_params.yscale_uicontrols = ud.descr.yscale_uicontrols;
50 if isfield(ud.descr,'xscale_gui');
51 ud.plot_params.xscale_gui = ud.descr.xscale_gui;
53 if isfield(ud.descr,'clim');
54 ud.plot_params.clim = ud.descr.clim;
56 if isfield(ud.descr,'show_colorbar');
57 ud.plot_params.show_colorbar = ud.descr.show_colorbar;
60 % ud.grid = ud.detailed_data.grid;
62 disp(
'Preparing offline-quantities...')
64 ud.reduced_data = gen_reduced_data(ud.model, ud.detailed_data);
66 ud.reduced_data = list{3};
69 set(f,
'Name',list{5});
73 di = 0.05; % relative distance between gui_objects
76 yscale_uicontrols = 1.0;
79 if isfield(ud.plot_params,
'yscale_uicontrols')
80 yscale_uicontrols = ud.plot_params.yscale_uicontrols;
82 if isfield(ud.plot_params,'xscale_gui')
83 xscale_gui = ud.plot_params.xscale_gui;
87 p = get(gcf,'Position');
88 p(3) = p(3) * xscale_gui;
89 set(gcf,'Position',p);
91 % create one txt and slider for each mu_name
92 for i=1:length(ud.model.mu_names)
93 % set mu-param-values to minimum of ranges as the position of a
94 % slider does not seem to be adjustable
95 tmprange = cell2mat(ud.model.mu_ranges);
96 ud.model = set_mu(ud.model,tmprange(1:2:end));
97 mu = get_mu(ud.model);
99 ra = ud.model.mu_ranges{i};
100 norm_val = (val-ra(1))/(ra(2)-ra(1));
101 txt(i) = uicontrol(f,
'Style',
'text',
'Units',
'normalized',...
103 [di,(i*di+(i-1)*textheight)*yscale_uicontrols,...
104 textwidth,textheight*yscale_uicontrols],...
105 'String',[ud.model.mu_names{i},
'=',num2str(val)],...
106 'Tag',[
'text_',ud.model.mu_names{i}]);
107 slider(i) = uicontrol(f,
'Style',
'slider',
'Units',
'normalized',...
109 [ 2*di+textwidth, ...
110 (i*di+(i-1)*textheight)*yscale_uicontrols, ...
112 textheight*yscale_uicontrols],...
113 'Tag',[
'slider_',ud.model.mu_names{i}],...
116 'value',norm_val, ...
117 'Callback',
'dune_demo_rb_gui([],[],[],[],[], gcbf,gcbo)');
118 %
'Min',ud.model.mu_ranges{i}(1), ...
119 %
'Max',ud.model.mu_ranges{i}(2), ...
122 set(f,
'Userdata',ud);
124 % N = number of RB slider
125 i = length(ud.model.mu_names)+1;
126 txt(i) = uicontrol(f,
'Style',
'text',
'Units',
'normalized',...
128 [di,(i*di+(i-1)*textheight)*yscale_uicontrols,...
129 textwidth,textheight*yscale_uicontrols],...
130 'String',[
'RB-size N = ',num2str(get_rb_size(ud.detailed_data, ud.model))],...
132 slider(i) = uicontrol(f,
'Style',
'slider',
'Units',
'normalized',...
135 (i*di + (i-1)*textheight)*yscale_uicontrols, ...
136 1-3*di-textwidth,textheight*yscale_uicontrols],...
139 get_rb_size(ud.detailed_data, ud.model),...
140 'value',ud.model.N, ...
141 'Callback',
'dune_demo_rb_gui([],[],[],[],[],gcbf,gcbo)',...
143 [1/((get_rb_size(ud.detailed_data, ud.model))-1),0.1]);
146 % M = number of CRB slider
147 if ud.model.crb_enabled
148 i = length(ud.model.mu_names)+2;
149 txt(i) = uicontrol(f,
'Style',
'text',
'Units',
'normalized',...
151 [di,(i*di+(i-1)*textheight)*yscale_uicontrols,...
152 textwidth,textheight*yscale_uicontrols],...
153 'String',[
'CRB-size M = ',num2str(get_Mratio(ud.model,ud.detailed_data))],...
155 slider(i) = uicontrol(f,
'Style',
'slider',
'Units',
'normalized',...
158 (i*di + (i-1)*textheight)*yscale_uicontrols, ...
159 1-3*di-textwidth,textheight*yscale_uicontrols],...
161 'min',0,
'max',1,
'value',...
162 get_Mratio(ud.model,ud.detailed_data), ...
163 'Callback',
'dune_demo_rb_gui([],[],[],[],[],gcbf,gcbo)',...
164 'sliderstep',[1/100,0.1]);
165 end; %
if nonlin-evol
168 if ~ud.descr.is_stationary
169 i = i+1; %length(ud.params.mu_names)+2; % or +3
if M-slider available!
170 txt(i) = uicontrol(f,
'Style',
'text',
'Units',
'normalized',...
172 [di,(i*di+(i-1)*textheight)*yscale_uicontrols,...
173 textwidth,textheight*yscale_uicontrols],...
174 'String',
'timestep 0',
'Tag',
'text_time');
175 slider(i) = uicontrol(f,
'Style',
'slider',
'Units',
'normalized',...
178 (i*di + (i-1)*textheight)*yscale_uicontrols, ...
179 1-3*di-textwidth,textheight*yscale_uicontrols],...
180 'Tag',
'slider_time',...
181 'min',0,
'max',ud.descr.nt,
'value',0, ...
182 'Callback',
'dune_demo_rb_gui([],[],[],[],[],gcbf,gcbo)',...
183 'sliderstep',[1/ud.descr.nt,0.1]);
186 pos = [10 300 100 10];
187 ht = uicontrol(f,
'Style',
'Text',
'Position',pos);
188 string = {
'This is a string for the left text uicontrol.',...
189 'to be wrapped in Units of Pixels,',...
190 'with a position determined by TEXTWRAP.'};
191 % Wrap string, also returning a
new position
for ht
192 [outstring,newpos] = textwrap(ht,
string)
195 % set(f,'Resize','on');
198 if nargin >=6 % callback-function
201 ud =
get(cbf,
'Userdata');
202 % disp(
'performing callback call of plot_fv_data');
203 % set
new parameters in ud.params
204 tag =
get(cbo,
'Tag');
205 if isequal(tag,
'slider_time')
206 val = round(get(cbo,'value'));
207 set(cbo,'value',val);
208 % disp('check value of timestep!');
211 txt = findobj(cbf,'Tag','text_time');
212 set(txt,'String',['timestep = ',num2str(val)]);
214 elseif isequal(tag,'slider_N')
215 val = round(get(cbo,'value'));
216 set(cbo,'value',val);
218 txt = findobj(cbf,'Tag','text_N');
219 set(txt,'String',['RB-size N = ',num2str(val)]);
221 elseif isequal(tag,'slider_M')
222 val = get(cbo,'value');
223 set(cbo,'value',val);
224 ud.model.M = ceil(val * get_ei_size(ud.detailed_data.datatree));
225 txt = findobj(cbf,'Tag','text_M');
226 set(txt,'String',['CRB-size M = ',num2str(val)]);
230 for i=1:length(ud.model.mu_names)
231 if isequal(tag,['slider_',ud.model.mu_names{i}])
234 val =
get(cbo,
'value')*...
235 (ud.model.mu_ranges{i}(2)-...
236 ud.model.mu_ranges{i}(1)) + ...
237 ud.model.mu_ranges{i}(1);
239 mu = get_mu(ud.model);
241 ud.model = set_mu(ud.model,mu);
243 txt = findobj(cbf,
'Tag',[
'text_',ud.model.mu_names{i}]);
244 set(txt,
'String',[ud.model.mu_names{i},
' = ',num2str(val)]);
249 error(
'callback object unknown!!');
252 set(cbf,
'Userdata',ud);
253 replot(cbf,sourcestr);
256 function replot(f,tag)
257 ud = get(f,'Userdata');
259 enable_error_estimator = ud.model.enable_error_estimator;
261 data_reload_required = false;
262 % if required perform new RB simulation
263 if ismember(tag,{
'new',
'mu',
'N',
'M'})
264 % in our problem the two bounds can be chosen 1
265 % ud.model.descr.error_norm =
'l2';
267 data_reload_required =
true;
269 mu = get_mu(ud.model);
270 % prepare mu-independent but N-dependent online-data
271 %ud.params.N = size(ud.detailed_data.RB,2);
272 if ud.model.crb_enabled
273 disp([
'performing RB simulation with N = ',num2str(ud.model.N),...
274 ', M = ', num2str(ud.model.M),...
275 ' for mu = [',num2str(mu(:)
'),']
']);
277 disp(['performing RB simulation with N =
',num2str(ud.model.N),...
278 ' for mu = [
',num2str(mu(:)'),
']']);
280 reduced_data = extract_reduced_data_subset(ud.model,ud.reduced_data);
282 % perform RB-simulation
283 ud.model = set_mu(ud.model,mu);
285 simulation_data = rb_simulation(ud.model,reduced_data);
287 rb_sim_data = rb_reconstruction(ud.model,ud.detailed_data,simulation_data);
288 if enable_error_estimator
289 ud.Delta = ud.model.get_estimators_from_sim_data(simulation_data);
290 if isfield(simulation_data,
'reslog')
291 ud.reslog = simulation_data.reslog;
292 ud.eilog = simulation_data.eilog;
295 ud.sim_data = rb_sim_data;
296 if isfield(ud.descr,'name_output_functional')
297 ud.s = simulation_data.s;
298 if enable_error_estimator
299 ud.Delta_s = simulation_data.Delta_s;
302 if ~isfield(ud.plot_params,'clim')
303 U = ud.model.get_dofs_from_sim_data(rb_sim_data);
304 ud.cmin = min(min(U));
305 ud.cmax = max(max(U));
306 if (ud.cmin==ud.cmax)
307 ud.cmin = ud.cmin-eps;
308 ud.cmax = ud.cmax+eps;
312 ud.cmin = ud.plot_params.clim(1);
313 ud.cmax = ud.plot_params.clim(2);
315 set(f,'Userdata',ud);
319 % plot current slice;
321 if enable_error_estimator
322 disp(['error_estimator Delta(',num2str(ud.timestep),') = ',...
323 num2str(ud.Delta(ud.timestep+1))]);
324 if isfield(ud.descr,'name_output_functional')
325 disp(['output-estimator s(U(',num2str(ud.timestep),')) = ',...
326 num2str(ud.s(ud.timestep+1))]);
327 disp(['output-error-estimator Delta_s(',num2str(ud.timestep),...
328 ') = ', num2str(ud.Delta_s(ud.timestep+1))]);
330 if isfield(ud,'reslog')
331 disp(['error_estimator reslog(',num2str(ud.timestep),') = ',...
332 num2str(ud.reslog(ud.timestep+1))]);
333 disp(['error_estimator eilog(',num2str(ud.timestep),') = ',...
334 num2str(ud.eilog(ud.timestep+1))]);
337 fprintf('plotting...');
339 ud.plot_params.timestep = ud.timestep;
340 ud.plot_params.gcf = gcf;
341 ud.plot_params.reload_required = data_reload_required;
343 ud.detailed_data, ...
function dune_demo_rb_gui(varargin)
reduced basis demo with sliders for a remotely running DUNE-rb server application ...
function p = plot_sim_data(model, model_data, sim_data, plot_params)
function performing the plot of the simulation results as specified in model.