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(dimension(md.mesh)==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 | recomputeadjacency='on';
|
---|
44 | end
|
---|
45 |
|
---|
46 | %adjacency matrix if needed:
|
---|
47 | if strcmpi(recomputeadjacency,'on'),
|
---|
48 | md=adjacency(md);
|
---|
49 | else
|
---|
50 | disp('skipping adjacency matrix computation as requested in the options');
|
---|
51 | end
|
---|
52 |
|
---|
53 | if strcmpi(package,'chaco'),
|
---|
54 |
|
---|
55 | % default method (from chaco.m)
|
---|
56 | method=[1 1 0 0 1 1 50 0 .001 7654321]';
|
---|
57 | method(1)=3; % global method (3=inertial (geometric))
|
---|
58 | method(3)=0; % vertex weights (0=off, 1=on)
|
---|
59 |
|
---|
60 | %specify bisection
|
---|
61 | method(6)=getfieldvalue(options,'section');% ndims (1=bisection, 2=quadrisection, 3=octasection)
|
---|
62 |
|
---|
63 | %are we using weights?
|
---|
64 | if strcmpi(getfieldvalue(options,'weighting'),'on'),
|
---|
65 | weights=floor(md.qmu.vertex_weight/min(md.qmu.vertex_weight));
|
---|
66 | method(3)=1;
|
---|
67 | else
|
---|
68 | weights=[];
|
---|
69 | end
|
---|
70 |
|
---|
71 | % partition into nparts
|
---|
72 | if isa(md.mesh,'mesh2d'),
|
---|
73 | 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.
|
---|
74 | else
|
---|
75 | 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.
|
---|
76 | end
|
---|
77 |
|
---|
78 | elseif strcmpi(package,'scotch'),
|
---|
79 |
|
---|
80 | %are we using weights?
|
---|
81 | if strcmpi(getfieldvalue(options,'weighting'),'on'),
|
---|
82 | weights=floor(md.qmu.vertex_weight/min(md.qmu.vertex_weight));
|
---|
83 | else
|
---|
84 | weights=[];
|
---|
85 | end
|
---|
86 | maptab=Scotch(md.qmu.adjacency,[],weights,[],'cmplt',[npart]);
|
---|
87 |
|
---|
88 | part=maptab(:,2)+1;%index partitions from 1 up. like metis.
|
---|
89 |
|
---|
90 | elseif strcmpi(package,'linear'),
|
---|
91 |
|
---|
92 | part=1:1:md.mesh.numberofvertices;
|
---|
93 |
|
---|
94 | elseif strcmpi(package,'metis'),
|
---|
95 |
|
---|
96 | [element_partitioning,part]=MeshPartition(md.mesh,md.qmu.numberofpartitions);
|
---|
97 |
|
---|
98 | else
|
---|
99 |
|
---|
100 | error(['partitioner error message: could not find ' package ' partitioner']);
|
---|
101 | help partitioner
|
---|
102 | end
|
---|
103 |
|
---|
104 | %extrude if we are in 3D:
|
---|
105 | if dimension(md.mesh)==3,
|
---|
106 | md3d.qmu.vertex_weight=md.qmu.vertex_weight;
|
---|
107 | md3d.qmu.adjacency=md.qmu.adjacency;
|
---|
108 | md=md3d;
|
---|
109 | part=project3d(md,'vector',part','type','node');
|
---|
110 | end
|
---|
111 |
|
---|
112 | md.qmu.partition=part;
|
---|