-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchebguiWindow.m
More file actions
2079 lines (1737 loc) · 64.4 KB
/
chebguiWindow.m
File metadata and controls
2079 lines (1737 loc) · 64.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function varargout = chebguiWindow(varargin)
%CHEBGUIWINDOW Driver file for Chebfun's CHEBGUI
% This m-file populates and controls Chebfun's CHEBGUI.
%
% See also CHEBGUI.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DEVELOPER NOTE:
% This method implements most callback method of CHEBGUI, i.e., methods that
% get executed when the user interacts with the GUI figure. Many of these
% methods are automatically generated by MATLAB, which explains why a lot of
% them have input arguments that appear to be unused (but are needed for the
% calling mechanism of MATLAB).
%
% The more complicated methods of controlling the GUI layout live in the
% @chebguiController folder.
%
% The methods for actually solving problems using CHEBGUI live in the @chebgui/
% folder.
%
% The methods for dealing with exporting problems from the CHEBGUI figure to .m
% files live in the @chebguiExporter folder, and its subclasses.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Copyright 2014 by The University of Oxford and The Chebfun Developers.
% See http://www.chebfun.org/ for Chebfun information.
% Suppress irritating MLINT warnings:
%#ok<*INUSL,*DEFNU,*INUSD,*ST2NM,*MATCH2>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @chebguiWindow_OpeningFcn, ...
'gui_OutputFcn', @chebguiWindow_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if ( nargin && ischar(varargin{1}) )
gui_State.gui_Callback = str2func(varargin{1});
end
if ( nargout )
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
warnstate = warning('off', 'MATLAB:hg:uicontrol:ParameterValuesMustBeValid');
try
gui_mainfcn(gui_State, varargin{:});
warning(warnstate);
catch ME
warning(warnstate)
MEID = ME.identifier;
if ( ~isempty(strfind(MEID, 'Chebgui:')) )
% These are expected GUI errors. We only show the dialog
errordlg(cleanErrorMsg(ME.message), 'Chebgui error', 'modal');
uiwait
resetComponents(varargin{4});
% If in debug mode, we throw the error to the command window as well
if ( get(varargin{4}.menu_debug, 'UserData') )
rethrow(ME)
end
else
% Show an error dialog, but also throw the error to the command
% window
errordlg(cleanErrorMsg(ME.message), 'Chebgui error', 'modal');
uiwait
resetComponents(varargin{4});
rethrow(ME)
end
end
end
% End initialization code - DO NOT EDIT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
% --- Executes just before chebguiWindow is made visible.
function chebguiWindow_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see Output(1-x^2)*exp(-30*(x+.5)^2)Fcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to chebguiWindow (see VARARGIN)
% Initalize fonts in the CHEBGUI window:
chebguiController.initalizeFields(handles);
% Choose default command line output for chebguiWindow
handles.output = hObject;
% Initialise figures:
chebguiController.initialiseFigures(handles)
% Variable that determines whether a solution is available
handles.hasSolution = 0;
% Variable which stores the initial guess/condition
handles.init = [];
% Variable which stores imported variables from workspace
handles.importedVar = struct;
% Get the GUI object from the input argument
if ( ~isempty(varargin) )
handles.guifile = varargin{1};
else
handles.guifile = chebgui.demo(); % Load a random demo
end
% Create a new structure which contains information about the latest
% solution obtained
handles.latest = struct;
% Store the default length of pausing between plots for BVPs and the
% tolerance in the userdata field of relevant menu objects.
set(handles.menu_odeplottingpause, 'UserData', '0.5');
set(handles.menu_tolerance, 'UserData', '1e-10');
% Create UserData for the Fix-Y-axis options (so that we can display
% something if it gets called without selecting a demo).
set(handles.menu_pdefixon, 'UserData', {''});
% Populate the Demos menu, but only once (i.e. if user calls chebgui again,
% don't reload the examples).
if ( isempty(get(handles.menu_demos, 'UserData')) )
chebguiController.loadDemoMenu(handles);
handles.demosLoaded = 1;
end
% Load the input fields
chebguiController.populate(handles, handles.guifile);
% Make sure the GUI starts in the correct mode. We call SWITCHMODE() with the
% third argument equal to 'demo' so that we will plot the initial guess of the
% solution if it exists.
chebguiController.switchMode(handles, handles.guifile.type, 'demo');
% Get the system font size and store in handles
s = char(com.mathworks.services.FontPrefs.getCodeFont);
if ( s(end-2) == '=' )
fs = round(3/4*str2num(s(end-1)));
else
fs = round(3/4*str2num(s(end-2:end-1)));
end
set(handles.tempedit, 'FontSize', fs);
% Set the solve button to green
set(handles.button_solve, 'String', 'Solve');
set(handles.button_solve, 'BackgroundColor', [43 129 86]/256);
% Ensure that we have a light-blue color in background
set(handles.mainWindow, 'BackgroundColor', [.702 .78 1]);
% Default discretization is colloc2
handles.guifile.options.discretization = @colloc2;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes chebguiWindow wait for user response (see UIRESUME)
% uiwait(handles.chebguimainwindow);
end
% --- Outputs from this function are returned to the command line.
function varargout = chebguiWindow_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
if ( nargout > 0 )
varargout{1} = handles.output;
end
% If nargout == 2, return the fll set of handles
if ( nargout > 1 )
varargout{2} = handles;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ------------- Callback functions for the objects of the GUI -----------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ------------------ Functions which call chebgui methods ----------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function button_clear_Callback(hObject, eventdata, handles)
% Clear the GUI figure. This button also represents the 'Pause' button on the
% figure while problems are being solved.
if ( strcmp(get(handles.button_clear, 'String'), 'Clear all') )
handles = chebguiController.clear(handles);
% Clear information from the guifile as well
handles.guifile = chebgui('type', handles.guifile.type);
guidata(hObject, handles);
elseif strcmp(get(handles.button_clear, 'String'), 'Pause')
set(handles.button_clear, 'String', 'Continue');
set(handles.button_clear, 'BackgroundColor', [43 129 86]/256);
% Re-enable figure button
set(handles.button_figsol, 'Enable', 'on');
else
% Disable figure button
set(handles.button_figsol, 'Enable', 'off');
set(handles.button_clear, 'String', 'Pause');
set(handles.button_clear, 'BackgroundColor', [255 179 0]/256);
end
end
function button_solve_Callback(hObject, eventdata, handles)
handles = solveGUI(handles.guifile, handles);
guidata(hObject, handles);
end
function input_LBC_Callback(hObject, eventdata, handles)
newString = cellstr(get(hObject, 'String'));
newString = removeTabs(newString); % Remove tabs
set(hObject, 'String', newString);
handles = chebguiController.callbackBCs(handles, newString, 'lbc');
handles.guifile.LBC = newString;
guidata(hObject, handles);
end
function input_RBC_Callback(hObject, eventdata, handles)
newString = cellstr(get(hObject, 'String'));
newString = removeTabs(newString); % Remove tabs
set(hObject, 'String', newString);
handles = chebguiController.callbackBCs(handles, newString, 'rbc');
handles.guifile.RBC = newString;
guidata(hObject, handles);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ----------- Functions which do their work without chebgui methods ------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function dom_left_Callback(hObject, eventdata, handles)
% Store the contents of input1_editText as a string. if the string is not a
% number then input will be empty
input = str2num(get(hObject, 'String'));
% Checks to see if input is not numeric or empty. If so, default left end
% of the domain is taken to be -1.
if ( isempty(input) || isnan(input) )
warndlg('Left endpoint of domain unrecognized, default value -1 used.')
set(hObject, 'String', '-1')
end
set(handles.input_GUESS, 'Enable', 'on');
set(handles.toggle_useLatest, 'Value', 0);
set(handles.toggle_useLatest, 'Enable', 'off');
handles.guifile.DomLeft = get(hObject, 'String');
guidata(hObject, handles);
end
function dom_right_Callback(hObject, eventdata, handles)
input = str2num(get(hObject, 'String'));
% Checks to see if input is not numeric or empty. If so, default right end
% of the domain is taken to be 1.
if ( isempty(input) || isnan(input) )
warndlg('Right endpoint of domain unrecognized, default value 1 used.')
set(hObject, 'String', '1')
end
set(handles.input_GUESS, 'Enable', 'on');
set(handles.toggle_useLatest, 'Value', 0);
set(handles.toggle_useLatest, 'Enable', 'off');
handles.guifile.DomRight = get(hObject, 'String');
guidata(hObject, handles);
end
function input_domain_Callback(hObject, eventdata, handles)
in = get(hObject, 'String');
input = str2num(in);
% Checks to see if input is not numeric or empty. If so, default left end
% of the domain is taken to be -1.
if ( input(1) >= input(end) )
warndlg('Empty domain. Default value [-1, 1] used.')
in = '[-1, 1]';
set(hObject, 'String', in);
elseif ( isempty(input) || any(isnan(input)) || (length(input) < 2) )
warndlg('Domain unrecognized. Default value [-1, 1] used.')
in = '[-1, 1]';
set(hObject, 'String', in);
elseif ( ~any(strfind(in, '[')) )
in = ['[' in ']'];
set(hObject, 'String', in);
end
set(handles.input_GUESS, 'Enable', 'on');
set(handles.toggle_useLatest, 'Value', 0);
set(handles.toggle_useLatest, 'Enable', 'off');
handles.guifile.domain = in;
guidata(hObject, handles);
end
% --- Executes during object creation, after setting all properties.
function input_domain_CreateFcn(hObject, eventdata, handles)
bgColorIsDefault = isequal(get(hObject, 'BackgroundColor'), ...
get(0, 'defaultUicontrolBackgroundColor'));
if ( ispc && bgColorIsDefault )
set(hObject, 'BackgroundColor', 'white');
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% -------- Functions which do their work in a couple of lines of code ----------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function input_GUESS_Callback(hObject, eventdata, handles)
% Plot the initial guess/condition when it is entered in the appropriate field.
% Find the string.
newString = cellstr(get(hObject, 'String'));
% Remove tabs
newString = removeTabs(newString);
set(hObject, 'String', newString);
handles.guifile.init = newString;
if ( isempty(newString) || (iscell(newString) && (numel(newString) == 1) && ...
isempty(newString{1})) )
handles.init = '';
axes(handles.fig_sol);
cla(handles.fig_sol, 'reset');
guidata(hObject, handles);
return
end
loadVariables(handles.importedVar)
guidata(hObject, handles);
% Create the independent space variable:
xtTemp = chebfun(@(x) x, str2num(handles.guifile.domain));
% Assign it to the correct variable, either r, x or t.
if ( ~exist('r', 'var') )
r = xtTemp;
end
if ( ~exist('x', 'var') )
x = xtTemp;
end
if ( ~exist('t', 'var') )
t = xtTemp;
end
% Do something more clever with multiline input
str = cellstr(get(hObject, 'String'));
init = [];
for k = 1:numel(str)
strk = str{k};
equalSigns = find(strk == '=');
if ( numel(equalSigns) > 1 )
error('CHEBFUN:chebguiWindow:initInput', ...
'Too many equals signs in input.');
elseif ( numel(equalSigns) == 1 )
strk = strk(equalSigns+1:end);
elseif ( numel(str) > 1 )
error('CHEBFUN:chebguiWindow:initInput', ...
['Error constructing initial guess. Input must include the ' ...
'names of the dependent variables, i.e. be on the form ' ...
'"u = %s", ...'], strk)
end
strk = deblank(vectorize(strk));
try
if ( ~isempty(strk) )
init = [init eval(strk)]; %#ok<AGROW>
end
catch ME
error('CHEBFUN:chebguiWindow:initInput', ME.message)
end
end
% Plot the initial guess/solution:
handles.init = init;
axes(handles.fig_sol);
plot(handles.init, 'linewidth', 2)
if ( ~isempty(handles.guifile.options.fixYaxisLower) )
ylim([str2num(handles.guifile.options.fixYaxisLower) ...
str2num(handles.guifile.options.fixYaxisUpper)]);
end
% Show grid?
if ( handles.guifile.options.grid )
grid on
end
% Update the figure and the handles.
guidata(hObject, handles);
end
function loadVariables(importedVar)
% Load variables from the workspace to the workspace of the GUI
fNames = fieldnames(importedVar);
for i = 1:length(fNames)
assignin('caller', fNames{i}, importedVar.(fNames{i}))
end
end
function input_DE_Callback(hObject, eventdata, handles)
% Called when the differential equation is entered.
% Obtain the input:
str = cellstr(get(hObject, 'String'));
% Remove tabs:
str = removeTabs(str);
% Update the DE input and store in guifile:
set(handles.input_DE, 'String', str);
handles.guifile.DE = str;
% Auto PDE and EIG detection
for k = 1:numel(str)
strk = str{k};
if ( any(strfind(strk, '_')) )
if ( ~get(handles.button_pde, 'value') )
handles = chebguiController.switchMode(handles, 'pde');
end
break
elseif ( any(strfind(strk, 'lam') | strfind(strk, 'lambda')) )
if ( ~get(handles.button_eig, 'value') )
handles = chebguiController.switchMode(handles, 'eig');
end
break
end
end
guidata(hObject, handles);
end
function str = removeTabs(str)
% Remove tabs from inputs
for k = 1:numel(str)
idx = 1;
strk = str{k};
while ( ~isempty(idx) )
idx = strfind(strk, double(9));
strk(idx) = [];
end
str{k} = strk;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ----------------------------- Keypresses -------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% These methods go from one input box to another when the user presses the 'tab'
% button.
function input_DE_KeyPressFcn(hObject, eventdata, handles)
if ( strcmp(eventdata.Key, 'tab') )
if ( strcmp(eventdata.Modifier, 'shift') )
if ( get(handles.button_pde, 'value') )
uicontrol(handles.input_timedomain);
else
uicontrol(handles.input_domain);
end
elseif ( get(handles.button_pde, 'value') )
uicontrol(handles.input_LBC);
else
uicontrol(handles.input_BC);
end
end
end
function input_BC_KeyPressFcn(hObject, eventdata, handles)
if ( strcmp(eventdata.Key, 'tab') )
if ( strcmp(eventdata.Modifier, 'shift') )
uicontrol(handles.input_DE);
else
uicontrol(handles.input_GUESS);
end
end
end
function input_LBC_KeyPressFcn(hObject, eventdata, handles)
if ( strcmp(eventdata.Key, 'tab') )
if ( strcmp(eventdata.Modifier, 'shift') )
uicontrol(handles.input_DE);
else
uicontrol(handles.input_RBC);
end
end
end
function input_RBC_KeyPressFcn(hObject, eventdata, handles)
if ( strcmp(eventdata.Key, 'tab') )
if ( strcmp(eventdata.Modifier, 'shift') )
uicontrol(handles.input_LBC);
else
uicontrol(handles.input_GUESS);
end
end
end
function input_GUESS_KeyPressFcn(hObject, eventdata, handles)
if ( strcmp(eventdata.Key, 'tab') )
if ( strcmp(eventdata.Modifier, 'shift') )
uicontrol(handles.input_BC);
else
uicontrol(handles.button_solve);
set(handles.button_solve, 'selected', 'on');
end
end
end
function popupmenu_sigma_KeyPressFcn(hObject, eventdata, handles)
if ( strcmp(eventdata.Key, 'tab') )
if ( strcmp(eventdata.Modifier, 'shift') )
uicontrol(handles.edit_eigN);
else
uicontrol(handles.button_solve);
end
end
end
function button_solve_KeyPressFcn(hObject, eventdata, handles)
if ( strcmp(eventdata.Key, 'tab') )
if ( strcmp(eventdata.Modifier, 'shift') )
if ( get(handles.button_eig, 'value') )
uicontrol(handles.input_BC);
else
uicontrol(handles.input_GUESS);
end
else
uicontrol(handles.button_clear);
end
elseif ( strcmp(eventdata.Key, 'return') )
button_solve_Callback(hObject, eventdata, handles);
end
end
function button_clear_KeyPressFcn(hObject, eventdata, handles)
if ( strcmp(eventdata.Key, 'tab') )
if ( strcmp(eventdata.Modifier, 'shift') )
uicontrol(handles.button_solve);
else
uicontrol(handles.button_export);
end
elseif ( strcmp(eventdata.Key, 'return') )
button_clear_Callback(hObject, eventdata, handles);
end
end
function button_export_KeyPressFcn(hObject, eventdata, handles)
if ( strcmp(eventdata.Key, 'tab') )
if ( strcmp(eventdata.Modifier, 'shift') )
uicontrol(handles.button_clear);
elseif ( get(handles.button_exportsoln, 'enabled') )
uicontrol(handles.button_exportsoln);
else
uicontrol(handles.input_domain);
end
elseif ( strcmp(eventdata.Key, 'return') )
button_export_Callback(hObject, eventdata, handles);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ------------------------- Unsorted functions --------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function input_timedomain_Callback(hObject, eventdata, handles)
% Passing time range for PDEs.
str = get(hObject, 'String');
if ( iscell(str) )
str = str{:};
end
num = str2num(str);
options.WindowStyle = 'modal';
% Indicates we had timedomain with negative spacing (0:-.1:1)
while ( isempty(num) )
str = inputdlg(['Time domain should be a vector of length > 2, with ' ...
'positive spacing, at which times solution is returned'], ['Set ' ...
'time domain'], 1, {'0:.1:1'}, options);
if ( isempty(str) )
str = '';
break
end
str = str{:};
num = str2num(str);
end
while ( ~isempty(str) && (numel(num) < 3) )
h = (num(2) - num(1))/20;
def = sprintf('%s:%s:%s', num2str(num(1), '%0.0f'), num2str(h, '%0.2g'), ...
num2str(num(2), '%0.0f'));
str = inputdlg(['Time domain should be a vector of length > 2 at which ' ...
'times solution is returned'], 'Set time domain', 1, {def}, options);
if ( isempty(str) )
str = '';
break
end
str = str{:};
num = str2num(str);
end
set(handles.input_timedomain, 'String', str);
handles.guifile.timedomain = str;
guidata(hObject, handles);
end
function button_figsol_Callback(hObject, eventdata, handles)
% Executed when the user wants to show figures in new window.
if ( get(handles.button_ode, 'Value') )
% We're in ODE mode.
% Plot the latest solution obtained:
figure
latestSolution = handles.latest.solution;
plot(latestSolution, 'Linewidth', 2)
title('Solution at end of iteration')
xlabel(handles.indVarName);
varnames = handles.varnames;
if ( numel(varnames) == 1 )
ylabel(varnames)
end
% Turn on grid
if ( handles.guifile.options.grid )
grid on
end
if ( numel(handles.varnames) > 1 )
legend(handles.varnames)
end
latestNorms = handles.latest.norms;
% Also open the bottom figure in now window. This is either going to be the
% PLOTCOEFFS, or a plot showing the norm of the updates during the Newton
% iteration:
figure
plotType = get(handles.popupmenu_bottomFig, 'Value');
if ( plotType == 1) % Show the norm plot
semilogy(latestNorms, '-*', 'Linewidth', 2)
title('Norm of updates')
xlabel('Number of iteration')
if ( length(latestNorms) > 1 )
skip = max(floor(length(latestNorms) / 5), 1);
XTickVec = 1:skip:length(latestNorms);
set(gca, 'XTick', XTickVec)
xlim([1 length(latestNorms)])
grid on
else % Don't display fractions on iteration plots
set(gca, 'XTick', 1)
end
else % Show PLOTCOEFFS
plotcoeffs(latestSolution, 'linewidth', 2)
title('Chebyshev coefficients of the solution')
grid on
set(handles.popupmenu_bottomFig, 'Value', 2);
end
elseif ( get(handles.button_pde, 'Value') )
% We're in PDE mode.
% Obtain solution and time range.
u = handles.latest.solution;
tt = handles.latest.solutionT;
% Find out what our variables were called.
varnames = handles.varnames;
xLab = handles.indVarName{1};
tLab = handles.indVarName{2};
titleStr = sprintf('Solution at final time, %s = %f', tLab, tt(end));
figure
if ( ~iscell(u) )
plot(u(:, end), 'Linewidth', 2)
xlabel(xLab);
ylabel(varnames);
title(titleStr)
else
v = chebfun;
for k = 1:numel(u)
uk = u{k};
v(:, k) = uk(:, end);
end
plot(v, 'Linewidth', 2);
xlabel(xLab);
legend(varnames);
title(titleStr)
end
% Turn on grid
if ( handles.guifile.options.grid )
grid on
end
% Turn on fixed y-limits
if ( ~isempty(handles.guifile.options.fixYaxisLower) )
ylim([str2num(handles.guifile.options.fixYaxisLower) ...
str2num(handles.guifile.options.fixYaxisUpper)]);
end
% Plot waterfall plots of the solution:
if ( ~isa(u, 'chebmatrix') )
figure
waterfall(u, tt, 'simple', 'linewidth', 2)
xlabel(xLab);
ylabel(tLab);
zlabel(varnames{1});
else
figure
for k = 1:size(u, 1)
subplot(1, size(u, 1), k);
waterfall(u(k, :), tt, 'linewidth', 2)
xlabel(xLab)
ylabel(tLab)
zlabel(varnames{k})
title(varnames{k})
end
figure
cols = get(0, 'DefaultAxesColorOrder');
% Dummy plot to get legends right:
for k = 1:size(u, 1)
plot(0, NaN, 'linewidth', 2, 'color', cols(k, :))
hold on
end
legend(varnames{:});
% CHEBMATRIX/WATERFALL()
waterfall(u, tt, 'linewidth', 2, 'edgecolors', cols)
% Much pretty. Wow.
view([322.5 30])
box off
grid on
end
else
figure
h1 = gca;
if ( strcmp(handles.latest.type, 'eig') )
selection = get(handles.iter_list, 'Value');
chebguiController.plotEigenmodes(handles, selection, h1, []);
end
end
end
function toggle_useLatest_Callback(hObject, eventdata, handles)
% Called when user toggles between using the latest solution as an initial
% guess.
newVal = get(hObject, 'Value');
if ( newVal ) % User wants to use latest solution
set(handles.input_GUESS, 'String', 'Using latest solution');
else
set(handles.input_GUESS, 'String', '');
set(handles.input_GUESS, 'Enable', 'On');
handles.guifile.init = '';
end
guidata(hObject, handles);
end
% --- Executes when chebguimainwindow is resized.
function chebguimainwindow_ResizeFcn(hObject, eventdata, handles)
% hObject handle to chebguimainwindow (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
end
function button_ode_Callback(hObject, eventdata, handles)
% Switch to ODE mode.
handles = chebguiController.switchMode(handles, 'bvp');
guidata(hObject, handles);
end
% --- Executes on button press in button_pde.
function button_pde_Callback(hObject, eventdata, handles)
% Switch to PDE mode.
handles = chebguiController.switchMode(handles, 'pde');
guidata(hObject, handles);
end
% --- Executes on button press in button_pde.
function button_eig_Callback(hObject, eventdata, handles)
% Switch to EIG mode.
handles = chebguiController.switchMode(handles, 'eig');
guidata(hObject, handles);
end
% --- Executes on selection change in iter_list.
function iter_list_Callback(hObject, eventdata, handles)
% Called when user selects an eigenvalue from the list after solving.
% Developer note:
% contents = cellstr(get(hObject, 'String')) returns iter_list contents as
% cell array
% contents{get(hObject, 'Value')} returns selected item from iter_list
% Selecting from the list only does something when we are in EIG mode. Display
% corresponding eigenfunctions when clicking on eigenvalues.
if ( strcmp(handles.latest.type, 'eig') )
selection = get(handles.iter_list, 'Value');
chebguiController.plotEigenmodes(handles, selection);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ------------------------- Other subfunctions ---------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ----------------------All CreateFcn are stored here --------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DEVELOPER NOTE: Most of these are automatically created by MATLAB.
function dom_left_CreateFcn(hObject, eventdata, handles)
bgColorIsDefault = isequal(get(hObject, 'BackgroundColor'), ...
get(0, 'defaultUicontrolBackgroundColor'));
if ( ispc && bgColorIsDefault )
set(hObject, 'BackgroundColor', 'white');
end
end
function dom_right_CreateFcn(hObject, eventdata, handles)
bgColorIsDefault = isequal(get(hObject, 'BackgroundColor'), ...
get(0, 'defaultUicontrolBackgroundColor'));
if ( ispc && bgColorIsDefault )
set(hObject, 'BackgroundColor', 'white');
end
end
function input_DE_CreateFcn(hObject, eventdata, handles)
bgColorIsDefault = isequal(get(hObject, 'BackgroundColor'), ...
get(0, 'defaultUicontrolBackgroundColor'));
if ( ispc && bgColorIsDefault )
set(hObject, 'BackgroundColor', 'white');
end
end
function input_RBC_CreateFcn(hObject, eventdata, handles)
bgColorIsDefault = isequal(get(hObject, 'BackgroundColor'), ...
get(0, 'defaultUicontrolBackgroundColor'));
if ( ispc && bgColorIsDefault )
set(hObject, 'BackgroundColor', 'white');
end
end
function input_GUESS_CreateFcn(hObject, eventdata, handles)
bgColorIsDefault = isequal(get(hObject, 'BackgroundColor'), ...
get(0, 'defaultUicontrolBackgroundColor'));
if ( ispc && bgColorIsDefault )
set(hObject, 'BackgroundColor', 'white');
end
end
function input_LBC_CreateFcn(hObject, eventdata, handles)
bgColorIsDefault = isequal(get(hObject, 'BackgroundColor'), ...
get(0, 'defaultUicontrolBackgroundColor'));
if ( ispc && bgColorIsDefault )
set(hObject, 'BackgroundColor', 'white');
end
end
function iter_list_CreateFcn(hObject, eventdata, handles)
bgColorIsDefault = isequal(get(hObject, 'BackgroundColor'), ...
get(0, 'defaultUicontrolBackgroundColor'));
if ( ispc && bgColorIsDefault )
set(hObject, 'BackgroundColor', 'white');
end
end
function fig_sol_CreateFcn(hObject, eventdata, handles)
% Hint: place code in OpeningFcn to populate fig_sol
end
function fig_norm_CreateFcn(hObject, eventdata, handles)
% Hint: place code in OpeningFcn to populate fig_norm
end
function input_timedomain_CreateFcn(hObject, eventdata, handles)
bgColorIsDefault = isequal(get(hObject, 'BackgroundColor'), ...
get(0, 'defaultUicontrolBackgroundColor'));
if ( ispc && bgColorIsDefault )
set(hObject, 'BackgroundColor', 'white');
end
end
function tempedit_CreateFcn(hObject, eventdata, handles)
end
function ylim1_CreateFcn(hObject, eventdata, handles)
end
function ylim1_Callback(hObject, eventdata, handles)
end
function ylim2_CreateFcn(hObject, eventdata, handles)
end
function ylim2_Callback(hObject, eventdata, handles)
end
function button_solve_ButtonDownFcn(hObject, eventdata, handles)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ---------------------- Right-clicking functions ------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DEVELOPER NOTE: These methods will open the CHEBGUIEDIT sub-GUI
function input_DE_ButtonDownFcn(hObject, eventdata, handles)
chebguiEdit('chebguiWindow', handles.chebguimainwindow, 'input_DE');
input_DE_Callback(hObject, eventdata, handles);
end
function input_LBC_ButtonDownFcn(hObject, eventdata, handles)
chebguiEdit('chebguiWindow', handles.chebguimainwindow, 'input_LBC');
input_LBC_Callback(hObject, eventdata, handles);
end
function input_RBC_ButtonDownFcn(hObject, eventdata, handles)
chebguiEdit('chebguiWindow', handles.chebguimainwindow, 'input_RBC');
input_RBC_Callback(hObject, eventdata, handles);
end
function input_BC_ButtonDownFcn(hObject, eventdata, handles)
chebguiEdit('chebguiWindow', handles.chebguimainwindow, 'input_BC');
input_BC_Callback(hObject, eventdata, handles);
end
function input_GUESS_ButtonDownFcn(hObject, eventdata, handles)
chebguiEdit('chebguiWindow', handles.chebguimainwindow, 'input_GUESS');
input_GUESS_Callback(hObject, eventdata, handles);
end
function editfontsize_CreateFcn(hObject, eventdata, handles)
bgColorIsDefault = isequal(get(hObject, 'BackgroundColor'), ...
get(0, 'defaultUicontrolBackgroundColor'));
if ( ispc && bgColorIsDefault )
set(hObject, 'BackgroundColor', 'white');
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ----------------------- Callbacks for menu items ----------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function menu_file_Callback(hObject, eventdata, handles)
end