www.mooseframework.org
LibmeshPartitioner.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "MooseMesh.h"
16 
17 #include "LibmeshPartitioner.h"
18 #include "libmesh/linear_partitioner.h"
19 #include "libmesh/centroid_partitioner.h"
20 #include "libmesh/parmetis_partitioner.h"
21 #include "libmesh/metis_partitioner.h"
22 #include "libmesh/hilbert_sfc_partitioner.h"
23 #include "libmesh/morton_sfc_partitioner.h"
24 #include "libmesh/subdomain_partitioner.h"
25 
26 template <>
29 {
31  MooseEnum partitioning(
32  "metis=-2 parmetis=-1 linear=0 centroid hilbert_sfc morton_sfc subdomain_partitioner");
34  "partitioner",
35  partitioning,
36  "Specifies a mesh partitioner to use when splitting the mesh for a parallel computation.");
37  MooseEnum direction("x y z radial");
38  params.addParam<MooseEnum>("centroid_partitioner_direction",
39  direction,
40  "Specifies the sort direction if using the centroid partitioner. "
41  "Available options: x, y, z, radial");
42  params.addParam<std::vector<std::vector<SubdomainName>>>(
43  "blocks", "Block is seperated by ;, and partition mesh block by block. ");
44  return params;
45 }
46 
48  : MoosePartitioner(params),
49  _partitioner_name(getParam<MooseEnum>("partitioner")),
50  _subdomain_blocks(getParam<std::vector<std::vector<SubdomainName>>>("blocks")),
51  _mesh(*getParam<MooseMesh *>("mesh"))
52 {
53  switch (_partitioner_name)
54  {
55  case -2: // metis
56  _partitioner = libmesh_make_unique<MetisPartitioner>();
57  break;
58  case -1: // parmetis
59  _partitioner = libmesh_make_unique<ParmetisPartitioner>();
60  break;
61 
62  case 0: // linear
63  _partitioner = libmesh_make_unique<LinearPartitioner>();
64  break;
65  case 1: // centroid
66  {
67  if (!isParamValid("centroid_partitioner_direction"))
68  mooseError(
69  "If using the centroid partitioner you _must_ specify centroid_partitioner_direction!");
70 
71  MooseEnum direction = getParam<MooseEnum>("centroid_partitioner_direction");
72 
73  if (direction == "x")
74  _partitioner = libmesh_make_unique<CentroidPartitioner>(CentroidPartitioner::X);
75  else if (direction == "y")
76  _partitioner = libmesh_make_unique<CentroidPartitioner>(CentroidPartitioner::Y);
77  else if (direction == "z")
78  _partitioner = libmesh_make_unique<CentroidPartitioner>(CentroidPartitioner::Z);
79  else if (direction == "radial")
80  _partitioner = libmesh_make_unique<CentroidPartitioner>(CentroidPartitioner::RADIAL);
81  break;
82  }
83  case 2: // hilbert_sfc
84  _partitioner = libmesh_make_unique<HilbertSFCPartitioner>();
85  break;
86  case 3: // morton_sfc
87  _partitioner = libmesh_make_unique<MortonSFCPartitioner>();
88  break;
89  case 4: // subdomain_partitioner
90  _partitioner = libmesh_make_unique<SubdomainPartitioner>();
91  break;
92  }
93 }
94 
96 
97 std::unique_ptr<Partitioner>
99 {
100  switch (_partitioner_name)
101  {
102  case -2: // metis
103  return libmesh_make_unique<MetisPartitioner>();
104  break;
105  case -1: // parmetis
106  return libmesh_make_unique<ParmetisPartitioner>();
107  break;
108 
109  case 0: // linear
110  return libmesh_make_unique<LinearPartitioner>();
111  break;
112  case 1: // centroid
113  {
114  if (!isParamValid("centroid_partitioner_direction"))
115  mooseError(
116  "If using the centroid partitioner you _must_ specify centroid_partitioner_direction!");
117 
118  MooseEnum direction = getParam<MooseEnum>("centroid_partitioner_direction");
119 
120  if (direction == "x")
121  return libmesh_make_unique<CentroidPartitioner>(CentroidPartitioner::X);
122  else if (direction == "y")
123  return libmesh_make_unique<CentroidPartitioner>(CentroidPartitioner::Y);
124  else if (direction == "z")
125  return libmesh_make_unique<CentroidPartitioner>(CentroidPartitioner::Z);
126  else if (direction == "radial")
127  return libmesh_make_unique<CentroidPartitioner>(CentroidPartitioner::RADIAL);
128  break;
129  }
130  case 2: // hilbert_sfc
131  return libmesh_make_unique<HilbertSFCPartitioner>();
132  break;
133  case 3: // morton_sfc
134  return libmesh_make_unique<MortonSFCPartitioner>();
135  break;
136  case 4: // subdomain_partitioner
137  return libmesh_make_unique<LibmeshPartitioner>(parameters());
138  break;
139  }
140  // this cannot happen but I need to trick the compiler into
141  // believing me
142  mooseError("Error in LibmeshPartitioner: Supplied partitioner option causes error in clone()");
143  return libmesh_make_unique<MetisPartitioner>();
144 }
145 
146 void
148  SubdomainPartitioner & subdomain_partitioner)
149 {
150  auto group_begin = _subdomain_blocks.begin();
151  auto group_end = _subdomain_blocks.end();
152 
153  subdomain_partitioner.chunks.clear();
154  for (auto group = group_begin; group != group_end; ++group)
155  {
156  std::set<subdomain_id_type> subdomain_ids;
157  auto subdomain_ids_vec = _mesh.getSubdomainIDs(*group);
158  auto subdomain_begin = subdomain_ids_vec.begin();
159  auto subdomain_end = subdomain_ids_vec.end();
160  for (auto subdomain_id = subdomain_begin; subdomain_id != subdomain_end; ++subdomain_id)
161  {
162  subdomain_ids.insert(*subdomain_id);
163  }
164  subdomain_partitioner.chunks.push_back(subdomain_ids);
165  }
166 }
167 
168 void
169 LibmeshPartitioner::partition(MeshBase & mesh, const unsigned int n)
170 {
171  if (_partitioner_name == "subdomain_partitioner")
172  {
173  mooseAssert(_partitioner.get(), "Paritioner is a NULL object");
175  static_cast<SubdomainPartitioner &>(*_partitioner.get()));
176  }
177 
178  _partitioner->partition(mesh, n);
179 }
180 
181 void
183 {
184  if (_partitioner_name == "subdomain_partitioner")
185  {
186  mooseAssert(_partitioner.get(), "Paritioner is a NULL object");
188  static_cast<SubdomainPartitioner &>(*_partitioner.get()));
189  }
190 
191  _partitioner->partition(mesh);
192 }
193 
194 void
195 LibmeshPartitioner::_do_partition(MeshBase & /*mesh*/, const unsigned int /*n*/)
196 {
197 }
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual void prepare_blocks_for_subdomain_partitioner(SubdomainPartitioner &subdomain_partitioner)
std::unique_ptr< Partitioner > _partitioner
virtual void partition(MeshBase &mesh, const unsigned int n)
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
const std::vector< std::vector< SubdomainName > > & _subdomain_blocks
virtual std::unique_ptr< Partitioner > clone() const
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:37
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseObject.h:67
PetscInt n
Base class for MOOSE partitioner.
virtual void _do_partition(MeshBase &mesh, const unsigned int n)
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseObject.h:53
InputParameters validParams< LibmeshPartitioner >()
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
std::vector< SubdomainID > getSubdomainIDs(const std::vector< SubdomainName > &subdomain_name) const
Get the associated subdomainIDs for the subdomain names that are passed in.
Definition: MooseMesh.C:1012
LibmeshPartitioner(const InputParameters &params)
InputParameters validParams< MoosePartitioner >()