comparison spdiagsVariablePeriodic.m @ 681:7368affc8f78 feature/poroelastic

Add D2 variable periodic for second order.
author Martin Almquist <malmquist@stanford.edu>
date Wed, 07 Feb 2018 15:42:50 -0800
parents
children 50e77b15d841
comparison
equal deleted inserted replaced
680:cd1a76c38565 681:7368affc8f78
1 function A = spdiagsVariablePeriodic(vals,diags)
2 % Creates an m x m periodic discretization matrix.
3 % vals - m x ndiags matrix of values
4 % diags - 1 x ndiags vector of the 'center diagonals' that vals end up on
5 % vals that are not on main diagonal are going to spill over to
6 % off-diagonal corners.
7
8 default_arg('diags',0);
9
10 [m, ~] = size(vals);
11
12 A = sparse(m,m);
13
14 for i = 1:length(diags)
15
16 d = diags(i);
17 a = vals(:,i);
18
19 % Sub-diagonals
20 if d < 0
21 a_bulk = a(1+abs(d):end);
22 a_corner = a(1:1+abs(d)-1);
23 corner_diag = m-abs(d);
24 A = A + spdiagVariable(a_bulk, d);
25 A = A + spdiagVariable(a_corner, corner_diag);
26
27 % Super-diagonals
28 elseif d > 0
29 a_bulk = a(1:end-d);
30 a_corner = a(end-d+1,end);
31 corner_diag = -m + d;
32 A = A + spdiagVariable(a_bulk, d);
33 A = A + spdiagVariable(a_corner, corner_diag);
34
35 % Main diagonal
36 else
37 A = A + spdiagVariable(a, 0);
38 end
39
40 end
41
42 end