Skip to content

Commit

Permalink
Rework RenameBlockGenerator
Browse files Browse the repository at this point in the history
- Remove _id and _name params to the single old_block and new_block params
- Allow merging that is independent of ordering

refs idaholab#17710
  • Loading branch information
loganharbour committed Apr 29, 2021
1 parent aa717d2 commit 999ad0e
Show file tree
Hide file tree
Showing 18 changed files with 892 additions and 436 deletions.
67 changes: 9 additions & 58 deletions framework/include/meshgenerators/RenameBlockGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,62 +32,13 @@ class RenameBlockGenerator : public MeshGenerator
protected:
std::unique_ptr<MeshBase> & _input;

std::vector<subdomain_id_type> _old_block_id;

std::vector<SubdomainName> _old_block_name;

std::vector<subdomain_id_type> _new_block_id;

std::vector<SubdomainName> _new_block_name;

/**
* Given a new_block_id, provide a block name, based
* on the old block names provided (or deduced from
* the old_block_ids provided).
*
* Eg, if
* old_block_name = 'block1 block2'
* new_block_id = '4 5'
* Then
* newBlockName(4) = block1
* newBlockName(5) = block2
*
* In the case of merging blocks, the *first encountered*
* block's name is used.
* Eg, if
* old_block_name = 'asdf block4 block1'
* new_block_id = '3 1 1'
* then
* newBlockName(1) = block4, because we look along
* new_block_id until we first encounter 1, and then get the corresponding name
* @param new_block_id the new block's ID number
* @return the name that will be given to that block
*/
SubdomainName newBlockName(const subdomain_id_type & new_block_id);

/**
* Given a new_block_name, provide a block ID, based
* on the old block IDs provided (or deduced from
* the old_block_names provided).
*
* Eg, if
* old_block_id = '4 5'
* new_block_name = 'block1 block2'
* Then
* newBlockID(block1) = 4
* newBlockID(block2) = 5
*
* In the case of merging blocks, the *first encountered*
* block's ID is used.
* Eg, if
* old_block_id = '3 1 1'
* new_block_name = 'asdf block4 block4'
* then
* newBlockID(block4) = 1, because we look along
* new_block_name until we first encounter block4, and then get the corresponding ID
* @param new_block_name the new block's name
* @return the ID number that will be given to that block
*/
SubdomainID newBlockID(const SubdomainName & new_block_name);
private:
/// The old blocks
std::vector<SubdomainName> _old_block;
/// The new blocks
std::vector<SubdomainName> _new_block;
/// The name of the parameter that specifies the old blocks
std::string _old_block_param_name;
/// The name of the parameter that specifies the new blocks
std::string _new_block_param_name;
};

8 changes: 8 additions & 0 deletions framework/include/utils/MooseMeshUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ getBoundaryIDs(const libMesh::MeshBase & mesh,
*/
BoundaryID getBoundaryID(const BoundaryName & boundary_name, const MeshBase & mesh);

/**
* Gets the subdomain ID associated with the given SubdomainName.
*
* This is needed because the SubdomainName can be either an ID or a name.
* If it is a name, the mesh is queried for the ID associated with said name.
*/
SubdomainID getSubdomainID(const SubdomainName & subdomain_name, const MeshBase & mesh);

std::vector<subdomain_id_type> getSubdomainIDs(const libMesh::MeshBase & mesh,
const std::vector<SubdomainName> & subdomain_name);
}
16 changes: 2 additions & 14 deletions framework/src/mesh/MooseMesh.C
Original file line number Diff line number Diff line change
Expand Up @@ -1357,13 +1357,7 @@ MooseMesh::getSubdomainID(const SubdomainName & subdomain_name) const
if (subdomain_name == "ANY_BLOCK_ID")
mooseError("Please use getSubdomainIDs() when passing \"ANY_BLOCK_ID\"");

SubdomainID id = Moose::INVALID_BLOCK_ID;
std::istringstream ss(subdomain_name);

if (!(ss >> id) || !ss.eof())
id = getMesh().get_id_by_name(subdomain_name);

return id;
return MooseMeshUtils::getSubdomainID(subdomain_name, getMesh());
}

std::vector<SubdomainID>
Expand All @@ -1382,13 +1376,7 @@ MooseMesh::getSubdomainIDs(const std::vector<SubdomainName> & subdomain_name) co
break;
}

SubdomainID id = Moose::INVALID_BLOCK_ID;
std::istringstream ss(subdomain_name[i]);

if (!(ss >> id) || !ss.eof())
id = getMesh().get_id_by_name(subdomain_name[i]);

ids[i] = id;
ids[i] = MooseMeshUtils::getSubdomainID(subdomain_name[i], getMesh());
}

return ids;
Expand Down

0 comments on commit 999ad0e

Please sign in to comment.