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