forked from chebfun/chebfun
-
Notifications
You must be signed in to change notification settings - Fork 1
/
chebguiExporterBVP.m
140 lines (107 loc) · 5.1 KB
/
chebguiExporterBVP.m
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
classdef chebguiExporterBVP < chebguiExporter
%CHEBGUIEXPORTERBVP Export a BVP from CHEBGUI.
% This is a an concrete implementation of the class CHEBGUIEXPORTER, which
% exports BVPs from CHEBGUI to .m-files, to the workspace, or to a .chebgui
% file. It is not intended to be called directly by the end user.
%
% See also CHEBGUI, CHEBGUIEXPORTER.
% Copyright 2017 by The University of Oxford and The Chebfun Developers.
% See http://www.chebfun.org/ for Chebfun information.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% CLASS PROPERTIES:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
properties
% The default file name when exporting to an .m-file:
defaultFileName = 'chebbvp.m';
% Description for printing to .m files:
description = 'a boundary-value problem';
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% CLASS CONSTRUCTOR:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
methods ( Access = public, Static = false )
function A = chebguiExporterBVP(varargin)
% Do nothing!
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% STATIC METHODS:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
methods ( Access = public, Static = true )
% Extract information from the CHEBGUI object to a struct
expInfo = exportInfo(guifile)
% Print problem description:
printDescription(fid, expInfo)
% Print options for solving the problem:
printOptions(fid, expInfo)
% Print lines for setting up the problem:
printSetup(fid, expInfo, guifile)
% Print the actual lines for calling the solver method:
printSolver(fid, expInfo)
% Print steps taken after the solver finishes:
printPostSolver(fid, expInfo)
function toWorkspaceSolutionOnly(handles)
%TOWORKSPACESOLUTIONONLY Export the solution to the workspace
%
% Note: this method exports fewer objects to the workspace than the
% toWorkspace() method.
% Obtain the variable names:
varnames = handles.varnames;
nv = numel(varnames);
% Obtain the latest solution:
sol = handles.latest.solution;
% Export to the workspace!
for k = 1:nv
assignin('base', varnames{k}, sol(:,k));
evalin('base', varnames{k});
end
end
function toMat(handles)
%TOMAT Export from the CHEBGUI figure to a .mat-file.
% Obtain the variable names involved in the problem.
varnames = handles.varnames;
for k = 1:numel(varnames);
eval([varnames{k} ' = handles.latest.solution(:,k);']);
end
% Extract the norm of the updates, the CHEBOP and all options.
normVec = handles.latest.normDelta; %#ok<NASGU>
N = handles.latest.chebop; %#ok<NASGU>
options = handles.latest.options; %#ok<NASGU>
% Show the user a figure for selecting where to save.
uisave([varnames', 'normVec', 'N', 'options'], 'bvp');
end
function toWorkspace(handles)
%TOWORKSPACE Export from the CHEBGUI figure to the workspace.
% Setup dialog for asking the user for variable names to be used.
numlines = 1;
options.Resize ='on';
options.WindowStyle ='modal';
% Need slightly different dialogs depending on whether we were
% solving scalar problem or a coupled system.
varnames = handles.varnames;
nv = numel(varnames);
if ( nv == 1 )
prompt = {'Differential operator', 'Solution:',...
'Vector with norm of updates', 'Options'};
else
prompt = ['Differential operator', varnames.',...
'Vector with norm of updates', 'Options'];
end
name = 'Export to workspace';
defaultAnswer = ['N', varnames', 'normVec', 'options'];
% Show the user a dialog.
answer = inputdlg(prompt, name, numlines, defaultAnswer, options);
% Obtain the latest solution:
sol = handles.latest.solution;
% Export to the workspace!
if ( ~isempty(answer) )
assignin('base', answer{1}, handles.latest.chebop);
for k = 1:nv
assignin('base', answer{k+1}, sol(:,k));
end
assignin('base', answer{nv+2}, handles.latest.normDelta);
assignin('base', answer{nv+3}, handles.latest.options);
end
end
end
end