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