comparison +multiblock/+domain/Rectangle.m @ 820:501750fbbfdb

Merge with feature/grids
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 07 Sep 2018 14:40:58 +0200
parents 4bb298faa8dc
children 375f73edbbd4 b0208b130880
comparison
equal deleted inserted replaced
819:fdf0ef9150f4 820:501750fbbfdb
1 classdef Rectangle < multiblock.Definition
2 properties
3
4 blockTi % Transfinite interpolation objects used for plotting
5 xlims
6 ylims
7 blockNames % Cell array of block labels
8 nBlocks
9 connections % Cell array specifying connections between blocks
10 boundaryGroups % Structure of boundaryGroups
11
12 end
13
14
15 methods
16 % Creates a divided rectangle
17 % x and y are vectors of boundary and interface positions.
18 % blockNames: cell array of labels. The id is default.
19 function obj = Rectangle(x,y,blockNames)
20 default_arg('blockNames',[]);
21
22 n = length(y)-1; % number of blocks in the y direction.
23 m = length(x)-1; % number of blocks in the x direction.
24 N = n*m; % number of blocks
25
26 if ~issorted(x)
27 error('The elements of x seem to be in the wrong order');
28 end
29 if ~issorted(flip(y))
30 error('The elements of y seem to be in the wrong order');
31 end
32
33 % Dimensions of blocks and number of points
34 blockTi = cell(N,1);
35 xlims = cell(N,1);
36 ylims = cell(N,1);
37 for i = 1:n
38 for j = 1:m
39 p1 = [x(j), y(i+1)];
40 p2 = [x(j+1), y(i)];
41 I = flat_index(m,j,i);
42 blockTi{I} = parametrization.Ti.rectangle(p1,p2);
43 xlims{I} = {x(j), x(j+1)};
44 ylims{I} = {y(i+1), y(i)};
45 end
46 end
47
48 % Interface couplings
49 conn = cell(N,N);
50 for i = 1:n
51 for j = 1:m
52 I = flat_index(m,j,i);
53 if i < n
54 J = flat_index(m,j,i+1);
55 conn{I,J} = {'s','n'};
56 end
57
58 if j < m
59 J = flat_index(m,j+1,i);
60 conn{I,J} = {'e','w'};
61 end
62 end
63 end
64
65 % Block names (id number as default)
66 if isempty(blockNames)
67 obj.blockNames = cell(1, N);
68 for i = 1:N
69 obj.blockNames{i} = sprintf('%d', i);
70 end
71 else
72 assert(length(blockNames) == N);
73 obj.blockNames = blockNames;
74 end
75 nBlocks = N;
76
77 % Boundary groups
78 boundaryGroups = struct();
79 nx = m;
80 ny = n;
81 E = cell(1,ny);
82 W = cell(1,ny);
83 S = cell(1,nx);
84 N = cell(1,nx);
85 for i = 1:ny
86 E_id = flat_index(m,nx,i);
87 W_id = flat_index(m,1,i);
88 E{i} = {E_id,'e'};
89 W{i} = {W_id,'w'};
90 end
91 for j = 1:nx
92 S_id = flat_index(m,j,ny);
93 N_id = flat_index(m,j,1);
94 S{j} = {S_id,'s'};
95 N{j} = {N_id,'n'};
96 end
97 boundaryGroups.E = multiblock.BoundaryGroup(E);
98 boundaryGroups.W = multiblock.BoundaryGroup(W);
99 boundaryGroups.S = multiblock.BoundaryGroup(S);
100 boundaryGroups.N = multiblock.BoundaryGroup(N);
101 boundaryGroups.all = multiblock.BoundaryGroup([E,W,S,N]);
102 boundaryGroups.WS = multiblock.BoundaryGroup([W,S]);
103 boundaryGroups.WN = multiblock.BoundaryGroup([W,N]);
104 boundaryGroups.ES = multiblock.BoundaryGroup([E,S]);
105 boundaryGroups.EN = multiblock.BoundaryGroup([E,N]);
106
107 obj.connections = conn;
108 obj.nBlocks = nBlocks;
109 obj.boundaryGroups = boundaryGroups;
110 obj.blockTi = blockTi;
111 obj.xlims = xlims;
112 obj.ylims = ylims;
113
114 end
115
116
117 % Returns a multiblock.Grid given some parameters
118 % ms: cell array of [mx, my] vectors
119 % For same [mx, my] in every block, just input one vector.
120 function g = getGrid(obj, ms, varargin)
121
122 default_arg('ms',[21,21])
123
124 % Extend ms if input is a single vector
125 if (numel(ms) == 2) && ~iscell(ms)
126 m = ms;
127 ms = cell(1,obj.nBlocks);
128 for i = 1:obj.nBlocks
129 ms{i} = m;
130 end
131 end
132
133 grids = cell(1, obj.nBlocks);
134 for i = 1:obj.nBlocks
135 grids{i} = grid.equidistant(ms{i}, obj.xlims{i}, obj.ylims{i});
136 end
137
138 g = multiblock.Grid(grids, obj.connections, obj.boundaryGroups);
139 end
140
141 % label is the type of label used for plotting,
142 % default is block name, 'id' show the index for each block.
143 function show(obj, label, gridLines, varargin)
144 default_arg('label', 'name')
145 default_arg('gridLines', false);
146
147 if isempty('label') && ~gridLines
148 for i = 1:obj.nBlocks
149 obj.blockTi{i}.show(2,2);
150 end
151 axis equal
152 return
153 end
154
155 if gridLines
156 m = 10;
157 for i = 1:obj.nBlocks
158 obj.blockTi{i}.show(m,m);
159 end
160 end
161
162
163 switch label
164 case 'name'
165 labels = obj.blockNames;
166 case 'id'
167 labels = {};
168 for i = 1:obj.nBlocks
169 labels{i} = num2str(i);
170 end
171 otherwise
172 axis equal
173 return
174 end
175
176 for i = 1:obj.nBlocks
177 parametrization.Ti.label(obj.blockTi{i}, labels{i});
178 end
179
180 axis equal
181 end
182
183 % Returns the grid size of each block in a cell array
184 % The input parameters are determined by the subclass
185 function ms = getGridSizes(obj, varargin)
186 end
187 end
188 end