https://mooseframework.inl.gov
BlockWeightedPartitioner.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
11 #include "MooseMeshUtils.h"
12 #include "MooseApp.h"
13 
14 #include "libmesh/elem.h"
15 
17 
20 {
22 
23  params.addRequiredParam<std::vector<SubdomainName>>(
24  "block", "The list of block ids (SubdomainID) that this object will be applied");
25 
26  params.addRequiredParam<std::vector<dof_id_type>>(
27  "weight", "The list of weights (integer) that specify how heavy each block is");
28 
29  params.set<bool>("apply_element_weight") = true;
30 
31  params.addClassDescription("Partition mesh by weighting blocks");
32 
33  return params;
34 }
35 
37  : PetscExternalPartitioner(params),
38  _blocks(getParam<std::vector<SubdomainName>>("block")),
39  _weights(getParam<std::vector<dof_id_type>>("weight"))
40 {
41  if (_blocks.size() != _weights.size())
42  paramError("block",
43  "Number of weights ",
44  _weights.size(),
45  " does not match with the number of blocks ",
46  _blocks.size());
47 }
48 
49 std::unique_ptr<Partitioner>
51 {
52  return _app.getFactory().clone(*this);
53 }
54 
55 void
57 {
58  // Get the IDs from the supplied names
59  const auto block_ids = MooseMeshUtils::getSubdomainIDs(mesh, _blocks);
60 
61  // Make sure all of the blocks exist
62  std::set<subdomain_id_type> mesh_block_ids;
63  mesh.subdomain_ids(mesh_block_ids);
64  for (const auto block_id : block_ids)
65  if (!mesh_block_ids.count(block_id))
66  paramError("block", "The block ", block_id, " was not found on the mesh");
67 
68  // Setup the block -> weight map for use in computeElementWeight
69  _blocks_to_weights.reserve(_weights.size());
70  for (MooseIndex(block_ids.size()) i = 0; i < block_ids.size(); i++)
71  _blocks_to_weights[block_ids[i]] = _weights[i];
72 }
73 
76 {
77  mooseAssert(_blocks_to_weights.count(elem.subdomain_id()), "Missing weight for block");
78  return _blocks_to_weights[elem.subdomain_id()];
79 }
std::unordered_map< SubdomainID, dof_id_type > _blocks_to_weights
A map from subdomain to weight.
const std::vector< dof_id_type > & _weights
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseBase.h:435
const std::vector< SubdomainName > & _blocks
Vector the block names supplied by the user via the input file.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
MeshBase & mesh
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
registerMooseObject("MooseApp", BlockWeightedPartitioner)
virtual std::unique_ptr< Partitioner > clone() const override
std::vector< subdomain_id_type > getSubdomainIDs(const libMesh::MeshBase &mesh, const std::vector< SubdomainName > &subdomain_name)
Get the associated subdomainIDs for the subdomain names that are passed in.
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...
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
Definition: MooseApp.h:394
void initialize(MeshBase &mesh) override
Fills _blocks_to_weights before performing the partition.
BlockWeightedPartitioner(const InputParameters &params)
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:353
Partition a mesh by weighting blocks.
virtual dof_id_type computeElementWeight(Elem &elm) override
static InputParameters validParams()
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
std::unique_ptr< T > clone(const T &object)
Clones the object object.
Definition: Factory.h:275
Partitions a mesh using external petsc partitioners such as parmetis, ptscotch, chaco, party, etc.
uint8_t dof_id_type