0
|
1 % Creates a multi block square grid with defined boundary conditions.
|
|
2 % x,y defines the grid lines. Rember to think of the indexing as a matrix. Order matters!
|
|
3 % bc is a struct defining the boundary conditions on each side of the block.
|
|
4 % bc.w = {'dn',[function or value]}
|
|
5 function [block,conn,bound,ms] = multiblockgrid(x,y,mx,my,bc)
|
|
6 n = length(y)-1; % number of blocks in the y direction.
|
|
7 m = length(x)-1; % number of blocks in the x direction.
|
|
8 N = n*m; % number of blocks
|
|
9
|
|
10 if ~issorted(x)
|
|
11 error('The elements of x seem to be in the wrong order');
|
|
12 end
|
|
13 if ~issorted(flip(y))
|
|
14 error('The elements of y seem to be in the wrong order');
|
|
15 end
|
|
16 % y = sort(y,'descend');
|
|
17
|
|
18 % Dimensions of blocks and number of points
|
|
19 block = cell(n,m);
|
|
20 for i = 1:n
|
|
21 for j = 1:m
|
|
22 block{i,j} = {
|
|
23 {x(j),x(j+1)}, {y(i+1),y(i)};
|
|
24 };
|
|
25
|
|
26 ms{i,j} = [mx(i),my(j)];
|
|
27 end
|
|
28 end
|
|
29
|
|
30 % Interface couplings
|
|
31 conn = cell(N,N);
|
|
32 for i = 1:n
|
|
33 for j = 1:m
|
|
34 I = flat_index(n,i,j);
|
|
35 if i < n
|
|
36 J = flat_index(n,i+1,j);
|
|
37 conn{I,J} = {'s','n'};
|
|
38 end
|
|
39
|
|
40 if j < m
|
|
41 J = flat_index(n,i,j+1);
|
|
42 conn{I,J} = {'e','w'};
|
|
43 end
|
|
44 end
|
|
45 end
|
|
46
|
|
47
|
|
48 % Boundary conditions
|
|
49 bound = cell(n,m);
|
|
50 for i = 1:n
|
|
51 if isfield(bc,'w')
|
|
52 bound{i,1}.w = bc.w;
|
|
53 end
|
|
54
|
|
55 if isfield(bc,'e')
|
|
56 bound{i,n}.e = bc.e;
|
|
57 end
|
|
58 end
|
|
59
|
|
60 for j = 1:m
|
|
61 if isfield(bc,'n')
|
|
62 bound{1,j}.n = bc.n;
|
|
63 end
|
|
64
|
|
65 if isfield(bc,'s')
|
|
66 bound{m,j}.s = bc.s;
|
|
67 end
|
|
68 end
|
|
69 end
|
|
70
|