comparison +grid/Curvilinear.m @ 170:62b5f3c34bcb feature/grids

Implemented Curvilinear and equdistantCurvilinear.
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 25 Feb 2016 11:10:25 +0100
parents ce10ebde3123
children c3483685116a
comparison
equal deleted inserted replaced
169:ba8adcaf4681 170:62b5f3c34bcb
1 classdef Curvilinear < grid.Structured 1 classdef Curvilinear < grid.Structured & grid.Mapped
2 % General grid mapping 2 properties
3 methods (Abstract) 3 logic % Grid of Logical domain
4 % baseGrid returns the domain grid of the mapping. 4 coords % N x D matrix with coordinates of each point in the physical domain
5 g = baseGrid(obj); 5 end
6
7 methods
8 % Creates a curvilinear grid.
9 % Ex: grid.Curvilinear(mapping, xi, eta, ...)
10 % mapping -- either a matrix or a cell array with physical coordinates.
11 % A matrix should be a grid function (N*D x 1 vector) or a N x D
12 % A cell array should be a 1 x D cell array with either N x 1 vectors
13 % or matrices of the same dimesions as the logical grid.
14 % xi, eta, ... -- are the coordinate positions of the cartesian logical grid.
15 function obj = Curvilinear(mapping, varargin)
16 xi = varargin;
17 obj.logic = grid.Cartesian(xi{:});
18
19 % If mapping is a function evaluate it
20 if isa(mapping, 'function_handle')
21 mapping = grid.evalOn(obj.logic, mapping);
22 end
23
24 D = obj.logic.D();
25 N = obj.logic.N();
26
27 obj.coords = zeros(N,D);
28
29 if iscell(mapping)
30 if ~isequal(size(mapping),[1 D])
31 error('grid:Curvilinear:Curvilinear','The cell array must be a row array.');
32 end
33
34 if isequal(size(mapping{1}),[N 1])
35 obj.coords = cell2mat(mapping);
36 elseif isequal(size(mapping{1}), obj.logic.m)
37 for i = 1:length(mapping)
38 obj.coords(:,i) = reshapeRowMaj(mapping{i}, [N 1]);
39 end
40 else
41 error('grid:Curvilinear:Curvilinear','The matrix must have size [N 1] or the same dimension as the grid. Actual: %s', toString(obj.logic.m));
42 end
43
44 elseif isnumeric(mapping)
45 if isequal(size(mapping), [N, D])
46 obj.coords = mapping;
47 elseif isequal(size(mapping), [N*D, 1])
48 obj.coords = reshapeRowMaj(mapping,[N D]);
49 else
50 error('grid:Curvilinear:Curvilinear','A matrix mapping must be of size [N D] or [N*D 1].');
51 end
52 else
53 error('grid:Curvilinear:Curvilinear','mapping must be a matrix or a cell array.');
54 end
55 end
56
57 function m = size(obj)
58 m = obj.logic.size();
59 end
60
61 % logicalGrid returns the domain grid of the mapping.
62 function g = logicalGrid(obj)
63 g = obj.logic;
64 end
6 65
7 % mapping returns the mapped coordinates as a grid.Function 66 % mapping returns the mapped coordinates as a grid.Function
8 m = mapping(obj); 67 function m = mapping(obj);
68 m = obj.coords;
69 end
70
71 % n returns the number of points in the grid
72 function o = N(obj)
73 o = obj.logic.N();
74 end
75
76 % d returns the spatial dimension of the grid
77 function o = D(obj)
78 o = obj.logic.D();
79 end
80
81 % points returns a n x d matrix containing the coordinates for all points.
82 function X = points(obj)
83 X = obj.coords;
84 end
85
86 % Restricts the grid function gf on obj to the subgrid g.
87 function gf = restrictFunc(obj, gf, g)
88 gf = obj.logic.restrictFunc(gf, g.baseGrid());
89 end
90
91 % Projects the grid function gf on obj to the grid g.
92 function gf = projectFunc(obj, gf, g)
93 gf = obj.logic.projectFunc(gf,g.baseGrid());
94 end
9 end 95 end
10 end 96 end