rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
rhs_part.m
Go to the documentation of this file.
1 function vec = rhs_part(int_kernel, model, df_info, bc_info)
2 %function vec = rhs_part(int_kernel, model, df_info, bc_info)
3 % Fem right-hand side assembly.
4 %
5 % Assembly of volume or boundary Fem right hand side. This function
6 % is used in Fem.Assembly.operator().
7 %
8 % boundary integrals are computed if bc_info is provided. Then int_kernel
9 % is a cell array of length bc_info.nbint_parts.
10 
11 % IM 16.07.2013
12 
13 
14 %% initialize
15 is_boundary = (nargin > 3);
16 
17 nint_parts = 1;
18 if is_boundary
19  nint_parts = bc_info.nbint_parts;
20 end
21 
22 vec = zeros(df_info.ndofs, 1);
23 vec_cell = {};
24 
25 
26 %% assemble each integral part
27 for j = 1:nint_parts
28 
29  % if available
30  if ~is_boundary || ~isempty(int_kernel{j})
31 
32  if is_boundary
33  lin_ind = sub2ind(size(df_info.grid.EL), bc_info.elinds{j}, bc_info.edgeinds{j});
34  c = df_info.grid.EL(lin_ind);
35  else
36  c = df_info.detDF;
37 
38  end
39 
40  for i = 1:df_info.ndofs_per_element
41 
42  if is_boundary
43  func = @(x) int_kernel{j}(x, model, df_info, i, bc_info.elinds{j}, bc_info.edgeinds{j});
44  res = intervalquadrature(model.qdeg, func);
45 
46  gids = df_info.get_global_dof_index(bc_info.elinds{j}, i);
47  else
48  func = @(x) int_kernel(x, model, df_info, i);
49  res = triaquadrature(model.qdeg, func);
50 
51  gids = df_info.get_global_dof_index(1:df_info.grid.nelements, i);
52  end
53 
54  if ~isempty(res)
55 
56  % depending on decomp_mode the output is a single vector or a cell
57  % array of vectors
58  if ~iscell(res)
59 
60  res = c .* res;
61 
62  vec_tmp = sparse(gids, ones(length(gids), 1), res, df_info.ndofs, 1);
63  vec = vec + vec_tmp;
64  else
65 
66  if ~iscell(vec)
67  vec = cell(1, length(res));
68  for q = 1:length(res)
69  vec{q} = zeros(df_info.ndofs, 1);
70  end
71  end
72 
73  for q = 1:length(res)
74 
75  res{q} = c .* res{q};
76 
77  vec_tmp = sparse(gids, ones(length(gids), 1), res{q}, df_info.ndofs, 1);
78  vec{q} = vec{q} + vec_tmp;
79  end
80  end % iscell
81  end % isempty
82  end
83 
84  if is_boundary
85  % concatenate cell arrays
86  if iscell(vec)
87 
88  vec_cell = [vec_cell, vec(:)'];
89  vec = [];
90  end
91  end
92 
93  end
94 
95 end
96 
97 if ~isempty(vec_cell)
98  vec = vec_cell;
99 end
100 
101 end
102 
function res = intervalquadrature(poldeg, func, varargin)
integration of function func over reference interval == unit interval. by Gaussian quadrature exactly...