rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
newton_oo_model.m
1 function model = newton_oo_model(params)
2 % function model = newton_model(params)
3 %
4 % optional fields of params:
5 % model_size: - 'big' simulations are done on a larger grid with very
6 % small time steps
7 % - 'small' simulations are done on a smaller grid with
8 % bigger time steps
9 % model_type: - 'buckley_leverett' -- A Buckley-Leverett problem
10 % - 'linear_diffusion' -- A linear parabolic problem with
11 % constant diffusion
12 % `` \partial_{t} u - \nabla \cdot ( \mu_1 \nabla u ) = 0 ``
13 % - 'exponential_diffusion' -- A non-linear parabolic problem
14 % with exponential function as diffusion coefficient
15 % `` \partial_{t} u
16 % - \nabla \cdot ( k_0 + \mu_1 u^{\mu_2} \nabla u ) ``
17 % - 'eoc' -- A linear diffusion problem with known exact
18 % solution for validation of numerical scheme
19 % - 'eoc_nonlinear' -- A nonlinear diffusion problem with known
20 % exact solution for validation of numerical scheme
21 %
22 
23  if nargin == 0
24  params = [];
25  end
26 
27  if ~isfield(params, 'model_size')
28  params.model_size = 'normal';
29  end
30 
31  if ~isfield(params, 'model_type')
32  params.model_type = 'exponential_diffusion';
33  end
34 
35  model = NonlinEvol.descr_default;
36  model.name = 'newton_oo_model';
37  model.rb_problem_type = 'NonlinEvol';
38 
39  %% grid
40  model = unitcube(model);
41  model.xnumintervals = 100;
42  model.ynumintervals = 100;
43 
44  %% time domain
45  model.T = 1.0;
46  model.nt = 80;
47 
48  %% model size, affecting grid & time domain
49  if isfield(params, 'model_size')
50  if isequal(params.model_size, 'big')
51  model.xnumintervals = 200;
52  model.ynumintervals = 200;
53  elseif isequal(params.model_size, 'small')
54  model.xnumintervals = 50;
55  model.ynumintervals = 50;
56  model.nt = 25;
57  end
58  end
59 
60  %% boundary settings
61  % set all to dirichlet-boundary by specifying "rectangles", all
62  % boundary within is set to boundary type by bnd_rect_index
63  model.bnd_rect_corner1 = [-0.999999, 0; ...
64  0, -0.9999999 ];
65  model.bnd_rect_corner2 = [ 2, 0.999999; ...
66  0.999999, 2 ];
67  % -1 means dirichlet, -2 means neumann
68  model.bnd_rect_index = [ -2, -2 ];
69 
70  %% diffusivity
71  model.diffusivity_ptr = @diffusivity_exponential;
72  model.diffusivity_derivative_ptr = @diffusivity_exponential_derivative;
73  model.diff_k0 = 0.00;
74  model.diff_m = 1.0;
75  model.diff_p = 2.0;
76 
77  %% fluxes
78  model.num_conv_flux_ptr = @fv_num_conv_flux_engquist_osher;
79  model.num_diff_flux_ptr = @fv_num_diff_flux_gradient;
80  model.flux_linear = 0;
81  model.name_flux = 'exponential';
82  model.geometry_transformation = 'none';
83 
84  model.k = 0.005;
85  model.gravity = 0;
86 
87  %% operators
88  model.operators_diff_implicit = @fv_operators_diff_implicit_gradient;
89  model.operators_conv_implicit = @fv_operators_zero;
90  model.operators_neumann_implicit = @fv_operators_zero;
91  model.fv_expl_conv_weight = 0.0;
92  model.fv_impl_diff_weight = 1.0;
93  model.implicit_gradient_operators_algorithm = ...
94  @fv_frechet_operators_diff_implicit_gradient;
95 
96  model.implicit_nonlinear = true;
97 
98  model.data_const_in_time = false;
99 
100  %% dirichlet values
101  model.dirichlet_values_ptr = @dirichlet_values_leftright;
102  model.c_dir_left = 0.1;
103  model.c_dir_right = 0.6;
104  model.dir_middle = 0.5;
105 
106  %% neumann values
107  model.neumann_values_ptr = @neumann_values_homogeneous;
108  %model.neumann_values_ptr = @neumann_values_outflow;
109  model.c_neu = 0.00;
110 
111  %% init values
112  model.init_values_ptr = @init_values_bars;
113  model.c_init = 0.1;
114 
115  %% velocity/convection
116  model.filecache_velocity_matrixfile_extract = 0;
117  model.divclean_mode = false;
118  model.flux_quad_degree = 1;
119 
120  model.conv_flux_ptr = @conv_flux_linear;
121 
122  model.velocity_ptr = @velocity_transport;
123  model.transport_x = 0.1;
124  model.transport_y = 0.1;
125 
126  model.conv_flux_derivative_ptr = @(glob, U, params) ...
127  params.velocity_ptr(glob, params);
128 
129 
130  %% solver
131  model.newton_solver = 1;
132  model.newton_steps = 60;
133 
134  model.newton_regularisation = 0;
135 
136  model.stencil_mode = 'edge';
137  model.local_stencil_size = 1;
138 
139  %% parameters
140  model.mu_names = {'diff_k0'};
141  model.mu_ranges = {[0.01, 0.5]};
142 
143  % default rb values
144  model.parspacesize = 8;
145  stop_Nmax = 20;
146  stop_epsilon = 1e-4;
147  stop_timeout = 24*60*60;
148 
149  if isfield(params, 'model_type')
150  if strcmp(params.model_type, 'linear_diffusion')
151  model.mu_names = {'diff_k0'};
152  model.mu_ranges = {[0.01, 0.5]};
153  elseif strcmp(params.model_type, 'exponential_diffusion')
154  model.diff_k0 = 0.0000;
155  model.diff_m = 0.01;
156  model.bnd_rect_index = [-2,-2];
157  model.c_init = 0.0001;
158  model.newton_regularisation = 0;
159  model.diff_p = 2.0;
160 
161  model.T = 1;
162  model.nt = 80;
163 
164  model.mu_names = {'diff_p','diff_m','c_init'};
165  model.mu_ranges = {[1 5],[0 0.01],[0 0.2]};
166 
167  if isfield(params, 'use_laplacian') && params.use_laplacian
168  model.laplacian_derivative_ptr = @(glob, U, model) ...
169  real((model.diff_m*U.^(model.diff_p-1)));
170  model.laplacian_ptr = @(glob, U, model) ...
171  real((1/model.diff_p * model.diff_m * U.^(model.diff_p)));
172  model.diffusivity_ptr = @(glob, U, model) ...
173  struct('K',1,'epsilon',0);
174  model.diffusivity_derivative = @(glob, U, model) ...
175  struct('K',1,'epsilon',0);
176  model.implicit_gradient_operators_algorithm = ...
178  end
179 
180  model.parspacesize = [4, 1, 2];
181 
182  elseif strcmp(params.model_type, 'eoc')
183 
184  model.xnumintervals = 10;
185  model.ynumintervals = 10;
186  model.diff_k0 = 0.05;
187  model.diff_m = 0;
188  model.nt = 50;
189 
190  model.init_values_ptr = @exact_function_heat_equation;
191  model.dirichlet_values_ptr = @exact_function_heat_equation;
192 
193  model.bnd_rect_index = [ -1, -1 ];
194 
195  elseif strcmp(params.model_type, 'eoc_nonlinear')
196  model.xnumintervals = 10;
197  model.ynumintervals = 10;
198 
199  model.newton_regularisation = 0;
200 
201  model.diff_k0 = 0.0;
202  model.diff_m = 1;
203  model.diff_p = 1.0;
204 
205  model.T = 1.0;
206  model.nt = 150;
207 
208  model.init_values_ptr = @exact_function_plaplace;
209  model.dirichlet_values_ptr = @exact_function_plaplace;
210 
211  model.bnd_rect_index = [ -1, -2 ];
212 
213  elseif strcmp(params.model_type, 'buckley_leverett')
214  error('buckley leverett problem type is not implemented yet.');
215  end
216  end
217 
218  model.enable_error_estimator = 1;
219  model.Mstrich = 1;
220 
221  % error norm for residual in error estimation
222  model.error_norm = 'l2';
223 
224  %% finalize the model
225  model = model_default(model);
226 
227  if ~isfield(model, 'ei_space_operators')
228  model.ei_space_operators = { model.L_E_local_ptr, model.L_I_local_ptr };
229  end
230 
231  if isfield(params, 'verbose')
232  model.verbose = params.verbose;
233  else
234  model.verbose = 0;
235  end
236  model.debug = 0;
237 
238 
239 end
240 
241 % vim: set et sw=2:
function [ L_I_diff , bdir_I_diff ] = fv_operators_diff_implicit_gradient(model, model_data, U, NU_ind)
computes diffusion contributions to finite volume time evolution matrices, or their Frechet derivati...
function model = model_default(model, T, nt)
model = model_default(model)
Definition: model_default.m:17
function model = unitcube(model)
function adding fields to model for generating a 2D rectgrid with 100 x 100 elements on the unit-squa...
Definition: unitcube.m:17
function buckley_leverett()
small script demonstrating a buckley leverett problem discretization and RB model reduction ...