Mercurial > repos > public > sbplib
diff +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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/+grid/primalDual1D.m Tue Apr 14 17:50:49 2020 -0700 @@ -0,0 +1,30 @@ +% Creates a 1D staggered grid of dimension length(m). +% over the interval xlims +% Primal grid: equidistant with m points. +% Dual grid: m + 1 points, h/2 spacing first point. +% Examples +% g = grid.primal_dual_1D(m, xlim) +% g = grid.primal_dual_1D(11, {0,1}) +function [g_primal, g_dual] = primalDual1D(m, xlims) + + if ~iscell(xlims) || numel(xlims) ~= 2 + error('grid:primalDual1D:InvalidLimits','The limits should be cell arrays with 2 elements.'); + end + + if xlims{1} > xlims{2} + error('grid:primalDual1D:InvalidLimits','The elements of the limit must be increasing.'); + end + + xl = xlims{1}; + xr = xlims{2}; + h = (xr-xl)/(m-1); + + % Primal grid + g_primal = grid.equidistant(m, xlims); + g_primal.h = h; + + % Dual grid + x = [xl; linspace(xl+h/2, xr-h/2, m-1)'; xr]; + g_dual = grid.Cartesian(x); + g_dual.h = h; +end \ No newline at end of file