comparison +scheme/Elastic2dVariable.m @ 855:5751262b323b feature/poroelastic

Add 1D quadrature matrices as property in Elastic2dVariable.
author Martin Almquist <malmquist@stanford.edu>
date Sun, 16 Sep 2018 18:00:14 -0700
parents 1f6b2fb69225
children 607c631f175e
comparison
equal deleted inserted replaced
838:bd43256f0c41 855:5751262b323b
1 classdef Elastic2dVariable < scheme.Scheme 1 classdef Elastic2dVariable < scheme.Scheme
2 2
3 % Discretizes the elastic wave equation: 3 % Discretizes the elastic wave equation:
4 % rho u_{i,tt} = di lambda dj u_j + dj mu di u_j + dj mu dj u_i 4 % rho u_{i,tt} = di lambda dj u_j + dj mu di u_j + dj mu dj u_i
5 % opSet should be cell array of opSets, one per dimension. This 5 % opSet should be cell array of opSets, one per dimension. This
6 % is useful if we have periodic BC in one direction. 6 % is useful if we have periodic BC in one direction.
7 7
8 properties 8 properties
9 m % Number of points in each direction, possibly a vector 9 m % Number of points in each direction, possibly a vector
28 28
29 % Traction operators used for BC 29 % Traction operators used for BC
30 T_l, T_r 30 T_l, T_r
31 tau_l, tau_r 31 tau_l, tau_r
32 32
33 H, Hi % Inner products 33 H, Hi, H_1D % Inner products
34 phi % Borrowing constant for (d1 - e^T*D1) from R 34 phi % Borrowing constant for (d1 - e^T*D1) from R
35 gamma % Borrowing constant for d1 from M 35 gamma % Borrowing constant for d1 from M
36 H11 % First element of H 36 H11 % First element of H
37 e_l, e_r 37 e_l, e_r
38 d1_l, d1_r % Normal derivatives at the boundary 38 d1_l, d1_r % Normal derivatives at the boundary
39 E % E{i}^T picks out component i 39 E % E{i}^T picks out component i
40 40
41 H_boundary % Boundary inner products 41 H_boundary % Boundary inner products
42 42
43 % Kroneckered norms and coefficients 43 % Kroneckered norms and coefficients
44 RHOi_kron 44 RHOi_kron
45 Hi_kron 45 Hi_kron
169 obj.H = kron(H{1},H{2}); 169 obj.H = kron(H{1},H{2});
170 obj.Hi = inv(obj.H); 170 obj.Hi = inv(obj.H);
171 obj.H_boundary = cell(dim,1); 171 obj.H_boundary = cell(dim,1);
172 obj.H_boundary{1} = H{2}; 172 obj.H_boundary{1} = H{2};
173 obj.H_boundary{2} = H{1}; 173 obj.H_boundary{2} = H{1};
174 obj.H_1D = {H{1}, H{2}};
174 175
175 % E{i}^T picks out component i. 176 % E{i}^T picks out component i.
176 E = cell(dim,1); 177 E = cell(dim,1);
177 I = speye(m_tot,m_tot); 178 I = speye(m_tot,m_tot);
178 for i = 1:dim 179 for i = 1:dim
228 % Loop over components 229 % Loop over components
229 for i = 1:dim 230 for i = 1:dim
230 tau_l{j}{i} = sparse(m_tot,dim*m_tot); 231 tau_l{j}{i} = sparse(m_tot,dim*m_tot);
231 tau_r{j}{i} = sparse(m_tot,dim*m_tot); 232 tau_r{j}{i} = sparse(m_tot,dim*m_tot);
232 for k = 1:dim 233 for k = 1:dim
233 T_l{j}{i,k} = ... 234 T_l{j}{i,k} = ...
234 -d(i,j)*LAMBDA*(d(i,k)*e_l{k}*d1_l{k}' + db(i,k)*D1{k})... 235 -d(i,j)*LAMBDA*(d(i,k)*e_l{k}*d1_l{k}' + db(i,k)*D1{k})...
235 -d(j,k)*MU*(d(i,j)*e_l{i}*d1_l{i}' + db(i,j)*D1{i})... 236 -d(j,k)*MU*(d(i,j)*e_l{i}*d1_l{i}' + db(i,j)*D1{i})...
236 -d(i,k)*MU*e_l{j}*d1_l{j}'; 237 -d(i,k)*MU*e_l{j}*d1_l{j}';
237 238
238 T_r{j}{i,k} = ... 239 T_r{j}{i,k} = ...
239 d(i,j)*LAMBDA*(d(i,k)*e_r{k}*d1_r{k}' + db(i,k)*D1{k})... 240 d(i,j)*LAMBDA*(d(i,k)*e_r{k}*d1_r{k}' + db(i,k)*D1{k})...
240 +d(j,k)*MU*(d(i,j)*e_r{i}*d1_r{i}' + db(i,j)*D1{i})... 241 +d(j,k)*MU*(d(i,j)*e_r{i}*d1_r{i}' + db(i,j)*D1{i})...
241 +d(i,k)*MU*e_r{j}*d1_r{j}'; 242 +d(i,k)*MU*e_r{j}*d1_r{j}';
242 243
243 tau_l{j}{i} = tau_l{j}{i} + T_l{j}{i,k}*E{k}'; 244 tau_l{j}{i} = tau_l{j}{i} + T_l{j}{i,k}*E{k}';
244 tau_r{j}{i} = tau_r{j}{i} + T_r{j}{i,k}*E{k}'; 245 tau_r{j}{i} = tau_r{j}{i} + T_r{j}{i,k}*E{k}';
245 end 246 end
268 269
269 % Closure functions return the operators applied to the own domain to close the boundary 270 % Closure functions return the operators applied to the own domain to close the boundary
270 % Penalty functions return the operators to force the solution. In the case of an interface it returns the operator applied to the other doamin. 271 % Penalty functions return the operators to force the solution. In the case of an interface it returns the operator applied to the other doamin.
271 % boundary is a string specifying the boundary e.g. 'l','r' or 'e','w','n','s'. 272 % boundary is a string specifying the boundary e.g. 'l','r' or 'e','w','n','s'.
272 % bc is a cell array of component and bc type, e.g. {1, 'd'} for Dirichlet condition 273 % bc is a cell array of component and bc type, e.g. {1, 'd'} for Dirichlet condition
273 % on the first component. 274 % on the first component.
274 % data is a function returning the data that should be applied at the boundary. 275 % data is a function returning the data that should be applied at the boundary.
275 % neighbour_scheme is an instance of Scheme that should be interfaced to. 276 % neighbour_scheme is an instance of Scheme that should be interfaced to.
276 % neighbour_boundary is a string specifying which boundary to interface to. 277 % neighbour_boundary is a string specifying which boundary to interface to.
277 function [closure, penalty] = boundary_condition(obj, boundary, bc, tuning) 278 function [closure, penalty] = boundary_condition(obj, boundary, bc, tuning)
278 default_arg('tuning', 1.2); 279 default_arg('tuning', 1.2);
315 316
316 d = @kroneckerDelta; % Kronecker delta 317 d = @kroneckerDelta; % Kronecker delta
317 db = @(i,j) 1-d(i,j); % Logical not of Kronecker delta 318 db = @(i,j) 1-d(i,j); % Logical not of Kronecker delta
318 alpha = @(i,j) tuning*( d(i,j)* a_lambda*LAMBDA ... 319 alpha = @(i,j) tuning*( d(i,j)* a_lambda*LAMBDA ...
319 + d(i,j)* a_mu_i*MU ... 320 + d(i,j)* a_mu_i*MU ...
320 + db(i,j)*a_mu_ij*MU ); 321 + db(i,j)*a_mu_ij*MU );
321 322
322 % Loop over components that Dirichlet penalties end up on 323 % Loop over components that Dirichlet penalties end up on
323 for i = 1:dim 324 for i = 1:dim
324 C = T{k,i}; 325 C = T{k,i};
325 A = -d(i,k)*alpha(i,j); 326 A = -d(i,k)*alpha(i,j);
326 B = A + C; 327 B = A + C;
327 closure = closure + E{i}*RHOi*Hi*B'*e*H_gamma*(e'*E{k}' ); 328 closure = closure + E{i}*RHOi*Hi*B'*e*H_gamma*(e'*E{k}' );
328 penalty = penalty - E{i}*RHOi*Hi*B'*e*H_gamma; 329 penalty = penalty - E{i}*RHOi*Hi*B'*e*H_gamma;
329 end 330 end
330 331
331 % Free boundary condition 332 % Free boundary condition
332 case {'F','f','Free','free','traction','Traction','t','T'} 333 case {'F','f','Free','free','traction','Traction','t','T'}
333 closure = closure - E{k}*RHOi*Hi*e*H_gamma* (e'*tau{k} ); 334 closure = closure - E{k}*RHOi*Hi*e*H_gamma* (e'*tau{k} );
334 penalty = penalty + E{k}*RHOi*Hi*e*H_gamma; 335 penalty = penalty + E{k}*RHOi*Hi*e*H_gamma;
335 336
336 % Unknown boundary condition 337 % Unknown boundary condition
337 otherwise 338 otherwise
338 error('No such boundary condition: type = %s',type); 339 error('No such boundary condition: type = %s',type);
355 356
356 % Operators and quantities that correspond to the own domain only 357 % Operators and quantities that correspond to the own domain only
357 Hi = obj.Hi; 358 Hi = obj.Hi;
358 RHOi = obj.RHOi; 359 RHOi = obj.RHOi;
359 dim = obj.dim; 360 dim = obj.dim;
360 361
361 %--- Other operators ---- 362 %--- Other operators ----
362 m_tot_u = obj.grid.N(); 363 m_tot_u = obj.grid.N();
363 E = obj.E; 364 E = obj.E;
364 LAMBDA_u = obj.LAMBDA; 365 LAMBDA_u = obj.LAMBDA;
365 MU_u = obj.MU; 366 MU_u = obj.MU;
371 LAMBDA_v = neighbour_scheme.LAMBDA; 372 LAMBDA_v = neighbour_scheme.LAMBDA;
372 MU_v = neighbour_scheme.MU; 373 MU_v = neighbour_scheme.MU;
373 lambda_v = e_v'*LAMBDA_v*e_v; 374 lambda_v = e_v'*LAMBDA_v*e_v;
374 mu_v = e_v'*MU_v*e_v; 375 mu_v = e_v'*MU_v*e_v;
375 %------------------------- 376 %-------------------------
376 377
377 % Borrowing constants 378 % Borrowing constants
378 phi_u = obj.phi{j}; 379 phi_u = obj.phi{j};
379 h_u = obj.h(j); 380 h_u = obj.h(j);
380 h11_u = obj.H11{j}*h_u; 381 h11_u = obj.H11{j}*h_u;
381 gamma_u = obj.gamma{j}; 382 gamma_u = obj.gamma{j};
384 h_v = neighbour_scheme.h(j_v); 385 h_v = neighbour_scheme.h(j_v);
385 h11_v = neighbour_scheme.H11{j_v}*h_v; 386 h11_v = neighbour_scheme.H11{j_v}*h_v;
386 gamma_v = neighbour_scheme.gamma{j_v}; 387 gamma_v = neighbour_scheme.gamma{j_v};
387 388
388 % E > sum_i 1/(2*alpha_ij)*(tau_i)^2 389 % E > sum_i 1/(2*alpha_ij)*(tau_i)^2
389 function [alpha_ii, alpha_ij] = computeAlpha(phi,h,h11,gamma,lambda,mu) 390 function [alpha_ii, alpha_ij] = computeAlpha(phi,h,h11,gamma,lambda,mu)
390 th1 = h11/(2*dim); 391 th1 = h11/(2*dim);
391 th2 = h11*phi/2; 392 th2 = h11*phi/2;
392 th3 = h*gamma; 393 th3 = h*gamma;
393 a1 = ( (th1 + th2)*th3*lambda + 4*th1*th2*mu ) / (2*th1*th2*th3); 394 a1 = ( (th1 + th2)*th3*lambda + 4*th1*th2*mu ) / (2*th1*th2*th3);
394 a2 = ( 16*(th1 + th2)*lambda*mu ) / (th1*th2*th3); 395 a2 = ( 16*(th1 + th2)*lambda*mu ) / (th1*th2*th3);
396 397
397 alpha_ij = mu*(2/h11 + 1/(phi*h11)); 398 alpha_ij = mu*(2/h11 + 1/(phi*h11));
398 end 399 end
399 400
400 [alpha_ii_u, alpha_ij_u] = computeAlpha(phi_u,h_u,h11_u,gamma_u,lambda_u,mu_u); 401 [alpha_ii_u, alpha_ij_u] = computeAlpha(phi_u,h_u,h11_u,gamma_u,lambda_u,mu_u);
401 [alpha_ii_v, alpha_ij_v] = computeAlpha(phi_v,h_v,h11_v,gamma_v,lambda_v,mu_v); 402 [alpha_ii_v, alpha_ij_v] = computeAlpha(phi_v,h_v,h11_v,gamma_v,lambda_v,mu_v);
402 sigma_ii = tuning*(alpha_ii_u + alpha_ii_v)/4; 403 sigma_ii = tuning*(alpha_ii_u + alpha_ii_v)/4;
403 sigma_ij = tuning*(alpha_ij_u + alpha_ij_v)/4; 404 sigma_ij = tuning*(alpha_ij_u + alpha_ij_v)/4;
404 405
405 d = @kroneckerDelta; % Kronecker delta 406 d = @kroneckerDelta; % Kronecker delta
406 db = @(i,j) 1-d(i,j); % Logical not of Kronecker delta 407 db = @(i,j) 1-d(i,j); % Logical not of Kronecker delta
418 closure = closure - 1/2*E{i}*RHOi*Hi*e*H_gamma*e'*tau{i}; 419 closure = closure - 1/2*E{i}*RHOi*Hi*e*H_gamma*e'*tau{i};
419 penalty = penalty - 1/2*E{i}*RHOi*Hi*e*H_gamma*e_v'*tau_v{i}; 420 penalty = penalty - 1/2*E{i}*RHOi*Hi*e*H_gamma*e_v'*tau_v{i};
420 421
421 % Loop over components that we have interface conditions on 422 % Loop over components that we have interface conditions on
422 for k = 1:dim 423 for k = 1:dim
423 closure = closure + 1/2*E{i}*RHOi*Hi*T{k,i}'*e*H_gamma*e'*E{k}'; 424 closure = closure + 1/2*E{i}*RHOi*Hi*T{k,i}'*e*H_gamma*e'*E{k}';
424 penalty = penalty - 1/2*E{i}*RHOi*Hi*T{k,i}'*e*H_gamma*e_v'*E_v{k}'; 425 penalty = penalty - 1/2*E{i}*RHOi*Hi*T{k,i}'*e*H_gamma*e_v'*E_v{k}';
425 end 426 end
426 end 427 end
427 end 428 end
428 429
429 % Returns the coordinate number and outward normal component for the boundary specified by the string boundary. 430 % Returns the coordinate number and outward normal component for the boundary specified by the string boundary.
430 function [j, nj] = get_boundary_number(obj, boundary) 431 function [j, nj] = get_boundary_number(obj, boundary)
492 switch boundary 493 switch boundary
493 case {'w','W','west','West','s','S','south','South'} 494 case {'w','W','west','West','s','S','south','South'}
494 varargout{i} = obj.tau_l{j}; 495 varargout{i} = obj.tau_l{j};
495 case {'e', 'E', 'east', 'East','n', 'N', 'north', 'North'} 496 case {'e', 'E', 'east', 'East','n', 'N', 'north', 'North'}
496 varargout{i} = obj.tau_r{j}; 497 varargout{i} = obj.tau_r{j};
497 end 498 end
498 otherwise 499 otherwise
499 error(['No such operator: operator = ' op{i}]); 500 error(['No such operator: operator = ' op{i}]);
500 end 501 end
501 end 502 end
502 503