comparison +grid/Staggered1d.m @ 640:4046b046c1f7 feature/d1_staggered

Add staggered grid class, Staggered<Structured.
author Martin Almquist <malmquist@stanford.edu>
date Sat, 11 Nov 2017 20:25:12 -0800
parents
children
comparison
equal deleted inserted replaced
639:021caf7194b8 640:4046b046c1f7
1 classdef Staggered1d < grid.Structured
2 properties
3 grids % Cell array of grids
4 Ngrids % Number of grids
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 function obj = Staggered1d(varargin)
13
14 obj.d = 1;
15
16 obj.Ngrids = length(varargin);
17 obj.grids = cell(obj.Ngrids, 1);
18 for i = 1:obj.Ngrids
19 obj.grids{i} = varargin{i};
20 end
21
22 obj.h = [];
23 end
24
25 % N returns the total number of points
26 function o = N(obj)
27 o = 0;
28 for i=1:obj.Ngrids
29 o = o+obj.grids{i}.size();
30 end
31 end
32
33 % D returns the spatial dimension of the grid
34 function o = D(obj)
35 o = obj.d;
36 end
37
38 % size returns the number of points on the primal grid
39 function m = size(obj)
40 m = obj.grids{1}.size();
41 end
42
43 % points returns an n x 1 vector containing the coordinates for all points.
44 function X = points(obj)
45 X = [];
46 for i = 1:obj.Ngrids
47 X = [X; obj.grids{i}.points()];
48 end
49 end
50
51 % matrices returns a cell array with coordinates in matrix form.
52 % For 2d case these will have to be transposed to work with plotting routines.
53 function X = matrices(obj)
54
55 % There is no 1d matrix data type in matlab, handle special case
56 X{1} = reshape(obj.points(), [obj.m 1]);
57
58 end
59
60 function h = scaling(obj)
61 if isempty(obj.h)
62 error('grid:Staggered1d:NoScalingSet', 'No scaling set')
63 end
64
65 h = obj.h;
66 end
67
68 % Restricts the grid function gf on obj to the subgrid g.
69 % Only works for even multiples
70 function gf = restrictFunc(obj, gf, g)
71 error('grid:Staggered1d:NotImplemented','This method does not exist yet')
72 end
73
74 % Projects the grid function gf on obj to the grid g.
75 function gf = projectFunc(obj, gf, g)
76 error('grid:Staggered1d:NotImplemented','This method does not exist yet')
77 end
78
79 % Return the names of all boundaries in this grid.
80 function bs = getBoundaryNames(obj)
81 switch obj.D()
82 case 1
83 bs = {'l', 'r'};
84 case 2
85 bs = {'w', 'e', 's', 'n'};
86 case 3
87 bs = {'w', 'e', 's', 'n', 'd', 'u'};
88 otherwise
89 error('not implemented');
90 end
91 end
92
93 % Return coordinates for the given boundary
94 function X = getBoundary(obj, name)
95 % Use boundaries of first grid
96 X = obj.grids{1}.getBoundary(name);
97 end
98 end
99 end