[25920] | 1 | function [partitionvector,md]=partitioner(md,varargin)
|
---|
[3016] | 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
|
---|
[3039] | 9 | % section: 1 by defaults(1=bisection, 2=quadrisection, 3=octasection)
|
---|
[4713] | 10 | % recomputeadjacency: 'on' by default (set to 'off' to compute existing one)
|
---|
[24173] | 11 | % type: 'node' or 'element' partition vector (default to 'node')
|
---|
[24998] | 12 | % Output: partitionvector: the partition vector
|
---|
[3016] | 13 | %
|
---|
| 14 | % Usage:
|
---|
[24998] | 15 | % partitionvector=partitioner(md,'package','chaco','npart',100,'weighting','on');
|
---|
[25165] | 16 | % [partitionvector,md]=partitioner(md,'package','chaco','npart',100,'weighting','on');
|
---|
[3016] | 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);
|
---|
[3039] | 25 | options=addfielddefault(options,'weighting','on');
|
---|
| 26 | options=addfielddefault(options,'section',1);
|
---|
[4713] | 27 | options=addfielddefault(options,'recomputeadjacency','on');
|
---|
[24173] | 28 | options=addfielddefault(options,'type','node');
|
---|
[3016] | 29 |
|
---|
| 30 | %get package:
|
---|
| 31 | package=getfieldvalue(options,'package');
|
---|
| 32 | npart=getfieldvalue(options,'npart');
|
---|
[4713] | 33 | recomputeadjacency=getfieldvalue(options,'recomputeadjacency');
|
---|
[24173] | 34 | vectortype=getfieldvalue(options,'type');
|
---|
[3016] | 35 |
|
---|
[17686] | 36 | if(dimension(md.mesh)==3),
|
---|
[9013] | 37 | %partitioning essentially happens in 2D. So partition in 2D, then
|
---|
| 38 | %extrude the partition vector vertically.
|
---|
[25165] | 39 | md3d=md; %save for later
|
---|
[9733] | 40 | md.mesh.elements=md.mesh.elements2d;
|
---|
[9734] | 41 | md.mesh.x=md.mesh.x2d;
|
---|
| 42 | md.mesh.y=md.mesh.y2d;
|
---|
[9725] | 43 | md.mesh.numberofvertices=md.mesh.numberofvertices2d;
|
---|
| 44 | md.mesh.numberofelements=md.mesh.numberofelements2d;
|
---|
[9671] | 45 | md.qmu.vertex_weight=[];
|
---|
[9729] | 46 | md.mesh.vertexconnectivity=[];
|
---|
[21905] | 47 | recomputeadjacency='on';
|
---|
[9013] | 48 | end
|
---|
| 49 |
|
---|
[4659] | 50 | %adjacency matrix if needed:
|
---|
[9207] | 51 | if strcmpi(recomputeadjacency,'on'),
|
---|
| 52 | md=adjacency(md);
|
---|
| 53 | else
|
---|
| 54 | disp('skipping adjacency matrix computation as requested in the options');
|
---|
[4659] | 55 | end
|
---|
| 56 |
|
---|
[3016] | 57 | if strcmpi(package,'chaco'),
|
---|
| 58 |
|
---|
[24173] | 59 | if strcmpi(vectortype,'element')
|
---|
| 60 | error(['partitioner error message: package ' package ' does not allow element partitions.']);
|
---|
| 61 | else
|
---|
[13646] | 62 |
|
---|
[24173] | 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)
|
---|
[3016] | 67 |
|
---|
[24173] | 68 | %specify bisection
|
---|
| 69 | method(6)=getfieldvalue(options,'section');% ndims (1=bisection, 2=quadrisection, 3=octasection)
|
---|
[13646] | 70 |
|
---|
[24173] | 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'),
|
---|
[25165] | 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.
|
---|
[24173] | 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 |
|
---|
[17559] | 86 | end
|
---|
[3016] | 87 |
|
---|
| 88 | elseif strcmpi(package,'scotch'),
|
---|
| 89 |
|
---|
[24173] | 90 | if strcmpi(vectortype,'element')
|
---|
| 91 | error(['partitioner error message: package ' package ' does not allow element partitions.']);
|
---|
[21905] | 92 | else
|
---|
[24173] | 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.
|
---|
[3921] | 102 | end
|
---|
[13646] | 103 |
|
---|
[3058] | 104 | elseif strcmpi(package,'linear'),
|
---|
| 105 |
|
---|
[24173] | 106 | if strcmpi(vectortype,'element')
|
---|
[22069] | 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
|
---|
[3058] | 112 |
|
---|
[3016] | 113 | elseif strcmpi(package,'metis'),
|
---|
| 114 |
|
---|
[24173] | 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
|
---|
[3016] | 120 |
|
---|
| 121 | else
|
---|
| 122 |
|
---|
| 123 | error(['partitioner error message: could not find ' package ' partitioner']);
|
---|
| 124 | help partitioner
|
---|
[4663] | 125 | end
|
---|
[3016] | 126 |
|
---|
[9013] | 127 | %extrude if we are in 3D:
|
---|
[17686] | 128 | if dimension(md.mesh)==3,
|
---|
[11315] | 129 | md3d.qmu.vertex_weight=md.qmu.vertex_weight;
|
---|
| 130 | md3d.qmu.adjacency=md.qmu.adjacency;
|
---|
[9013] | 131 | md=md3d;
|
---|
[24173] | 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
|
---|
[9013] | 137 | end
|
---|
| 138 |
|
---|
[24161] | 139 | if size(part,1)==1
|
---|
| 140 | part=part';
|
---|
| 141 | end
|
---|
[24173] | 142 |
|
---|
[24998] | 143 | %output
|
---|
| 144 | partitionvector=part;
|
---|