Line data Source code
1 : // The libMesh Finite Element Library. 2 : // Copyright (C) 2002-2025 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 : #ifndef LIBMESH_PARMETIS_PARTITIONER_H 21 : #define LIBMESH_PARMETIS_PARTITIONER_H 22 : 23 : // Local Includes 24 : #include "libmesh/id_types.h" 25 : #include "libmesh/partitioner.h" 26 : 27 : // C++ Includes 28 : #include <cstddef> 29 : #include <memory> 30 : #include <unordered_map> 31 : #include <vector> 32 : 33 : namespace libMesh 34 : { 35 : 36 : // Forward declarations 37 : class ParmetisHelper; 38 : 39 : /** 40 : * The \p ParmetisPartitioner uses the Parmetis graph partitioner 41 : * to partition the elements. 42 : * 43 : * \author Benjamin S. Kirk 44 : * \date 2003 45 : * \brief Partitioner which provides an interface to ParMETIS. 46 : */ 47 1370 : class ParmetisPartitioner : public Partitioner 48 : { 49 : public: 50 : 51 : /** 52 : * Default and copy ctors. 53 : */ 54 : ParmetisPartitioner (); 55 : ParmetisPartitioner (const ParmetisPartitioner & other); 56 : 57 : /** 58 : * This class contains a unique_ptr member, so it can't be default 59 : * copy assigned. 60 : */ 61 : ParmetisPartitioner & operator= (const ParmetisPartitioner &) = delete; 62 : 63 : /** 64 : * Move ctor, move assignment operator, and destructor are 65 : * all explicitly inline-defaulted for this class. 66 : */ 67 : ParmetisPartitioner (ParmetisPartitioner &&) = default; 68 : ParmetisPartitioner & operator= (ParmetisPartitioner &&) = default; 69 : 70 : /** 71 : * The destructor is out-of-line-defaulted to play nice with forward 72 : * declarations. 73 : */ 74 : virtual ~ParmetisPartitioner(); 75 : 76 : virtual PartitionerType type () const override; 77 : 78 : /** 79 : * \returns A copy of this partitioner wrapped in a smart pointer. 80 : */ 81 16674 : virtual std::unique_ptr<Partitioner> clone () const override 82 : { 83 16674 : return std::make_unique<ParmetisPartitioner>(*this); 84 : } 85 : 86 : 87 : protected: 88 : 89 : /** 90 : * Parmetis can handle dynamically repartitioning a mesh such 91 : * that the redistribution costs are minimized. This method 92 : * takes a previously partitioned mesh (which may have 93 : * then been adaptively refined) and repartitions it. 94 : */ 95 : virtual void _do_repartition (MeshBase & mesh, 96 : const unsigned int n) override; 97 : 98 : /** 99 : * Partition the \p MeshBase into \p n subdomains. 100 : */ 101 : virtual void _do_partition (MeshBase & mesh, 102 : const unsigned int n) override; 103 : 104 : #ifdef LIBMESH_HAVE_PARMETIS 105 : /** 106 : * Build the graph. 107 : */ 108 : virtual void build_graph (const MeshBase & mesh) override; 109 : 110 : private: 111 : 112 : // These methods and data only need to be available if the 113 : // ParMETIS library is available. 114 : 115 : /** 116 : * Initialize data structures. 117 : */ 118 : void initialize (const MeshBase & mesh, const unsigned int n_sbdmns); 119 : 120 : /** 121 : * Pointer to the Parmetis-specific data structures. Lets us avoid 122 : * including parmetis.h here. 123 : */ 124 : std::unique_ptr<ParmetisHelper> _pmetis; 125 : 126 : #endif 127 : }; 128 : 129 : } // namespace libMesh 130 : 131 : #endif // LIBMESH_PARMETIS_PARTITIONER_H