libMesh
linear_partitioner.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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 
19 
20 // Local Includes
21 #include "libmesh/linear_partitioner.h"
22 #include "libmesh/libmesh_logging.h"
23 #include "libmesh/elem.h"
24 
25 namespace libMesh
26 {
27 
31  const unsigned int n)
32 {
33  libmesh_assert_greater (n, 0);
34 
35  // Check for an easy return
36  if (n == 1)
37  {
38  this->single_partition_range (it, end);
39  return;
40  }
41 
42  // Create a simple linear partitioning
43  LOG_SCOPE ("partition_range()", "LinearPartitioner");
44 
45  const dof_id_type blksize = std::distance(it, end) / n;
46 
47  dof_id_type e = 0;
48  for ( ; it != end; ++it)
49  {
50  Elem * elem = *it;
51  if ((e/blksize) < n)
52  elem->processor_id() = cast_int<processor_id_type>(e/blksize);
53 
54  else
55  elem->processor_id() = 0;
56 
57  e++;
58  }
59 }
60 
61 
62 
64  const unsigned int n)
65 {
66  this->partition_range(mesh,
67  mesh.active_elements_begin(),
68  mesh.active_elements_end(),
69  n);
70 }
71 
72 } // namespace libMesh
The definition of the element_iterator struct.
Definition: mesh_base.h:1476
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
MeshBase & mesh
IterBase * end
Also have a polymorphic pointer to the end object, this prevents iterating past the end...
The libMesh namespace provides an interface to certain functionality in the library.
virtual void partition_range(MeshBase &mesh, MeshBase::element_iterator it, MeshBase::element_iterator end, const unsigned int n) libmesh_override
Called by the SubdomainPartitioner to partition elements in the range (it, end).
Real distance(const Point &p)
This is the MeshBase class.
Definition: mesh_base.h:68
void single_partition_range(MeshBase::element_iterator it, MeshBase::element_iterator end)
Slightly generalized version of single_partition which acts on a range of elements defined by the pai...
Definition: partitioner.C:159
virtual void _do_partition(MeshBase &mesh, const unsigned int n) libmesh_override
Partition the MeshBase into n subdomains.
virtual element_iterator active_elements_begin()=0
Active, local, and negation forms of the element iterators described above.
virtual element_iterator active_elements_end()=0
uint8_t dof_id_type
Definition: id_types.h:64
processor_id_type processor_id() const
Definition: dof_object.h:694