libMesh
mapped_subdomain_partitioner.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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 
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 ( ; it != end; ++it)
49  {
50  Elem * elem = *it;
51 
52  subdomain_id_type sbd_id = elem->subdomain_id();
53 
54  // Find which processor id corresponds to this element's subdomain id.
55  std::map<subdomain_id_type, processor_id_type>::iterator
56  it = subdomain_to_proc.find(sbd_id);
57 
58  // If an element has a subdomain we don't know how to
59  // partition, throw an error.
60  if (it == subdomain_to_proc.end())
61  libmesh_error_msg("Could not find processor id corresponding to subdomain id " << sbd_id);
62 
63  elem->processor_id() = it->second;
64  }
65 }
66 
67 
68 
70  const unsigned int n)
71 {
72  this->partition_range(mesh,
73  mesh.active_elements_begin(),
74  mesh.active_elements_end(),
75  n);
76 }
77 
78 } // namespace libMesh
The definition of the element_iterator struct.
Definition: mesh_base.h:1476
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
MeshBase & mesh
IterBase * end
Also have a polymorphic pointer to the end object, this prevents iterating past the end...
virtual void _do_partition(MeshBase &mesh, const unsigned int n) libmesh_override
Partition the MeshBase into n subdomains.
The libMesh namespace provides an interface to certain functionality in the library.
This is the MeshBase class.
Definition: mesh_base.h:68
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:159
subdomain_id_type subdomain_id() const
Definition: elem.h:1951
virtual element_iterator active_elements_begin()=0
Active, local, and negation forms of the element iterators described above.
virtual element_iterator active_elements_end()=0
virtual void partition_range(MeshBase &mesh, MeshBase::element_iterator it, MeshBase::element_iterator end, const unsigned int n) libmesh_override
Called by the SubdomainPartitioner to partition elements in the range (it, end).
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...
processor_id_type processor_id() const
Definition: dof_object.h:694