comparison +grid/primalDual1D.m @ 1259:99f92bfc1157 feature/poroelastic

Add staggered operators and 1D grids
author Martin Almquist <malmquist@stanford.edu>
date Tue, 14 Apr 2020 17:50:49 -0700
parents
children
comparison
equal deleted inserted replaced
1253:89dad61cad22 1259:99f92bfc1157
1 % Creates a 1D staggered grid of dimension length(m).
2 % over the interval xlims
3 % Primal grid: equidistant with m points.
4 % Dual grid: m + 1 points, h/2 spacing first point.
5 % Examples
6 % g = grid.primal_dual_1D(m, xlim)
7 % g = grid.primal_dual_1D(11, {0,1})
8 function [g_primal, g_dual] = primalDual1D(m, xlims)
9
10 if ~iscell(xlims) || numel(xlims) ~= 2
11 error('grid:primalDual1D:InvalidLimits','The limits should be cell arrays with 2 elements.');
12 end
13
14 if xlims{1} > xlims{2}
15 error('grid:primalDual1D:InvalidLimits','The elements of the limit must be increasing.');
16 end
17
18 xl = xlims{1};
19 xr = xlims{2};
20 h = (xr-xl)/(m-1);
21
22 % Primal grid
23 g_primal = grid.equidistant(m, xlims);
24 g_primal.h = h;
25
26 % Dual grid
27 x = [xl; linspace(xl+h/2, xr-h/2, m-1)'; xr];
28 g_dual = grid.Cartesian(x);
29 g_dual.h = h;
30 end