Mercurial > repos > public > sbplib
comparison +multiblock/+domain/Rectangle.m @ 593:37948bfe9d79 feature/better_multiblock_defs
Complete Rectangle definition
| author | Martin Almquist <malmquist@stanford.edu> |
|---|---|
| date | Mon, 18 Sep 2017 19:41:12 +0200 |
| parents | 7789a844ab65 |
| children | 4bb298faa8dc |
comparison
equal
deleted
inserted
replaced
| 590:7789a844ab65 | 593:37948bfe9d79 |
|---|---|
| 1 classdef Rectangle < multiblock.Definition | 1 classdef Rectangle < multiblock.Definition |
| 2 properties | 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 | |
| 3 | 11 |
| 4 end | 12 end |
| 5 | 13 |
| 6 | 14 |
| 7 methods | 15 methods |
| 8 % Creates a ... | 16 % Creates a divided rectangle |
| 9 % x and y are vectors of boundary and interface positions. | 17 % x and y are vectors of boundary and interface positions. |
| 10 function obj = Rectangle(x,y) | 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 | |
| 103 obj.connections = conn; | |
| 104 obj.nBlocks = nBlocks; | |
| 105 obj.boundaryGroups = boundaryGroups; | |
| 106 obj.blockTi = blockTi; | |
| 107 obj.xlims = xlims; | |
| 108 obj.ylims = ylims; | |
| 11 | 109 |
| 12 end | 110 end |
| 13 | 111 |
| 14 | 112 |
| 15 % Returns a multiblock.Grid given some parameters | 113 % Returns a multiblock.Grid given some parameters |
| 16 function g = getGrid(obj, varargin) | 114 % ms: cell array of [mx, my] vectors |
| 115 % For same [mx, my] in every block, just input one vector. | |
| 116 function g = getGrid(obj, ms, varargin) | |
| 117 | |
| 118 default_arg('ms',[21,21]) | |
| 119 | |
| 120 % Extend ms if input is a single vector | |
| 121 if (numel(ms) == 2) && ~iscell(ms) | |
| 122 m = ms; | |
| 123 ms = cell(1,obj.nBlocks); | |
| 124 for i = 1:obj.nBlocks | |
| 125 ms{i} = m; | |
| 126 end | |
| 127 end | |
| 128 | |
| 129 grids = cell(1, obj.nBlocks); | |
| 130 for i = 1:obj.nBlocks | |
| 131 grids{i} = grid.equidistant(ms{i}, obj.xlims{i}, obj.ylims{i}); | |
| 132 end | |
| 133 | |
| 134 g = multiblock.Grid(grids, obj.connections, obj.boundaryGroups); | |
| 17 end | 135 end |
| 18 | 136 |
| 19 % label is the type of label used for plotting, | 137 % label is the type of label used for plotting, |
| 20 % default is block name, 'id' show the index for each block. | 138 % default is block name, 'id' show the index for each block. |
| 21 function show(obj, label, gridLines, varargin) | 139 function show(obj, label, gridLines, varargin) |
| 140 default_arg('label', 'name') | |
| 141 default_arg('gridLines', false); | |
| 22 | 142 |
| 143 if isempty('label') && ~gridLines | |
| 144 for i = 1:obj.nBlocks | |
| 145 obj.blockTi{i}.show(2,2); | |
| 146 end | |
| 147 axis equal | |
| 148 return | |
| 149 end | |
| 150 | |
| 151 if gridLines | |
| 152 m = 10; | |
| 153 for i = 1:obj.nBlocks | |
| 154 obj.blockTi{i}.show(m,m); | |
| 155 end | |
| 156 end | |
| 157 | |
| 158 | |
| 159 switch label | |
| 160 case 'name' | |
| 161 labels = obj.blockNames; | |
| 162 case 'id' | |
| 163 labels = {}; | |
| 164 for i = 1:obj.nBlocks | |
| 165 labels{i} = num2str(i); | |
| 166 end | |
| 167 otherwise | |
| 168 axis equal | |
| 169 return | |
| 170 end | |
| 171 | |
| 172 for i = 1:obj.nBlocks | |
| 173 parametrization.Ti.label(obj.blockTi{i}, labels{i}); | |
| 174 end | |
| 175 | |
| 176 axis equal | |
| 23 end | 177 end |
| 24 | 178 |
| 25 % Returns the grid size of each block in a cell array | 179 % Returns the grid size of each block in a cell array |
| 26 % The input parameters are determined by the subclass | 180 % The input parameters are determined by the subclass |
| 27 function ms = getGridSizes(obj, varargin) | 181 function ms = getGridSizes(obj, varargin) |
