libMesh
mapped_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/mesh_base.h"
22 #include "libmesh/mapped_subdomain_partitioner.h"
23 #include "libmesh/libmesh_logging.h"
24 #include "libmesh/elem.h"
25 #include "libmesh/utility.h"
26 
27 namespace libMesh
28 {
29 
30 
34  const unsigned int n)
35 {
36  libmesh_assert_greater (n, 0);
37 
38  // Check for an easy return. If the user has not specified any
39  // entries in subdomain_to_proc, we just do a single partitioning.
40  if ((n == 1) || subdomain_to_proc.empty())
41  {
42  this->single_partition_range (it, end);
43  return;
44  }
45 
46  // Now actually do the partitioning.
47  LOG_SCOPE ("partition_range()", "MappedSubdomainPartitioner");
48 
49  for (auto & elem : as_range(it, end))
50  {
51  subdomain_id_type sbd_id = elem->subdomain_id();
52 
53  // Find which processor id corresponds to this element's subdomain id.
54  elem->processor_id() = libmesh_map_find(subdomain_to_proc, sbd_id);
55  }
56 }
57 
58 
59 
61  const unsigned int n)
62 {
63  this->partition_range(mesh,
64  mesh.active_elements_begin(),
65  mesh.active_elements_end(),
66  n);
67 }
68 
69 } // namespace libMesh
libMesh::Partitioner::single_partition_range
void single_partition_range(MeshBase::element_iterator it, MeshBase::element_iterator end)
Slightly generalized version of single_partition which acts on a range of elements defined by the pai...
Definition: partitioner.C:179
libMesh::MeshBase::element_iterator
The definition of the element_iterator struct.
Definition: mesh_base.h:1873
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
end
IterBase * end
Also have a polymorphic pointer to the end object, this prevents iterating past the end.
Definition: variant_filter_iterator.h:343
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::MeshBase
This is the MeshBase class.
Definition: mesh_base.h:78
libMesh::as_range
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
Helper function that allows us to treat a homogenous pair as a range.
Definition: simple_range.h:57
libMesh::MappedSubdomainPartitioner::partition_range
virtual void partition_range(MeshBase &mesh, MeshBase::element_iterator it, MeshBase::element_iterator end, const unsigned int n) override
Called by the SubdomainPartitioner to partition elements in the range (it, end).
Definition: mapped_subdomain_partitioner.C:31
libMesh::MappedSubdomainPartitioner::_do_partition
virtual void _do_partition(MeshBase &mesh, const unsigned int n) override
Partition the MeshBase into n subdomains.
Definition: mapped_subdomain_partitioner.C:60
libMesh::MappedSubdomainPartitioner::subdomain_to_proc
std::map< subdomain_id_type, processor_id_type > subdomain_to_proc
Before calling partition() or partition_range(), the user must assign all the Mesh subdomains to cert...
Definition: mapped_subdomain_partitioner.h:79
libMesh::TestClass
Definition: id_types.h:33