libMesh
centroid_partitioner.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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 #ifndef LIBMESH_CENTROID_PARTITIONER_H
20 #define LIBMESH_CENTROID_PARTITIONER_H
21 
22 // Local includes
23 #include "libmesh/partitioner.h"
24 #include "libmesh/point.h"
25 #include "libmesh/auto_ptr.h" // libmesh_make_unique
26 
27 // C++ includes
28 #include <utility> // pair
29 #include <vector>
30 
31 namespace libMesh
32 {
33 
34 // Forward declarations
35 class Elem;
36 
49 {
50 public:
51 
58  Y,
59  Z,
62 
67  explicit
69 
74  CentroidPartitioner (const CentroidPartitioner &) = default;
78  virtual ~CentroidPartitioner() = default;
79 
83  virtual std::unique_ptr<Partitioner> clone () const override
84  {
85  return libmesh_make_unique<CentroidPartitioner>(*this);
86  }
87 
92 
97 
101  virtual void partition_range(MeshBase & mesh,
104  const unsigned int n) override;
105 
106 protected:
107 
111  virtual void _do_partition (MeshBase & mesh,
112  const unsigned int n) override;
113 
114 private:
115 
121 
126  static bool sort_x (const std::pair<Point, Elem *> & lhs,
127  const std::pair<Point, Elem *> & rhs);
128 
133  static bool sort_y (const std::pair<Point, Elem *> & lhs,
134  const std::pair<Point, Elem *> & rhs);
135 
140  static bool sort_z (const std::pair<Point, Elem *> & lhs,
141  const std::pair<Point, Elem *> & rhs);
142 
147  static bool sort_radial (const std::pair<Point, Elem *> & lhs,
148  const std::pair<Point, Elem *> & rhs);
149 
154 
159  std::vector<std::pair<Point, Elem *>> _elem_centroids;
160 };
161 
162 } // namespace libMesh
163 
164 #endif // LIBMESH_CENTROID_PARTITIONER_H
libMesh::MeshBase::element_iterator
The definition of the element_iterator struct.
Definition: mesh_base.h:1873
libMesh::CentroidPartitioner::CentroidPartitioner
CentroidPartitioner(const CentroidSortMethod sm=X)
Constructor.
Definition: centroid_partitioner.h:68
libMesh::CentroidPartitioner::sort_y
static bool sort_y(const std::pair< Point, Elem * > &lhs, const std::pair< Point, Elem * > &rhs)
Helper function which sorts by the centroid's y-coordinate in the internal std::sort call.
Definition: centroid_partitioner.C:154
libMesh::CentroidPartitioner::operator=
CentroidPartitioner & operator=(const CentroidPartitioner &)=default
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
end
IterBase * end
Also have a polymorphic pointer to the end object, this prevents iterating past the end.
Definition: variant_filter_iterator.h:343
libMesh::Partitioner
The Partitioner class provides a uniform interface for partitioning algorithms.
Definition: partitioner.h:50
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::CentroidPartitioner::compute_centroids
void compute_centroids(MeshBase::element_iterator it, MeshBase::element_iterator end)
Computes a list of element centroids for the mesh.
Definition: centroid_partitioner.C:133
libMesh::CentroidPartitioner::CentroidSortMethod
CentroidSortMethod
A typedef which controls the sorting method used for ordering the centroids.
Definition: centroid_partitioner.h:57
libMesh::CentroidPartitioner::sort_radial
static bool sort_radial(const std::pair< Point, Elem * > &lhs, const std::pair< Point, Elem * > &rhs)
Helper function which sorts by the centroid's distance from the origin in the internal std::sort call...
Definition: centroid_partitioner.C:172
libMesh::CentroidPartitioner::~CentroidPartitioner
virtual ~CentroidPartitioner()=default
libMesh::CentroidPartitioner
Partitions the Mesh based on the locations of element centroids.
Definition: centroid_partitioner.h:48
libMesh::MeshBase
This is the MeshBase class.
Definition: mesh_base.h:78
libMesh::CentroidPartitioner::_sort_method
CentroidSortMethod _sort_method
Flag indicating the type of sort method we are using.
Definition: centroid_partitioner.h:153
libMesh::CentroidPartitioner::INVALID_METHOD
Definition: centroid_partitioner.h:61
libMesh::CentroidPartitioner::sort_method
CentroidSortMethod sort_method() const
Getter for the current sorting method.
Definition: centroid_partitioner.h:91
libMesh::CentroidPartitioner::_elem_centroids
std::vector< std::pair< Point, Elem * > > _elem_centroids
Vector which holds pairs of centroids and their respective element pointers.
Definition: centroid_partitioner.h:159
libMesh::CentroidPartitioner::clone
virtual std::unique_ptr< Partitioner > clone() const override
Definition: centroid_partitioner.h:83
libMesh::CentroidPartitioner::sort_x
static bool sort_x(const std::pair< Point, Elem * > &lhs, const std::pair< Point, Elem * > &rhs)
Helper function which sorts by the centroid's x-coordinate in the internal std::sort call.
Definition: centroid_partitioner.C:145
libMesh::CentroidPartitioner::partition_range
virtual void partition_range(MeshBase &mesh, MeshBase::element_iterator it, MeshBase::element_iterator end, const unsigned int n) override
Called by the SubdomainPartitioner to partition elements in the range (it, end).
Definition: centroid_partitioner.C:30
libMesh::CentroidPartitioner::Y
Definition: centroid_partitioner.h:58
libMesh::CentroidPartitioner::RADIAL
Definition: centroid_partitioner.h:60
libMesh::CentroidPartitioner::sort_z
static bool sort_z(const std::pair< Point, Elem * > &lhs, const std::pair< Point, Elem * > &rhs)
Helper function which sorts by the centroid's z-coordinate in the internal std::sort call.
Definition: centroid_partitioner.C:164
libMesh::CentroidPartitioner::X
Definition: centroid_partitioner.h:57
libMesh::CentroidPartitioner::Z
Definition: centroid_partitioner.h:59
libMesh::CentroidPartitioner::set_sort_method
void set_sort_method(const CentroidSortMethod sm)
Setter for the current sorting method.
Definition: centroid_partitioner.h:96
libMesh::CentroidPartitioner::_do_partition
virtual void _do_partition(MeshBase &mesh, const unsigned int n) override
Partitions the mesh into n subdomains.
Definition: centroid_partitioner.C:122