comparison +rv/constructDiffOps.m @ 1033:037f203b9bf5 feature/burgers1d

Merge with branch feature/advectioRV to utilize the +rv package
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Thu, 17 Jan 2019 10:44:12 +0100
parents 44c3ea38097e
children 1a5c8723c9be 2d7ba44340d0
comparison
equal deleted inserted replaced
854:18162a0a5bb5 1033:037f203b9bf5
1 function [D_rv, D_flux, DvDt, solutionPenalties, residualPenalties] = constructDiffOps(scheme, grid, order, opSet, waveSpeed, BCs, fluxSplitting)
2 default_arg('fluxSplitting',[]);
3
4 %% DiffOps for solution vector
5 [D, solutionPenalties] = constructTotalFluxDiffOp(scheme, grid, order, opSet, waveSpeed, BCs, fluxSplitting);
6 D2 = constructSymmetricD2Operator(grid, order, opSet);
7 D_rv = @(v,viscosity)(D + D2(viscosity))*v;
8
9 %% DiffOps for residual viscosity
10 [D_flux, residualPenalties] = constructTotalFluxDiffOp(scheme, grid, max(order-2,2), opSet, waveSpeed, BCs, fluxSplitting);
11 % DiffOp for flux in residual viscosity. Due to sign conventions of the implemnted schemes, we need to
12 % change the sign.
13 D_flux = -D_flux;
14 D_flux = @(v) D_flux*v;
15 % DiffOp for time derivative in residual viscosity
16 DvDt = @(v)D*v;
17 end
18
19 function [D, penalties] = constructTotalFluxDiffOp(scheme, grid, order, opSet, waveSpeed, BCs, fluxSplitting)
20 if isequal(opSet, @sbp.D1Upwind)
21 diffOp = scheme(grid, order, opSet, waveSpeed, fluxSplitting);
22 else
23 diffOp = scheme(grid, order, opSet, waveSpeed);
24 end
25 [D, penalties] = addClosuresToDiffOp(diffOp, BCs);
26 end
27
28 function [D, penalties] = addClosuresToDiffOp(diffOp, BCs)
29 D = diffOp.D;
30 penalties = cell(size(BCs));
31 for i = 1:size(BCs,1)
32 for j = 1:size(BCs,2)
33 [closure, penalties{i,j}] = diffOp.boundary_condition(BCs{i,j}.boundary, BCs{i,j}.type);
34 D = D + closure;
35 end
36 end
37 end
38
39 function D2 = constructSymmetricD2Operator(grid, order, opSet)
40 % TODO:
41 % Currently only implemented for upwind operators.
42 % Remove this part once the time-dependent D2 operator is implemented for other opSets
43 % or if it is decided that it should only be supported for upwind operators.
44 assert(isequal(opSet,@sbp.D1Upwind))
45
46 m = grid.size();
47 ops = cell(grid.D(),1);
48 I = cell(grid.D(),1);
49 for i = 1:grid.D()
50 lim = {grid.x{i}(1), grid.x{i}(end)};
51 ops{i} = opSet(m(i), lim, order);
52 I{i} = speye(m(i));
53 end
54
55 % TBD: How is this generalized to a loop over dimensions or similar?
56 switch grid.D()
57 case 1
58 e_r = ops{1}.e_r;
59 e_l = ops{1}.e_l;
60 Dm = ops{1}.Dm;
61 Dp = ops{1}.Dp;
62 Hi = ops{1}.HI;
63 B = e_r*e_r' - e_l*e_l';
64 D2 = @(viscosity) Dm*spdiag(viscosity)*Dp-Hi*(B*spdiag(viscosity)*Dp);
65 case 2
66 e_e = kron(ops{1}.e_r,I{2});
67 e_w = kron(ops{1}.e_l,I{2});
68 Dm_x = kron(ops{1}.Dm,I{2});
69 Dp_x = kron(ops{1}.Dp,I{2});
70 H_x = kron(ops{1}.HI,I{2});
71 B_x = e_e*e_e' - e_w*e_w';
72 D2_x = @(viscosity) Dm_x*spdiag(viscosity)*Dp_x-H_x*(B_x*spdiag(viscosity)*Dp_x);
73
74 e_n = kron(I{1},ops{2}.e_r);
75 e_s = kron(I{1},ops{2}.e_l);
76 Dm_y = kron(I{1},ops{2}.Dm);
77 Dp_y = kron(I{1},ops{2}.Dp);
78 H_y = kron(I{1},ops{2}.HI);
79 B_y = e_n*e_n' - e_s*e_s';
80 D2_y = @(viscosity) Dm_y*spdiag(viscosity)*Dp_y-H_y*(B_y*spdiag(viscosity)*Dp_y);
81 D2 = @(viscosity)D2_x(viscosity) + D2_y(viscosity);
82 otherwise
83 error('3D not yet implemented')
84 end
85 end