Mercurial > repos > public > sbplib
comparison +multiblock/DiffOp.m @ 186:1fc2eeb4f4e6 feature/grids
Moved multiblock grid to the multiblock package. Continued implementation. Added multiblock diffOp and removed some functions no longer needed.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 03 Mar 2016 20:03:06 +0100 |
parents | |
children | 38f203f00f3a |
comparison
equal
deleted
inserted
replaced
185:fad5e81389c1 | 186:1fc2eeb4f4e6 |
---|---|
1 classdef DiffOp < scheme.Scheme | |
2 properties | |
3 grid | |
4 order | |
5 diffOps | |
6 D | |
7 H | |
8 end | |
9 | |
10 methods | |
11 function obj = DiffOp(doHand, grid, order, doParam) | |
12 % doHand -- may either be a function handle or a cell array of | |
13 % function handles for each grid. The function handle(s) | |
14 % should be on the form do = doHand(grid, order, ...) | |
15 % Additional parameters for each doHand may be provided in | |
16 % the doParam input. | |
17 % grid -- a multiblock grid | |
18 % order -- integer specifying the order of accuracy | |
19 % doParam -- may either be a cell array or a cell array of cell arrays | |
20 % for each block. If it is a cell array with length equal | |
21 % to the number of blocks then each element is sent to the | |
22 % corresponding function handle as extra parameters: | |
23 % doHand(..., doParam{i}{:}) Otherwise doParam is sent as | |
24 % extra parameters to all doHand: doHand(..., doParam{:}) | |
25 default_arg('doParam', []) | |
26 | |
27 [getHand, getParam] = parseInput(doHand, grid, doParam); | |
28 | |
29 nBlocks = grid.nBlocks(); | |
30 | |
31 obj.order = order; | |
32 | |
33 % Create the diffOps for each block | |
34 obj.diffOps = cell(1, nBlocks); | |
35 for i = 1:nBlocks | |
36 h = getHand(i); | |
37 p = getParam(i); | |
38 obj.diffOps{i} = h(grid.grid{i}, order, p{:}); | |
39 end | |
40 | |
41 | |
42 % Build the norm matrix | |
43 H = cell(nBlocks, nBlocks); | |
44 for i = 1:nBlocks | |
45 H{i,i} = obj.diffOps{i}.H; | |
46 end | |
47 obj.H = cell2sparse(H); | |
48 | |
49 | |
50 % Build the differentiation matrix | |
51 D = cell(nBlocks, nBlocks); | |
52 for i = 1:nBlocks | |
53 D{i,i} = obj.diffOps{i}.D; | |
54 end | |
55 | |
56 for i = 1:nBlocks | |
57 for j = i:nBlocks | |
58 intf = grid.connections{i,j}; | |
59 if isempty(intf) | |
60 continue | |
61 end | |
62 | |
63 [ii, ij] = obj.diffOps{i}.inteface_coupling(intf{1}, obj.diffOps{j}, intf{2}); | |
64 D{i,i} = D{i,i} + ii; | |
65 D{i,j} = D{i,j} + ij; | |
66 | |
67 [jj, ji] = obj.diffOps{j}.inteface_coupling(intf{2}, obj.diffOps{i}, intf{1}); | |
68 D{j,j} = D{j,j} + jj; | |
69 D{j,i} = D{j,i} + ji; | |
70 end | |
71 end | |
72 obj.D = cell2sparse(D); | |
73 | |
74 % end | |
75 | |
76 function [getHand, getParam] = parseInput(doHand, grid, doParam) | |
77 if ~isa(grid, 'multiblock.Grid') | |
78 error('multiblock:DiffOp:DiffOp:InvalidGrid', 'Requires a multiblock grid.'); | |
79 end | |
80 | |
81 if iscell(doHand) && length(doHand) == grid.nBlocks() | |
82 getHand = @(i)doHand{i}; | |
83 elseif isa(doHand, 'function_handle') | |
84 getHand = @(i)doHand; | |
85 else | |
86 error('multiblock:DiffOp:DiffOp:InvalidGridDoHand', 'doHand must be a function handle or a cell array of length grid.nBlocks'); | |
87 end | |
88 | |
89 if isempty(doParam) | |
90 getParam = @(i){}; | |
91 elseif iscell(doParam) && length(doParam) == grid.nBlocks() | |
92 getParam = @(i)doParam{i}; | |
93 else | |
94 getParam = @(i)doParam; | |
95 end | |
96 end | |
97 end | |
98 | |
99 function ops = splitOp(obj, op) | |
100 % Splits a matrix operator into a cell-matrix of matrix operators for | |
101 % each grid. | |
102 ops = sparse2cell(op, obj.NNN); | |
103 end | |
104 | |
105 function m = boundary_condition(obj,boundary,type,data) | |
106 | |
107 end | |
108 | |
109 function m = interface(obj,boundary,neighbour_scheme,neighbour_boundary) | |
110 | |
111 end | |
112 | |
113 | |
114 function N = size(obj) | |
115 N = 0; | |
116 for i = 1:length(diffOps) | |
117 N = N + diffOps.size(); | |
118 end | |
119 end | |
120 end | |
121 end |