comparison +grid/Staggered.m @ 1331:60c875c18de3 feature/D2_boundary_opt

Merge with feature/poroelastic for Elastic schemes
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Thu, 10 Mar 2022 16:54:26 +0100
parents dc0ef82e3ec7
children
comparison
equal deleted inserted replaced
1330:855871e0b852 1331:60c875c18de3
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 logic % Grid in logical domain, if any.
8 end
9
10 methods
11
12 % Accepts multiple grids and combines them into a staggered grid
13 % Each grid entry is a cell array of grids that store the same field
14 function obj = Staggered(d, varargin)
15 default_arg('d', 2);
16
17 obj.d = d;
18
19 obj.nGroups = length(varargin);
20 obj.gridGroups = cell(obj.nGroups, 1);
21 for i = 1:obj.nGroups
22 obj.gridGroups{i} = varargin{i};
23 end
24
25 obj.h = [];
26 obj.logic = [];
27 end
28
29 % N returns the number of points in the first grid group
30 function o = N(obj)
31 o = 0;
32 gs = obj.gridGroups{1};
33 for i = 1:length(gs)
34 o = o+gs{i}.N();
35 end
36 end
37
38 % D returns the spatial dimension of the grid
39 function o = D(obj)
40 o = obj.d;
41 end
42
43 % size returns a reference size
44 function m = size(obj)
45 m = obj.gridGroups{1}{1};
46 end
47
48 % points returns an n x 1 vector containing the coordinates for the first grid group.
49 function X = points(obj)
50 X = [];
51 gs = obj.gridGroups{1};
52 for i = 1:length(gs)
53 X = [X; gs{i}.points()];
54 end
55 end
56
57 % matrices returns a cell array with coordinates in matrix form.
58 % For 2d case these will have to be transposed to work with plotting routines.
59 function X = matrices(obj)
60 error('grid:Staggered1d:matrices', 'Not implemented')
61 end
62
63 function h = scaling(obj)
64 if isempty(obj.h)
65 error('grid:Staggered1d:NoScalingSet', 'No scaling set')
66 end
67
68 h = obj.h;
69 end
70
71 % Restricts the grid function gf on obj to the subgrid g.
72 % Only works for even multiples
73 function gf = restrictFunc(obj, gf, g)
74 error('grid:Staggered1d:NotImplemented','This method does not exist yet')
75 end
76
77 % Projects the grid function gf on obj to the grid g.
78 function gf = projectFunc(obj, gf, g)
79 error('grid:Staggered1d:NotImplemented','This method does not exist yet')
80 end
81
82 % Return the names of all boundaries in this grid.
83 function bs = getBoundaryNames(obj)
84 switch obj.d()
85 case 1
86 bs = {'l', 'r'};
87 case 2
88 bs = {'w', 'e', 's', 'n'};
89 case 3
90 bs = {'w', 'e', 's', 'n', 'd', 'u'};
91 otherwise
92 error('not implemented');
93 end
94 end
95
96 % Return coordinates for the given boundary
97 % gridGroup (scalar) - grid group to return coordinates for
98 % subGrids (array) - specifies which grids in the grid group to include (default: all grids in the grid group)
99 function X = getBoundary(obj, name, gridGroup, subGrids)
100
101 default_arg('gridGroup' , 1);
102 grids = obj.gridGroups{gridGroup};
103 default_arg('subGrids' , 1:numel(grids));
104
105 X = [];
106 for i = subGrids
107 X = [X; grids{i}.getBoundary(name)];
108 end
109 end
110
111 end
112 end