rbmatlab  1.13.10
 All Classes Namespaces Files Functions Variables Groups Pages
conservation_test.m
Go to the documentation of this file.
1 % test of conservativity of galerkin projection by the linear-fv approach.
2 % motivation of a conservative RB scheme is demonstrated
3 % with this example: The reduced scheme is not conservative, the
4 % missing conservativity correlates with the l1-error. So
5 % a conservative RB-scheme may result in a more accurate RB-scheme
6 
7 % Bernard Haasdonk 25.1.2008
8 
9 % parameters defining a linear problem with zero boundary conditions
10 % (then mass conservation follows)
11 
12 params = [];
13 % rectangular or triangular
14 params.gridtype = 'triagrid';
15 params.grid_initfile = '2dsquaretriang';
16 
17 %params.gridtype = 'rectgrid';
18 %params.xnumintervals = 20;
19 %params.ynumintervals = 20;
20 %params.xrange = [0,1];
21 %params.yrange = [0,1];
22 
23 % set all to neuman-boundary by specifying "rectangles", all
24 % boundary within is set to boundary type
25 params.bnd_rect_corner1 = [-1; ...
26  -1];
27 params.bnd_rect_corner2 = [ 2; ...
28  2];
29 
30 % -1 means dirichlet, -2 means neumann
31 params.bnd_rect_index = -2; % first is dirichlet, second neuman
32 
33 % time discretization
34 %params.T = 1.0;
35 %params.nt = 200; % guess and adjust later
36 
37 params.T = 1.0;
38 params.nt = 80; % guess and adjust later
39 
40 % output settings
41 params.verbose = 10;
42 params.axis_equal = 1;
43 params.clim = [-1,1];
44 
45 % data functions
46 % name of function in RBmatlab/datafunc/init_values
47 params.name_init_values = 'gradient_box';
48 % parameters for data functions
49 params.c_init_up = 1.0;
50 %params.c_init_lo = 1.0;
51 params.c_init_lo = 0.0;
52 %params.c_init_lo = -1.0;
53 
54 % name of function in RBmatlab/datafunc/dirichlet_values
55 params.name_dirichlet_values = 'zero';
56 %params.c_dir = 0;
57 %params.name_dirichlet_values = 'homogeneous';
58 %params.c_dir = 0;
59 
60 % name of function in RBmatlab/datafunc/neuman_values
61 %params.name_neuman_values = 'homogeneous';
62 %params.c_neu = 0;
63 params.name_neuman_values = 'zero';
64 
65 %params.name_neuman_values = 'homogeneous';
66 %params.c_neu = 0;
67 
68 % convective flux
69 
70 params.name_flux = 'parabola';
71 % maximum velocity:
72 params.c = 1;
73 % for simplifying computation in case of linear flux:
74 params.flux_linear = 1;
75 params.flux_quad_degree = 1;
76 
77 %params.name_flux = 'burgers_parabola';
78 % for simplifying computation in case of linear flux:
79 %params.flux_linear = 0;
80 %params.flux_quad_degree = 2;
81 
82 % parameter of chosen conv-flux
83 %params.vmax = 0.30;
84 %params.vrot_angle = 0;
85 %params.vrot_angle = -pi/4;
86 %params.vrot_angle = -pi/10;
87 %params.flux_pdeg = 2; % burgers exponent
88 
89 % rb-formulation
90 params.mu_names = {'c_init_lo','c_init_up'};
91 params.mu_ranges = {[-1,1],[-1, 1]};
92 %params.rb_problem_type = 'nonlin_evol';
93 params.rb_problem_type = 'lin_evol';
94 
95 % finite volume settings
96 params.name_diffusive_num_flux = 'none';
97 params.name_convective_num_flux = 'lax-friedrichs';
98 
99 % determine maximum lxf
100 params.lxf_lambda = 3.6
101 if ~isfield(params,'lxf_lambda')
102  disp('Lxf-Lambda is not set!! Computing empirically maximum possible...');
103  params.lxf_lambda = 0.9 * fv_search_max_lxf_lambda([],params);
104  disp(['Found maximum lxF-lambda =', num2str(params.lxf_lambda)]);
105  disp('Please set this value in your script for skipping search next time!');
106  keyboard;
107 end;
108 % later set explicit:
109 %params.lxf_lambda = 1.25;
110 %params.name_convective_num_flux = 'enquist-osher';
111 
112 % projection of analytical initial data to discrete function
113 params.init_values_algorithm = 'fv_init_values';
114 % get mass matrix for inner product computation from DOF-vectors
115 params.inner_product_matrix_algorithm = 'fv_inner_product_matrix';
116 params.data_const_in_time = 1;
117 params.L_I_inv_norm_bound = 1;
118 params.L_E_norm_bound = 1;
119 
120 % settings for operators (only lin_evol)
121 params.operators_algorithm = 'fv_operators_implicit_explicit';
122 
123 
124 % settings for empirical interpolation (only for nonlin_evol)
125 %params.implicit_operators_algorithm = 'fv_operators_implicit';
126 %params.L_E_local_name = 'fv_conv_explicit_space';
127 %par.range = params.mu_ranges;
128 %params.ei_numintervals = [4,4]; % 8x8 parameter grid
129 %params.Mmax = 150;
130 %params.ei_detailed_savepath = 'burgers_fv_5x5_detailed';
131 %params.ei_operator_savepath = 'burgers_fv_5x5_ei_operator';
132 %params.ei_time_indices = 1:params.nt;
133 %params.CRB_generation_mode = 'param-time-space-grid';
134 %params.ei_target_error = 'interpol';
135 
136 % settings for reduced basis generation
137 params.detailed_simulation_algorithm = 'detailed_simulation';
138 %params.init_values_algorithm = 'fv_init_values';
139 %params.inner_product_matrix_algorithm = 'fv_inner_product_matrix';
140 params.error_algorithm = 'fv_error';
141 %params.lxf_lambda = 1.0194e+003;
142 %params.data_const_in_time = 1;
143 params.error_norm = 'l2';
144 params.RB_extension_algorithm = 'RB_extension_PCA_fixspace';
145 % 'RB_extension_max_error_snapshot'};
146 params.RB_stop_timeout = 2*60*60; % 2 hours
147 params.RB_stop_epsilon = 1e-5;
148 params.RB_error_indicator = 'error'; % true error
149 %params.RB_error_indicator = 'estimator'; % Delta from rb_simulation
150 params.RB_stop_Nmax = 100;
151 %params.RB_generation_mode = 'uniform_fixed';
152 params.RB_numintervals = 5;
153 params.RB_detailed_train_savepath = 'conservation_test';
154 
155 
156 %disp('detailed simulation:');
157 
158 detailed_data.grid = construct_grid(params);
159 U = detailed_simulation([],params);
160 params.title = 'detailed simulation';
161 plot_element_data_sequence(detailed_data.grid, U, params);
162 M = inner_product_matrix(detailed_data.grid,params);
163 % 1-norm
164 norm1U = sum( abs(M * U) );
165 
166 % reduced simulation based on single trajectory
167 
168 params.RB_generation_mode = 'PCA_trajectory';
169 detailed_data = rb_detailed_prep(params);
170 
171 params.N = ceil(size(detailed_data.RB,2)/8);
172 
173 offline_data = rb_offline_prep(detailed_data,params);
174 reduced_data = rb_online_prep(offline_data,params);
175 simulation_data = rb_simulation(reduced_data,params);
176 Urb = rb_reconstruction(detailed_data, simulation_data);
177 
178 params.title = 'reduced simulation';
179 plot_element_data_sequence(detailed_data.grid, U, params);
180 norm1Urb = sum( abs(M * Urb) );
181 
182 figure;
183 plot([norm1U; norm1Urb]')
184 legend({'detailed','reduced'});
185 title('1-norm of detailed and approximate solution');
186 xlabel('time-index k');
187 ylabel('1-norm');
188 
189 figure;
190 err = fv_l2_error(U,Urb,detailed_data.W);
191 plot(err);
192 title('l2-error between detailed and approximate solution');
193 xlabel('time-index k');
194 ylabel('l2-error');
195 
196 
197 
198 
199 
200 % TO BE ADJUSTED TO NEW SYNTAX
201 %| \docupdate