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 : // Local Includes 21 : #include "libmesh/mapped_subdomain_partitioner.h" 22 : #include "libmesh/elem.h" 23 : #include "libmesh/enum_partitioner_type.h" 24 : #include "libmesh/libmesh_logging.h" 25 : #include "libmesh/mesh_base.h" 26 : #include "libmesh/utility.h" 27 : 28 : namespace libMesh 29 : { 30 : 31 : 32 0 : PartitionerType MappedSubdomainPartitioner::type() const 33 : { 34 0 : return MAPPED_SUBDOMAIN_PARTITIONER; 35 : } 36 : 37 : 38 69 : void MappedSubdomainPartitioner::partition_range(MeshBase & /*mesh*/, 39 : MeshBase::element_iterator it, 40 : MeshBase::element_iterator end, 41 : const unsigned int n) 42 : { 43 2 : libmesh_assert_greater (n, 0); 44 : 45 : // Check for an easy return. If the user has not specified any 46 : // entries in subdomain_to_proc, we just do a single partitioning. 47 69 : if ((n == 1) || subdomain_to_proc.empty()) 48 : { 49 0 : this->single_partition_range (it, end); 50 0 : return; 51 : } 52 : 53 : // Now actually do the partitioning. 54 4 : LOG_SCOPE ("partition_range()", "MappedSubdomainPartitioner"); 55 : 56 69136 : for (auto & elem : as_range(it, end)) 57 : { 58 69000 : subdomain_id_type sbd_id = elem->subdomain_id(); 59 : 60 : // Find which processor id corresponds to this element's subdomain id. 61 69000 : elem->processor_id() = libmesh_map_find(subdomain_to_proc, sbd_id); 62 65 : } 63 : } 64 : 65 : 66 : 67 69 : void MappedSubdomainPartitioner::_do_partition (MeshBase & mesh, 68 : const unsigned int n) 69 : { 70 69 : this->partition_range(mesh, 71 138 : mesh.active_elements_begin(), 72 71 : mesh.active_elements_end(), 73 4 : n); 74 69 : } 75 : 76 : } // namespace libMesh