Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
BoundaryMarker.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "BoundaryMarker.h"
11 #include "MooseMesh.h"
12 
14 
17 {
19  params.addClassDescription(
20  "Marks all elements with sides on a given boundary for refinement/coarsening");
21  MooseEnum marker_states = Marker::markerStates();
22 
24  "mark", marker_states, "How to mark elements adjacent to the boundary.");
25  params.addRequiredParam<std::vector<BoundaryName>>("next_to",
26  "Boundaries to refine elements along");
27  params.addParam<Real>("distance", 0.0, "Distance from the boundary to refine within");
28  return params;
29 }
30 
32  : Marker(parameters),
33  _distance(getParam<Real>("distance")),
34  _bnd_elem_ids(_mesh.getBoundariesToActiveSemiLocalElemIds()),
35  _mark(parameters.get<MooseEnum>("mark").getEnum<MarkerValue>()),
36  _boundary_ids(_mesh.getBoundaryIDs(getParam<std::vector<BoundaryName>>("next_to")))
37 {
38  if (_mesh.isDistributedMesh() && _distance > 0)
39  mooseWarning("Elements with in `distance ` of a boundary segment on a different processor "
40  "might not get marked when running with a distributed mesh.");
41 }
42 
45 {
46  if (_distance == 0.0)
47  {
48  // is the current element member of any selected boundary element set?
49  for (const auto boundary : _boundary_ids)
50  if (_mesh.isBoundaryElem(_current_elem->id(), boundary))
51  return _mark;
52 
53  return DONT_MARK;
54  }
55  else
56  {
57  for (const auto boundary : _boundary_ids)
58  {
59  const auto it = _bnd_elem_ids.find(boundary);
60  if (it != _bnd_elem_ids.end())
61  for (const auto id : it->second)
62  {
63  // shortcut if we are checing the current element itself
64  if (id == _current_elem->id())
65  return _mark;
66 
67  // otherwise compute distance to the boundary elements
68  const auto elem = _mesh.elemPtr(id);
69  const auto r = _current_elem->vertex_average() - elem->vertex_average();
70  if (r.norm() < _distance)
71  return _mark;
72  }
73  }
74  return DONT_MARK;
75  }
76 }
virtual Elem * elemPtr(const dof_id_type i)
Definition: MooseMesh.C:3108
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1125
Definition: Marker.h:41
const Elem *const & _current_elem
Pointer to the current element being considered in the marker element-based loop. ...
Definition: Marker.h:122
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
MarkerValue
This mirrors the main refinement flag values in libMesh in Elem::RefinementState but adds "dont_mark"...
Definition: Marker.h:59
virtual MarkerValue computeElementMarker() override
BoundaryMarker(const InputParameters &parameters)
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
const std::vector< BoundaryID > _boundary_ids
boundary near which to mark elements
static InputParameters validParams()
Marks all elements near a given boundary for refinement/coarsening.
const Real _distance
distance from the boundary (centroid of boundary element to centroid of marked element) ...
MooseMesh & _mesh
Reference to the mesh, obtained from the subproblem.
Definition: Marker.h:125
registerMooseObject("MooseApp", BoundaryMarker)
static MooseEnum markerStates()
Helper function for getting the valid refinement flag states a marker can use as a MooseEnum...
Definition: Marker.C:62
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
const MarkerValue _mark
which way to mark elements near the boundary
std::vector< BoundaryID > getBoundaryIDs(const libMesh::MeshBase &mesh, const std::vector< BoundaryName > &boundary_name, bool generate_unknown, const std::set< BoundaryID > &mesh_boundary_ids)
Gets the boundary IDs with their names.
const std::unordered_map< boundary_id_type, std::unordered_set< dof_id_type > > & _bnd_elem_ids
lists of boundary elements for all boundaries
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
static InputParameters validParams()
Definition: Marker.C:19
bool isBoundaryElem(dof_id_type elem_id) const
Returns true if the requested element is in the list of boundary elements, false otherwise.
Definition: MooseMesh.C:3586
virtual bool isDistributedMesh() const
Returns the final Mesh distribution type.
Definition: MooseMesh.h:1001