rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
dom_dec_detailed_simulation.m
Go to the documentation of this file.
1 function sim_data = dom_dec_detailed_simulation(model,model_data)
2 % function sim_data = dom_dec_detailed_simulation(model,model_data)
3 % the detailed solution is computed via the iterative
4 % Dirichlet-Neumann schema.
5 %
6 % Return values:
7 % sim_data: struct containing the solution and further information
8 %
9 % Generated fields of sim_data:
10 % uh: cell of discrete functions, which contains the last
11 % iteratives
12 % all_dofs: cell of matrizes containing the dofs of all iteratives
13 % theta: the last relaxation-parameter
14 % numiter: number of iterations
15 % reached_maxiter: indicates the cause of termination
16 % reached_tolerance: indicates the cause of termination
17 
18 % I.Maier, 31.10.2011
19 
20 model.decomp_mode = 0;
21 dir = model.dirichlet_side;
22 no_dir = mod(dir,2)+1;
23 
24 sim_data = [];
25 sim_data.reached_maxiter = 0;
26 sim_data.reached_tolerance = 0;
27 
28 if model.verbose >= 1
29  fprintf('start detailed simulation ');
30 end;
31 
32 % compute required matrizes and vectors
33 [A, r, A_gamma, r_gamma] = model.operators(model,model_data);
34 
35 % initialize iterative schema
36 uh = cell(1,2);
37 uh_old = cell(1,2);
38 uh_tilde = cell(1,2);
39 zh = cell(1,2);
40 for i = 1:2
41  uh{i} = femdiscfunc([],model_data.df_infos{i});
42  uh_old{i} = zeros(uh{i}.ndofs,1);
43  uh_tilde{i} = zeros(uh{i}.ndofs,1);
44  zh{i} = zeros(uh{i}.ndofs,1);
45 end;
46 a = [];
47 sigma = 0;
48 tau = 0;
49 theta = [];
50 
51 % initialize output
52 sim_data.uh = cell(1,2);
53 for i = 1:2
54  sim_data.uh{i} = uh{i};
55 end;
56 sim_data.all_dofs = cell(1,2);
57 for i = 1:2
58  sim_data.all_dofs{i} = zeros(uh{i}.ndofs,model.maxiter);
59 end;
60 
61 % step 0
62 uh{dir}.dofs = A_gamma{dir} \ r_gamma{dir};
63 uh{no_dir}.dofs = A{no_dir} \ r{no_dir};
64 uh_0_no_dir = uh{no_dir}.dofs;
65 
66 for i = 1:2
67  r_gamma{i} = zeros(size(r_gamma{i}));
68  r_gamma{i}(model_data.gamma_dofs{i}) = ...
69  uh{i}.dofs(model_data.gamma_dofs{i});
70  uh_tilde{i} = A_gamma{i} \ r_gamma{i};
71 end;
72 
73 % delete matrizes not needed any longer
74 A_gamma_dir = A_gamma{dir};
75 clear('A_gamma');
76 r_dir = r{dir};
77 clear('r');
78 
79 % step >=1
80 continue_loop = 1;
81 numiter = 0;
82 diff_norm = zeros(1,2);
83 while continue_loop
84 
85  % ...
86  numiter = numiter+1;
87  for i = 1:2
88  uh_old{i} = uh{i}.dofs;
89  end;
90 
91  % ...
92  r_gamma{dir}(model_data.gamma_dofs{dir}) = ...
93  uh_tilde{no_dir}(model_data.gamma_dofs{no_dir});
94  zh{dir} = A_gamma_dir \ r_gamma{dir};
95 
96  % ...
97  a = (zh{dir}'*A{dir}*zh{dir}) / (uh_tilde{no_dir}'*A{no_dir}* ...
98  uh_tilde{no_dir});
99  sigma = max(sigma,a);
100  tau = max(tau,1/a);
101  theta = (tau+1)/(sigma^2*tau+tau+2)/2*model.relaxation_factor;
102 
103  % ...
104  uh{dir}.dofs = uh{dir}.dofs + theta*(zh{dir}-uh_tilde{dir});
105  uh_tilde{dir} = uh_tilde{dir} + theta*(zh{dir}-uh_tilde{dir});
106 
107  % ...
108  zh{dir} = r_dir - A{dir}*uh{dir}.dofs;
109  r_gamma{no_dir}(model_data.gamma_dofs{no_dir}) = ...
110  zh{dir}(model_data.gamma_dofs{dir});
111  zh{no_dir} = A{no_dir} \ r_gamma{no_dir};
112 
113  % ...
114  uh{no_dir}.dofs = uh_0_no_dir + zh{no_dir};
115  uh_tilde{no_dir} = uh_tilde{no_dir} + uh{no_dir}.dofs - ...
116  uh_old{no_dir};
117 
118  % save dofs
119  for i = 1:2
120  sim_data.all_dofs{i}(:,numiter) = uh{i}.dofs;
121  end;
122 
123  % stopping criteria
124  for i = 1:2
125  diff_norm(i) = sqrt((uh{i}.dofs-uh_old{i})' * A{i} * ...
126  (uh{i}.dofs-uh_old{i}));
127  end;
128  if sum(diff_norm) < model.det_sim_tol
129  continue_loop = 0;
130  sim_data.reached_tolerance = 1;
131  end;
132  if numiter == model.maxiter
133  continue_loop = 0;
134  sim_data.reached_maxiter = 1;
135  end;
136 
137  if (mod(numiter,100) == 1) && (model.verbose >= 1)
138  fprintf('.');
139  end;
140 
141 end;
142 
143 % further information
144 sim_data.theta = theta;
145 sim_data.numiter = numiter;
146 for i = 1:2
147  sim_data.all_dofs{i} = sim_data.all_dofs{i}(:,1:numiter);
148 end;
149 
150 % compute output
151 if model.base_model.compute_output_functional
152  s = 0;
153  for i = 1:2
154  model.base_model.decomp_mode = model.decomp_mode;
155 
156  model_data.df_info = model_data.df_infos{i};
157  v = model.operators_output(model.base_model,model_data);
158  s = s + (v(:)') * sim_data.uh{i}.dofs;
159  end
160  sim_data.s = s;
161 end
162 
163 if model.verbose >= 1
164  fprintf('\n');
165 end;
class representing a continous piecewise polynomial function of arbitrary dimension. DOFS correspond to the values of Lagrange-nodes.
Definition: femdiscfunc.m:17
function sim_data = dom_dec_detailed_simulation(model, model_data)
the detailed solution is computed via the iterative Dirichlet-Neumann schema.