Mercurial > repos > public > sbplib
comparison +grid/generalCurvilinear.m @ 1336:0666629aa183 feature/D2_boundary_opt
Add methods for creating grids with different grid point distributions for each coordinate direction, and also supports constructing periodic grids
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Fri, 13 May 2022 13:26:16 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1335:8d9fc7981796 | 1336:0666629aa183 |
---|---|
1 % Creates a curvilinear grid of dimension length(m). | |
2 % over the logical domain xi_lim, eta_lim, using a provided | |
3 % coordinate mapping. The grid point distribution is | |
4 % specified is | |
5 % Examples: | |
6 % g = grid.generalCurvilinear(mapping, [mx, my], xlim, ylim, {'equidist'}, {'boundaryopt', order, 'accurate'}) | |
7 function g = generalCurvilinear(mapping, m, varargin) | |
8 n = length(m); | |
9 | |
10 % Check that parameters matches dimensions | |
11 matchingParams = false; | |
12 if length(varargin) == 2*n | |
13 matchingParams = iscell([varargin{1:2*n}]); | |
14 end | |
15 assert(matchingParams,'grid:generalCurvilinear:NonMatchingParameters','The number of parameters per dimensions do not match.'); | |
16 | |
17 X = []; | |
18 h = []; | |
19 inds_periodic = []; | |
20 for i = 1:n | |
21 lim = varargin{i}; | |
22 opts = varargin{i+n}; | |
23 gridtype = opts{1}; | |
24 switch gridtype | |
25 case 'equidist' | |
26 gridgenerator = @()util.get_grid(lim{1},lim{2},m(i)); | |
27 case 'boundaryopt' | |
28 order = opts{2}; | |
29 stencil_type = opts{3}; | |
30 switch stencil_type | |
31 case {'Accurate','accurate','A','acc'} | |
32 gridgenerator = @()sbp.grid.accurateBoundaryOptimizedGrid(lim,m(i),order); | |
33 case {'Minimal','minimal','M','min'} | |
34 gridgenerator = @()sbp.grid.minimalBoundaryOptimizedGrid(lim,m(i),order); | |
35 end | |
36 case 'periodic' | |
37 gridgenerator = @()util.get_periodic_grid(lim{1},lim{2},m(i)); | |
38 inds_periodic = [inds_periodic, i]; | |
39 otherwise | |
40 error("grid type %s not supported. Must be one of 'equidist', 'boundaryopt', 'periodic'",gridtype); | |
41 end | |
42 try | |
43 [X{i},h(i)] = gridgenerator(); | |
44 catch exception % Propagate any errors in the grid generation functions. | |
45 msgText = getReport(exception); | |
46 error('grid:boundaryOptimizedCurvilinear:InvalidParameter',msgText) | |
47 end | |
48 end | |
49 g = grid.Curvilinear(mapping, X{:}); | |
50 g.logic.h = h; | |
51 for i = inds_periodic | |
52 g.logic.lim{i}{2} = g.logic.lim{i}{2}+h(i); | |
53 end | |
54 end |