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_MAPPED_SUBDOMAIN_PARTITIONER_H 21 : #define LIBMESH_MAPPED_SUBDOMAIN_PARTITIONER_H 22 : 23 : // Local Includes 24 : #include "libmesh/partitioner.h" 25 : 26 : // C++ Includes 27 : #include <memory> 28 : 29 : namespace libMesh 30 : { 31 : 32 : /** 33 : * The \p MappedSubdomainPartitioner partitions the elements based on their 34 : * subdomain ids. The user must set up the values in the public 35 : * subdomain_to_proc map in order to specify which subdomains should 36 : * be partitioned onto which processors. More than one subdomain can 37 : * be partitioned onto a given processor, but every subdomain must be 38 : * assigned to exactly 1 processor. 39 : * 40 : * \author John W. Peterson 41 : * \date 2017 42 : * \brief Partitions elements based on user-defined mapping from subdomain ids -> processor ids. 43 : */ 44 : class MappedSubdomainPartitioner : public Partitioner 45 : { 46 : public: 47 : 48 : /** 49 : * Ctors, assignment operators, and destructor are all explicitly 50 : * defaulted for this class. 51 : */ 52 0 : MappedSubdomainPartitioner () = default; 53 0 : MappedSubdomainPartitioner (const MappedSubdomainPartitioner &) = default; 54 : MappedSubdomainPartitioner (MappedSubdomainPartitioner &&) = default; 55 : MappedSubdomainPartitioner & operator= (const MappedSubdomainPartitioner &) = default; 56 : MappedSubdomainPartitioner & operator= (MappedSubdomainPartitioner &&) = default; 57 4 : virtual ~MappedSubdomainPartitioner() = default; 58 : 59 : virtual PartitionerType type () const override; 60 : 61 : /** 62 : * \returns A copy of this partitioner wrapped in a smart pointer. 63 : */ 64 0 : virtual std::unique_ptr<Partitioner> clone () const override 65 : { 66 0 : return std::make_unique<MappedSubdomainPartitioner>(*this); 67 : } 68 : 69 : /** 70 : * Before calling partition() or partition_range(), the user must 71 : * assign all the Mesh subdomains to certain processors by adding 72 : * them to this std::map. For example: 73 : * subdomain_to_proc[1] = 0; 74 : * subdomain_to_proc[2] = 0; 75 : * subdomain_to_proc[3] = 0; 76 : * subdomain_to_proc[4] = 1; 77 : * subdomain_to_proc[5] = 1; 78 : * subdomain_to_proc[6] = 2; 79 : * Would partition the mesh onto three processors, with subdomains 80 : * 1, 2, and 3 on processor 0, subdomains 4 and 5 on processor 1, 81 : * and subdomain 6 on processor 2. 82 : */ 83 : std::map<subdomain_id_type, processor_id_type> subdomain_to_proc; 84 : 85 : /** 86 : * Called by the SubdomainPartitioner to partition elements in the range (it, end). 87 : */ 88 : virtual void partition_range(MeshBase & mesh, 89 : MeshBase::element_iterator it, 90 : MeshBase::element_iterator end, 91 : const unsigned int n) override; 92 : 93 : protected: 94 : 95 : /** 96 : * Partition the \p MeshBase into \p n subdomains. 97 : */ 98 : virtual void _do_partition (MeshBase & mesh, 99 : const unsigned int n) override; 100 : }; 101 : 102 : } // namespace libMesh 103 : 104 : #endif // LIBMESH_MAPPED_SUBDOMAIN_PARTITIONER_H