Mercurial > repos > public > sbplib
comparison +multiblock/DiffOp.m @ 721:c29eca357028 feature/grids
Change name of grid parameter in multiblock.DiffOp to avoid conflict with package
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 19 Mar 2018 17:11:15 +0100 |
parents | c360bbecf260 |
children | 89e14a85a2d0 |
comparison
equal
deleted
inserted
replaced
665:facb8ffb5c34 | 721:c29eca357028 |
---|---|
8 | 8 |
9 blockmatrixDiv | 9 blockmatrixDiv |
10 end | 10 end |
11 | 11 |
12 methods | 12 methods |
13 function obj = DiffOp(doHand, grid, order, doParam) | 13 function obj = DiffOp(doHand, g, order, doParam) |
14 % doHand -- may either be a function handle or a cell array of | 14 % doHand -- may either be a function handle or a cell array of |
15 % function handles for each grid. The function handle(s) | 15 % function handles for each grid. The function handle(s) |
16 % should be on the form do = doHand(grid, order, ...) | 16 % should be on the form do = doHand(grid, order, ...) |
17 % Additional parameters for each doHand may be provided in | 17 % Additional parameters for each doHand may be provided in |
18 % the doParam input. | 18 % the doParam input. |
19 % grid -- a multiblock grid | 19 % g -- a multiblock grid |
20 % order -- integer specifying the order of accuracy | 20 % order -- integer specifying the order of accuracy |
21 % doParam -- may either be a cell array or a cell array of cell arrays | 21 % doParam -- may either be a cell array or a cell array of cell arrays |
22 % for each block. If it is a cell array with length equal | 22 % for each block. If it is a cell array with length equal |
23 % to the number of blocks then each element is sent to the | 23 % to the number of blocks then each element is sent to the |
24 % corresponding function handle as extra parameters: | 24 % corresponding function handle as extra parameters: |
25 % doHand(..., doParam{i}{:}) Otherwise doParam is sent as | 25 % doHand(..., doParam{i}{:}) Otherwise doParam is sent as |
26 % extra parameters to all doHand: doHand(..., doParam{:}) | 26 % extra parameters to all doHand: doHand(..., doParam{:}) |
27 default_arg('doParam', []) | 27 default_arg('doParam', []) |
28 | 28 |
29 [getHand, getParam] = parseInput(doHand, grid, doParam); | 29 [getHand, getParam] = parseInput(doHand, g, doParam); |
30 | 30 |
31 nBlocks = grid.nBlocks(); | 31 nBlocks = g.nBlocks(); |
32 | 32 |
33 obj.order = order; | 33 obj.order = order; |
34 | 34 |
35 % Create the diffOps for each block | 35 % Create the diffOps for each block |
36 obj.diffOps = cell(1, nBlocks); | 36 obj.diffOps = cell(1, nBlocks); |
38 h = getHand(i); | 38 h = getHand(i); |
39 p = getParam(i); | 39 p = getParam(i); |
40 if ~iscell(p) | 40 if ~iscell(p) |
41 p = {p}; | 41 p = {p}; |
42 end | 42 end |
43 obj.diffOps{i} = h(grid.grids{i}, order, p{:}); | 43 obj.diffOps{i} = h(g.grids{i}, order, p{:}); |
44 end | 44 end |
45 | 45 |
46 | 46 |
47 % Build the norm matrix | 47 % Build the norm matrix |
48 H = cell(nBlocks, nBlocks); | 48 H = cell(nBlocks, nBlocks); |
51 end | 51 end |
52 obj.H = blockmatrix.toMatrix(H); | 52 obj.H = blockmatrix.toMatrix(H); |
53 | 53 |
54 | 54 |
55 % Build the differentiation matrix | 55 % Build the differentiation matrix |
56 obj.blockmatrixDiv = {grid.Ns, grid.Ns}; | 56 obj.blockmatrixDiv = {g.Ns, g.Ns}; |
57 D = blockmatrix.zero(obj.blockmatrixDiv); | 57 D = blockmatrix.zero(obj.blockmatrixDiv); |
58 for i = 1:nBlocks | 58 for i = 1:nBlocks |
59 D{i,i} = obj.diffOps{i}.D; | 59 D{i,i} = obj.diffOps{i}.D; |
60 end | 60 end |
61 | 61 |
62 for i = 1:nBlocks | 62 for i = 1:nBlocks |
63 for j = 1:nBlocks | 63 for j = 1:nBlocks |
64 intf = grid.connections{i,j}; | 64 intf = g.connections{i,j}; |
65 if isempty(intf) | 65 if isempty(intf) |
66 continue | 66 continue |
67 end | 67 end |
68 | 68 |
69 | 69 |
77 end | 77 end |
78 end | 78 end |
79 obj.D = blockmatrix.toMatrix(D); | 79 obj.D = blockmatrix.toMatrix(D); |
80 | 80 |
81 | 81 |
82 function [getHand, getParam] = parseInput(doHand, grid, doParam) | 82 function [getHand, getParam] = parseInput(doHand, g, doParam) |
83 if ~isa(grid, 'multiblock.Grid') | 83 if ~isa(g, 'multiblock.Grid') |
84 error('multiblock:DiffOp:DiffOp:InvalidGrid', 'Requires a multiblock grid.'); | 84 error('multiblock:DiffOp:DiffOp:InvalidGrid', 'Requires a multiblock grid.'); |
85 end | 85 end |
86 | 86 |
87 if iscell(doHand) && length(doHand) == grid.nBlocks() | 87 if iscell(doHand) && length(doHand) == g.nBlocks() |
88 getHand = @(i)doHand{i}; | 88 getHand = @(i)doHand{i}; |
89 elseif isa(doHand, 'function_handle') | 89 elseif isa(doHand, 'function_handle') |
90 getHand = @(i)doHand; | 90 getHand = @(i)doHand; |
91 else | 91 else |
92 error('multiblock:DiffOp:DiffOp:InvalidGridDoHand', 'doHand must be a function handle or a cell array of length grid.nBlocks'); | 92 error('multiblock:DiffOp:DiffOp:InvalidGridDoHand', 'doHand must be a function handle or a cell array of length grid.nBlocks'); |
102 return | 102 return |
103 end | 103 end |
104 | 104 |
105 % doParam is a non-empty cell-array | 105 % doParam is a non-empty cell-array |
106 | 106 |
107 if length(doParam) == grid.nBlocks() && all(cellfun(@iscell, doParam)) | 107 if length(doParam) == g.nBlocks() && all(cellfun(@iscell, doParam)) |
108 % doParam is a cell-array of cell-arrays | 108 % doParam is a cell-array of cell-arrays |
109 getParam = @(i)doParam{i}; | 109 getParam = @(i)doParam{i}; |
110 return | 110 return |
111 end | 111 end |
112 | 112 |
114 end | 114 end |
115 end | 115 end |
116 | 116 |
117 function ops = splitOp(obj, op) | 117 function ops = splitOp(obj, op) |
118 % Splits a matrix operator into a cell-matrix of matrix operators for | 118 % Splits a matrix operator into a cell-matrix of matrix operators for |
119 % each grid. | 119 % each g. |
120 ops = sparse2cell(op, obj.NNN); | 120 ops = sparse2cell(op, obj.NNN); |
121 end | 121 end |
122 | 122 |
123 % Get a boundary operator specified by opName for the given boundary/BoundaryGroup | 123 % Get a boundary operator specified by opName for the given boundary/BoundaryGroup |
124 function op = getBoundaryOperator(obj, opName, boundary) | 124 function op = getBoundaryOperator(obj, opName, boundary) |