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