function dispespicWell(M,logdensity,showgrid,fixed) %dispespicFields Allows to display the time evolution of the density, electric potential and electric fields % M is of class espic2dhdf5 and contains the simulation results fieldstep=1; if nargin <2 logdensity=false; showgrid=false; fixed=false; end if nargin <3 showgrid=false; fixed=false; end if nargin <4 fixed=false; end fixed=fi(fixed); f=uifigure('Name',sprintf('Well data %s',M.name)); mf=uipanel(f,'Position',[5 50 f.Position(3)-10 f.Position(4)-55]); mf.AutoResizeChildren='off'; m=uipanel(f,'Position',[5 5 f.Position(3)-10 40]); sgtitle(mf,sprintf('step=%d t=%0.5e s',fieldstep*M.it1,M.t2d(fieldstep))) sld = uislider(m,'Position',[10 30 0.6*m.Position(3) 3]); sld.Value=fieldstep; sld.Limits=[1 size(M.t2d,1)]; edt = uieditfield(m,'numeric','Limits',[1 size(M.t2d,1)],'Value',1); edt.Position=[sld.Position(1)+sld.Position(3)+25 5 40 20]; edt.RoundFractionalValues='on'; MaxN=0; Minwell=0; Maxwell=0; plotaxes=gobjects(2); Printbt=uibutton(m,'Position',[edt.Position(1)+edt.Position(3)+10 5 40 20],'Text', 'Save'); Play=uibutton(m,'Position',[Printbt.Position(1)+Printbt.Position(3)+10 5 40 20],'Text', 'Play'); Pause=uibutton(m,'Position',[Play.Position(1)+Play.Position(3)+10 5 40 20],'Text', 'Pause'); %Playbt=uibutton(m,'Position',[Printbt.Position(1)+Printbt.Position(3)+10 5 40 20],'Text', 'Play/Pause'); stop=false; sld.ValueChangingFcn={@updatefigdata,edt,mf}; edt.ValueChangedFcn={@updatefigdata,sld,mf}; Printbt.ButtonPushedFcn={@plotGridButtonPushed}; Play.ButtonPushedFcn={@plotPlayButtonPushed}; Pause.ButtonPushedFcn={@PauseButtonPushed}; PlotEspic2dgriddata(mf,M,fieldstep); function plotPlayButtonPushed(btn,ax) stop=false; for i=edt.Value:sld.Limits(2) edt.Value=i; sld.Value=i; updatesubplotsdata(i,mf); pause(0.01) if stop stop=false; break; end end end function PauseButtonPushed(btn,ax) stop = true; end function PlotEspic2dgriddata(fig,M,fieldstep) %PlotEspic2dgriddata Plot the 2d data of espic2d at time step fieldstep sgtitle(fig,sprintf('step=%d t=%0.5e s',(fieldstep-1)*M.it1,M.t2d(fieldstep))) plotaxes(1)=subplot(1,2,1,'Parent',fig); sf=surface(plotaxes(1),M.zgrid,M.rgrid,M.N(:,:,fieldstep),'edgecolor','none'); if(showgrid) set(sf,'edgecolor','black') end xlim(plotaxes(1),[M.zgrid(1) M.zgrid(end)]) ylim(plotaxes(1),[M.rgrid(1) M.rgrid(end)]) xlabel(plotaxes(1),'z [m]') ylabel(plotaxes(1),'r [m]') title(plotaxes(1),'Density') c = colorbar(plotaxes(1)); c.Label.String= 'n[m^{-3}]'; %c.Limits=[0 max(M.N(:))]; if(isboolean(fixed) && fixed) climits=caxis(plotaxes(1)); MaxN=climits(2); elseif(~isboolean(fixed)) MaxN=fixed.data; caxis(plotaxes(1),[-Inf MaxN]); end view(plotaxes(1),2) if logdensity set(plotaxes(1),'zscale','log') set(plotaxes(1),'colorscale','log') end plotaxes(2)=subplot(1,2,2,'Parent',fig); well=-PotentialWell(M.pot(:,:,fieldstep),M.Athet(:,:),M.rgrid,M.zgrid,false); sf=surface(plotaxes(2),M.zgrid(2:end),M.rgrid(2:end),well(2:end,2:end),'edgecolor','none'); if(showgrid) set(sf,'edgecolor','black') end xlim(plotaxes(2),[M.zgrid(1) M.zgrid(end)]) ylim(plotaxes(2),[M.rgrid(1) M.rgrid(end)]) xlabel(plotaxes(2),'z [m]') ylabel(plotaxes(2),'r [m]') title(plotaxes(2),'Well') c = colorbar(plotaxes(2)); c.Label.String= 'depth [V]'; %c.Limits=[0 max(M.N(:))]; if(isboolean(fixed) && fixed) climits=caxis(plotaxes(2)); Minwell=climits(1); Maxwell=climits(2); elseif(~isboolean(fixed)) climits=caxis(plotaxes(2)); Minwell=climits(1); Maxwell=climits(2); end view(plotaxes(2),2) colormap(plotaxes(2),'jet'); linkaxes(plotaxes); end function plotGridButtonPushed(btn,ax) f=figure(); PlotEspic2dgriddata(f,M,sld.Value); f.PaperOrientation='landscape'; [~, name, ~] = fileparts(M.file); print(f,sprintf('%sGrid%d',name,sld.Value),'-dpdf','-fillpage') end function updatefigdata(control, event, Othercontrol, fig) if strcmp(event.EventName,'ValueChanged') fieldstep=floor(control.Value); control.Value=fieldstep; else fieldstep=floor(event.Value); end Othercontrol.Value=fieldstep; updatesubplotsdata(fieldstep, fig); end function updatesubplotsdata(fieldstep, fig) sgtitle(fig,sprintf('step=%d t=%0.5e s',(fieldstep-1)*M.it1,double((fieldstep-1)*M.it1)*M.dt)) %% update Position histogram dens=M.N(:,:,fieldstep); well=-PotentialWell(M.pot(:,:,fieldstep),M.Athet(:,:),M.rgrid,M.zgrid,false); well=well(2:end,2:end); plotaxes(1).Children.ZData=dens; plotaxes(1).Children.CData=dens; if(isboolean(fixed) && fixed) climits=caxis(plotaxes(1)); MaxN=climits(2); nmax=max(dens(:)); if(nmax>MaxN) MaxN=nmax; end caxis(plotaxes(1),[0 MaxN]); elseif(~isboolean(fixed)) MaxN=fixed.data; caxis(plotaxes(1),[-Inf MaxN]); end plotaxes(2).Children.ZData=well; plotaxes(2).Children.CData=well; if(isboolean(fixed) && fixed || ~isboolean(fixed)) climits=caxis(plotaxes(2)); Maxwell=max([well(:);climits(2)]); Minwell=min([well(:);climits(1)]); caxis(plotaxes(2),[Minwell Maxwell]); end drawnow limitrate end end