1 function advection_fv_output_optimization(step)
2 % script
using the advection_fv_output_opt model to demonstrate
3 % optimization
using a reduced basis.
7 % mu_names = {
'cone_weight',
'vx_weight',
'vy_weight'};
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
16 % step = 4, % loading optimization-data from a file
17 % step = 5, % detailed optimization by gradient method
20 % Markus Dihlmann 06.02.2010
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;
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 %step = 1; % initialization of model and plot of model data
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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);
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 %step = 2; % detailed simulation of lin_evol
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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);
59 % disp(
'model debugging turned on.')
61 model.cone_weight = 0.5;
62 model.vx_weight = 0.5;
63 model.vy_weight = 0.75;
66 %model.cone_weight = 1.0;
67 % model.vx_weight = 1;
68 % model.vy_weight = 0;
69 sim_data = detailed_simulation(model,model_data);
71 disp('Value of the outputfunctional at the end of simulation:');
72 sim_data.y(size(sim_data.y))
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 %step = 3; simple detailed optimization of lin_evol
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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);
84 [opt_data,model] =
optimize(model, model_data, [],[]);%model.detailed_optimization(model, model_data);
85 disp('Maximal output:')
87 disp('Parametersets for which this maximal value was reached:')
88 opt_data.max_output_paramsets
90 %plot output_data from detailed simulations (plotting last two parameters with first parameter fixed to optimal value)
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);
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);
100 save_opt_data(
'Test.dat', opt_data, model);
103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 % step = 4; loading data from file
105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 disp(
'Loading data from file')
108 model = advection_fv_output_opt_model(params);
109 model_data =gen_model_data(model);
113 %plot output_data from detailed simulations (plotting last two parameters with first parameter fixed to optimal value)
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);
122 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123 % step = 5; detailed optimization by gradient method
124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126 disp(
'Detailed optimization by gradient method');
127 model = advection_fv_output_opt_model(params);
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';
135 %insert gradient optimization method pointer here:
136 %model.optimization.optimizer = @...
137 model.optimization.get_Jacobian = @lin_evol_opt_get_Jacobian;
139 %genrerate model_data:
144 [opt_data, model] =
optimize(model, model_data, [],[]);
151 save_opt_data(
'gradient_results.dat',opt_data, model);