1 function sim_data = ellipt_compliant_detailed_simulation(model,model_data)
2 %
function sim_data = ellipt_compliant_detailed_simulation(model,model_data)
4 % computation of FEM solution
for elliptic problem
5 % input: model_data, parameter independent contains grid, p,e,t,
8 % model.gammatop/bottom
11 % sim_data.bm: boundary condition matrix, dependent of mu
12 % sim_data.u : vector of nodal values of solution in gridpoints
13 % sim_data.s : real value, functional output of problem
14 % sim_data.plot_title: title of the plot
16 % following data are representation of the elliptic pde
17 % -grad(c*grad u)+a*u=f
18 % sim_data.a:
'reaction' term.
19 % sim_data.f:
'source' term.
20 % sim_data.c:
'diffusivity' term.
21 % sim_data.A_matlab: left hand side, computed with assempde
22 % sim_data.F_matlab: right hand side, computed with assempde
23 % sim_data.M_matlab: Stiffness matrix
24 % sim_data.K_matlab: Stiffness matrix
25 % sim_data.F_matlab: Stiffness matrix
26 % sim_data.Q_matlab: boundary condition (Neumann)
27 % sim_data.G_matlab: boundary condition (Neumann)
28 % sim_data.H_matlab: boundary condition (Dirichlet)
29 % sim_data.B_matlab: boundary condition (Dirichlet)
32 % B. Haasdonk 21.7.2009
37 sim_data.plot_title=
'Plot of a detailed simulation';
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%create boundary matrix
41 %set boundary condition
42 %bottom+top: from left to right
43 %left+right: from bottom to top
47 noc_bm=length(dl); %number of columns
49 check_left_region = dl(6,:); %number of block left hand side
50 check_right_region = dl(7,:);
51 check_region = dl(6:7,:);
53 zeros_left=find(check_left_region == 0); %find 0
's. this edge is an outer
54 zeros_right=find(check_right_region == 0); %boundary
56 nonzeros_left=find(check_left_region);
57 nonzeros_right=find(check_right_region);
59 inner_boundary_index=intersect(nonzeros_left, nonzeros_right); %index of non zero columns in dl
61 zero_index=find(check_region==0);
62 outer_boundary_index=ceil(zero_index/2);
63 outer_boundary_index=outer_boundary_index';
65 check_max_length = zeros(4,max(model.B1,model.B2));
67 check_max_length(1,i)=length(model.gamma_bottom{i}{1})+length(model.gamma_bottom{i}{2})+4; %bottom
68 check_max_length(2,i)=length(model.gamma_top{i}{3})+length(model.gamma_top{i}{4})+8; %top
71 check_max_length(3,l)=length(model.gamma_left{l}{1})+length(model.gamma_left{l}{2})+4; %left
72 check_max_length(4,l)=length(model.gamma_right{l}{1})+length(model.gamma_right{l}{2})+4; %right
75 nor_bm=max(max(check_max_length)); %number of rows BM
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 BM=zeros(nor_bm, noc_bm); %zeros BM Matrix
84 %%%%% x1/x2, y1/y2 values
91 %find indices of gamma top
92 one_y1_index=find(check_y1 == 1);
93 one_y2_index=find(check_y1 == 1);
95 one_y_index = intersect(one_y1_index, one_y2_index);
97 check_x1_one = check_x1(one_y_index);
100 [tmp, top_tmp]=sort(check_x1_one);
106 top_index(k)=one_y_index(l); %top_index: top indices from left to right
109 %find indices of gamma bottom
111 zero_y1_index=find(check_y1 == 0);
112 zero_y2_index=find(check_y2 == 0);
114 zero_y_index= intersect(zero_y1_index, zero_y2_index);
116 check_x1_zero=check_x1(zero_y_index);
119 [tmp, bottom_tmp]=sort(check_x1_zero);
124 bottom_index(k)=zero_y_index(l); %bottom index: bottom indices from left to right
129 zero_x1_index=find(check_x1 == 0);
130 zero_x2_index=find(check_x2 == 0);
132 zero_x_index=intersect(zero_x1_index, zero_x2_index);
134 check_y1_zero=check_y1(zero_x_index); %
137 [tmp, left_tmp]=sort(check_y1_zero);
142 left_index(k)=zero_x_index(l); %left index: left indices from left to right
147 one_x1_index=find(check_x1 == 1);
148 one_x2_index=find(check_x2 == 1);
150 one_x_index=intersect(one_x1_index, one_x2_index);
152 check_y1_one=check_y1(one_x_index); %
155 [tmp, right_tmp]=sort(check_y1_one);
160 right_index(k)=one_x_index(l); %right index: right indices from left to right
164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
165 %%%%%%
final creation of boundaries
168 outer_bound=[top_index, bottom_index, right_index, left_index];
169 outer_bound=sort(outer_bound);
172 tmp_noc_vec=1:noc_bm;
176 inner_bound=find(tmp_noc_vec >=0);
180 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55
182 std_inner_boundary_char=[
'0',
'0',
'1',
'0']; %double(...) -> 48 48 49 48
183 std_inner_boundary_num=[0,repmat(1,1,5)];
185 std_inner_boundary=[std_inner_boundary_num,double(std_inner_boundary_char)];
187 if length(std_inner_boundary) < nor_bm %fill up with zeros
188 std_inner_boundary(nor_bm);
191 %positioning of inner boundary condition
193 BM(:,i)=std_inner_boundary(:);
197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203 %l_top_bound=max(check_max_length(2,:));
205 %TOP=zeros(l_top_bound, model.B1);
207 fronttail=repmat(1,1,4); %definition of dim, diri, lq, lg
210 lh=length(model.gamma_top{i}{3}); %number of chars
for h
211 lr=length(model.gamma_top{i}{4}); %number of chars
for r
212 outer_topboundary_num(i,:)=[fronttail,lh, lr, 48, 48];
215 outer_topboundary_num=outer_topboundary_num
';
219 tmp_char3=model.gamma_top{i}{3};
220 tmp_char4=model.gamma_top{i}{4};
222 tmp_char{i}=[tmp_char3,tmp_char4]; %
226 outer_topboundary(:,i)=[outer_topboundary_num(:,i);double(tmp_char{i})'];
227 if length(outer_topboundary(:,i)) < nor_bm
228 outer_topboundary(nor_bm,i) = 0;
233 %positioning of top boundary conditions
234 outer_topbound_loop=outer_topboundary;
236 BM(:,i)=outer_topbound_loop(:,1);
237 outer_topbound_loop(:,1)=[];
240 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
244 fronttail=[1,0]; %definition of dim, diri, lq, lg
247 lq=length(model.gamma_bottom{i}{1}); %number of chars
for
248 lg=length(model.gamma_bottom{i}{2}); %number of chars
for
249 outer_bottomboundary_num(i,:)=[fronttail,lq, lg];
252 outer_bottomboundary_num=outer_bottomboundary_num
';
256 tmp_char1=model.gamma_bottom{i}{1};
257 tmp_char2=model.gamma_bottom{i}{2};
259 tmp_char{i}=[tmp_char1,tmp_char2]; %
265 a=[outer_bottomboundary_num(:,i);double(tmp_char{i})'];
266 if length(a) < nor_bm
269 outer_bottomboundary(:,i)=a;
271 % outer_bottomboundary(:,i)=[outer_bottomboundary_num(:,i);double(tmp_char{i})
'];
272 % if length(outer_bottomboundary(:,i)) < nor_bm
273 % outer_bottomboundary(nor_bm,i) = 0;
277 %positioning of bottom boundary conditions
278 outer_bottombound_loop=outer_bottomboundary;
280 BM(:,i)=outer_bottombound_loop(:,1);
281 outer_bottombound_loop(:,1)=[];
285 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
286 %%%%%%left boundaries
288 fronttail=[1,0]; %definition of dim, diri, lq, lg
291 lq=length(model.gamma_left{i}{1}); %number of chars for
292 lg=length(model.gamma_left{i}{2}); %number of chars for
293 outer_leftboundary_num(i,:)=[fronttail,lq, lg];
296 outer_leftboundary_num=outer_leftboundary_num';
300 tmp_char1=model.gamma_left{i}{1};
301 tmp_char2=model.gamma_left{i}{2};
303 tmp_char{i}=[tmp_char1,tmp_char2]; %
309 a=[outer_leftboundary_num(:,i);double(tmp_char{i})
'];
310 if length(a) < nor_bm
313 outer_leftboundary(:,i)=a;
315 % outer_bottomboundary(:,i)=[outer_bottomboundary_num(:,i);double(tmp_char{i})'];
316 %
if length(outer_bottomboundary(:,i)) < nor_bm
317 % outer_bottomboundary(nor_bm,i) = 0;
321 %positioning of left boundary conditions
322 outer_leftbound_loop=outer_leftboundary;
324 BM(:,i)=outer_leftbound_loop(:,1);
325 outer_leftbound_loop(:,1)=[];
328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
329 %%%%%%right boundaries
331 fronttail=[1,0]; %definition of dim, diri, lq, lg
334 lq=length(model.gamma_right{i}{1}); %number of chars
for
335 lg=length(model.gamma_right{i}{2}); %number of chars
for
336 outer_rightboundary_num(i,:)=[fronttail,lq, lg];
339 outer_rightboundary_num=outer_rightboundary_num
';
343 tmp_char1=model.gamma_right{i}{1};
344 tmp_char2=model.gamma_right{i}{2};
346 tmp_char{i}=[tmp_char1,tmp_char2]; %
352 a=[outer_rightboundary_num(:,i);double(tmp_char{i})'];
353 if length(a) < nor_bm
356 outer_rightboundary(:,i)=a;
358 % outer_bottomboundary(:,i)=[outer_bottomboundary_num(:,i);double(tmp_char{i})
'];
359 % if length(outer_bottomboundary(:,i)) < nor_bm
360 % outer_bottomboundary(nor_bm,i) = 0;
364 %positioning of left boundary conditions
365 outer_rightbound_loop=outer_rightboundary;
367 BM(:,i)=outer_rightbound_loop(:,1);
368 outer_rightbound_loop(:,1)=[];
374 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
375 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
377 % falls stueckweise konstante Diffusivitaet:
381 % for p=1:params.B1*params.B2
382 % mu_p = getfield(model,['mu
',num2str(p)])
383 % c = [c,'!
',numstr(mu_p)]
387 % c = richtige_kombination_und_parameter von model.diffusitivy_ptr(...)
394 % tmp_sum=sum(tmp_p,2);
395 % com_t{i}=tmp_sum/3; %CELL ARRAY!!
398 % glob = aus com_t konstruieren;
401 %%%%%simplify p,e,t call
406 % Mittelwert von allen Dreiecken:
411 px = reshape(px,3,ntria);
413 % selbes spielchen fuer py
415 py = reshape(py,3,ntria);
419 c = model.diffusivity(glob,model);
424 % Source-Term: f = model.source(glob,model);
428 f=zeros(1,length(c));
431 % Reaction: a = model.reaction(glob,model);
433 a=zeros(1,length(c));
436 % possible to use dir_vals = model.dirichlet_values(dglob,model)
440 % dir_vals = model.dirichlet_values(dglob,model)
443 % possible to use model.neumann_values(nglob,model) % g_N(x)
446 % neu_vals = model.neumann_values(bglob,model)
451 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
452 %%%%%ASSEMBLING+solving%%%%%%%%%%%%%%
464 %%assembling system with
'stiff springs' (dirichlet conditions)
465 % [A,F]=assempde(BM,p,e,t,c,a,f); %A stiffness matrix, F right-hand side
469 % sim_data.A_matlab_assempde=A;
470 % sim_data.F_matlab_assempde=F;
471 %%%assembling system, first eliminating diri condi
475 [A,F,B,ud]=assempde(BM,p,e,t,c,a,f);
479 Afull = speye(size(p,2));
480 non_diri_values=find(p(2,:)~=1);
481 Afull(non_diri_values,non_diri_values) = A;
484 Bfull(non_diri_values)= F;
488 %Bfull = F + A * B' * ud;
499 % eventuell ueberfluessig:
501 sim_data.u_tmp=u_tmp;
505 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
506 % %split into assembly of area
int contribution + boundary condi contribution
507 K=[]; %stiffness matrix
509 F=[]; %right-hand side
510 [K,M,F]=assema(p,t,c,a,f);
516 [Q,G,H,B]=assemb(BM,p,e);
518 sim_data.K_matlab = K;
519 sim_data.M_matlab = M;
520 sim_data.F_matlab = F;
522 sim_data.Q_matlab = Q;
523 sim_data.G_matlab = G;
524 sim_data.H_matlab = H;
525 sim_data.B_matlab = B;
527 % %%%%%%% 3 different types
528 % %u=assempde(K,M,F,Q,G,H,B);
530 % %%%%%%%%%%%%%%%%%%%%%%
533 % [K1,F1]=assempde(K,M,F,Q,G,H,B);
534 % u_split_matlab=K1\F1;
535 % sim_data.A_split_assempde = K1;
536 % sim_data.F_split_assempde = F1;
537 % sim_data.u_split_matlab=u_split_matlab;
538 % %%%%%%%%%%%%%%%%%%%%%%%
544 % [K2,F2,B,ud]=assempde(K,M,F,Q,G,H,B);
547 % sim_data.K2_no_stiff = K2;
548 % sim_data.F2_no_stiff = F2;
549 % sim_data.B_no_stiff = B;
550 % sim_data.ud_no_stiff = ud;
551 % sim_data.u_no_stiff_springs=u;
558 %u=assempde(BM,p,e,t,c,a,f);
563 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5%
564 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
565 % output computation: Integral over boundary segment
567 %sim_data.s=thermalblock_output_function(model.plot_output,model_data)
569 %sim_data.s=thermalblock_output_function(glob,model)
576 % ausarbeiten des folgenden:
578 calc_mode = model.output_calc_mode;
580 %calc_mode = 2; % 2 only lower edge, 1 all edges
583 ei6 = find(e(6,:)==0); %indices of outer boundary
584 ei7 = find(e(7,:)==0); %edges
587 % glob = Mittelpunkt von Kante / midpoint of edge
589 oe=e(:,ei); %outer boundary edges
590 oestart=oe(1,:); %index of starting point
591 oeend=oe(2,:); %index of ending point
593 poestart=p(:,oestart); %x,y coordinates of correspondign points
594 poeend=p(:,oeend); %
'' ''
596 glob=0.5.*(poestart+poeend)
';
598 weight = model.output_weight_function(glob,model);
599 % %% eventuell indexmenge von nichtnull-weights bestimmen
600 u_start = sim_data.u(oestart);
601 u_end = sim_data.u(oeend);
602 u_values_in_midpoints = 0.5*(u_start + u_end); %column
603 edge_lengths = sqrt(sum((poeend-poestart).^2)); %row
604 edge_lengths=edge_lengths(:); %column
605 integral = edge_lengths.*u_values_in_midpoints.*weight;
607 sim_data.s=sum(integral);
609 else % calc_mode ==2 %only lower edge
611 zero_y_ind=find(p(2,:)==0); %find indices with y=0
614 x_value=x_values(zero_y_ind); %corresponding x values with y=0
616 [x_value_sort,i]=sort(x_value); %sort vector
617 glob = [x_value_sort(:),zeros(length(x_value),1)];
620 u_zero_y=u(zero_y_ind); %u values at y=0
621 u_zero_y_sort=u_zero_y(i); %corresponding u values sorted
623 %the following section tests, if the vector x_value contains 0,1, because
624 %we want to compute the integral in the intervall [0,1].
626 warning('x=0 not found!!! extrapolating values!!
')
628 u_zero=interp1(x_value_sort, u_zero_y_sort,0, 'cubic
');
629 u_zero_y_sort=[u_zero,u_zero_y_sort];
633 warning('x=1 not found!!! extrapolating values!!
')
634 x_value=[x_value ,1];
635 u_one = interp1(x_value_sort,u_zero_y_sort,1,'cubic
');
636 u_zero_y_sort=[u_zero_y_sort,u_one];
639 weight_values = model.output_weight_function(glob,model);
640 integrand_values = u_zero_y_sort.* weight_values;
641 sim_data.s = trapz(x_value_sort, integrand_values);
645 %if model.plot_output ==1
647 % plot(x_value_sort, u_zero_y_sort)