Mercurial > repos > public > sbplib
comparison +grid/boundaryOptimized.m @ 1297:e53b1e25970a feature/boundary_optimized_grids
Change +sbp/+util/ to +sbp/+grid and change function names to camel case
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Tue, 07 Jul 2020 16:08:08 +0200 |
parents | +grid/boundaryoptimized.m@2853b655c172 |
children | 7df63b17e078 |
comparison
equal
deleted
inserted
replaced
1296:2853b655c172 | 1297:e53b1e25970a |
---|---|
1 % Creates a Cartesian grid of dimension length(m) | |
2 % over the domain xlim, ylim, ... | |
3 % The grid is non-equidistant in the boundary regions, | |
4 % with node placement based on 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.grid.accurateBoundaryOptimizedGrid; | |
37 case {'Minimal','minimal','M'} | |
38 gridgenerator = @sbp.grid.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 |