forked from idaholab/moose
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs idaholab#13675
- Loading branch information
Showing
2 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//* This file is part of the MOOSE framework | ||
//* https://www.mooseframework.org | ||
//* | ||
//* All rights reserved, see COPYRIGHT for full restrictions | ||
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
//* | ||
//* Licensed under LGPL 2.1, please see LICENSE for details | ||
//* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
||
#pragma once | ||
|
||
// MOOSE includes | ||
#include "MooseEnum.h" | ||
#include "PetscExternalPartitioner.h" | ||
|
||
class BlockWeightedPartitioner; | ||
class MooseMesh; | ||
|
||
template <> | ||
InputParameters validParams<BlockWeightedPartitioner>(); | ||
|
||
/** | ||
* Partition a mesh by weighting blocks. The motivation is that differenct | ||
* blocks may have different physics. The work load per element is different | ||
* block-by-block. This partitioner allows users to assign high weights for | ||
* heavy blocks and low weights for other light blocks. | ||
*/ | ||
class BlockWeightedPartitioner : public PetscExternalPartitioner | ||
{ | ||
public: | ||
BlockWeightedPartitioner(const InputParameters & params); | ||
|
||
virtual std::unique_ptr<Partitioner> clone() const override; | ||
|
||
virtual dof_id_type computeElementWeight(Elem & elm) override; | ||
|
||
private: | ||
|
||
/// Vector the block names supplied by the user via the input file | ||
std::vector<SubdomainName> _blocks; | ||
/// Block weights | ||
std::vector<dof_id_type> _weights; | ||
/// A map from subdomain to weight | ||
std::unordered_map<SubdomainID, dof_id_type> _blocks_to_weights; | ||
/// Moose mesh | ||
MooseMesh & _mesh; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
//* This file is part of the MOOSE framework | ||
//* https://www.mooseframework.org | ||
//* | ||
//* All rights reserved, see COPYRIGHT for full restrictions | ||
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
//* | ||
//* Licensed under LGPL 2.1, please see LICENSE for details | ||
//* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
||
#include "BlockWeightedPartitioner.h" | ||
#include "MooseMesh.h" | ||
|
||
#include "libmesh/elem.h" | ||
|
||
registerMooseObject("MooseApp", BlockWeightedPartitioner); | ||
|
||
template <> | ||
InputParameters | ||
validParams<BlockWeightedPartitioner>() | ||
{ | ||
InputParameters params = validParams<PetscExternalPartitioner>(); | ||
|
||
params.addRequiredParam<std::vector<SubdomainName>>( | ||
"block", "The list of block ids (SubdomainID) that this object will be applied"); | ||
|
||
params.addRequiredParam<std::vector<dof_id_type>>( | ||
"weight", "The list of weights (integer) that specify how heavy each block is"); | ||
|
||
params.set<bool>("apply_element_weight") = true; | ||
|
||
params.addClassDescription( | ||
"Partition mesh by weighting blocks"); | ||
|
||
return params; | ||
} | ||
|
||
BlockWeightedPartitioner::BlockWeightedPartitioner(const InputParameters & params) | ||
: PetscExternalPartitioner(params), | ||
_blocks(getParam<std::vector<SubdomainName>>("block")), | ||
_weights(getParam<std::vector<dof_id_type>>("weight")), | ||
_mesh(*getParam<MooseMesh *>("mesh")) | ||
{ | ||
if (_blocks.size() != _weights.size()) | ||
paramError("block", "Number of weights ",_weights.size(), " does not match with the number of blocks ", _blocks.size()); | ||
|
||
// Get the IDs from the supplied names | ||
auto block_ids = _mesh.getSubdomainIDs(_blocks); | ||
|
||
if (block_ids.size() != _blocks.size()) | ||
mooseError("Number of block ids ", block_ids.size(), " does not match with the number of blocks ", _blocks.size()); | ||
|
||
_blocks_to_weights.reserve(_weights.size()); | ||
|
||
for (MooseIndex(block_ids.size()) i = 0; i<block_ids.size(); i++) | ||
{ | ||
_blocks_to_weights[block_ids[i]] = _weights[i]; | ||
} | ||
} | ||
|
||
std::unique_ptr<Partitioner> | ||
BlockWeightedPartitioner::clone() const | ||
{ | ||
return libmesh_make_unique<BlockWeightedPartitioner>(_pars); | ||
} | ||
|
||
dof_id_type | ||
BlockWeightedPartitioner::computeElementWeight(Elem & elem) | ||
{ | ||
auto blockid_to_weight = _blocks_to_weights.find(elem.subdomain_id()); | ||
|
||
if (blockid_to_weight == _blocks_to_weights.end()) | ||
mooseError("Can not find a weight for block id ",elem.subdomain_id()); | ||
|
||
return blockid_to_weight->second; | ||
} |