Mercurial > repos > public > sbplib
comparison +grid/boundaryoptimized.m @ 1289:2fd2e2337b77 feature/boundary_optimized_grids
Add utility function for constructing a (possibly multidimensional) grid based on the grid points used by the boundary optimized SBP operators
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Wed, 01 Jul 2020 15:15:30 +0200 |
parents | |
children | 2853b655c172 |
comparison
equal
deleted
inserted
replaced
1288:e059a43bb675 | 1289:2fd2e2337b77 |
---|---|
1 % Creates a cartesian grid of dimension length(m) | |
2 % over the doman xlim, ylim, ... | |
3 % The grid is non-equidistant in the boundary regions, | |
4 % with node node placement based of boundary-optimized SBP operators. | |
5 % Examples: | |
6 % g = grid.boundaryoptimized([mx, my], xlim, ylim, order, opt) | |
7 % g = grid.boundaryoptimized([10, 15], {0,1}, {0,2}, 4) - defaults to 'accurate' stencils | |
8 % g = grid.boundaryoptimized([10, 15], {0,1}, {0,2}, 4, 'minimal') | |
9 function g = boundaryoptimized(m, varargin) | |
10 n = length(m); | |
11 | |
12 % Check that parameters matches dimensions | |
13 matchingParams = false; | |
14 if length(varargin) == n+1 % Minimal number of arguments | |
15 matchingParams = iscell([varargin{1:n}]) && ... | |
16 isfloat([varargin{n+1}]); | |
17 elseif length(varargin) == n+2 % Stencil options supplied | |
18 matchingParams = iscell([varargin{1:n}]) && ... | |
19 isfloat([varargin{n+1}]) && ... | |
20 ischar([varargin{n+2}]); | |
21 end | |
22 assert(matchingParams,'grid:boundaryoptimized:NonMatchingParameters','The number of parameters per dimensions do not match.'); | |
23 | |
24 % Check that stencil options are passed correctly (if supplied) | |
25 if length(varargin) == n+2 % Stencil options supplied | |
26 availabe_opts = ["Accurate","accurate","A","Minimal","minimal","M"]; | |
27 assert(any(varargin{n+2} == availabe_opts), ... | |
28 'grid:boundaryoptimized:InvalidOption',"The operator option must be 'accurate' or 'minimal.'"); | |
29 else %If not passed, populate varargin with default option 'accurate' | |
30 varargin(n+2) = {'accurate'}; | |
31 end | |
32 | |
33 % Specify generating function | |
34 switch varargin{n+2} | |
35 case {'Accurate','accurate','A'} | |
36 gridgenerator = @sbp.util.accurateBoundaryOptimizedGrid; | |
37 case {'Minimal','minimal','M'} | |
38 gridgenerator = @sbp.util.minimalBoundaryOptimizedGrid; | |
39 end | |
40 | |
41 X = {}; | |
42 h = []; | |
43 for i = 1:n | |
44 try | |
45 [X{i},h(i)] = gridgenerator(varargin{i},m(i),varargin{n+1}); | |
46 catch exception % Propagate any errors in the grid generation functions. | |
47 msgText = getReport(exception); | |
48 error('grid:boundaryoptimized:InvalidParameter',msgText) | |
49 end | |
50 end | |
51 | |
52 g = grid.Cartesian(X{:}); | |
53 g.h = h; | |
54 end |