libMesh
centroid_partitioner.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2024 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 
26 // C++ includes
27 #include <memory>
28 #include <utility> // pair
29 #include <vector>
30 
31 namespace libMesh
32 {
33 
34 // Forward declarations
35 class Elem;
36 
54 {
55 public:
56 
63  Y,
64  Z,
67 
72  explicit
74 
79  CentroidPartitioner (const CentroidPartitioner &) = default;
83  virtual ~CentroidPartitioner() = default;
84 
85  virtual PartitionerType type () const override;
86 
90  virtual std::unique_ptr<Partitioner> clone () const override
91  {
92  return std::make_unique<CentroidPartitioner>(*this);
93  }
94 
99 
104 
108  virtual void partition_range(MeshBase & mesh,
111  const unsigned int n) override;
112 
113 protected:
114 
118  virtual void _do_partition (MeshBase & mesh,
119  const unsigned int n) override;
120 
121 private:
122 
128 
133  static bool sort_x (const std::pair<Point, Elem *> & lhs,
134  const std::pair<Point, Elem *> & rhs);
135 
140  static bool sort_y (const std::pair<Point, Elem *> & lhs,
141  const std::pair<Point, Elem *> & rhs);
142 
147  static bool sort_z (const std::pair<Point, Elem *> & lhs,
148  const std::pair<Point, Elem *> & rhs);
149 
154  static bool sort_radial (const std::pair<Point, Elem *> & lhs,
155  const std::pair<Point, Elem *> & rhs);
156 
161 
166  std::vector<std::pair<Point, Elem *>> _elem_vertex_avgs;
167 };
168 
169 } // namespace libMesh
170 
171 #endif // LIBMESH_CENTROID_PARTITIONER_H
The definition of the element_iterator struct.
Definition: mesh_base.h:2103
virtual void _do_partition(MeshBase &mesh, const unsigned int n) override
Partitions the mesh into n subdomains.
CentroidSortMethod
A typedef which controls the sorting method used for ordering the vertex averages.
MeshBase & mesh
The libMesh namespace provides an interface to certain functionality in the library.
This is the MeshBase class.
Definition: mesh_base.h:74
The Partitioner class provides a uniform interface for partitioning algorithms.
Definition: partitioner.h:51
CentroidPartitioner & operator=(const CentroidPartitioner &)=default
virtual PartitionerType type() const override
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).
PartitionerType
Defines an enum for mesh partitioner types.
virtual ~CentroidPartitioner()=default
Partitions the Mesh based on the locations of element vertex averages.
static bool sort_radial(const std::pair< Point, Elem *> &lhs, const std::pair< Point, Elem *> &rhs)
Helper function which sorts by the vertex averages&#39;s distance from the origin in the internal std::so...
std::vector< std::pair< Point, Elem * > > _elem_vertex_avgs
Vector which holds pairs of vertex averages and their respective element pointers.
static bool sort_y(const std::pair< Point, Elem *> &lhs, const std::pair< Point, Elem *> &rhs)
Helper function which sorts by the vertex average&#39;s y-coordinate in the internal std::sort call...
void set_sort_method(const CentroidSortMethod sm)
Setter for the current sorting method.
CentroidSortMethod _sort_method
Flag indicating the type of sort method we are using.
CentroidSortMethod sort_method() const
Getter for the current sorting method.
static bool sort_x(const std::pair< Point, Elem *> &lhs, const std::pair< Point, Elem *> &rhs)
Helper function which sorts by the vertex average&#39;s x-coordinate in the internal std::sort call...
void compute_vertex_avgs(MeshBase::element_iterator it, MeshBase::element_iterator end)
Computes a list of element vertex averages for the mesh.
virtual std::unique_ptr< Partitioner > clone() const override
static bool sort_z(const std::pair< Point, Elem *> &lhs, const std::pair< Point, Elem *> &rhs)
Helper function which sorts by the vertex average&#39;s z-coordinate in the internal std::sort call...
CentroidPartitioner(const CentroidSortMethod sm=X)
Constructor.