rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
comsol_rb_init_data_basis.m
1 function init_rb = comsol_rb_init_data_basis(model,detailed_data)
2 %function init_rb = comsol_rb_init_data_basis(model,detailed_data)
3 %
4 % This function returns the initial basis for reduced basis generation.
5 % When using comsol, this is solution after the first time step, i.e. the second solution vector!
6 % (due to homogenization of the problem the first solution-vector (without
7 % adding model_data.operators_init_values) is zero!)
8 % The parameter is set to the midpoint of the parameter domain.
9 %
10 % Input:
11 % - model
12 % - detailed_data
13 %
14 % Output:
15 % - init_rb : normalized solution vector at t=0
16 %
17 % Oliver Zeeb, 2013
18 
19 
20 %sets initial data for basis generation
21 if strcmp(model.type,'stat') %stationary problem
22  if model.use_comsol
23  mu_old = get_mu(model);
24  mu=get_mu(model);
25  mu_init=zeros(size(mu));
26  for k=1:length(model.mu_ranges)
27  mu_init(k) = 0.5*(model.mu_ranges{k}(1) + model.mu_ranges{k}(2));
28  end
29  model = set_mu(model,mu_init);
30  cmodel=comsol_set_mu_from_rbmatlab_model(model,detailed_data.comsol_model);
31  cmodel.sol(model.comsol_tags.sol).runAll;
32  init_rb=mphgetu(cmodel);
33  %normalize the init basis vector:
34  inProd_matrix = model.get_inner_product_matrix(detailed_data);
35  norm_init_rb = sqrt(init_rb' * inProd_matrix * init_rb);
36  init_rb = init_rb / norm_init_rb;
37  %reset mu in the model and cmodel
38  model=set_mu(model,mu_old);
39  cmodel=comsol_set_mu_from_rbmatlab_model(model,detailed_data.comsol_model);
40  else
41  mu_init=zeros(size(get_mu(model)));
42  for k=1:length(model.mu_ranges)
43  mu_init(k) = 0.5*(model.mu_ranges{k}(1) + model.mu_ranges{k}(2));
44  end
45  model = set_mu(model,mu_init);
46  sim_data = detailed_simulation(model,detailed_data);
47  init_rb = sim_data.U;
48  inProd_matrix = model.get_inner_product_matrix(detailed_data);
49  norm_init_rb = sqrt(init_rb' * inProd_matrix * init_rb);
50  init_rb = init_rb / norm_init_rb;
51  end
52 elseif strcmp(model.type,'evol') %evolution problem
53  if model.use_comsol
54  mu_old = get_mu(model);
55  mu=get_mu(model);
56  mu_init=zeros(size(mu));
57  for k=1:length(model.mu_ranges)
58  mu_init(k) = 0.5*(model.mu_ranges{k}(1) + model.mu_ranges{k}(2));
59  end
60  model = set_mu(model,mu_init);
61  cmodel=comsol_set_mu_from_rbmatlab_model(model,detailed_data.comsol_model);
62  cmodel.sol('sol1').run;
63  init_rb=mphgetu(detailed_data.comsol_model,'solnum',1);
64  %normalize the init basis vector:
65  inProd_matrix = model.get_inner_product_matrix(detailed_data);
66  norm_init_rb = sqrt(init_rb' * inProd_matrix * init_rb);
67  init_rb = init_rb / norm_init_rb;
68  %reset mu in the model and cmodel
69  model=set_mu(model,mu_old);
70  cmodel=comsol_set_mu_from_rbmatlab_model(model,detailed_data.comsol_model);
71  else %~model.use_comsol
72  mu=get_mu(model);
73  mu_init=zeros(size(mu));
74  for k=1:length(model.mu_ranges)
75  mu_init(k) = 0.5*(model.mu_ranges{k}(1) + model.mu_ranges{k}(2));
76  end
77  model = set_mu(model,mu_init);
78  model.decomp_mode = 1;
79  [L_I_comp, ~, b_comp] = model.operators_ptr(model,detailed_data);
80  model.decomp_mode = 2;
81  [L_I_coeff, ~, b_coeff] = model.operators_ptr(model,detailed_data);
82  L_I = lincomb_sequence(L_I_comp, L_I_coeff);
83  b = lincomb_sequence(b_comp, b_coeff);
84  init_rb = detailed_data.ind_vectors.Null*(L_I \ b) ;
85  %normalize the init basis vector:
86  inProd_matrix = model.get_inner_product_matrix(detailed_data);
87  norm_init_rb = sqrt(init_rb' * inProd_matrix * init_rb);
88  init_rb = init_rb / norm_init_rb;
89  end
90 else
91  error('model type not known!')
92 end