1 | function [partitionvector,md]=partitioner(md,varargin)
|
---|
2 | %PARTITIONER - partition mesh
|
---|
3 | %
|
---|
4 | % List of options to partitioner:
|
---|
5 | %
|
---|
6 | % package: 'chaco', 'metis' or 'scotch'
|
---|
7 | % npart: number of partitions.
|
---|
8 | % weighting: 'on' or 'off': default off
|
---|
9 | % section: 1 by defaults(1=bisection, 2=quadrisection, 3=octasection)
|
---|
10 | % recomputeadjacency: 'on' by default (set to 'off' to compute existing one)
|
---|
11 | % type: 'node' or 'element' partition vector (default to 'node')
|
---|
12 | % Output: partitionvector: the partition vector
|
---|
13 | %
|
---|
14 | % Usage:
|
---|
15 | % partitionvector=partitioner(md,'package','chaco','npart',100,'weighting','on');
|
---|
16 | % [partitionvector,md]=partitioner(md,'package','chaco','npart',100,'weighting','on');
|
---|
17 | %
|
---|
18 |
|
---|
19 | %get options:
|
---|
20 | options=pairoptions(varargin{:});
|
---|
21 |
|
---|
22 | %set defaults
|
---|
23 | options=addfielddefault(options,'package','chaco');
|
---|
24 | options=addfielddefault(options,'npart',10);
|
---|
25 | options=addfielddefault(options,'weighting','on');
|
---|
26 | options=addfielddefault(options,'section',1);
|
---|
27 | options=addfielddefault(options,'recomputeadjacency','on');
|
---|
28 | options=addfielddefault(options,'type','node');
|
---|
29 |
|
---|
30 | %get package:
|
---|
31 | package=getfieldvalue(options,'package');
|
---|
32 | npart=getfieldvalue(options,'npart');
|
---|
33 | recomputeadjacency=getfieldvalue(options,'recomputeadjacency');
|
---|
34 | vectortype=getfieldvalue(options,'type');
|
---|
35 |
|
---|
36 | if(dimension(md.mesh)==3),
|
---|
37 | %partitioning essentially happens in 2D. So partition in 2D, then
|
---|
38 | %extrude the partition vector vertically.
|
---|
39 | md3d=md; %save for later
|
---|
40 | md.mesh.elements=md.mesh.elements2d;
|
---|
41 | md.mesh.x=md.mesh.x2d;
|
---|
42 | md.mesh.y=md.mesh.y2d;
|
---|
43 | md.mesh.numberofvertices=md.mesh.numberofvertices2d;
|
---|
44 | md.mesh.numberofelements=md.mesh.numberofelements2d;
|
---|
45 | md.qmu.vertex_weight=[];
|
---|
46 | md.mesh.vertexconnectivity=[];
|
---|
47 | recomputeadjacency='on';
|
---|
48 | end
|
---|
49 |
|
---|
50 | %adjacency matrix if needed:
|
---|
51 | if strcmpi(recomputeadjacency,'on'),
|
---|
52 | md=adjacency(md);
|
---|
53 | else
|
---|
54 | disp('skipping adjacency matrix computation as requested in the options');
|
---|
55 | end
|
---|
56 |
|
---|
57 | if strcmpi(package,'chaco'),
|
---|
58 |
|
---|
59 | if strcmpi(vectortype,'element')
|
---|
60 | error(['partitioner error message: package ' package ' does not allow element partitions.']);
|
---|
61 | else
|
---|
62 |
|
---|
63 | % default method (from chaco.m)
|
---|
64 | method=[1 1 0 0 1 1 50 0 .001 7654321]';
|
---|
65 | method(1)=3; % global method (3=inertial (geometric))
|
---|
66 | method(3)=0; % vertex weights (0=off, 1=on)
|
---|
67 |
|
---|
68 | %specify bisection
|
---|
69 | method(6)=getfieldvalue(options,'section');% ndims (1=bisection, 2=quadrisection, 3=octasection)
|
---|
70 |
|
---|
71 | %are we using weights?
|
---|
72 | if strcmpi(getfieldvalue(options,'weighting'),'on'),
|
---|
73 | weights=floor(md.qmu.vertex_weight/min(md.qmu.vertex_weight));
|
---|
74 | method(3)=1;
|
---|
75 | else
|
---|
76 | weights=[];
|
---|
77 | end
|
---|
78 |
|
---|
79 | % partition into nparts
|
---|
80 | if isa(md.mesh,'mesh2d'),
|
---|
81 | part=Chaco(md.qmu.adjacency,weights,[],md.mesh.x,md.mesh.y,zeros(md.mesh.numberofvertices,1),method,npart,[])'+1; %index partitions from 1 up. like metis.
|
---|
82 | else
|
---|
83 | part=Chaco(md.qmu.adjacency,weights,[],md.mesh.x, md.mesh.y,md.mesh.z,method,npart,[])'+1; %index partitions from 1 up. like metis.
|
---|
84 | end
|
---|
85 |
|
---|
86 | end
|
---|
87 |
|
---|
88 | elseif strcmpi(package,'scotch'),
|
---|
89 |
|
---|
90 | if strcmpi(vectortype,'element')
|
---|
91 | error(['partitioner error message: package ' package ' does not allow element partitions.']);
|
---|
92 | else
|
---|
93 | %are we using weights?
|
---|
94 | if strcmpi(getfieldvalue(options,'weighting'),'on'),
|
---|
95 | weights=floor(md.qmu.vertex_weight/min(md.qmu.vertex_weight));
|
---|
96 | else
|
---|
97 | weights=[];
|
---|
98 | end
|
---|
99 | maptab=Scotch(md.qmu.adjacency,[],weights,[],'cmplt',[npart]);
|
---|
100 |
|
---|
101 | part=maptab(:,2)+1;%index partitions from 1 up. like metis.
|
---|
102 | end
|
---|
103 |
|
---|
104 | elseif strcmpi(package,'linear'),
|
---|
105 |
|
---|
106 | if strcmpi(vectortype,'element')
|
---|
107 | part=1:1:md.mesh.numberofelements;
|
---|
108 | disp('Linear partitioner requesting partitions on elements');
|
---|
109 | else
|
---|
110 | part=1:1:md.mesh.numberofvertices;
|
---|
111 | end
|
---|
112 |
|
---|
113 | elseif strcmpi(package,'metis'),
|
---|
114 |
|
---|
115 | if strcmpi(vectortype,'element')
|
---|
116 | error(['partitioner error message: package ' package ' does not allow element partitions.']);
|
---|
117 | else
|
---|
118 | [element_partitioning,part]=MeshPartition(md,md.qmu.numberofpartitions);
|
---|
119 | end
|
---|
120 |
|
---|
121 | else
|
---|
122 |
|
---|
123 | error(['partitioner error message: could not find ' package ' partitioner']);
|
---|
124 | help partitioner
|
---|
125 | end
|
---|
126 |
|
---|
127 | %extrude if we are in 3D:
|
---|
128 | if dimension(md.mesh)==3,
|
---|
129 | md3d.qmu.vertex_weight=md.qmu.vertex_weight;
|
---|
130 | md3d.qmu.adjacency=md.qmu.adjacency;
|
---|
131 | md=md3d;
|
---|
132 | if strcmpi(vectortype,'element')
|
---|
133 | part=project3d(md,'vector',part','type','element');
|
---|
134 | else
|
---|
135 | part=project3d(md,'vector',part','type','node');
|
---|
136 | end
|
---|
137 | end
|
---|
138 |
|
---|
139 | if size(part,1)==1
|
---|
140 | part=part';
|
---|
141 | end
|
---|
142 |
|
---|
143 | %output
|
---|
144 | partitionvector=part;
|
---|