mapped_subdomain_partitioner.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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"
24 #include "libmesh/elem.h"
25 
26 namespace libMesh
27 {
28 
29 
33  const unsigned int n)
34 {
35  libmesh_assert_greater (n, 0);
36 
37  // Check for an easy return. If the user has not specified any
38  // entries in subdomain_to_proc, we just do a single partitioning.
39  if ((n == 1) || subdomain_to_proc.empty())
40  {
41  this->single_partition_range (it, end);
42  return;
43  }
44 
45  // Now actually do the partitioning.
46  LOG_SCOPE ("partition_range()", "MappedSubdomainPartitioner");
47 
48  for (auto & elem : as_range(it, end))
49  {
50  subdomain_id_type sbd_id = elem->subdomain_id();
51 
52  // Find which processor id corresponds to this element's subdomain id.
53  std::map<subdomain_id_type, processor_id_type>::iterator
54  s2p_it = subdomain_to_proc.find(sbd_id);
55 
56  // If an element has a subdomain we don't know how to
57  // partition, throw an error.
58  if (s2p_it == subdomain_to_proc.end())
59  libmesh_error_msg("Could not find processor id corresponding to subdomain id " << sbd_id);
60 
61  elem->processor_id() = s2p_it->second;
62  }
63 }
64 
65 
66 
68  const unsigned int n)
69 {
70  this->partition_range(mesh,
71  mesh.active_elements_begin(),
72  mesh.active_elements_end(),
73  n);
74 }
75 
76 } // namespace libMesh
MeshBase & mesh
IterBase * end
Base class for Mesh.
Definition: mesh_base.h:77
virtual void _do_partition(MeshBase &mesh, const unsigned int n) override
void single_partition_range(MeshBase::element_iterator it, MeshBase::element_iterator end)
Definition: partitioner.C:172
SimpleRange< I > as_range(const std::pair< I, I > &p)
Definition: simple_range.h:57
virtual void partition_range(MeshBase &mesh, MeshBase::element_iterator it, MeshBase::element_iterator end, const unsigned int n) override
std::map< subdomain_id_type, processor_id_type > subdomain_to_proc