comparison +grid/Multiblock.m @ 183:3587cb106b54 feature/grids

Made Multiblock a concrete class. Started implementation.
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 01 Mar 2016 13:47:46 +0100
parents c700b26ad304
children
comparison
equal deleted inserted replaced
182:c2db0294f8ed 183:3587cb106b54
1 classdef Multiblock < grid.Grid 1 classdef Multiblock < grid.Grid
2 properties
3 grids
4 connections
5
6 nPoints
7 end
8
2 % General multiblock grid 9 % General multiblock grid
3 methods (Abstract) 10 methods
4 % NBlocks returns the number of blocks in the grid.
5 o = NBlocks(obj);
6 11
7 % Grid returns the ith grid in the multiblockgrid 12 % grids -- cell array of N grids
8 gs = grid(obj,i); 13 % connections -- NxN cell matrix. connections{i,j} specifies the connection
14 % between block i and j. If it's empty there is no
15 % connection otherwise it's a 2-cell-vector with strings
16 % naming the boundaries to be connected. (inverted coupling?)
17 function obj = Multiblock(grids, connections)
18 obj.grids = grids;
19 obj.connections = connections;
9 20
10 % Grids returns a cell array of all the grids in the multiblock grid. 21 obj.nPoints = 0;
11 gs = grids(obj); 22 for i = 1:length(grids)
23 obj.nPoints = obj.nPoints + grids{i}.N();
24 end
25 end
26
27 function n = size(obj)
28 n = length(obj.grids);
29 end
30
31 % n returns the number of points in the grid
32 function o = N(obj)
33 o = obj.nPoints;
34 end
35
36 % d returns the spatial dimension of the grid
37 function o = D(obj)
38 o = obj.grids{1}.D();
39 end
40
41 % points returns a n x d matrix containing the coordinates for all points.
42 function X = points(obj)
43 X = [];
44 for i = 1:length(obj.grids)
45 X = [X; obj.grids{i}.points];
46 end
47 end
12 48
13 % Split a grid function on obj to a cell array of grid function on each block 49 % Split a grid function on obj to a cell array of grid function on each block
14 gf = splitFunc(gf) 50 function gfs = splitFunc(obj, gf)
51 nComponents = length(gf)/obj.nPoints;
52 nBlocks = length(obj.grids);
53
54 % Collect number of points in each block
55 N = cell(1,nBlocks);
56 for i = 1:nBlocks
57 N{i} = obj.grids{i}.N();
58 end
59
60 gfs = mat2cell(gf, N, 1);
61 end
62
63 % Restricts the grid function gf on obj to the subgrid g.
64 function gf = restrictFunc(obj, gf, g)
65 gfs = obj.splitFunc(gf);
66
67 for i = 1:length(obj.grids)
68 gfs{i} = obj.grids{i}.restrictFunc(gfs{i}, g.grids{i});
69 end
70
71 gf = cell2mat(gfs);
72 end
73
74 % Projects the grid function gf on obj to the grid g.
75 function o = projectFunc(obj, gf, g)
76 error('not implemented')
77
78 p = g.points();
79 o = zeros(length(p),1);
80 for i = 1:length(p)
81 I = whatGrid(p(i));
82 o(i) = obj.grids{I}.projectFunc(gf, p(i));
83 end
84
85
86 function I = whatGrid(p)
87 % Find what grid a point lies on
88 end
89
90 end
15 end 91 end
16 end 92 end
17
18
19 % Should define boundaries and connections between grids.