centroid_partitioner.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 // C++ includes
19 #include <algorithm> // for std::sort
20 
21 // Local includes
23 #include "libmesh/mesh_base.h"
24 #include "libmesh/elem.h"
25 
26 namespace libMesh
27 {
28 
29 
30 //---------------------------------------------------------
31 // CentroidPartitioner methods
33  const unsigned int n)
34 {
35  // Check for an easy return
36  if (n == 1)
37  {
38  this->single_partition (mesh);
39  return;
40  }
41 
42 
43  // Possibly reconstruct centroids
44  if (mesh.n_elem() != _elem_centroids.size())
45  this->compute_centroids (mesh);
46 
47 
48 
49  switch (this->sort_method())
50  {
51  case X:
52  {
53  std::sort(_elem_centroids.begin(),
54  _elem_centroids.end(),
56 
57  break;
58  }
59 
60 
61  case Y:
62  {
63  std::sort(_elem_centroids.begin(),
64  _elem_centroids.end(),
66 
67  break;
68 
69  }
70 
71 
72  case Z:
73  {
74  std::sort(_elem_centroids.begin(),
75  _elem_centroids.end(),
77 
78  break;
79  }
80 
81 
82  case RADIAL:
83  {
84  std::sort(_elem_centroids.begin(),
85  _elem_centroids.end(),
87 
88  break;
89  }
90  default:
91  libmesh_error();
92  }
93 
94 
95  // Make sure the user has not handed us an
96  // invalid number of partitions.
98 
99  // the number of elements, e.g. 1000
100  const dof_id_type n_elem = mesh.n_elem();
101  // the number of elements per processor, e.g 400
102  const dof_id_type target_size = n_elem / n;
103 
104  // Make sure the mesh hasn't changed since the
105  // last time we computed the centroids.
106  libmesh_assert_equal_to (mesh.n_elem(), _elem_centroids.size());
107 
108  for (dof_id_type i=0; i<n_elem; i++)
109  {
110  Elem* elem = _elem_centroids[i].second;
111 
112  elem->processor_id() =
113  std::min (libmesh_cast_int<processor_id_type>(i / target_size),
114  libmesh_cast_int<processor_id_type>(n-1));
115  }
116 }
117 
118 
119 
120 
121 
122 
123 
124 
126 {
127  _elem_centroids.clear();
128  _elem_centroids.reserve(mesh.n_elem());
129 
130 // elem_iterator it(mesh.elements_begin());
131 // const elem_iterator it_end(mesh.elements_end());
132 
134  const MeshBase::element_iterator it_end = mesh.elements_end();
135 
136  for (; it != it_end; ++it)
137  {
138  Elem* elem = *it;
139 
140  _elem_centroids.push_back(std::make_pair(elem->centroid(), elem));
141  }
142 }
143 
144 
145 
146 
147 bool CentroidPartitioner::sort_x (const std::pair<Point, Elem*>& lhs,
148  const std::pair<Point, Elem*>& rhs)
149 {
150  return (lhs.first(0) < rhs.first(0));
151 }
152 
153 
154 
155 
156 bool CentroidPartitioner::sort_y (const std::pair<Point, Elem*>& lhs,
157  const std::pair<Point, Elem*>& rhs)
158 {
159  return (lhs.first(1) < rhs.first(1));
160 }
161 
162 
163 
164 
165 
166 bool CentroidPartitioner::sort_z (const std::pair<Point, Elem*>& lhs,
167  const std::pair<Point, Elem*>& rhs)
168 {
169  return (lhs.first(2) < rhs.first(2));
170 }
171 
172 
173 
174 bool CentroidPartitioner::sort_radial (const std::pair<Point, Elem*>& lhs,
175  const std::pair<Point, Elem*>& rhs)
176 {
177  return (lhs.first.size() < rhs.first.size());
178 }
179 
180 } // namespace libMesh

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:04 UTC

Hosted By:
SourceForge.net Logo