Mercurial > repos > public > sbplib
comparison +scheme/Elastic2dVariable.m @ 813:b374a8aa9246 feature/grids
Correct interface penalty strength in Elastic2dVariable
author | Martin Almquist <malmquist@stanford.edu> |
---|---|
date | Wed, 08 Aug 2018 14:42:24 -0700 |
parents | 1f6b2fb69225 |
children | 386ef449df51 21394c78c72e |
comparison
equal
deleted
inserted
replaced
812:6b83dcb46f54 | 813:b374a8aa9246 |
---|---|
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 |
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 % Inner products |
34 | |
34 phi % Borrowing constant for (d1 - e^T*D1) from R | 35 phi % Borrowing constant for (d1 - e^T*D1) from R |
35 gamma % Borrowing constant for d1 from M | 36 gamma % Borrowing constant for d1 from M |
36 H11 % First element of H | 37 H11 % First element of H |
38 | |
39 % Borrowing from H, M, and R | |
40 thH | |
41 thM | |
42 thR | |
43 | |
37 e_l, e_r | 44 e_l, e_r |
38 d1_l, d1_r % Normal derivatives at the boundary | 45 d1_l, d1_r % Normal derivatives at the boundary |
39 E % E{i}^T picks out component i | 46 E % E{i}^T picks out component i |
40 | 47 |
41 H_boundary % Boundary inner products | 48 H_boundary % Boundary inner products |
42 | 49 |
43 % Kroneckered norms and coefficients | 50 % Kroneckered norms and coefficients |
44 RHOi_kron | 51 RHOi_kron |
45 Hi_kron | 52 Hi_kron |
82 for i = 1:dim | 89 for i = 1:dim |
83 beta = ops{i}.borrowing.R.delta_D; | 90 beta = ops{i}.borrowing.R.delta_D; |
84 obj.H11{i} = ops{i}.borrowing.H11; | 91 obj.H11{i} = ops{i}.borrowing.H11; |
85 obj.phi{i} = beta/obj.H11{i}; | 92 obj.phi{i} = beta/obj.H11{i}; |
86 obj.gamma{i} = ops{i}.borrowing.M.d1; | 93 obj.gamma{i} = ops{i}.borrowing.M.d1; |
94 | |
95 % Better names | |
96 obj.thR{i} = ops{i}.borrowing.R.delta_D; | |
97 obj.thM{i} = ops{i}.borrowing.M.d1; | |
98 obj.thH{i} = ops{i}.borrowing.H11; | |
87 end | 99 end |
88 | 100 |
89 I = cell(dim,1); | 101 I = cell(dim,1); |
90 D1 = cell(dim,1); | 102 D1 = cell(dim,1); |
91 D2 = cell(dim,1); | 103 D2 = cell(dim,1); |
228 % Loop over components | 240 % Loop over components |
229 for i = 1:dim | 241 for i = 1:dim |
230 tau_l{j}{i} = sparse(m_tot,dim*m_tot); | 242 tau_l{j}{i} = sparse(m_tot,dim*m_tot); |
231 tau_r{j}{i} = sparse(m_tot,dim*m_tot); | 243 tau_r{j}{i} = sparse(m_tot,dim*m_tot); |
232 for k = 1:dim | 244 for k = 1:dim |
233 T_l{j}{i,k} = ... | 245 T_l{j}{i,k} = ... |
234 -d(i,j)*LAMBDA*(d(i,k)*e_l{k}*d1_l{k}' + db(i,k)*D1{k})... | 246 -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})... | 247 -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}'; | 248 -d(i,k)*MU*e_l{j}*d1_l{j}'; |
237 | 249 |
238 T_r{j}{i,k} = ... | 250 T_r{j}{i,k} = ... |
239 d(i,j)*LAMBDA*(d(i,k)*e_r{k}*d1_r{k}' + db(i,k)*D1{k})... | 251 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})... | 252 +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}'; | 253 +d(i,k)*MU*e_r{j}*d1_r{j}'; |
242 | 254 |
243 tau_l{j}{i} = tau_l{j}{i} + T_l{j}{i,k}*E{k}'; | 255 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}'; | 256 tau_r{j}{i} = tau_r{j}{i} + T_r{j}{i,k}*E{k}'; |
245 end | 257 end |
268 | 280 |
269 % Closure functions return the operators applied to the own domain to close the boundary | 281 % 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. | 282 % 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'. | 283 % 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 | 284 % bc is a cell array of component and bc type, e.g. {1, 'd'} for Dirichlet condition |
273 % on the first component. | 285 % on the first component. |
274 % data is a function returning the data that should be applied at the boundary. | 286 % 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. | 287 % neighbour_scheme is an instance of Scheme that should be interfaced to. |
276 % neighbour_boundary is a string specifying which boundary to interface to. | 288 % neighbour_boundary is a string specifying which boundary to interface to. |
277 function [closure, penalty] = boundary_condition(obj, boundary, bc, tuning) | 289 function [closure, penalty] = boundary_condition(obj, boundary, bc, tuning) |
278 default_arg('tuning', 1.2); | 290 default_arg('tuning', 1.2); |
315 | 327 |
316 d = @kroneckerDelta; % Kronecker delta | 328 d = @kroneckerDelta; % Kronecker delta |
317 db = @(i,j) 1-d(i,j); % Logical not of Kronecker delta | 329 db = @(i,j) 1-d(i,j); % Logical not of Kronecker delta |
318 alpha = @(i,j) tuning*( d(i,j)* a_lambda*LAMBDA ... | 330 alpha = @(i,j) tuning*( d(i,j)* a_lambda*LAMBDA ... |
319 + d(i,j)* a_mu_i*MU ... | 331 + d(i,j)* a_mu_i*MU ... |
320 + db(i,j)*a_mu_ij*MU ); | 332 + db(i,j)*a_mu_ij*MU ); |
321 | 333 |
322 % Loop over components that Dirichlet penalties end up on | 334 % Loop over components that Dirichlet penalties end up on |
323 for i = 1:dim | 335 for i = 1:dim |
324 C = T{k,i}; | 336 C = T{k,i}; |
325 A = -d(i,k)*alpha(i,j); | 337 A = -d(i,k)*alpha(i,j); |
326 B = A + C; | 338 B = A + C; |
327 closure = closure + E{i}*RHOi*Hi*B'*e*H_gamma*(e'*E{k}' ); | 339 closure = closure + E{i}*RHOi*Hi*B'*e*H_gamma*(e'*E{k}' ); |
328 penalty = penalty - E{i}*RHOi*Hi*B'*e*H_gamma; | 340 penalty = penalty - E{i}*RHOi*Hi*B'*e*H_gamma; |
329 end | 341 end |
330 | 342 |
331 % Free boundary condition | 343 % Free boundary condition |
332 case {'F','f','Free','free','traction','Traction','t','T'} | 344 case {'F','f','Free','free','traction','Traction','t','T'} |
333 closure = closure - E{k}*RHOi*Hi*e*H_gamma* (e'*tau{k} ); | 345 closure = closure - E{k}*RHOi*Hi*e*H_gamma* (e'*tau{k} ); |
334 penalty = penalty + E{k}*RHOi*Hi*e*H_gamma; | 346 penalty = penalty + E{k}*RHOi*Hi*e*H_gamma; |
335 | 347 |
336 % Unknown boundary condition | 348 % Unknown boundary condition |
337 otherwise | 349 otherwise |
338 error('No such boundary condition: type = %s',type); | 350 error('No such boundary condition: type = %s',type); |
355 | 367 |
356 % Operators and quantities that correspond to the own domain only | 368 % Operators and quantities that correspond to the own domain only |
357 Hi = obj.Hi; | 369 Hi = obj.Hi; |
358 RHOi = obj.RHOi; | 370 RHOi = obj.RHOi; |
359 dim = obj.dim; | 371 dim = obj.dim; |
360 | 372 |
361 %--- Other operators ---- | 373 %--- Other operators ---- |
362 m_tot_u = obj.grid.N(); | 374 m_tot_u = obj.grid.N(); |
363 E = obj.E; | 375 E = obj.E; |
364 LAMBDA_u = obj.LAMBDA; | 376 LAMBDA_u = obj.LAMBDA; |
365 MU_u = obj.MU; | 377 MU_u = obj.MU; |
371 LAMBDA_v = neighbour_scheme.LAMBDA; | 383 LAMBDA_v = neighbour_scheme.LAMBDA; |
372 MU_v = neighbour_scheme.MU; | 384 MU_v = neighbour_scheme.MU; |
373 lambda_v = e_v'*LAMBDA_v*e_v; | 385 lambda_v = e_v'*LAMBDA_v*e_v; |
374 mu_v = e_v'*MU_v*e_v; | 386 mu_v = e_v'*MU_v*e_v; |
375 %------------------------- | 387 %------------------------- |
376 | 388 |
377 % Borrowing constants | 389 % Borrowing constants |
378 phi_u = obj.phi{j}; | |
379 h_u = obj.h(j); | 390 h_u = obj.h(j); |
380 h11_u = obj.H11{j}*h_u; | 391 thR_u = obj.thR{j}*h_u; |
381 gamma_u = obj.gamma{j}; | 392 thM_u = obj.thM{j}*h_u; |
382 | 393 thH_u = obj.thH{j}*h_u; |
383 phi_v = neighbour_scheme.phi{j_v}; | 394 |
384 h_v = neighbour_scheme.h(j_v); | 395 h_v = neighbour_scheme.h(j_v); |
385 h11_v = neighbour_scheme.H11{j_v}*h_v; | 396 thR_v = neighbour_scheme.thR{j_v}*h_v; |
386 gamma_v = neighbour_scheme.gamma{j_v}; | 397 thH_v = neighbour_scheme.thH{j_v}*h_v; |
387 | 398 thM_v = neighbour_scheme.thM{j_v}*h_v; |
388 % E > sum_i 1/(2*alpha_ij)*(tau_i)^2 | 399 |
389 function [alpha_ii, alpha_ij] = computeAlpha(phi,h,h11,gamma,lambda,mu) | 400 % alpha = penalty strength for normal component, beta for tangential |
390 th1 = h11/(2*dim); | 401 alpha_u = dim*lambda_u/(4*thH_u) + lambda_u/(4*thR_u) + mu_u/(2*thM_u); |
391 th2 = h11*phi/2; | 402 alpha_v = dim*lambda_v/(4*thH_v) + lambda_v/(4*thR_v) + mu_v/(2*thM_v); |
392 th3 = h*gamma; | 403 beta_u = mu_u/(2*thH_u) + mu_u/(4*thR_u); |
393 a1 = ( (th1 + th2)*th3*lambda + 4*th1*th2*mu ) / (2*th1*th2*th3); | 404 beta_v = mu_v/(2*thH_v) + mu_v/(4*thR_v); |
394 a2 = ( 16*(th1 + th2)*lambda*mu ) / (th1*th2*th3); | 405 alpha = alpha_u + alpha_v; |
395 alpha_ii = a1 + sqrt(a2 + a1^2); | 406 beta = beta_u + beta_v; |
396 | |
397 alpha_ij = mu*(2/h11 + 1/(phi*h11)); | |
398 end | |
399 | |
400 [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 sigma_ii = tuning*(alpha_ii_u + alpha_ii_v)/4; | |
403 sigma_ij = tuning*(alpha_ij_u + alpha_ij_v)/4; | |
404 | 407 |
405 d = @kroneckerDelta; % Kronecker delta | 408 d = @kroneckerDelta; % Kronecker delta |
406 db = @(i,j) 1-d(i,j); % Logical not of Kronecker delta | 409 db = @(i,j) 1-d(i,j); % Logical not of Kronecker delta |
407 sigma = @(i,j) tuning*(d(i,j)*sigma_ii + db(i,j)*sigma_ij); | 410 strength = @(i,j) tuning*(d(i,j)*alpha + db(i,j)*beta); |
408 | 411 |
409 % Preallocate | 412 % Preallocate |
410 closure = sparse(dim*m_tot_u, dim*m_tot_u); | 413 closure = sparse(dim*m_tot_u, dim*m_tot_u); |
411 penalty = sparse(dim*m_tot_u, dim*m_tot_v); | 414 penalty = sparse(dim*m_tot_u, dim*m_tot_v); |
412 | 415 |
413 % Loop over components that penalties end up on | 416 % Loop over components that penalties end up on |
414 for i = 1:dim | 417 for i = 1:dim |
415 closure = closure - E{i}*RHOi*Hi*e*sigma(i,j)*H_gamma*e'*E{i}'; | 418 closure = closure - E{i}*RHOi*Hi*e*strength(i,j)*H_gamma*e'*E{i}'; |
416 penalty = penalty + E{i}*RHOi*Hi*e*sigma(i,j)*H_gamma*e_v'*E_v{i}'; | 419 penalty = penalty + E{i}*RHOi*Hi*e*strength(i,j)*H_gamma*e_v'*E_v{i}'; |
417 | 420 |
418 closure = closure - 1/2*E{i}*RHOi*Hi*e*H_gamma*e'*tau{i}; | 421 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}; | 422 penalty = penalty - 1/2*E{i}*RHOi*Hi*e*H_gamma*e_v'*tau_v{i}; |
420 | 423 |
421 % Loop over components that we have interface conditions on | 424 % Loop over components that we have interface conditions on |
422 for k = 1:dim | 425 for k = 1:dim |
423 closure = closure + 1/2*E{i}*RHOi*Hi*T{k,i}'*e*H_gamma*e'*E{k}'; | 426 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}'; | 427 penalty = penalty - 1/2*E{i}*RHOi*Hi*T{k,i}'*e*H_gamma*e_v'*E_v{k}'; |
425 end | 428 end |
426 end | 429 end |
427 end | 430 end |
428 | 431 |
429 % Returns the coordinate number and outward normal component for the boundary specified by the string boundary. | 432 % 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) | 433 function [j, nj] = get_boundary_number(obj, boundary) |
492 switch boundary | 495 switch boundary |
493 case {'w','W','west','West','s','S','south','South'} | 496 case {'w','W','west','West','s','S','south','South'} |
494 varargout{i} = obj.tau_l{j}; | 497 varargout{i} = obj.tau_l{j}; |
495 case {'e', 'E', 'east', 'East','n', 'N', 'north', 'North'} | 498 case {'e', 'E', 'east', 'East','n', 'N', 'north', 'North'} |
496 varargout{i} = obj.tau_r{j}; | 499 varargout{i} = obj.tau_r{j}; |
497 end | 500 end |
498 otherwise | 501 otherwise |
499 error(['No such operator: operator = ' op{i}]); | 502 error(['No such operator: operator = ' op{i}]); |
500 end | 503 end |
501 end | 504 end |
502 | 505 |