Debian Codegraph @

packages/muelu/research/max/XpetraSplitting/create_regions.m

raw
1 function [global_indices, nodesToRegion, nodesOwnership, nodes_neighbourhood] = create_regions( nregion_nodes_x, nregion_nodes_y, nintervals_x, nintervals_y )
2
3 % INPUT:
4 % nregions_nodes_x : number of nodes along the x direction for each region
5 % nregions_nodes_y : number of nodes along the y direction for each region
6 % nintervals_x : number of intervals splitting the domain along the x direction
7 % nintervals_y : number of intervals splitting the domain along the y direction
8 %
9 % OUTPUT:
10 % global_indices: global node labels with region index associated with it
11 % nodesToRegion: cell structure that contains the list of regions a node belongs to
12 % nodesOwnership: structure that associates a globally idnexed node with the region that owns it
13 % (even if a node sits in more than one region, only a single region can own it)
14 % nodes_neighbourhood: for each node, this structure provides the list of neighbors (itself included) with distance equal to 1
15
16 % number of nodes along the x direction of the main
17 ntotal_nodes_x = nregion_nodes_x * nintervals_x - (nintervals_x-1);
18
19 % number of nodes along the y direction of the domain
20 ntotal_nodes_y = nregion_nodes_y * nintervals_y - (nintervals_y-1);
21
22 % total number of nodes that discretize the domain
23 ntotal_nodes = ntotal_nodes_x * ntotal_nodes_y;
24
25 % detects the global indices ONLY for nodes in region 1
26 global_indices_region1 = zeros(nregion_nodes_x*nregion_nodes_y,1);
27
28 for i = 1 : nregion_nodes_x
29
30 for j = 1 : nregion_nodes_y
31
32 global_indices_region1( (i-1)*nregion_nodes_y + j ) = j + (i-1) * ntotal_nodes_y;
33
34 end
35
36 end
37
38
39 % use the global indices of nodes in region 1 to reconstruct the global indices of the nodes
40 % in every other region
41 global_indices = [];
42
43 for i = 1 : nintervals_x
44
45 for j = 1 : nintervals_y
46
47 region_index = (i-1)*nintervals_y + j;
48
49 global_indices = [global_indices; [global_indices_region1 + (i-1) * (nregion_nodes_x-1) * ntotal_nodes_y + (j-1) * (nregion_nodes_y-1), region_index * ones(nregion_nodes_x*nregion_nodes_y,1) ] ];
50
51 end
52
53 end
54
55 nodesToRegion = cell(ntotal_nodes, 1);
56
57 parfor i = 1 : ntotal_nodes
58
59 find_result = global_indices(:,1)==i;
60 regions = global_indices(find_result,2);
61 nodesToRegion{i} = regions;
62
63 end
64
65 nodesOwnership = zeros(ntotal_nodes, 1);
66
67 % for i = 1 : ntotal_nodes
68 %
69 % nodesOwnership(i) = min(nodesToRegion{i});
70 %
71 % end
72
73 nodes_neighbourhood = cell(ntotal_nodes, 1);
74
75 parfor i = 1 : ntotal_nodes
76
77 neighbourhood = [];
78 regions = nodesToRegion{i};
79
80 for region = 1 : length(regions)
81
82 find_result = global_indices(:,2)==regions(region);
83 regional_nodes = global_indices(find_result,1);
84
85 neighbours = [ i-ntotal_nodes_y, i-ntotal_nodes_y-1, i-ntotal_nodes_y+1, i, i-1, i+1, i+ntotal_nodes_y, i+ntotal_nodes_y-1, i+ntotal_nodes_y+1 ];
86 neighbours = intersect( neighbours, regional_nodes );
87
88 if(~isempty(neighbours))
89 neighbourhood = [neighbourhood; neighbours];
90 end
91
92 end
93
94 nodes_neighbourhood{i} = unique(neighbourhood);
95
96 end
97
98 end
99
100
101
102
103
104
105