rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
fem_rhs_volume_part_assembly.m
1 function r_comp = fem_rhs_volume_part_assembly(...
2  r_int_kernel,model,df_info)
3 %function r_comp = fem_rhs_volume_part_assembly(...
4 % r_int_kernel,model,df_info)
5 %
6 % auxiliary function assembling the volume integral components of
7 % right hand side, i.e. source components
8 % note: cell-array valued kernels can be integrated.
9 
10 % B. Haasdonk 22.2.2011
11 % I. Maier 24.03.2011
12 
13 r_comp = zeros(df_info.ndofs,1);
14 
15 for i = 1:df_info.nlagrange_nodes
16  basis_func_i = @(x) fem_evaluate_basis_function(df_info,x,i);
17  gids = df_info.global_dof_index(1:df_info.grid.nelements,i);
18  % integral kernel: q*phi on all elements simultaneously
19  % and transformation on reference triangle, i.e. mult with detDF
20  % here x is in reference triangle! auxiliary function defined below
21  f = @(x) int_kernel_mult_phi_i(x,r_int_kernel,basis_func_i,model,df_info);
22 
23  res = triaquadrature(model.qdeg,f);
24  if ~iscell(res)
25  res = res.* df_info.detDF; % due to transformation formula
26 
27  % caution: if multiple gids identical, only the last entry is
28  % added in case of real vectors!
29  % => r_source(gids) = r_source(gids) + res_unique; !!!
30  % Instead here sparse matrix is
31  % used, there assignment is incremental
32  % add all increments of identical gids!!!
33  r_comp_incr = sparse(gids,ones(length(gids),1),res,df_info.ndofs,1);
34  r_comp = r_comp + r_comp_incr;
35  % r_source_nterms_incr = sparse(gids,ones(length(gids),1),...
36  % ones(length(gids),1),ndofs,1);
37  % r_source_nterms = r_source_nterms + r_source_nterms_incr;
38 
39  else % iscell!!!
40  if ~iscell(r_comp)
41  % for first time: initialize r_comp
42  r_comp = cell(1,length(res));
43  for q=1:length(res)
44  r_comp{q} = zeros(df_info.ndofs,1);
45  end;
46  end;
47  for q = 1:length(res)
48  res{q} = res{q}.* df_info.detDF; % due to transformation formula
49  r_comp_incr = sparse(gids,ones(length(gids),1),res{q},df_info.ndofs,1);
50  r_comp{q} = r_comp{q} + r_comp_incr;
51  end;
52  end;
53 end;
54 
55 if ~isempty(df_info.dirichlet_gids)
56  if ~iscell(r_comp)
57  r_comp(df_info.dirichlet_gids) = 0;
58  else
59  for q = 1:length(r_comp)
60  r_comp{q}(df_info.dirichlet_gids) = 0;
61  end;
62  end;
63 end;
64 
65 
66 %%%%%%%%%%%%%%%%%%%%%%%%%% auxiliary function %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 function res = int_kernel_mult_phi_i(x,r_int_kernel,basis_func_i,model,df_info)
68 
69 r_int = r_int_kernel(df_info.grid,1:df_info.grid.nelements,x,model);
70 if ~iscell(r_int)
71  res = r_int * ...
72  basis_func_i(x);
73 else
74  res = cell(1,length(r_int));
75  for q = 1:length(r_int)
76  res{q} = r_int{q} * ...
77  basis_func_i(x);
78 
79  end;
80 end;