Skip to content

Commit

Permalink
Merge pull request #24646 from dschwen/boundary_geometry_24645
Browse files Browse the repository at this point in the history
Fix Geometry UOs and Boundary Marker
  • Loading branch information
lindsayad committed Jun 21, 2023
2 parents dd3ae2a + 38e9f82 commit d2a66a5
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 56 deletions.
2 changes: 1 addition & 1 deletion framework/include/markers/BoundaryMarker.h
Expand Up @@ -34,5 +34,5 @@ class BoundaryMarker : public Marker
const MarkerValue _mark;

/// boundary near which to mark elements
const BoundaryID _boundary;
const std::vector<BoundaryID> _boundary_ids;
};
3 changes: 3 additions & 0 deletions framework/include/userobjects/GeometryBase.h
Expand Up @@ -41,4 +41,7 @@ class GeometryBase : public GeneralUserObject

/// List of boundaries (or node sets) that will be snapped to a geometry
const std::vector<BoundaryID> _boundary_ids;

/// List of blocks (likely lower D blocks) that will be snapped to a geometry
const std::vector<SubdomainID> _subdomain_ids;
};
36 changes: 23 additions & 13 deletions framework/src/markers/BoundaryMarker.C
Expand Up @@ -21,7 +21,8 @@ BoundaryMarker::validParams()

params.addRequiredParam<MooseEnum>(
"mark", marker_states, "How to mark elements adjacent to the boundary.");
params.addRequiredParam<BoundaryName>("next_to", "Boundary to refine elements along");
params.addRequiredParam<std::vector<BoundaryName>>("next_to",
"Boundaries to refine elements along");
params.addParam<Real>("distance", 0.0, "Distance from the boundary to refine within");
return params;
}
Expand All @@ -31,7 +32,7 @@ BoundaryMarker::BoundaryMarker(const InputParameters & parameters)
_distance(getParam<Real>("distance")),
_bnd_elem_ids(_mesh.getBoundariesToActiveSemiLocalElemIds()),
_mark(parameters.get<MooseEnum>("mark").getEnum<MarkerValue>()),
_boundary(_mesh.getBoundaryID(getParam<BoundaryName>("next_to")))
_boundary_ids(_mesh.getBoundaryIDs(getParam<std::vector<BoundaryName>>("next_to")))
{
if (_mesh.isDistributedMesh() && _distance > 0)
mooseWarning("Elements with in `distance ` of a boundary segment on a different processor "
Expand All @@ -43,23 +44,32 @@ BoundaryMarker::computeElementMarker()
{
if (_distance == 0.0)
{
if (_mesh.isBoundaryElem(_current_elem->id(), _boundary))
return _mark;
// is the current element member of any selected boundary element set?
for (const auto boundary : _boundary_ids)
if (_mesh.isBoundaryElem(_current_elem->id(), boundary))
return _mark;

return DONT_MARK;
}
else
{
const auto it = _bnd_elem_ids.find(_boundary);
if (it != _bnd_elem_ids.end())
for (const auto id : it->second)
{
const auto elem = _mesh.elemPtr(id);
const auto r = _current_elem->vertex_average() - elem->vertex_average();
if (r.norm() < _distance)
return _mark;
}
for (const auto boundary : _boundary_ids)
{
const auto it = _bnd_elem_ids.find(boundary);
if (it != _bnd_elem_ids.end())
for (const auto id : it->second)
{
// shortcut if we are checing the current element itself
if (id == _current_elem->id())
return _mark;

// otherwise compute distance to the boundary elements
const auto elem = _mesh.elemPtr(id);
const auto r = _current_elem->vertex_average() - elem->vertex_average();
if (r.norm() < _distance)
return _mark;
}
}
return DONT_MARK;
}
}
24 changes: 22 additions & 2 deletions framework/src/userobjects/GeometryBase.C
Expand Up @@ -15,16 +15,20 @@ InputParameters
GeometryBase::validParams()
{
InputParameters params = GeneralUserObject::validParams();
params.addClassDescription("Snap refined nodes on a given boundary to a given geometry");
params.addClassDescription(
"Snap refined nodes on a given boundary or block to a given geometry.");
params.addParam<std::vector<BoundaryName>>(
"boundary", "List of boundaries whose nodes are snapped to a given geometry");
params.addParam<std::vector<SubdomainName>>(
"block", "List of blocks whose nodes are snapped to a given geometry");
return params;
}

GeometryBase::GeometryBase(const InputParameters & parameters)
: GeneralUserObject(parameters),
_mesh(_subproblem.mesh()),
_boundary_ids(_mesh.getBoundaryIDs(getParam<std::vector<BoundaryName>>("boundary")))
_boundary_ids(_mesh.getBoundaryIDs(getParam<std::vector<BoundaryName>>("boundary"))),
_subdomain_ids(_mesh.getSubdomainIDs(getParam<std::vector<SubdomainName>>("block")))
{
}

Expand All @@ -48,6 +52,7 @@ GeometryBase::meshChanged()
{
auto & mesh = _mesh.getMesh();

// go over boundaries
for (auto & boundary_id : _boundary_ids)
{
auto node_ids = _mesh.getNodeList(boundary_id);
Expand All @@ -58,4 +63,19 @@ GeometryBase::meshChanged()
snapNode(node);
}
}

// go over blocks
MeshBase::node_iterator node = mesh.active_nodes_begin();
MeshBase::node_iterator node_end = mesh.active_nodes_end();
for (; node != node_end; ++node)
{
// check if node is part of any of the selected blocks
const auto & node_blocks = _mesh.getNodeBlockIds(**node);
for (const auto subdomain_id : _subdomain_ids)
if (node_blocks.count(subdomain_id))
{
snapNode(**node);
break;
}
}
}
9 changes: 0 additions & 9 deletions test/tests/markers/boundary_marker/adjacent.i
@@ -1,12 +1,3 @@
###########################################################
# This is a test of the Mesh Marker System. It marks
# elements with flags indicating whether they should be
# refined, coarsened, or left alone. This system
# has the ability to use the Mesh Indicator System.
#
# @Requirement F2.50
###########################################################

[Mesh]
type = GeneratedMesh
dim = 2
Expand Down
9 changes: 0 additions & 9 deletions test/tests/markers/boundary_marker/distance.i
@@ -1,12 +1,3 @@
###########################################################
# This is a test of the Mesh Marker System. It marks
# elements with flags indicating whether they should be
# refined, coarsened, or left alone. This system
# has the ability to use the Mesh Indicator System.
#
# @Requirement F2.50
###########################################################

[Mesh]
type = GeneratedMesh
dim = 2
Expand Down
Binary file not shown.
35 changes: 35 additions & 0 deletions test/tests/markers/boundary_marker/multiple.i
@@ -0,0 +1,35 @@
[Mesh]
type = GeneratedMesh
dim = 2
[]

[Variables]
[u]
[]
[]

[Problem]
kernel_coverage_check = false
solve = false
[]

[Executioner]
type = Steady
[]

# Mesh Marker System
[Adaptivity]
[Markers]
[boundary]
type = BoundaryMarker
next_to = 'right bottom'
mark = refine
[]
[]
initial_marker = boundary
initial_steps = 3
[]

[Outputs]
exodus = true
[]
17 changes: 12 additions & 5 deletions test/tests/markers/boundary_marker/tests
@@ -1,21 +1,28 @@
[Tests] # NOTE: This file is used for testing by the python/moosesqa package
group = 'Boundary Marker'
design = "/Markers/index.md /BoundaryMarker.md"
issues = '#1275'
issues = '#1275 #24645'

[./adjacent]
[adjacent]
type = 'Exodiff'
input = 'adjacent.i'
exodiff = 'adjacent_out.e'
requirement = "The adaptivity system shall create an auxiliary field variable that marks "
"elements for refinement adjacent to a boundary."
[../]
[./distance]
[]
[distance]
type = 'Exodiff'
input = 'distance.i'
exodiff = 'distance_out.e'
requirement = "The adaptivity system shall create an auxiliary field variable that marks "
"elements for refinement within a given distance of a boundary."
mesh_mode = REPLICATED
[../]
[]
[multiple]
type = 'Exodiff'
input = 'multiple.i'
exodiff = 'multiple_out.e'
requirement = "The adaptivity system shall create an auxiliary field variable that marks "
"elements for refinement adjacent to any of a given set of boundaries."
[]
[]
51 changes: 51 additions & 0 deletions test/tests/userobjects/geometry_snap/block.i
@@ -0,0 +1,51 @@
[Mesh]
[gen]
type = PolyLineMeshGenerator
points = "0 0 0
0 1 0
1 1 0
1 0 0"
loop = true
[]
[]

[Variables]
[u]
initial_condition = 1
[]
[]

[Problem]
kernel_coverage_check = false
solve = false
[]

[Executioner]
type = Steady
[]

[UserObjects]
[sphere]
type = GeometrySphere
center = '0.5 0.5 0'
radius = 0.7071
block = 0
[]
[]

[Adaptivity]
[Markers]
[const]
type = UniformMarker
mark = REFINE
[]
[]
marker = const
steps = 3
[]

[Outputs]
[out]
type = Exodus
[]
[]
26 changes: 14 additions & 12 deletions test/tests/userobjects/geometry_snap/geometrysphere.i
@@ -1,12 +1,14 @@
[Mesh]
type = GeneratedMesh
dim = 2
[gen]
type = GeneratedMeshGenerator
dim = 2
[]
[]

[Variables]
[./u]
[u]
initial_condition = 1
[../]
[]
[]

[Problem]
Expand All @@ -19,27 +21,27 @@
[]

[UserObjects]
[./sphere]
[sphere]
type = GeometrySphere
boundary = 'left right top bottom'
center = '0.5 0.5 0'
radius = 0.7071
[../]
[]
[]

[Adaptivity]
[./Markers]
[./const]
[Markers]
[const]
type = UniformMarker
mark = REFINE
[../]
[../]
[]
[]
marker = const
steps = 3
[]

[Outputs]
[./out]
[out]
type = Exodus
[../]
[]
[]
Binary file not shown.
20 changes: 15 additions & 5 deletions test/tests/userobjects/geometry_snap/tests
@@ -1,11 +1,21 @@
[Tests]
[./geometrysphere]
design = 'GeometrySphere.md'
[geometrysphere]
type = 'Exodiff'
input = 'geometrysphere.i'
exodiff = 'geometrysphere_out.e-s004'

design = 'GeometrySphere.md'
issues = '#9578'
requirement = 'The system shall support "snapping" or moving new nodes and sides created by mesh adaptivity to the surface of a geometric sphere to capture high fidelity features on curved geometries.'
[../]
requirement = "The system shall support 'snapping' or moving new nodes in sidesets created by "
"mesh adaptivity to the surface of a geometric sphere to capture high fidelity "
"features on curved geometries."
[]
[block]
type = 'Exodiff'
input = 'block.i'
exodiff = 'block_out.e-s004'
issues = '#24645'
requirement = "The system shall support 'snapping' or moving new nodes in lower dimensional "
"subdomains created by mesh adaptivity to the surface of a geometric sphere to "
"capture high fidelity features on curved geometries."
[]
[]

0 comments on commit d2a66a5

Please sign in to comment.