rbmatlab  1.13.10
 All Classes Namespaces Files Functions Variables Groups Pages
advection_fv_output_optimization.m
1 function advection_fv_output_optimization(step)
2 % script using the advection_fv_output_opt model to demonstrate
3 % optimization using a reduced basis.
4 %
5 %
6 %
7 % mu_names = {'cone_weight','vx_weight','vy_weight'};
8 % mu_ranges = [0,1]^3
9 %
10 % possible steps:
11 %
12 % step = 1; % initialization of model and plot of model data
13 % step = 2; % detailed simulation of lin_evol
14 % step = 3; % detailed optimization by grid-search of lin-evol and save
15 % data
16 % step = 4, % loading optimization-data from a file
17 % step = 5, % detailed optimization by gradient method
18 %
19 %
20 % Markus Dihlmann 06.02.2010
21 
22 % cartesian grid
23 
24 if nargin < 1
25  step = 1;
26 end;
27 
28 params = [];
29 
30 %params.coarse_factor = 2; % fact 2 => ndofs = 16384, nt = 1024, 15s detailed
31 %params.coarse_factor = 1; % fact 1 => ndofs = 32768, nt = 2048, 60s detailed
32 params.coarse_factor = 2;
33 %verbose(1);
34 
35 switch step
36 
37  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38  %step = 1; % initialization of model and plot of model data
39  case 1
40  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 
42 % verbose(1,'initializaton of lin_evol_model and plot model_data');
43  disp('initializaton of lin_evol_model and plot model_data');
44  model = advection_fv_output_opt_model(params);
45  model_data = gen_model_data(model);
46  params.axis_equal = 1;
47  params.axis_tight = 1;
48  plot(model_data.grid,params);
49 
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51  %step = 2; % detailed simulation of lin_evol
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53  case 2
54 % verbose(1,'detailed simulation of lin_evol_model and plot');
55  disp('detailed simulation of lin_evol_model_opt and plot');
56  model = advection_fv_output_opt_model(params);
57  model_data = gen_model_data(model);
58  % model.debug = 1;
59  % disp('model debugging turned on.')
60  model.verbose = 8;
61  model.cone_weight = 0.5;
62  model.vx_weight = 0.5;
63  model.vy_weight = 0.75;
64  %model.vx_weight = 1;
65  %model.vy_weight = 1;
66  %model.cone_weight = 1.0;
67 % model.vx_weight = 1;
68 % model.vy_weight = 0;
69  sim_data = detailed_simulation(model,model_data);
70  plot_sim_data(model,model_data,sim_data,[]);
71  disp('Value of the outputfunctional at the end of simulation:');
72  sim_data.y(size(sim_data.y))
73 
74 
75 
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77  %step = 3; simple detailed optimization of lin_evol
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 case 3
80  disp('detailed optimization of the lin_evol_opt_model');
81  model = advection_fv_output_opt_model(params);
82  model_data =gen_model_data(model);
83  model.verbose=8;
84  [opt_data,model] = optimize(model, model_data, [],[]);%model.detailed_optimization(model, model_data);
85  disp('Maximal output:')
86  opt_data.max_output
87  disp('Parametersets for which this maximal value was reached:')
88  opt_data.max_output_paramsets
89 
90  %plot output_data from detailed simulations (plotting last two parameters with first parameter fixed to optimal value)
91  plot_info{1}=[2 3];
92  plot_info{2}=[opt_data.max_output_paramsets(1,1),0,0];
93  plot_data_surf(opt_data.output, opt_data.parameter_sets, plot_info);
94 
95  disp('Performing a detailed simulation with an optimal parameter set');
96  model = model.set_mu(model,opt_data.max_output_paramsets(1,:));
97  sim_data = model.detailed_simulation(model, model_data);
98  plot_sim_data(model,model_data,sim_data,[]);
99  %save Data
100  save_opt_data('Test.dat', opt_data, model);
101 
102 
103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104  % step = 4; loading data from file
105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 case 4
107  disp('Loading data from file')
108  model = advection_fv_output_opt_model(params);
109  model_data =gen_model_data(model);
110  model.verbose=8;
111  opt_data = load_opt_data('Test.dat', model);
112 
113  %plot output_data from detailed simulations (plotting last two parameters with first parameter fixed to optimal value)
114  plot_info{1}=[2 3];
115  plot_info{2}=[opt_data.max_output_paramsets(1,1),0,0];
116  plot_data_surf(opt_data.output, opt_data.parameter_sets, plot_info);
117 
118 
119 
120 
121 
122 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123  % step = 5; detailed optimization by gradient method
124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
125 case 5
126  disp('Detailed optimization by gradient method');
127  model = advection_fv_output_opt_model(params);
128  model.verbose =8;
129 
130  %change some fields in model
131  model.optimization.init_params = [0.5,0.5,0.5];
132  model.optimization.params_to_optimize = [0,1,1];
133  model.optimization.opt_mode = 'detailed';
134  model.optimization.objective_function = @lin_evol_get_output_detailed;
135  %insert gradient optimization method pointer here:
136  %model.optimization.optimizer = @...
137  model.optimization.get_Jacobian = @lin_evol_opt_get_Jacobian;
138 
139  %genrerate model_data:
140  %...
141 
142 
143  %optimization
144  [opt_data, model] = optimize(model, model_data, [],[]);
145 
146 
147  %plot results
148  %....
149 
150  %save results
151  save_opt_data('gradient_results.dat',opt_data, model);
152 
153 
154 
155 end; %end switch