rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
evol_TB_2D_weak_form_operators_output.m
1 function [v, s_l2norm] = evol_TB_2D_weak_form_operators_output(model,model_data)
2 %function [v, s_l2norm] = evol_TB_2D_weak_form_operators_output(model,model_data)
3 %
4 % This function returns the output operator v for the Comsol 2D evolution
5 % Thermal Block model.
6 %
7 % The output is defined as the integral over the bottom of the Thermal
8 % block:
9 % s(\mu) = l(u(\mu)) = \int_0^1 u(x,0) dx
10 % and can be comupted s(\mu) = v' * (rb_)sim_data.U;
11 %
12 % This function checks whether linear or quadratic finfite elements are
13 % used and uses a Simpson-rule (pdeg=2) or an trapezoidal rule (pdeg=1)
14 % If other Finite Elements are used, a trapezoidal rule is used (BUT THIS
15 % CASE HAS NOT BEEN TESTED, SO BE CAREFUL!!!)
16 %
17 % The L2-Norm of the output operator is the square root of the integration
18 % area, so in this case should be equal to 1.
19 %
20 % Input:
21 % - model
22 % - model_data
23 %
24 % Output:
25 % - v : output_operator: s=v'*sim-data.U;
26 % - s_l2norm : L2-Norm of the ouput operator (can be used for error
27 % estimation)
28 %
29 % Oliver Zeeb, 2013/11/21
30 
31 
32 
33 if model.use_comsol
34  grid_info = model_data.grid_info;
35 
36  % get dof indices of the bottom
37  bnd_dof_ind = find(grid_info.dofs.coords(2,:) <= 10*eps);
38 
39  %get the according coords and values
40  bnd_coords = grid_info.dofs.coords(1,bnd_dof_ind);
41 
42  %resort for quadrature
43  [bnd_coord_sort,bnd_coord_sort_ind] = sort(bnd_coords);
44  %bnd_coord_sort is now:
45  %for pdeg=1: x1 x2 x3 x4 ...
46  %for pdeg=2: x1 (x1+x2)/2 x2 (x2+x3)/2 x3 ... --> coords in between of the mesh edges!
47 
48  if strcmp(model.element_type{1},'shlag') %check lagrange finite elements are used
49  v_dof = zeros(1,size(bnd_coords,2));
50  switch model.pdeg{1}
51  case 2 %fuer pdeg = 2: Simpson-Rule
52  v_dof(1) = 1/6*(bnd_coord_sort(3)-bnd_coord_sort(1));
53  v_dof(2:2:end-1) = diff(bnd_coord_sort(1:2:end))*2/3;
54  v_dof(3:2:end-2) = 1/6* (bnd_coord_sort(5:2:end) - bnd_coord_sort(1:2:end-3));
55  v_dof(end) = 1/6*(bnd_coord_sort(end)-bnd_coord_sort(end-2));
56  otherwise %pdeg = 1 or anything else: trapezoidal rule
57  v_dof(1) = 0.5*(bnd_coord_sort(2) - bnd_coord_sort(1));
58  v_dof(2:end-1) = 0.5 * (bnd_coord_sort(3:end) - bnd_coord_sort(1:end-2));
59  v_dof(end) = 0.5 * (bnd_coord_sort(end) - bnd_coord_sort(end-1));
60  end
61  else %no lagrangian elements!
62  warning('using trapezodial rule for output integration! Might be inaccurate since used element type is unknown!')
63  warning('THIS CASE HAS NOT BEEN TESTED EXTENSEVELY SO FAR...')
64  v_dof(1) = 0.5*(bnd_coord_sort(2) - bnd_coord_sort(1));
65  v_dof(2:end-1) = 0.5 * (bnd_coord_sort(3:end) - bnd_coord_sort(1:end-2));
66  v_dof(end) = 0.5 * (bnd_coord_sort(end) - bnd_coord_sort(end-1));
67  end
68 
69  %Blow up the Vector again to be able to calculate v' * sim_data.U
70  v = zeros(grid_info.ndofs,1);
71  bnd_dof_ind_sort = bnd_dof_ind(bnd_coord_sort_ind); %since v is sorted, the indices of the bnd_dofs have to be sorted accordingly
72  %now blow up the vector:
73  v(bnd_dof_ind_sort) = v_dof;
74  s_l2norm = sqrt(max(bnd_coords)-min(bnd_coords));
75 
76 
77 else %~model.use_comsol
78  v = model_data.operators.operators_output;
79  s_l2norm = model_data.operators.output_operator_l2norm;
80 end