https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
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
49std::unique_ptr<Partitioner>
51{
52 return _app.getFactory().clone(*this);
53}
54
55void
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
74dof_id_type
76{
77 mooseAssert(_blocks_to_weights.count(elem.subdomain_id()), "Missing weight for block");
78 return _blocks_to_weights[elem.subdomain_id()];
79}
registerMooseObject("MooseApp", BlockWeightedPartitioner)
Partition a mesh by weighting blocks.
void initialize(MeshBase &mesh) override
Fills _blocks_to_weights before performing the partition.
BlockWeightedPartitioner(const InputParameters &params)
virtual std::unique_ptr< Partitioner > clone() const override
const std::vector< dof_id_type > & _weights
static InputParameters validParams()
const std::vector< SubdomainName > & _blocks
Vector the block names supplied by the user via the input file.
virtual dof_id_type computeElementWeight(Elem &elm) override
std::unordered_map< SubdomainID, dof_id_type > _blocks_to_weights
A map from subdomain to weight.
std::unique_ptr< T > clone(const T &object)
Clones the object object.
Definition Factory.h:323
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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...
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.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
Definition MooseApp.h:407
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:457
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375
Partitions a mesh using external petsc partitioners such as parmetis, ptscotch, chaco,...
static InputParameters validParams()
MeshBase & mesh
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.