Mercurial > repos > public > sbplib
annotate +multiblock/stitchSchemes.m @ 569:f1a01a48779c feature/grids/laplace_refactor
Close branch feature/grids/laplace_refactor
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Fri, 01 Sep 2017 10:58:07 +0200 |
parents | 419ec303e97d |
children | 437fad4a47e1 |
rev | line source |
---|---|
0 | 1 % Stitch schemes together given connection matrix and BC vector. |
2 % schmHand - function_handle to a Scheme constructor | |
3 % order - order of accuracy | |
4 % schmParam - cell array of extra parameters sent to each Scheme stored as cell arrays | |
5 % blocks - block definitions, On whatever form the scheme expects. | |
6 % ms - grid points in each direction for each block. Ex {[10,10], [10, 20]} | |
7 % conn - connection matrix | |
8 % bound - boundary condition vector, array of structs with fields w,e,s,n | |
9 % each field with a parameter array that is sent to schm.boundary_condition | |
10 % | |
11 % Output parameters are cell arrays and cell matrices. | |
76
5c569cbef49e
Added more input parameter handling and fixed some bugs.
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
12 % |
5c569cbef49e
Added more input parameter handling and fixed some bugs.
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
13 % Ex: [schms, D, H] = stitchSchemes(schmHand, order, schmParam, blocks, ms, conn, bound) |
181
419ec303e97d
Made some local changes to stichSchemes.
Jonatan Werpers <jonatan@werpers.com>
parents:
120
diff
changeset
|
14 function [schms, D, H] = stitchSchemes(schmHand, order, schmParam, grids, conn, bound) |
76
5c569cbef49e
Added more input parameter handling and fixed some bugs.
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
15 default_arg('schmParam',[]); |
0 | 16 |
181
419ec303e97d
Made some local changes to stichSchemes.
Jonatan Werpers <jonatan@werpers.com>
parents:
120
diff
changeset
|
17 n_blocks = numel(grids); |
0 | 18 |
19 % Creating Schemes | |
20 for i = 1:n_blocks | |
76
5c569cbef49e
Added more input parameter handling and fixed some bugs.
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
21 if isempty(schmParam); |
181
419ec303e97d
Made some local changes to stichSchemes.
Jonatan Werpers <jonatan@werpers.com>
parents:
120
diff
changeset
|
22 schms{i} = schmHand(grids{i},order,[]); |
76
5c569cbef49e
Added more input parameter handling and fixed some bugs.
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
23 elseif ~iscell(schmParam) |
0 | 24 param = schmParam(i); |
181
419ec303e97d
Made some local changes to stichSchemes.
Jonatan Werpers <jonatan@werpers.com>
parents:
120
diff
changeset
|
25 schms{i} = schmHand(grids{i},order,param); |
0 | 26 else |
27 param = schmParam{i}; | |
76
5c569cbef49e
Added more input parameter handling and fixed some bugs.
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
28 if iscell(param) |
181
419ec303e97d
Made some local changes to stichSchemes.
Jonatan Werpers <jonatan@werpers.com>
parents:
120
diff
changeset
|
29 schms{i} = schmHand(grids{i},order,param{:}); |
76
5c569cbef49e
Added more input parameter handling and fixed some bugs.
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
30 else |
181
419ec303e97d
Made some local changes to stichSchemes.
Jonatan Werpers <jonatan@werpers.com>
parents:
120
diff
changeset
|
31 schms{i} = schmHand(grids{i},order,param); |
76
5c569cbef49e
Added more input parameter handling and fixed some bugs.
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
32 end |
0 | 33 end |
34 | |
35 % class(schmParam) | |
36 % class(ms) | |
37 % class(blocks) | |
38 % class(schmParam{i}) | |
39 % class(ms) | |
40 | |
76
5c569cbef49e
Added more input parameter handling and fixed some bugs.
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
41 |
0 | 42 end |
43 | |
44 | |
45 % Total norm | |
46 H = cell(n_blocks,n_blocks); | |
47 for i = 1:n_blocks | |
48 H{i,i} = schms{i}.H; | |
49 end | |
50 | |
51 %% Total system matrix | |
52 | |
53 % Differentiation terms | |
54 D = cell(n_blocks,n_blocks); | |
55 for i = 1:n_blocks | |
56 D{i,i} = schms{i}.D; | |
57 end | |
58 | |
59 % Boundary penalty terms | |
60 for i = 1:n_blocks | |
61 if ~isstruct(bound{i}) | |
62 continue | |
63 end | |
64 | |
65 fn = fieldnames(bound{i}); | |
66 for j = 1:length(fn); | |
67 bc = bound{i}.(fn{j}); | |
68 if isempty(bc) | |
69 continue | |
70 end | |
71 | |
120
8eb4e39df8a5
Changed variable name to make it clear boundary penatlies are currently skipped.
Jonatan Werpers <jonatan@werpers.com>
parents:
76
diff
changeset
|
72 [closure, ~] = schms{i}.boundary_condition(fn{j},bc{:}); |
8eb4e39df8a5
Changed variable name to make it clear boundary penatlies are currently skipped.
Jonatan Werpers <jonatan@werpers.com>
parents:
76
diff
changeset
|
73 D{i,i} = D{i,i}+closure; |
0 | 74 end |
75 end | |
76 | |
77 % Interface penalty terms | |
78 for i = 1:n_blocks | |
79 for j = 1:n_blocks | |
80 intf = conn{i,j}; | |
81 if isempty(intf) | |
82 continue | |
83 end | |
84 | |
76
5c569cbef49e
Added more input parameter handling and fixed some bugs.
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
85 [uu,uv,vv,vu] = schms{i}.interface_coupling(schms{i},intf{1},schms{j},intf{2}); |
0 | 86 D{i,i} = D{i,i} + uu; |
87 D{i,j} = uv; | |
88 D{j,j} = D{j,j} + vv; | |
89 D{j,i} = vu; | |
90 end | |
91 end | |
92 end |