Line data Source code
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 : 10 : #include "BlockWeightedPartitioner.h" 11 : #include "MooseMeshUtils.h" 12 : #include "MooseApp.h" 13 : 14 : #include "libmesh/elem.h" 15 : 16 : registerMooseObject("MooseApp", BlockWeightedPartitioner); 17 : 18 : InputParameters 19 14413 : BlockWeightedPartitioner::validParams() 20 : { 21 14413 : InputParameters params = PetscExternalPartitioner::validParams(); 22 : 23 14413 : params.addRequiredParam<std::vector<SubdomainName>>( 24 : "block", "The list of block ids (SubdomainID) that this object will be applied"); 25 : 26 14413 : params.addRequiredParam<std::vector<dof_id_type>>( 27 : "weight", "The list of weights (integer) that specify how heavy each block is"); 28 : 29 14413 : params.set<bool>("apply_element_weight") = true; 30 : 31 14413 : params.addClassDescription("Partition mesh by weighting blocks"); 32 : 33 14413 : return params; 34 0 : } 35 : 36 112 : BlockWeightedPartitioner::BlockWeightedPartitioner(const InputParameters & params) 37 : : PetscExternalPartitioner(params), 38 112 : _blocks(getParam<std::vector<SubdomainName>>("block")), 39 224 : _weights(getParam<std::vector<dof_id_type>>("weight")) 40 : { 41 112 : if (_blocks.size() != _weights.size()) 42 4 : paramError("block", 43 : "Number of weights ", 44 4 : _weights.size(), 45 : " does not match with the number of blocks ", 46 4 : _blocks.size()); 47 108 : } 48 : 49 : std::unique_ptr<Partitioner> 50 72 : BlockWeightedPartitioner::clone() const 51 : { 52 72 : return _app.getFactory().clone(*this); 53 : } 54 : 55 : void 56 32 : BlockWeightedPartitioner::initialize(MeshBase & mesh) 57 : { 58 : // Get the IDs from the supplied names 59 32 : const auto block_ids = MooseMeshUtils::getSubdomainIDs(mesh, _blocks); 60 : 61 : // Make sure all of the blocks exist 62 32 : std::set<subdomain_id_type> mesh_block_ids; 63 32 : mesh.subdomain_ids(mesh_block_ids); 64 128 : for (const auto block_id : block_ids) 65 96 : if (!mesh_block_ids.count(block_id)) 66 0 : paramError("block", "The block ", block_id, " was not found on the mesh"); 67 : 68 : // Setup the block -> weight map for use in computeElementWeight 69 32 : _blocks_to_weights.reserve(_weights.size()); 70 128 : for (MooseIndex(block_ids.size()) i = 0; i < block_ids.size(); i++) 71 96 : _blocks_to_weights[block_ids[i]] = _weights[i]; 72 32 : } 73 : 74 : dof_id_type 75 800 : BlockWeightedPartitioner::computeElementWeight(Elem & elem) 76 : { 77 : mooseAssert(_blocks_to_weights.count(elem.subdomain_id()), "Missing weight for block"); 78 800 : return _blocks_to_weights[elem.subdomain_id()]; 79 : }