Skip to content

Commit

Permalink
Rework RenameBoundaryGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
loganharbour authored and aeslaughter committed Jun 2, 2021
1 parent b0c9314 commit ab2d3b4
Show file tree
Hide file tree
Showing 14 changed files with 983 additions and 187 deletions.
Expand Up @@ -2,55 +2,60 @@

!syntax description /Mesh/RenameBoundaryGenerator

## Overview
## Renaming or Setting Boundary Names

`RenameBoundaryGenerator` is usually used to provide meaningful names to boundaries.
For instance
When using the `RenameBoundaryGenerator` to change boundary names, the result is independent of ordering.

```text
old_boundary_id = '1 2 3'
new_boundary_name = 'right top left'
```

Then the MOOSE input file can employ `boundary = right` rather than `boundary = 1`. `RenameBoundaryGenerator` may also
be used to provide more meaningful names to boundaries that are already named. For instance
The following will change the name for the boundary "meaningless" to "interior" and the name for boundary "5" to "exterior":

```text
old_boundary_name = 'silly meaningless crazy'
new_boundary_name = 'right top left'
```
[rename]
type = RenameBoundaryGenerator
input = some_mesh
old_boundary = 'meaningless 5'
new_boundary = 'interior exterior'
[]
```

Then the MOOSE input file can employ `boundary = left` rather than `block = crazy`.
## Merging Boundaries

!alert warning
`RenameBoundaryGenerator` may also be used to merge boundaries, but care must be taken.
When using the `RenameBoundaryGenerator` to merge boundaries, the result is not necessarily independent of ordering.

For instance
For example, take the following:

```
old_boundary_id = '1 2 3'
new_boundary_id = '4 4 4'
[merge]
type = RenameBoundaryGenerator
input = some_mesh
old_boundary = '0 1 2 3`
new_boundary = 'bottom_and_left bottom_and_left top_and_right top_and_right'
[]
```

Then boundaries 1, 2 and 3 will be merged together into one boundary that may be used in the remainder of
the input file. However, when merging boundaries problems and even inconsistencies can occur.
The above will result in two boundaries:

- Boundary "0" with name "bottom_and_left" that contains the sides from the original boundaries "0" and "1".
- Boundary "2" with name "top_and_right" that contains the sides from the original boundaries "2" and "3".

Firstly, in the example just given, what if the boundaries 1, 2 and 3 were named? What should the name
of the boundary 4 be? The convention is that it is the name of the first old boundary that is given the
boundary ID of 4, which is the name of the old boundary 1 in this case. The user needs to be aware of this
convention. Similarly, if `old_boundary_name = 'oldA oldB'` and `new_boundary_name = 'new1 new1'`, then
the boundary ID of new1 is the boundary ID of oldA.
Take the first execution, "0" to "bottom_and_left". The "RenameBoundaryGenerator" will use the original boundary ID, which is "0". The second execution, "1" to "bottom_and_left", will use the new ID associated with "bottom_and_left", which is "0", and merge "1" into it. The result is similar for the third and fourth executions.

Secondly, in the example above, what if boundary 4 already existed? An inconsistency could arise in the
input file, because boundary 4 is now given the name of the old boundary 1.
!alert! tip title=The use of ID is order independent
The order dependent behavior only exists when the new boundary provided is a name. Take the following instead:

```
[merge]
type = RenameBoundaryGenerator
input = some_mesh
old_boundary = '0 1 2 3'
new_boundary = '0 0 4 4'
[]
```

Thirdly, in this example `old_boundary_id = '1 2'` and `new_boundary_name = 'wheel wheel'`. What if another
boundary, with a different ID, already had the name "wheel"? This can lead to great confusion in the MOOSE input file.
The result is:

!alert note
Given all these potential problems, when merging boundaries it is strongly recommended to use just
*one* `RenameBoundaryGenerator` that includes the names or IDs of *all* the boundaries involved in the merging.
This will make the new boundary IDs and new boundary names unequivocally obvious.
- Boundary "0" that contains the sides from original boundaries "0" and "1".
- Boundary "4" that contains the sides from original boundaries "2" and "3".
!alert-end!

!syntax parameters /Mesh/RenameBoundaryGenerator

Expand Down
16 changes: 8 additions & 8 deletions framework/include/meshgenerators/RenameBoundaryGenerator.h
Expand Up @@ -32,12 +32,12 @@ class RenameBoundaryGenerator : public MeshGenerator
protected:
std::unique_ptr<MeshBase> & _input;

std::vector<boundary_id_type> _old_boundary_id;

std::vector<BoundaryName> _old_boundary_name;

std::vector<boundary_id_type> _new_boundary_id;

std::vector<BoundaryName> _new_boundary_name;
/// The old boundaries
std::vector<BoundaryName> _old_boundary;
/// The new boundaries
std::vector<BoundaryName> _new_boundary;
/// The name of the parameter that specifies the old boundaries
std::string _old_boundary_param_name;
/// The name of the parameter that specifies the new boundaries
std::string _new_boundary_param_name;
};

9 changes: 8 additions & 1 deletion framework/include/utils/MooseMeshUtils.h
Expand Up @@ -28,7 +28,14 @@ getBoundaryIDs(const libMesh::MeshBase & mesh,
const std::vector<BoundaryName> & boundary_name,
bool generate_unknown);

/**
* Gets the boundary ID associated with the given BoundaryName.
*
* This is needed because the BoundaryName can be either an ID or a name.
* If it is a name, the mesh is queried for the ID associated with said name.
*/
BoundaryID getBoundaryID(const BoundaryName & boundary_name, const MeshBase & mesh);

std::vector<subdomain_id_type> getSubdomainIDs(const libMesh::MeshBase & mesh,
const std::vector<SubdomainName> & subdomain_name);
}

9 changes: 2 additions & 7 deletions framework/src/mesh/MooseMesh.C
Expand Up @@ -20,6 +20,7 @@
#include "Assembly.h"
#include "SubProblem.h"
#include "MooseVariableBase.h"
#include "MooseMeshUtils.h"

#include <utility>

Expand Down Expand Up @@ -1143,13 +1144,7 @@ MooseMesh::getBoundaryID(const BoundaryName & boundary_name) const
if (boundary_name == "ANY_BOUNDARY_ID")
mooseError("Please use getBoundaryIDs() when passing \"ANY_BOUNDARY_ID\"");

BoundaryID id = Moose::INVALID_BOUNDARY_ID;
std::istringstream ss(boundary_name);

if (!(ss >> id))
id = getMesh().get_boundary_info().get_id_by_name(boundary_name);

return id;
return MooseMeshUtils::getBoundaryID(boundary_name, getMesh());
}

const Elem *
Expand Down

0 comments on commit ab2d3b4

Please sign in to comment.