1 | function 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 | % Output: md.qmu.partition recover the partition vector
|
---|
12 | %
|
---|
13 | % Usage:
|
---|
14 | % md=partitioner(md,'package','chaco','npart',100,'weighting','on');
|
---|
15 | %
|
---|
16 |
|
---|
17 | %get options:
|
---|
18 | options=pairoptions(varargin{:});
|
---|
19 |
|
---|
20 | %set defaults
|
---|
21 | options=addfielddefault(options,'package','chaco');
|
---|
22 | options=addfielddefault(options,'npart',10);
|
---|
23 | options=addfielddefault(options,'weighting','on');
|
---|
24 | options=addfielddefault(options,'section',1);
|
---|
25 | options=addfielddefault(options,'recomputeadjacency','on');
|
---|
26 |
|
---|
27 | %get package:
|
---|
28 | package=getfieldvalue(options,'package');
|
---|
29 | npart=getfieldvalue(options,'npart');
|
---|
30 | recomputeadjacency=getfieldvalue(options,'recomputeadjacency');
|
---|
31 |
|
---|
32 | if(md.mesh.dimension==3),
|
---|
33 | %partitioning essentially happens in 2D. So partition in 2D, then
|
---|
34 | %extrude the partition vector vertically.
|
---|
35 | md3d=md; %save for later
|
---|
36 | md.mesh.elements=md.mesh.elements2d;
|
---|
37 | md.mesh.x=md.mesh.x2d;
|
---|
38 | md.mesh.y=md.mesh.y2d;
|
---|
39 | md.mesh.numberofvertices=md.mesh.numberofvertices2d;
|
---|
40 | md.mesh.numberofelements=md.mesh.numberofelements2d;
|
---|
41 | md.qmu.vertex_weight=[];
|
---|
42 | md.mesh.vertexconnectivity=[];
|
---|
43 | end
|
---|
44 |
|
---|
45 | %adjacency matrix if needed:
|
---|
46 | if strcmpi(recomputeadjacency,'on'),
|
---|
47 | md=adjacency(md);
|
---|
48 | else
|
---|
49 | disp('skipping adjacency matrix computation as requested in the options');
|
---|
50 | end
|
---|
51 |
|
---|
52 | if strcmpi(package,'chaco'),
|
---|
53 |
|
---|
54 | % default method (from chaco.m)
|
---|
55 | method=[1 1 0 0 1 1 50 0 .001 7654321]';
|
---|
56 | method(1)=3; % global method (3=inertial (geometric))
|
---|
57 | method(3)=0; % vertex weights (0=off, 1=on)
|
---|
58 |
|
---|
59 | %specify bisection
|
---|
60 | method(6)=getfieldvalue(options,'section');% ndims (1=bisection, 2=quadrisection, 3=octasection)
|
---|
61 |
|
---|
62 | %are we using weights?
|
---|
63 | if strcmpi(getfieldvalue(options,'weighting'),'on'),
|
---|
64 | weights=floor(md.qmu.vertex_weight/min(md.qmu.vertex_weight));
|
---|
65 | method(3)=1;
|
---|
66 | else
|
---|
67 | weights=[];
|
---|
68 | end
|
---|
69 |
|
---|
70 | % partition into nparts
|
---|
71 | 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.
|
---|
72 |
|
---|
73 | elseif strcmpi(package,'scotch'),
|
---|
74 |
|
---|
75 | %are we using weights?
|
---|
76 | if strcmpi(getfieldvalue(options,'weighting'),'on'),
|
---|
77 | weights=floor(md.qmu.vertex_weight/min(md.qmu.vertex_weight));
|
---|
78 | end
|
---|
79 | maptab=Scotch(md.qmu.adjacency,[],weights,[],'cmplt',[npart]);
|
---|
80 |
|
---|
81 | part=maptab(:,2);%index partitions from 1 up. like metis.
|
---|
82 |
|
---|
83 | elseif strcmpi(package,'linear'),
|
---|
84 |
|
---|
85 | part=1:1:md.mesh.numberofvertices;
|
---|
86 |
|
---|
87 | elseif strcmpi(package,'metis'),
|
---|
88 |
|
---|
89 | [element_partitioning,part]=MeshPartition(md.mesh,md.qmu.numberofpartitions);
|
---|
90 |
|
---|
91 | else
|
---|
92 |
|
---|
93 | error(['partitioner error message: could not find ' package ' partitioner']);
|
---|
94 | help partitioner
|
---|
95 | end
|
---|
96 |
|
---|
97 | %extrude if we are in 3D:
|
---|
98 | if md.mesh.dimension==3,
|
---|
99 | md3d.qmu.vertex_weight=md.qmu.vertex_weight;
|
---|
100 | md3d.qmu.adjacency=md.qmu.adjacency;
|
---|
101 | md=md3d;
|
---|
102 | part=project3d(md,'vector',part','type','node');
|
---|
103 | end
|
---|
104 |
|
---|
105 | md.qmu.partition=part;
|
---|