libMesh
subdomain_partitioner.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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/subdomain_partitioner.h"
22 #include "libmesh/libmesh_logging.h"
23 #include "libmesh/elem.h"
24 #include "libmesh/metis_partitioner.h"
25 #include "libmesh/int_range.h"
26 
27 namespace libMesh
28 {
29 
31  _internal_partitioner(libmesh_make_unique<MetisPartitioner>())
32 {}
33 
34 
36  : Partitioner(other),
37  chunks(other.chunks),
38  _internal_partitioner(other._internal_partitioner->clone())
39 {}
40 
41 
43  const unsigned int n)
44 {
45  libmesh_assert_greater (n, 0);
46 
47  // Check for an easy return. If the user has not specified any
48  // entries in the chunks vector, we just do a single partitioning.
49  if ((n == 1) || chunks.empty())
50  {
51  this->single_partition (mesh);
52  return;
53  }
54 
55  // Now actually do the partitioning.
56  LOG_SCOPE ("_do_partition()", "SubdomainPartitioner");
57 
58  // For each chunk, construct an iterator range for the set of
59  // subdomains in question, and pass it to the internal Partitioner.
60  for (const auto & id_set : chunks)
63  mesh.active_subdomain_set_elements_begin(id_set),
64  mesh.active_subdomain_set_elements_end(id_set),
65  n);
66 }
67 
68 } // namespace libMesh
libMesh::SubdomainPartitioner::_internal_partitioner
std::unique_ptr< Partitioner > _internal_partitioner
The internal Partitioner we use.
Definition: subdomain_partitioner.h:118
libMesh::SubdomainPartitioner::_do_partition
virtual void _do_partition(MeshBase &mesh, const unsigned int n) override
Partition the MeshBase into n subdomains.
Definition: subdomain_partitioner.C:42
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::Partitioner
The Partitioner class provides a uniform interface for partitioning algorithms.
Definition: partitioner.h:50
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::MeshBase
This is the MeshBase class.
Definition: mesh_base.h:78
libMesh::MetisPartitioner
The MetisPartitioner uses the Metis graph partitioner to partition the elements.
Definition: metis_partitioner.h:38
libMesh::SubdomainPartitioner::chunks
std::vector< std::set< subdomain_id_type > > chunks
Each entry of "chunks" represents a set of subdomains which are to be partitioned together.
Definition: subdomain_partitioner.h:95
libMesh::Partitioner::single_partition
void single_partition(MeshBase &mesh)
Trivially "partitions" the mesh for one processor.
Definition: partitioner.C:166
libMesh::Partitioner::partition_range
virtual void partition_range(MeshBase &, MeshBase::element_iterator, MeshBase::element_iterator, const unsigned int)
Partitions elements in the range (it, end) into n parts.
Definition: partitioner.h:127
libMesh::SubdomainPartitioner
The SubdomainPartitioner partitions the elements in "chunks" of user-specified subdomain ids.
Definition: subdomain_partitioner.h:55
libMesh::SubdomainPartitioner::SubdomainPartitioner
SubdomainPartitioner()
Constructors.
Definition: subdomain_partitioner.C:30