source: issm/trunk-jpl/src/m/partition/partitioner.m@ 25109

Last change on this file since 25109 was 25109, checked in by jdquinn, 5 years ago

BUG: Number and order of arguments

File size: 4.2 KB
Line 
1function [partitionvector, 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% type: 'node' or 'element' partition vector (default to 'node')
12% Output: partitionvector: the partition vector
13%
14% Usage:
15% partitionvector=partitioner(md,'package','chaco','npart',100,'weighting','on');
16%
17
18%get options:
19options=pairoptions(varargin{:});
20
21%set defaults
22options=addfielddefault(options,'package','chaco');
23options=addfielddefault(options,'npart',10);
24options=addfielddefault(options,'weighting','on');
25options=addfielddefault(options,'section',1);
26options=addfielddefault(options,'recomputeadjacency','on');
27options=addfielddefault(options,'type','node');
28
29%get package:
30package=getfieldvalue(options,'package');
31npart=getfieldvalue(options,'npart');
32recomputeadjacency=getfieldvalue(options,'recomputeadjacency');
33vectortype=getfieldvalue(options,'type');
34
35if(dimension(md.mesh)==3),
36 %partitioning essentially happens in 2D. So partition in 2D, then
37 %extrude the partition vector vertically.
38 md3d=md; %save for later
39 md.mesh.elements=md.mesh.elements2d;
40 md.mesh.x=md.mesh.x2d;
41 md.mesh.y=md.mesh.y2d;
42 md.mesh.numberofvertices=md.mesh.numberofvertices2d;
43 md.mesh.numberofelements=md.mesh.numberofelements2d;
44 md.qmu.vertex_weight=[];
45 md.mesh.vertexconnectivity=[];
46 recomputeadjacency='on';
47end
48
49%adjacency matrix if needed:
50if strcmpi(recomputeadjacency,'on'),
51 md=adjacency(md);
52else
53 disp('skipping adjacency matrix computation as requested in the options');
54end
55
56if strcmpi(package,'chaco'),
57
58 if strcmpi(vectortype,'element')
59 error(['partitioner error message: package ' package ' does not allow element partitions.']);
60 else
61
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)
66
67 %specify bisection
68 method(6)=getfieldvalue(options,'section');% ndims (1=bisection, 2=quadrisection, 3=octasection)
69
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
85 end
86
87elseif strcmpi(package,'scotch'),
88
89 if strcmpi(vectortype,'element')
90 error(['partitioner error message: package ' package ' does not allow element partitions.']);
91 else
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.
101 end
102
103elseif strcmpi(package,'linear'),
104
105 if strcmpi(vectortype,'element')
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
111
112elseif strcmpi(package,'metis'),
113
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
119
120else
121
122 error(['partitioner error message: could not find ' package ' partitioner']);
123 help partitioner
124end
125
126%extrude if we are in 3D:
127if dimension(md.mesh)==3,
128 md3d.qmu.vertex_weight=md.qmu.vertex_weight;
129 md3d.qmu.adjacency=md.qmu.adjacency;
130 md=md3d;
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
136end
137
138if size(part,1)==1
139 part=part';
140end
141
142%output
143partitionvector=part;
Note: See TracBrowser for help on using the repository browser.