Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Geometry UOs and Boundary Marker #24646

Merged
merged 2 commits into from Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
};
32 changes: 18 additions & 14 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,26 @@ BoundaryMarker::computeElementMarker()
{
if (_distance == 0.0)
{
if (_mesh.isBoundaryElem(_current_elem->id(), _boundary))
return _mark;
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)
{
const auto elem = _mesh.elemPtr(id);
const auto r = _current_elem->vertex_average() - elem->vertex_average();
if (r.norm() < _distance)
lindsayad marked this conversation as resolved.
Show resolved Hide resolved
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;
}
}
lindsayad marked this conversation as resolved.
Show resolved Hide resolved
}
Binary file not shown.
44 changes: 44 additions & 0 deletions test/tests/markers/boundary_marker/multiple.i
@@ -0,0 +1,44 @@
###########################################################
# 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
###########################################################
dschwen marked this conversation as resolved.
Show resolved Hide resolved

[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.e-s004'
issues = '#24645'
requirement = "The system shall support 'snapping' or moving new nodes in lower dimensioanl "
"subdomains created by mesh adaptivity to the surface of a geometric sphere to "
"capture high fidelity features on curved geometries."
[]
[]