KerMor  0.9
Model order reduction for nonlinear dynamical systems and nonlinear approximation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tests.m
Go to the documentation of this file.
1 namespace models{
2 namespace burgers{
3 
4 
5 /* (Autoinserted by mtoc++)
6  * This source code has been filtered by the mtoc++ executable,
7  * which generates code that can be processed by the doxygen documentation tool.
8  *
9  * On the other hand, it can neither be interpreted by MATLAB, nor can it be compiled with a C++ compiler.
10  * Except for the comments, the function bodies of your M-file functions are untouched.
11  * Consequently, the FILTER_SOURCE_FILES doxygen switch (default in our Doxyfile.template) will produce
12  * attached source files that are highly readable by humans.
13  *
14  * Additionally, links in the doxygen generated documentation to the source code of functions and class members refer to
15  * the correct locations in the source code browser.
16  * However, the line numbers most likely do not correspond to the line numbers in the original MATLAB source files.
17  */
18 
19 class Tests {
38  public: /* ( Static ) */
39 
40 
41  static function d = getMoRePasDir() {
42  d = fullfile(KerMor.App.DataDirectory," test_Burgers_MoRePaS ");
43  if exist(d," file ") ~= 7
44  [~,~] = mkdir(d);
45  end
46  }
47 
48 
49  static function createMoRePaSIIPlots(models.Burgers.Burgers m,colvec<double> mu) {
50  d = models.burgers.Tests.getMoRePasDir;
51 
52 /* types = {'fig','pdf','jpg'};
53  * types = {'png','jpg'}; */
54  types = [" jpg "];
55  pm = PlotManager;
56  pm.NoTitlesOnSave= true;
57  pm.SingleSize= [720 540];
58  pm.LeaveOpen= false;
59  pm.UseFileTypeFolders= true;
60 
61  /* % Different dimension m' plots (model independent)
62  * load(fullfile(d,'minreqmdashorders.mat'));
63  * models.burgers.Tests.morepas12_plotDiffMeanReqErrs([6 7],pm,v500,v1500,v500_maxorder,v1500_maxo);
64  * h = legend(gca(pm.Figures(1)),'d=500','d=1500','d=500 (maxo)','d=1500 (maxo)');
65  * set(h,'Location','Best');
66  * h = legend(gca(pm.Figures(2)),'d=500','d=1500','d=500 (maxo)','d=1500 (maxo)');
67  * set(h,'Location','Best');
68  * pm.done;
69  * pm.FilePrefix = 'burgers';
70  * pm.savePlots(d,types,[],true);
71  * return; */
72 
73  /* % Model preparations
74  *m = r.FullModel; */
75  m.Approx.Order= [12 5];
76  r = m.buildReducedModel(100);
77 
78  if nargin < 2
79  mu = .0400574;
80  end
81  inputidx = 1;
82 
83  /* % Simulation pics
84  * m.PlotAzEl = [-49 34];
85  * [~,y] = m.simulate(mu, 1);
86  * [~,y1] = m.simulate(m.Data.ParamSamples(:,1), 1);
87  * [~,y2] = m.simulate(m.Data.ParamSamples(:,end), 1);
88  * r.ErrorEstimator.Enabled = false;
89  * [t,yr] = r.simulate(mu, 1);
90  * r.ErrorEstimator.Enabled = true;
91  *
92  * pm.FilePrefix = [m.SaveTag '_sim'];
93  * m.plot(t, y1, pm.nextPlot('full_sol_mumin',...
94  * sprintf('Full solution for \\mu=%g',m.Data.ParamSamples(:,1))));
95  *
96  * m.plot(t, y2, pm.nextPlot('full_sol_mumax',...
97  * sprintf('Full solution for \\mu=%g',m.Data.ParamSamples(:,end))));
98  * %view(-24,44);
99  * m.plot(t, y1-y2, pm.nextPlot('full_sol_muvar',...
100  * sprintf('Model variance over parameter range [%g, %g]',...
101  * m.Data.ParamSamples(:,1),m.Data.ParamSamples(:,end))));
102  * %view(-26,22);
103  * m.plot(t, y, pm.nextPlot('full_sol',...
104  * sprintf('Full solution for \\mu=%g',mu)));
105  * m.plot(t, y, pm.nextPlot('red_sol',...
106  * sprintf('Reduced solution for \\mu=%g',mu)));
107  * m.plot(t, y-yr, pm.nextPlot('abs_err','Absolute error'));
108  * % m.plot(t, abs((y-yr)./y), pm.nextPlot('rel_err','Relative error'));
109  * pm.done;
110  * pm.savePlots(d,types,[]); */
111 
112  /* Plot for different M,M' values
113  * pm.FilePrefix = sprintf('%s_m_mdash_errors',m.SaveTag);
114  * savefile = fullfile(d,pm.FilePrefix);
115  * if exist([savefile '.mat'],'file')
116  * load([savefile '.mat']);
117  * else
118  * errordata = testing.DEIM.computeDEIMErrors(...
119  * m.Approx, m.Data.ApproxTrainData);
120  * relerrs = [1e-1 1e-2 1e-4 1e-6];
121  * [t, valtrue] = testing.DEIM.getMinReqErrorOrdersTable(errordata, relerrs, m.Data.ApproxTrainData.xi.m);
122  * t.saveToFile([savefile '.tex']);
123  * [tmaxo, valmaxorder] = testing.DEIM.getMinReqErrorOrdersTable(errordata, relerrs, m.Data.ApproxTrainData.xi.m, m.Approx.MaxOrder);
124  * tmaxo.saveToFile([savefile '_true.tex']);
125  * save([savefile '.mat'],'errordata', 'relerrs', 't', 'tmaxo','valtrue','valmaxorder');
126  * end
127  *
128  * t.display;
129  * tmaxo.display;
130  * testing.DEIM.plotDEIMErrs(errordata, pm);
131  * figure(2); view(28,12);
132  * figure(6); view(-34,46);
133  * pm.done;
134  * pm.savePlots(d,types,[1 2 6],true); */
135 
136  /* % Estimator analysis
137  * ea = EstimatorAnalyzer(r);
138  * ea.LineWidth = 2;
139  * ea.MarkerSize = 12;
140  * ea.NumMarkers = 4;
141  * ea.PlotStartIndex = 4;
142  * e = r.ErrorEstimator; */
143 
144  /* % Error estimator check for M,M' DEIM approx error est ---------------------------
145  * Using true log lip const
146  * e.UseTrueLogLipConst = true;
147  *
148  * est = ea.getDefaultEstStruct;
149  * est(end+1).Name = 'Ref: True local const'; % Expensive versions
150  * est(end).Estimator = e.clone;
151  * est(end).Estimator.UseTrueDEIMErr = true;
152  * est(end).MarkerStyle = 'p';
153  * est(end).LineStyle = '-';
154  * est(end).Color = [0 0.5 0];
155  * ref1 = est(end);
156  * est = testing.DEIM.getDEIMEstimators_ErrOrders(r,est,[1 2 3 5 10]);
157  * ea.Est = est;
158  * ea.SaveTexTables = fullfile(d,'table_mdash.tex');
159  * [errs, relerrs, ctimes] = ea.compute(mu,1);
160  * ea.createPlots(errs, relerrs, ctimes, pm);
161  * pm.createZoom(1,[.7 1 .9*min(errs(:,end)) 1.1*max(errs(:,end))]);
162  * pm.done;
163  * pm.FilePrefix = sprintf('%s_err_mdash_trueloglip',m.SaveTag);
164  * pm.savePlots(d,types,[1 4],true); */
165 
166 /* %% Error estimator check for M,M' DEIM approx error est ---------------------------
167  * % Using full jac log norm
168  * e.UseTrueLogLipConst = false;
169  * e.UseFullJacobian = true;
170  * ea.SaveTexTables = fullfile(d,'table_mdash.tex');
171  *
172  * est = ea.getDefaultEstStruct;
173  * est(end+1).Name = 'L_G[J(y)]'; % Expensive versions
174  * est(end).Estimator = e.clone;
175  * est(end).Estimator.UseTrueDEIMErr = true;
176  * est(end).MarkerStyle = 'p';
177  * est(end).LineStyle = '-';
178  * est(end).Color = [.9 .6 0];
179  * ref2 = est(end);
180  * est(end+1) = ref1; % Expensive versions
181  * %est = testing.DEIM.getDEIMEstimators_ErrOrders(r, est, [1 2 3 5 10]);
182  * ea.Est = est;
183  * [errs, relerrs, ctimes] = ea.compute(mu,1);
184  * ea.createPlots(errs, relerrs, ctimes, pm);
185  * pm.createZoom(1,[.7 1 .9*min(errs(:,end)) 1.1*max(errs(:,end))]);
186  * pm.done;
187  * pm.FilePrefix = sprintf('%s_err_mdash_fulljac_lognorm',m.SaveTag);
188  * pm.savePlots(d,types,[1 4],true);
189  *
190  *
191  * %% JacMDEIM & SimTrans error plots ------------------------------------------------
192  * r.System.f.Order = [12 10];
193  * e.UseTrueLogLipConst = false;
194  * e.UseFullJacobian = false;
195  * e.UseTrueDEIMErr = false;
196  *
197  * % Expensive versions
198  * est = ea.getDefaultEstStruct;
199  * ref1.Estimator.UseTrueDEIMErr = false;
200  * %ref1.Name = 'Reference #1 m''';
201  * est(end+1) = ref1;
202  * ref2.Estimator.UseTrueDEIMErr = false;
203  * %ref2.Name = 'Reference #2 m''';
204  * est(end+1) = ref2;
205  * est = testing.DEIM.getDEIMEstimators_MDEIM_ST(r,est,[1 3 10],[1 3 10]);
206  * ea.Est = est;
207  * ea.NumMarkers = 3;
208  * ea.SaveTexTables = fullfile(d,'table_jac_st.tex');
209  * [errs, relerrs, ctimes] = ea.compute(mu,1);
210  * ea.createPlots(errs, relerrs, ctimes, pm);
211  * pm.createZoom(1,[.65 1 .9*min(errs(:,end)) 1.1*max(errs(:,end))]);
212  * pm.done;
213  * pm.FilePrefix = 'err_jac_st';
214  * pm.savePlots(d,types,[1 4],true,[true false]); */
215  }
227  static function morepas12_plotDiffMeanReqErrs(indices,pm,varargin) {
228  for k = 1:length(indices)
229  idx = indices(k);
230  h = pm.nextPlot(sprintf(" diffmeanreqerrs_%d ",idx),...
231  " Minimum/Mean required m "" values for relative errors ",...
232  " DEIM order m "," m "" values ");
233  hold(h," on ");
234  n = length(varargin);
235  l = LineSpecIterator(n);
236  for i=1:n
237  d = varargin[i];
238  d = d(1:138,[1 idx]);
239  sel = round(d(:,1)) == d(:,1);
240  d = d(sel,:);
241  plot(h,d(:,1),d(:,2)," Color ",l.nextColor," LineWidth ",2);
242  end
243  end
244  }
245 
246 
247  static function [res , m ] = testBurgers_DEIM_versions(dim,version) {
248  if nargin < 2
249  version = 1;
250  if nargin < 1
251  dim = 20;
252  end
253  end
254  m = models.burgers.Burgers(dim, version);
255 
256  if dim > 1000
257  m.Data.useFileTrajectoryData;
258  end
259 
260  /* % Sampling - manual */
261  s = sampling.ManualSampler;
262  s.Samples= logspace(log10(0.04),log10(0.08),10);
263  m.Sampler= s;
264 
265  /* % Approx */
266  a = approx.DEIM(m.System);
267  a.MaxOrder= 40;
268  m.Approx= a;
269 
270  m.offlineGenerations;
271  a.Order= [5 2];
272  r = m.buildReducedModel;
273  [t,y] = r.simulate(r.getRandomParam);
274  m.plot(t,y);
275  res = true;
276  }
277 
278 
279  static function res = test_BurgersModels() {
280  models.burgers.Tests.testBurgers_DEIM_versions(50, 1);
281  models.burgers.Tests.testBurgers_DEIM_versions(50, 2);
282  res = true;
283  }
284 
285 
286 
287 };
288 }
289 }
290 
logical NoTitlesOnSave
Flag that determines if any figures title's are removed when using savePlots.
Definition: PlotManager.m:199
static function res = test_BurgersModels()
Definition: Tests.m:279
static function createMoRePaSIIPlots(models.Burgers.Burgers m,colvec< double > mu)
Call with d500 version.
Definition: Tests.m:49
PlotManager: Small class that allows the same plots generated by some script to be either organized a...
Definition: PlotManager.m:17
A variable number of input arguments.
static function [ res , m ] = testBurgers_DEIM_versions(dim, version)
Definition: Tests.m:247
Tests: Some tests and simulation settings for Burger's equation models.
Definition: Tests.m:19
static function d = getMoRePasDir()
Definition: Tests.m:41
static function morepas12_plotDiffMeanReqErrs(indices, pm, varargin)
Definition: Tests.m:227
Global configuration class for all KerMor run-time settings.
Definition: KerMor.m:17
static function KerMor theinstance = App()
The singleton KerMor instance.
Definition: KerMor.m:910
LinSpecIterator: Small helper class to automatically iterate through different line styles/markers/co...