comparison +multiblock/Grid.m @ 704:111fcbcff2e9 feature/optim

merg with featuew grids
author Ylva Rydin <ylva.rydin@telia.com>
date Fri, 03 Nov 2017 10:53:15 +0100
parents b0386d2c180d
children a55d3c1e1f83
comparison
equal deleted inserted replaced
703:027f606fa691 704:111fcbcff2e9
7 nPoints 7 nPoints
8 end 8 end
9 9
10 % General multiblock grid 10 % General multiblock grid
11 methods 11 methods
12 12 % grids -- cell array of N grids
13 % grids -- cell array of N grids 13 % connections -- NxN upper triangular cell matrix. connections{i,j}
14 % connections -- NxN upper triangular cell matrix. connections{i,j} 14 % specifies the connection between block i and j. If
15 % specifies the connection between block i and j. If 15 % it's empty there is no connection otherwise it's a 2
16 % it's empty there is no connection otherwise it's a 2 16 % -cell-vector with strings naming the boundaries to be
17 % -cell-vector with strings naming the boundaries to be 17 % connected. (inverted coupling?)
18 % connected. (inverted coupling?) 18 % boundaryGroups -- A struct of BoundaryGroups. The field names of the
19 %% Should we have boundary groups at all? maybe it can be handled in a 19 % struct are the names of each boundary group.
20 %% cleaner way outside of the class. 20 % The boundary groups can be used to collect block
21 % boundaries into physical boundaries to simplify
22 % getting boundary operators and setting boundary conditions
21 function obj = Grid(grids, connections, boundaryGroups) 23 function obj = Grid(grids, connections, boundaryGroups)
24 default_arg('boundaryGroups', struct());
25 assertType(grids, 'cell')
22 obj.grids = grids; 26 obj.grids = grids;
23 obj.connections = connections; 27 obj.connections = connections;
24 28
25 obj.nPoints = 0; 29 obj.nPoints = 0;
26 for i = 1:length(grids) 30 for i = 1:length(grids)
27 obj.nPoints = obj.nPoints + grids{i}.N(); 31 obj.nPoints = obj.nPoints + grids{i}.N();
28 end 32 end
29 33
30 % if iscell(boundaryGroups) 34 obj.boundaryGroups = boundaryGroups;
31 end 35 end
32 36
33 function n = size(obj) 37 function n = size(obj)
34 n = length(obj.grids); 38 n = length(obj.grids);
35 end 39 end
40 end 44 end
41 45
42 % Ns returns the number of points in each sub grid as a vector 46 % Ns returns the number of points in each sub grid as a vector
43 function o = Ns(obj) 47 function o = Ns(obj)
44 ns = zeros(1,obj.nBlocks); 48 ns = zeros(1,obj.nBlocks);
45 for i = 1:obj.nBlocks; 49 for i = 1:obj.nBlocks
46 ns(i) = obj.grids{i}.N(); 50 ns(i) = obj.grids{i}.N();
47 end 51 end
48 o = ns; 52 o = ns;
49 end 53 end
50 54
57 o = obj.grids{1}.D(); 61 o = obj.grids{1}.D();
58 end 62 end
59 63
60 % points returns a n x d matrix containing the coordinates for all points. 64 % points returns a n x d matrix containing the coordinates for all points.
61 function X = points(obj) 65 function X = points(obj)
62 X = []; 66 X = sparse(0,obj.D());
63 for i = 1:length(obj.grids) 67 for i = 1:length(obj.grids)
64 X = [X; obj.grids{i}.points]; 68 X = [X; obj.grids{i}.points];
65 end 69 end
66 end 70 end
67 71
74 N = zeros(1,nBlocks); 78 N = zeros(1,nBlocks);
75 for i = 1:nBlocks 79 for i = 1:nBlocks
76 N(i) = obj.grids{i}.N(); 80 N(i) = obj.grids{i}.N();
77 end 81 end
78 82
79 gfs = mat2cell(gf, N, 1); 83 gfs = blockmatrix.fromMatrix(gf, {N,1});
80 end 84 end
85
86 % TODO: Split op?
87 % Should the method to split an operator be moved here instead of being in multiblock.DiffOp?
88
89 % Converts a gridfunction to a set of plot matrices
90 % Takes a grid function and and a structured grid.
91 function F = funcToPlotMatrices(obj, gf)
92 % TODO: This method should problably not be here.
93 % The funcToPlotMatrix uses .size poperty of the grids
94 % Which doesn't always exist for all types of grids.
95 % It's only valid for structured grids
96 gfs = obj.splitFunc(gf);
97
98 F = cell(1, obj.nBlocks());
99
100 for i = 1:obj.nBlocks()
101 F{i} = grid.funcToPlotMatrix(obj.grids{i}, gfs{i});
102 end
103 end
104
81 105
82 % Restricts the grid function gf on obj to the subgrid g. 106 % Restricts the grid function gf on obj to the subgrid g.
83 function gf = restrictFunc(obj, gf, g) 107 function gf = restrictFunc(obj, gf, g)
84 gfs = obj.splitFunc(gf); 108 gfs = obj.splitFunc(gf);
85 109
106 % Find what grid a point lies on 130 % Find what grid a point lies on
107 end 131 end
108 132
109 end 133 end
110 134
135 % Find all non interface boundaries of all blocks.
136 % Return their grid.boundaryIdentifiers in a cell array.
111 function bs = getBoundaryNames(obj) 137 function bs = getBoundaryNames(obj)
112 bs = []; 138 bs = {};
139 for i = 1:obj.nBlocks()
140 candidates = obj.grids{i}.getBoundaryNames();
141 for j = 1:obj.nBlocks()
142 if ~isempty(obj.connections{i,j})
143 candidates = setdiff(candidates, obj.connections{i,j}{1});
144 end
145
146 if ~isempty(obj.connections{j,i})
147 candidates = setdiff(candidates, obj.connections{j,i}{2});
148 end
149 end
150
151 for k = 1:length(candidates)
152 bs{end+1} = {i, candidates{k}};
153 end
154 end
113 end 155 end
114 156
115 % Return coordinates for the given boundary 157 % Return coordinates for the given boundary/boundaryGroup
116 function b = getBoundary(obj, name) 158 function b = getBoundary(obj, boundary)
117 b = []; 159 switch class(boundary)
160 case 'cell'
161 I = boundary{1};
162 name = boundary{2};
163 b = obj.grids{I}.getBoundary(name);
164 case 'multiblock.BoundaryGroup'
165 b = sparse(0,obj.D());
166 for i = 1:length(boundary)
167 b = [b; obj.getBoundary(boundary{i})];
168 end
169 otherwise
170 error('Unknown boundary indentifier')
171 end
118 end 172 end
119 end 173 end
120 end 174 end