rbmatlab 0.10.01
|
00001 function animate_basisgen(detailed_data,params) 00002 %function animate_basisgen(detailed_data,params) 00003 % 00004 % perform an animation of a 2D RB basis construction process for 00005 % grid-based approaches. i.e. the 'RB_generation_mode' in params 00006 % being 'uniform_fixed', 'uniform_refined', 'adaptive_refined' 00007 % the mesh is plotted, the colors indicating the numbers of the 00008 % basis-functions located in the parameter vertices. 00009 % Only 2 parameters, i.e. a 2D parameter grid are plotted currently 00010 % 00011 % optional fields of params: 00012 % animation_pause : number of seconds after each basis-vector addition 00013 % default is 0.1 sec. 00014 00015 % Bernard Haasdonk 29.3.2007 00016 00017 %save_avi = 1; % generate basisgen.avi 00018 save_avi = 0; % generate basisgen.avi 00019 00020 if ~isfield(params,'animation_pause') 00021 params.animation_pause = 0.05; % pause after each plot 00022 end; 00023 00024 if length(params.mu_names)~=2 00025 error('currently only 2D parameter spaces are animated!'); 00026 end; 00027 00028 params.axis_equal = 0; 00029 mu_values = detailed_data.RB_info.mu_sequence; 00030 mu_frequency = []; 00031 mesh_index_old = 0; 00032 nvertices_old = 0; 00033 vertices_old = zeros(0,2); 00034 00035 switch params.RB_generation_mode 00036 case {'refined'} 00037 mesh_index = detailed_data.RB_info.mesh_index_sequence; 00038 MMesh_sequence = detailed_data.RB_info.MMesh_list; 00039 case 'uniform_fixed' 00040 par.numintervals = params.RB_numintervals; 00041 par.range = params.mu_ranges; 00042 MMesh0 = cubegrid(par); 00043 MMesh_sequence = {MMesh0}; 00044 mesh_index = ones(1,size(mu_values,2)); 00045 otherwise 00046 error('RB_generation_mode not supported for animation.') 00047 end; 00048 00049 figure; 00050 00051 if save_avi == 1 00052 disp('generating basisgen.avi'); 00053 mov = avifile('basisgen_animat.avi'); 00054 mov.Quality = 100; 00055 mov = set(mov,'Compression','None'); 00056 frame_rep = ceil(15*params.animation_pause); 00057 end; 00058 00059 for i = 1:length(mesh_index) 00060 if isempty(find(isnan(mu_values(:,i)),1)) 00061 % get mu_frequency for current collection 00062 MMesh = MMesh_sequence{mesh_index(i)}; 00063 if (mesh_index(i)> mesh_index_old) 00064 % extend mu_frequency and check that vertices have remained the same! 00065 nvertices = get(MMesh_sequence{mesh_index(i)},'nvertices'); 00066 mu_frequency = [mu_frequency, ... 00067 zeros(1, nvertices-nvertices_old)]; 00068 vertices = get(MMesh_sequence{mesh_index(i)},'vertex'); 00069 if ~isequal(vertices(1:nvertices_old,:),vertices_old) 00070 error('grid vertices changes during refinement!'); 00071 end; 00072 vertices_old = vertices; 00073 nvertices_old = nvertices; 00074 end; 00075 % find mu_vector in vertex list 00076 epsilon = 1e-20; 00077 j = find_vector(mu_values(:,i), vertices',epsilon); 00078 if (isempty(j) || length(j)>1) 00079 error('vector not or multiply found in vertex list!!'); 00080 end; 00081 mu_frequency(j(1)) = mu_frequency(j(1)) + 1; 00082 cla; 00083 plot_leafvertex_data(MMesh,mu_frequency, params); hold on; 00084 p = plot(mu_values(1,i),mu_values(2,i),'.','Markersize',30); 00085 title([num2str(sum(mu_frequency)),' basis vectors added']); 00086 pause(params.animation_pause); 00087 xlabel(params.mu_names{1}); 00088 ylabel(params.mu_names{2}); 00089 00090 if save_avi 00091 F = getframe(gcf); 00092 for fr = 1:frame_rep 00093 mov = addframe(mov,F); 00094 end; 00095 end; 00096 else 00097 disp(['skipped animation of mu-point ',num2str(i)]); 00098 end; 00099 end; 00100 00101 if save_avi 00102 mov=close(mov); 00103 end; 00104 00105 set(p,'visible','off'); 00106 00107 00108 % TO BE ADJUSTED TO NEW SYNTAX 00109 %| \docupdate