Mercurial > repos > public > sbplib
comparison +multiblock/Grid.m @ 427:a613960a157b feature/quantumTriangles
merged with feature/beams
author | Ylva Rydin <ylva.rydin@telia.com> |
---|---|
date | Thu, 26 Jan 2017 15:59:25 +0100 |
parents | b8ee5212f651 |
children | 819345fe7ff1 |
comparison
equal
deleted
inserted
replaced
426:29944ea7674b | 427:a613960a157b |
---|---|
1 classdef Grid < grid.Grid | |
2 properties | |
3 grids | |
4 connections | |
5 boundaryGroups | |
6 | |
7 nPoints | |
8 end | |
9 | |
10 % General multiblock grid | |
11 methods | |
12 | |
13 % grids -- cell array of N grids | |
14 % connections -- NxN upper triangular cell matrix. connections{i,j} | |
15 % specifies the connection between block i and j. If | |
16 % it's empty there is no connection otherwise it's a 2 | |
17 % -cell-vector with strings naming the boundaries to be | |
18 % connected. (inverted coupling?) | |
19 %% Should we have boundary groups at all? maybe it can be handled in a | |
20 %% cleaner way outside of the class. | |
21 function obj = Grid(grids, connections, boundaryGroups) | |
22 obj.grids = grids; | |
23 obj.connections = connections; | |
24 | |
25 obj.nPoints = 0; | |
26 for i = 1:length(grids) | |
27 obj.nPoints = obj.nPoints + grids{i}.N(); | |
28 end | |
29 | |
30 % if iscell(boundaryGroups) | |
31 end | |
32 | |
33 function n = size(obj) | |
34 n = length(obj.grids); | |
35 end | |
36 | |
37 % N returns the number of points in the grid | |
38 function o = N(obj) | |
39 o = obj.nPoints; | |
40 end | |
41 | |
42 % Ns returns the number of points in each sub grid as a vector | |
43 function o = Ns(obj) | |
44 ns = zeros(1,obj.nBlocks); | |
45 for i = 1:obj.nBlocks; | |
46 ns(i) = obj.grids{i}.N(); | |
47 end | |
48 o = ns; | |
49 end | |
50 | |
51 function n = nBlocks(obj) | |
52 n = length(obj.grids); | |
53 end | |
54 | |
55 % d returns the spatial dimension of the grid | |
56 function o = D(obj) | |
57 o = obj.grids{1}.D(); | |
58 end | |
59 | |
60 % points returns a n x d matrix containing the coordinates for all points. | |
61 function X = points(obj) | |
62 X = []; | |
63 for i = 1:length(obj.grids) | |
64 X = [X; obj.grids{i}.points]; | |
65 end | |
66 end | |
67 | |
68 % Split a grid function on obj to a cell array of grid function on each block | |
69 function gfs = splitFunc(obj, gf) | |
70 nComponents = length(gf)/obj.nPoints; | |
71 nBlocks = length(obj.grids); | |
72 | |
73 % Collect number of points in each block | |
74 N = zeros(1,nBlocks); | |
75 for i = 1:nBlocks | |
76 N(i) = obj.grids{i}.N(); | |
77 end | |
78 | |
79 gfs = mat2cell(gf, N, 1); | |
80 end | |
81 | |
82 % Restricts the grid function gf on obj to the subgrid g. | |
83 function gf = restrictFunc(obj, gf, g) | |
84 gfs = obj.splitFunc(gf); | |
85 | |
86 for i = 1:length(obj.grids) | |
87 gfs{i} = obj.grids{i}.restrictFunc(gfs{i}, g.grids{i}); | |
88 end | |
89 | |
90 gf = cell2mat(gfs); | |
91 end | |
92 | |
93 % Projects the grid function gf on obj to the grid g. | |
94 function o = projectFunc(obj, gf, g) | |
95 error('not implemented') | |
96 | |
97 p = g.points(); | |
98 o = zeros(length(p),1); | |
99 for i = 1:length(p) | |
100 I = whatGrid(p(i)); | |
101 o(i) = obj.grids{I}.projectFunc(gf, p(i)); | |
102 end | |
103 | |
104 | |
105 function I = whatGrid(p) | |
106 % Find what grid a point lies on | |
107 end | |
108 | |
109 end | |
110 | |
111 function bs = getBoundaryNames(obj) | |
112 bs = []; | |
113 end | |
114 | |
115 % Return coordinates for the given boundary | |
116 function b = getBoundary(obj, name) | |
117 b = []; | |
118 end | |
119 end | |
120 end |