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

Last change on this file since 22069 was 22069, checked in by schlegel, 8 years ago

CHG: allow dakota to sample element vectors

File size: 3.5 KB
Line 
1function 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:
18options=pairoptions(varargin{:});
19
20%set defaults
21options=addfielddefault(options,'package','chaco');
22options=addfielddefault(options,'npart',10);
23options=addfielddefault(options,'weighting','on');
24options=addfielddefault(options,'section',1);
25options=addfielddefault(options,'recomputeadjacency','on');
26
27%get package:
28package=getfieldvalue(options,'package');
29npart=getfieldvalue(options,'npart');
30recomputeadjacency=getfieldvalue(options,'recomputeadjacency');
31
32if(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';
44end
45
46%adjacency matrix if needed:
47if strcmpi(recomputeadjacency,'on'),
48 md=adjacency(md);
49else
50 disp('skipping adjacency matrix computation as requested in the options');
51end
52
53if 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
78elseif 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
90elseif strcmpi(package,'linear'),
91
92 if npart==md.mesh.numberofelements | md.qmu.numberofpartitions==md.mesh.numberofelements
93 part=1:1:md.mesh.numberofelements;
94 disp('Linear partitioner requesting partitions on elements');
95 else
96 part=1:1:md.mesh.numberofvertices;
97 end
98
99elseif strcmpi(package,'metis'),
100
101 [element_partitioning,part]=MeshPartition(md,md.qmu.numberofpartitions);
102
103else
104
105 error(['partitioner error message: could not find ' package ' partitioner']);
106 help partitioner
107end
108
109%extrude if we are in 3D:
110if dimension(md.mesh)==3,
111 md3d.qmu.vertex_weight=md.qmu.vertex_weight;
112 md3d.qmu.adjacency=md.qmu.adjacency;
113 md=md3d;
114 part=project3d(md,'vector',part','type','node');
115end
116
117md.qmu.partition=part;
Note: See TracBrowser for help on using the repository browser.