LCOV - code coverage report
Current view: top level - include/partitioning - mapped_subdomain_partitioner.h (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4343 (6ea38c) with base 8c3130 Lines: 2 6 33.3 %
Date: 2026-10-13 21:47:33 Functions: 3 6 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // The libMesh Finite Element Library.
       2             : // Copyright (C) 2002-2026 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             :    * Elements are assigned from the user-supplied subdomain-to-processor map, with no
      71             :    * reference to the partitioning the mesh arrives with.
      72             :    */
      73          69 :   virtual bool partitions_from_scratch () const override { return true; }
      74             : 
      75             :   /**
      76             :    * Before calling partition() or partition_range(), the user must
      77             :    * assign all the Mesh subdomains to certain processors by adding
      78             :    * them to this std::map.  For example:
      79             :    * subdomain_to_proc[1] = 0;
      80             :    * subdomain_to_proc[2] = 0;
      81             :    * subdomain_to_proc[3] = 0;
      82             :    * subdomain_to_proc[4] = 1;
      83             :    * subdomain_to_proc[5] = 1;
      84             :    * subdomain_to_proc[6] = 2;
      85             :    * Would partition the mesh onto three processors, with subdomains
      86             :    * 1, 2, and 3 on processor 0, subdomains 4 and 5 on processor 1,
      87             :    * and subdomain 6 on processor 2.
      88             :    */
      89             :   std::map<subdomain_id_type, processor_id_type> subdomain_to_proc;
      90             : 
      91             :   /**
      92             :    * Called by the SubdomainPartitioner to partition elements in the range (it, end).
      93             :    */
      94             :   virtual void partition_range(MeshBase & mesh,
      95             :                                MeshBase::element_iterator it,
      96             :                                MeshBase::element_iterator end,
      97             :                                const unsigned int n) override;
      98             : 
      99             : protected:
     100             : 
     101             :   /**
     102             :    * Partition the \p MeshBase into \p n subdomains.
     103             :    */
     104             :   virtual void _do_partition (MeshBase & mesh,
     105             :                               const unsigned int n) override;
     106             : };
     107             : 
     108             : } // namespace libMesh
     109             : 
     110             : #endif  // LIBMESH_MAPPED_SUBDOMAIN_PARTITIONER_H

Generated by: LCOV version 1.14