% visco.m % % Created by Victor Camacho on 6/10/06 % % This file sets up the Graphical User Interface of this program. A window % is created and all the necesary control handels are defined. Further, % several global structure are defined which contain vital information to % be used in subsidiary files pertaining to this program. % If this file is run by the user, we assume they wish to start the program % from scratch. So these first lines of code check if any windows % pertaining to this program are currently open. If so the program deletes % these objects, clearing them from memory so that we may start from % scratch as desired. fig = findobj('Tag','viscosimwindow'); fig2 = findobj('Tag','analyzewindow'); fig3 = findobj('Tag','analyzewindow2'); if (~isempty(fig)) delete(fig); clear global; end if (~isempty(fig2)) delete(fig2); clear global; end if (~isempty(fig3)) delete(fig3); clear global; end % Next we define a set of global structures which contain vital information % about the program. The reason they need to be defined to be global is % because their information will be widely used in external files and % functions. It seemed more efficient to simply define these as global % rather than passing them as arguments to functions. global myfig; % myfig stores all of the vital information about the % dimensions of the figure object and its objects. global sol; % sol is a structure containing four large matrices % containing the calculated numerical solution to the % PDE. global playopts; % playopts is a structure containing information about % the playback options for the solution, based on user % input. global grid; % grid is a structure containing information about how % the solution mesh is defined based on user input. global parameters; % parameters is a structure containing information % about the parameters of the PDE as defined by the % user. global cancel; % cancel is a boolean that is checked at various points % while the program is running. It is normally false, % but will be set to true if the user wishes to cancel % the current calculation. cancel = false; % Define the optional analyzing plot figure and its demensions. Then set % it to invisible. It will appear at an appropriate user-specified time. fig3 = figure('name','Analysis II','resize', 'off', 'Tag','plotwind2','visible','off','position',[200,200,800,600],'Tag','analyewindow2','closerequestfcn','viscocmd(''close3'')'); myfig.figure3.ax1 = axes('units','pixels','position',[50,300,700,200],'parent',fig3); myfig.figure3.ax2 = axes('units','pixels','position',[50,50,700,200],'parent',fig3); fig2 = figure('name','Analysis','resize','off','Tag','plotwind','visible','off','position',[100,100,800,600],'Tag','analyzewindow','closerequestfcn','viscocmd(''close2'')'); bg = get(fig2,'color'); myfig.figure2.ax = axes('units','pixels','position',[75,75,650,450],'parent',fig2); myfig.figure2.measure = uicontrol('style','edit','units','pixels','position',[200, 575, 200, 20],'string','int(a^2*d_*dx(e_)-uw_*dx(uw_)*d_*(e_+d_))','HorizontalAlignment','left','BackgroundColor',[1 1 1]); myfig.figure2.measure2 = uicontrol('style','edit','units','pixels','position',[200, 540, 200, 20],'string','abs(int((1.5*dx(uw_)-b)*d_^2+dx(uw_)*e_^2/4*(2*theta+uw_^2)))','HorizontalAlignment','left','BackgroundColor',[1 1 1]); myfig.figure2.mlabel = uicontrol('style','text','units','pixels','position',[120,575,70,20],'string','Measure I','BackgroundColor',bg,'HorizontalAlignment','right'); myfig.figure2.m2label = uicontrol('style','text','units','pixels','position',[120,540,70,20],'string','Measure II','BackgroundColor',bg,'HorizontalAlignment','right'); myfig.figure2.button = uicontrol('style','pushbutton','string','Plot','visible','on','position',[420, 575, 75, 25],'callback','viscocmd(''analyze'')','enable','on'); myfig.figure2.checkL = uicontrol('style','checkbox','units','pixels','position',[260,545,50,15],'Value',0,'String','Left','BackgroundColor',bg,'Visible','off'); myfig.figure2.checkR = uicontrol('style','checkbox','units','pixels','position',[320,545,50,15],'Value',0,'String','Right','BackgroundColor',bg,'Visible','off'); myfig.figure2.menu = uicontrol('style','popup','units','pixels','position',[520,575,100,15],'Value',1,'String','Measure|Characteristics','BackgroundColor',bg, 'callback','viscocmd(''menu2'')'); % Define the main figure for the program and its calback routines, which % are all defined in the viscocmd.m file. Then set this figure to the % current figure. fig = figure('name','Viscoelastic Simulation','resize','off','Tag','viscosimwindow','closerequestfcn','viscocmd(''close'')','ButtonDownFcn','viscocmd(''button'')'); figure(fig); myfig.fig1 = fig; myfig.fig2 = fig2; myfig.fig3 = fig3; % Determine the size of the screen for which the program is being % displayed. Set a fixed size for the figure window and then center the % figure on the screen. scrsz = get(0,'ScreenSize'); figw = 896; % figure width figh = 716; % figure height figl = (scrsz(3)-figw)/2; % left of figure figb = (scrsz(4)-figh)/2; % bottom of figure set(fig,'Position',[figl figb figw figh],'Units','centimeters'); myfig.color.bg = get(fig,'color'); myfig.width = figw; myfig.height = figh; w = myfig.width; h = myfig.height; % Nearly all the rest of the file is dedicated to defining the objects in % the figure along with their desired dimensions. All of this information % is susequently stored in the myfig structure to be used by viscocmd.m. % Here we lay out a button bar containing three buttons of equal dimensions % in the top left corner of the figure. The callback routines for each % button are set in these command lines. bw = 75; % button width bh = 25; % button height bbb = 0.9*h; % bottom of button bar bbl = 0.05*w; % left of button bar bs = 5; % button spacing myfig.button.run = uicontrol('style','pushbutton','string','Run','visible','on','position',[bbl,bbb,bw,bh],'callback','viscocmd(''run'')'); myfig.button.play = uicontrol('style','pushbutton','string','Play','visible','on','position',[bbl+bs+bw,bbb,bw,bh],'callback','viscocmd(''play'')','enable','off'); myfig.button.continue = uicontrol('style','pushbutton','string','Continue','visible','on','position',[bbl+bs+bw,bbb+bs+bh,bw,bh],'callback','viscocmd(''continue'')','enable','off'); myfig.button.analyze = uicontrol('style','pushbutton','string','Analyze','visible','on','position',[bbl,bbb+bs+bh,bw,bh],'callback','viscocmd(''analyze'')','enable','off'); % Two sets of axes are displayed in the figure. One is intended to graph % the fluid velocity and the other its stress as a function of horizontal % distance. However, the user has the option of changing the definition of % these axes in the middle of the program's execution. In any case, the % dimensions of these axes as well as their relative placement on the % figure are defined here. Further, the program is set up to cancel the % current calculation when the user clicks anywhere on the axes by defining % an appropriate callback routine (i.e. cancel = true). aw = 0.8*w; % axis width ah = 0.3*h; % axis height al = 0.075*w; % axis left ab = 0.1*h; % axis bottom as = 0.1*h; % axis spacing myfig.Sax = axes('units','pixels','position',[al,ab,aw,ah],'ButtonDownFcn','viscocmd(''button'')'); myfig.Uax = axes('units','pixels','position',[al,ab+as+ah,aw,ah],'ButtonDownFcn','viscocmd(''button'')'); % Also appearing in the figure are a series of textfield groups where the % user inputs necessary information about the PDE parameters and how the % solution is both calculated and displayed. The dimensions of these % textfields are defined below as well as their relative placement on the % figure and their initial values. tw = 40; % text field width th = 15; % text field height tl = w*0.7; % text field left tb = h*0.85; % text field bottom ths = 70; % text field horizontal space tvs = 10; % text field vertical space % This group of text fields queries the parameters of the PDE itself. myfig.text.alpha = uicontrol('style','edit','units','pixels','position',[tl,tb,tw,th],'string','1','HorizontalAlignment','left','BackgroundColor',[1 1 1]); myfig.text.beta = uicontrol('style','edit','units','pixels','position',[tl,tb+(tvs+th),tw,th],'string','5','HorizontalAlignment','left','BackgroundColor',[1 1 1]); myfig.text.uL = uicontrol('style','edit','units','pixels','position',[tl,tb+2*(tvs+th),tw,th],'string','0.5','HorizontalAlignment','left','BackgroundColor',[1 1 1]); myfig.text.uR = uicontrol('style','edit','units','pixels','position',[tl,tb+3*(tvs+th),tw,th],'string','-0.5','HorizontalAlignment','left','BackgroundColor',[1 1 1]); % This group of text fields queries information about the desired domain % on which the solution will be calculated. myfig.text.xmax = uicontrol('style','edit','units','pixels','position',[tl+ths+tw,tb,tw,th],'string','10','HorizontalAlignment','left','BackgroundColor',[1 1 1]); myfig.text.xmin = uicontrol('style','edit','units','pixels','position',[tl+ths+tw,tb+(tvs+th),tw,th],'string','-10','HorizontalAlignment','left','BackgroundColor',[1 1 1]); myfig.text.tfinal = uicontrol('style','edit','units','pixels','position',[tl+ths+tw,tb+2*(tvs+th),tw,th],'string','5','HorizontalAlignment','left','BackgroundColor',[1 1 1]); myfig.text.xprec = uicontrol('style','edit','units','pixels','position',[tl+ths+tw,tb+3*(tvs+th),tw,th],'string','50','HorizontalAlignment','left','BackgroundColor',[1 1 1]); % These two text fields are where the user decribes the intial conditions % of the system that is to be solved. myfig.text.Sic = uicontrol('style','edit','units','pixels','position',[tl-6*tw,tb,4*tw,th],'string','0','HorizontalAlignment','left','BackgroundColor',[1 1 1]); myfig.text.Uic = uicontrol('style','edit','units','pixels','position',[tl-6*tw,tb+th+tvs,4*tw,th],'string','0','HorizontalAlignment','left','BackgroundColor',[1 1 1]); % The following group of text fields queries the user to define what each % of axes represents. myfig.text.bottomx = uicontrol('style','edit','units','pixels','position',[al+aw+10,ab+0.7*ah,tw,th],'string','x','HorizontalAlignment','left','BackgroundColor',[1 1 1]); myfig.text.bottomy = uicontrol('style','edit','units','pixels','position',[al+aw+10,ab+0.9*ah,tw,th],'string','s_','HorizontalAlignment','left','BackgroundColor',[1 1 1]); myfig.text.topx = uicontrol('style','edit','units','pixels','position',[al+aw+10,ab+1.7*ah+as,tw,th],'string','x','HorizontalAlignment','left','BackgroundColor',[1 1 1]); myfig.text.topy = uicontrol('style','edit','units','pixels','position',[al+aw+10,ab+1.9*ah+as,tw,th],'string','u_','HorizontalAlignment','left','BackgroundColor',[1 1 1]); % This group of text fields will allow the user to control the viewing % window of the two graph displayed in the figure. myfig.text.bottomymax = uicontrol('style','edit','units','pixels','position',[al+aw+10,ab+0.1*ah,tw,th],'string','','HorizontalAlignment','left','BackgroundColor',[1 1 1],'enable','off'); myfig.text.bottomymin = uicontrol('style','edit','units','pixels','position',[al+aw+10,ab+0.1*ah+th+tvs,tw,th],'string','','HorizontalAlignment','left','BackgroundColor',[1 1 1],'enable','off'); myfig.text.topymax = uicontrol('style','edit','units','pixels','position',[al+aw+10,ab+1.1*ah+as,tw,th],'string','','HorizontalAlignment','left','BackgroundColor',[1 1 1],'enable','off'); myfig.text.topymin = uicontrol('style','edit','units','pixels','position',[al+aw+10,ab+1.1*ah+as+th+tvs,tw,th],'string','','HorizontalAlignment','left','BackgroundColor',[1 1 1],'enable','off'); % This group of text fields set some of the user defined playback options. % The continue text box will allow the user to simulate the solution of the % PDE starting from where the last simulation ended and continuing for a % specified amount of time. The play start and play end define the time % window of the solution that is played back. myfig.text.continue = uicontrol('style','edit','units','pixels','position',[bbl+2*(bs+bw),bbb+bs+bh,0.5*tw,th],'string','','HorizontalAlignment','left','BackgroundColor',[1 1 1],'enable','off'); myfig.text.playstart = uicontrol('style','edit','units','pixels','position',[bbl+2*(bs+bw),bbb,0.5*tw,th],'string','','HorizontalAlignment','left','BackgroundColor',[1 1 1],'enable','off'); myfig.text.playend = uicontrol('style','edit','units','pixels','position',[bbl+2*(bs+bw)+tw,bbb,0.5*tw,th],'string','','HorizontalAlignment','left','BackgroundColor',[1 1 1],'enable','off'); % When the user wishes to introduce a viscous effect into the PDE, they % have the option of defining their own value of epsilon in this text % field. myfig.text.eps = uicontrol('style','edit','units','pixels','position',[0.45*w+tw+ths,0.95*h-tvs/2-th,tw,th],'string','','HorizontalAlignment','left','BackgroundColor',[1 1 1],'enable','off','visible','off'); % Every text field defined above needs an appropriate label. These labels % are defined here and match up logically with textfields defined above. % Further, they are positioned to the left of each text field with a % uniform spacing. lw = 40; % label width lh = th; % label height ls = 5; % label space from text field ll = tl - lw - ls; % label left lb = tb; % label bottom myfig.label.alpha = uicontrol('style','text','units','pixels','position',[ll,lb,lw,lh],'string','alpha','BackgroundColor',myfig.color.bg,'HorizontalAlignment','right'); myfig.label.beta = uicontrol('style','text','units','pixels','position',[ll,lb+(lh+tvs),lw,lh],'string','beta','BackgroundColor',myfig.color.bg,'HorizontalAlignment','right'); myfig.label.uL = uicontrol('style','text','units','pixels','position',[ll,lb+2*(lh+tvs),lw,lh],'string','uL','BackgroundColor',myfig.color.bg,'HorizontalAlignment','right'); myfig.label.uR = uicontrol('style','text','units','pixels','position',[ll,lb+3*(lh+tvs),lw,lh],'string','uR','BackgroundColor',myfig.color.bg,'HorizontalAlignment','right'); myfig.label.xmax = uicontrol('style','text','units','pixels','position',[ll+ths+tw,lb,lw,lh],'string','xmax','BackgroundColor',myfig.color.bg,'HorizontalAlignment','right'); myfig.label.xmin = uicontrol('style','text','units','pixels','position',[ll+ths+tw,lb+(lh+tvs),lw,lh],'string','xmin','BackgroundColor',myfig.color.bg,'HorizontalAlignment','right'); myfig.label.tfinal = uicontrol('style','text','units','pixels','position',[ll+ths+tw,lb+2*(lh+tvs),lw,lh],'string','tfinal','BackgroundColor',myfig.color.bg,'HorizontalAlignment','right'); myfig.label.xprec = uicontrol('style','text','units','pixels','position',[ll+ths+tw,lb+3*(lh+tvs),lw,lh],'string','xprec','BackgroundColor',myfig.color.bg,'HorizontalAlignment','right'); myfig.label.Sic = uicontrol('style','text','units','pixels','position',[ll-6*tw,lb,lw,lh],'string','s(x,0)','BackgroundColor',myfig.color.bg,'HorizontalAlignment','right'); myfig.label.Uic = uicontrol('style','text','units','pixels','position',[ll-6*tw,lb+(lh+tvs),lw,lh],'string','u(x,0)','BackgroundColor',myfig.color.bg,'HorizontalAlignment','right'); myfig.label.bottomvs = uicontrol('style','text','units','pixels','position',[al+aw+10+(tw-lw)/2,ab+0.8*ah,lw,lh],'string','vs.','BackgroundColor',myfig.color.bg,'HorizontalAlignment','center'); myfig.label.topvs = uicontrol('style','text','units','pixels','position',[al+aw+10+(tw-lw)/2,ab+1.8*ah+as,lw,lh],'string','vs.','BackgroundColor',myfig.color.bg,'HorizontalAlignment','center'); myfig.label.to = uicontrol('style','text','units','pixels','position',[bbl+2*(bs+bw)+0.5*tw,bbb,0.5*lw,lh],'string','to','BackgroundColor',myfig.color.bg,'HorizontalAlignment','center'); myfig.label.bottomymax = uicontrol('style','text','units','pixels','position',[al+aw+10+ls+tw,ab+0.1*ah,lw,lh],'string','ymax','BackgroundColor',myfig.color.bg,'HorizontalAlignment','left'); myfig.label.bottomymin = uicontrol('style','text','units','pixels','position',[al+aw+10+ls+tw,ab+0.1*ah+th+tvs,lw,lh],'string','ymin','BackgroundColor',myfig.color.bg,'HorizontalAlignment','left'); myfig.label.bottomymax = uicontrol('style','text','units','pixels','position',[al+aw+10+ls+tw,ab+1.1*ah+as,lw,lh],'string','ymax','BackgroundColor',myfig.color.bg,'HorizontalAlignment','left'); myfig.label.bottomymin = uicontrol('style','text','units','pixels','position',[al+aw+10+ls+tw,ab+1.1*ah+th+tvs+as,lw,lh],'string','ymin','BackgroundColor',myfig.color.bg,'HorizontalAlignment','left'); % The status bar appears on the bottom left corner of the figure and % displays the current status of the program or current calculation so that % the user may have a sense of progress or know where an error has occured % if necessary. If an error HAS occured, in most cases this is also % displayed in the status bar in RED font. sbh = 20; sbw = 0.4*w; myfig.status = uicontrol('style','text','units','pixels','position',[5,5,sbw,sbh],'string','Status','BackgroundColor',myfig.color.bg,'HorizontalAlignment','left'); % The time bar is placed on the bottom right corner of the figure and % displays what percentage of the current calculation has been completed. % This only offers an estimate in terms of time, and can be compared with % the total time estimation displayed in the status bar. tbh = 20; tbw = 0.4*w; myfig.progress = uicontrol('style','text','units','pixels','position',[0.5*w,5,sbw,sbh],'string','','BackgroundColor',myfig.color.bg,'HorizontalAlignment','left'); % Also appearing on the figure are a series of checkboxes that all of which % serve very necessary purposes. % (1) Whether or not to display the standing wave solution along with the % calculated solution. % (2) Whether or not to describe the initial condition in terms of a wave % perturbation. % (3) Whether or not a visco term should be added to the PDE system. % % Also defined below are the appropriate labels for each of these % checkboxes. cbw = 15; cbh = 15; cbl = bbl; cbb = 0.85*h; cbvs = 5; myfig.check.wave = uicontrol('style','checkbox','units','pixels','position',[cbl,cbb,cbw,cbh],'Value',1); myfig.label.wave = uicontrol('style','text','units','pixels','position',[cbl+cbw+ls,cbb,3*lw,lh],'string','Display Wave Solution','BackgroundColor',myfig.color.bg,'HorizontalAlignment','left'); myfig.check.pert = uicontrol('style','checkbox','units','pixels','position',[cbl,cbb-cbvs-cbh,cbw,cbh],'Value',1,'callback','viscocmd(''pert'')'); myfig.label.pert = uicontrol('style','text','units','pixels','position',[cbl+cbw+ls,cbb-cbvs-cbh,3*lw,lh],'string','Wave Perturbation','BackgroundColor',myfig.color.bg,'HorizontalAlignment','left'); myfig.check.save = uicontrol('style','checkbox','units','pixels','position',[cbl+cbw+3*lw+ls,cbb,cbw+2*lw,cbh],'Value',0,'String','Save Movie','BackgroundColor',myfig.color.bg); myfig.check.viscoterm = uicontrol('style','checkbox','units','pixels','position',[0.32*w,0.95*h-cbvs-cbh,cbw+2*tw,cbh],'Value',0,'String','Viscous Term','BackgroundColor',myfig.color.bg,'callback','viscocmd(''visco'')'); myfig.menu = uicontrol('style','popup','units','pixels','position',[0.32*w,0.95*h,cbw+3*tw,cbh],'Value',1,'String','Lax-Wendroff|Finite Volume|Characteristic I|Characteristic II','BackgroundColor',myfig.color.bg); myfig.menu2 = uicontrol('style','popup','units','pixels','position',[0.50*w,0.95*h,cbw+3*tw,cbh],'Value',1,'String','|Lax-Wendroff|Finite Volume|Characteristic I|Characteristic II','BackgroundColor',myfig.color.bg); myfig.menu3 = uicontrol('style','popup','units','pixels','position',[0.2*w,0.82*h,cbw+3*tw,cbh],'Value',1,'String','Examples|1 Hump|2 Humps|Sinusoid|Shock form.|Class I|Class II|Class III','BackgroundColor',myfig.color.bg,'callback','viscocmd(''examples'')'); % Two groups of radio buttons are defined in this figure, one for each % axis. They inquire as to whether the user would like to define their own % viewing window, or if it should be left up to Matlab. myfig.radio.group(1) = uibuttongroup('units','pixels','Position',[al+aw+10,ab+ah*0.3,30+tw,2*(tvs+th)],'parent',fig,'BackgroundColor',myfig.color.bg,'SelectionChangeFcn','viscocmd(''axis'')'); myfig.radio.group(2) = uibuttongroup('units','pixels','Position',[al+aw+10,ab+ah*1.3+as,30+tw,2*(tvs+th)],'parent',fig,'BackgroundColor',myfig.color.bg,'SelectionChangeFcn','viscocmd(''axis'')'); myfig.radio.top.auto = uicontrol('style','radio','units','pixels','position',[1, tvs+th,15+tw,15],'string','Auto','BackgroundColor',myfig.color.bg,'parent',myfig.radio.group(2)); myfig.radio.top.fixed = uicontrol('style','radio','units','pixels','position',[1, 1,15+tw,15],'string','Fixed','BackgroundColor',myfig.color.bg,'parent',myfig.radio.group(2)); myfig.radio.bottom.auto = uicontrol('style','radio','units','pixels','position',[1, tvs+th,15+tw,15],'string','Auto','BackgroundColor',myfig.color.bg,'parent',myfig.radio.group(1)); myfig.radio.bottom.fixed = uicontrol('style','radio','units','pixels','position',[1, 1,15+tw,15],'string','Fixed','BackgroundColor',myfig.color.bg,'parent',myfig.radio.group(1)); % The final task in this script is to initialize/erase the contents of the % sol structure. It will eventually contain four matrices containing the % calculated solutions to the PDE. Since these were defined as global we % need to take the precaution of setting them back to empty just in case % they were not deleted from the previous running of the program. sol.u = []; sol.uw = []; sol.s = []; sol.sw = []; sol2.u = []; sol2.uw = []; sol2.s = []; sol2.sw = []; % savedsettings(1).name = '1 Hump'; % % % savedsettings(1).wave=1; % savedsettings(1).pert=1; % savedsettings(1).save=0; % set(myfig.check.viscoterm,'Value',0); % % set(myfig.label.Uic,'string','e(x,t)'); % set(myfig.label.Sic,'string','d(x,t)'); % % set(myfig.text.alpha, 'string','1') % set(myfig.text.beta, 'string','5'); % set(myfig.text.uL, 'string','0.5'); % set(myfig.text.uR, 'string','-0.5'); % % set(myfig.text.xmax, 'string','10'); % set(myfig.text.xmin, 'string','-10'); % set(myfig.text.tfinal, 'string','5'); % set(myfig.text.xprec, 'string','50'); % % set(myfig.text.Uic, 'string','blob(-5,-4)'); % set(myfig.text.Sic, 'string','0'); % % set(myfig.text.topx,'string','x'); % set(myfig.text.topy,'string','u_'); % set(myfig.text.bottomx,'string','x'); % set(myfig.text.bottomy,'string','s_'); % % set(myfig.menu,'Value',1); % set(myfig.menu2,'Value',1); % % set(myfig.radio.top.auto, 'Value',1); % set(myfig.radio.top.fixed, 'Value',0); % set(myfig.radio.bottom.auto, 'Value',1); % set(myfig.radio.bottom.fixed, 'Value',0);