Mercurial > repos > public > sbplib
comparison +grid/Staggered.m @ 1262:b673081db86b feature/poroelastic
Rename the Staggered1d grid class Staggered
author | Martin Almquist <malmquist@stanford.edu> |
---|---|
date | Wed, 29 Apr 2020 21:03:28 -0700 |
parents | |
children | 8aa0909125a4 |
comparison
equal
deleted
inserted
replaced
1261:a3f2c1781612 | 1262:b673081db86b |
---|---|
1 classdef Staggered < grid.Structured | |
2 properties | |
3 gridGroups % Cell array of grid groups, each group is a cell array | |
4 nGroups % Number of grid groups | |
5 h % Interior grid spacing | |
6 d % Number of dimensions | |
7 end | |
8 | |
9 methods | |
10 | |
11 % Accepts multiple grids and combines them into a staggered grid | |
12 % Each grid entry is a cell array of grids that store the same field | |
13 function obj = Staggered(d, varargin) | |
14 default_arg('d', 2); | |
15 | |
16 obj.d = d; | |
17 | |
18 obj.nGroups = length(varargin); | |
19 obj.gridGroups = cell(obj.nGroups, 1); | |
20 for i = 1:obj.nGroups | |
21 obj.gridGroups{i} = varargin{i}; | |
22 end | |
23 | |
24 obj.h = []; | |
25 end | |
26 | |
27 % N returns the number of points in the first grid group | |
28 function o = N(obj) | |
29 o = 0; | |
30 gs = obj.gridGroups{1}; | |
31 for i = 1:length(gs) | |
32 o = o+gs{i}.N(); | |
33 end | |
34 end | |
35 | |
36 % D returns the spatial dimension of the grid | |
37 function o = D(obj) | |
38 o = obj.d; | |
39 end | |
40 | |
41 % size returns a reference size | |
42 function m = size(obj) | |
43 m = obj.gridGroups{1}{1}; | |
44 end | |
45 | |
46 % points returns an n x 1 vector containing the coordinates for the first grid group. | |
47 function X = points(obj) | |
48 X = []; | |
49 gs = obj.gridGroups{1}; | |
50 for i = 1:length(gs) | |
51 X = [X; gs{i}.points()]; | |
52 end | |
53 end | |
54 | |
55 % matrices returns a cell array with coordinates in matrix form. | |
56 % For 2d case these will have to be transposed to work with plotting routines. | |
57 function X = matrices(obj) | |
58 error('grid:Staggered1d:matrices', 'Not implemented') | |
59 end | |
60 | |
61 function h = scaling(obj) | |
62 if isempty(obj.h) | |
63 error('grid:Staggered1d:NoScalingSet', 'No scaling set') | |
64 end | |
65 | |
66 h = obj.h; | |
67 end | |
68 | |
69 % Restricts the grid function gf on obj to the subgrid g. | |
70 % Only works for even multiples | |
71 function gf = restrictFunc(obj, gf, g) | |
72 error('grid:Staggered1d:NotImplemented','This method does not exist yet') | |
73 end | |
74 | |
75 % Projects the grid function gf on obj to the grid g. | |
76 function gf = projectFunc(obj, gf, g) | |
77 error('grid:Staggered1d:NotImplemented','This method does not exist yet') | |
78 end | |
79 | |
80 % Return the names of all boundaries in this grid. | |
81 function bs = getBoundaryNames(obj) | |
82 switch obj.d() | |
83 case 1 | |
84 bs = {'l', 'r'}; | |
85 case 2 | |
86 bs = {'w', 'e', 's', 'n'}; | |
87 case 3 | |
88 bs = {'w', 'e', 's', 'n', 'd', 'u'}; | |
89 otherwise | |
90 error('not implemented'); | |
91 end | |
92 end | |
93 | |
94 % Return coordinates for the given boundary | |
95 function X = getBoundary(obj, name) | |
96 % Use boundaries of first grid | |
97 X = obj.gridGroups{1}{1}.getBoundary(name); | |
98 end | |
99 end | |
100 end |