https://mooseframework.inl.gov
BoundaryPreservedMarker.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 
11 #include "MooseMeshUtils.h"
12 #include "MooseMesh.h"
13 
14 #include "libmesh/error_vector.h"
15 
17 
20 {
22  params.addRequiredParam<BoundaryName>(
23  "preserved_boundary",
24  "The name of the boundary to be preserved. Will try to preserve the boundary during AMR");
25  params.addRequiredParam<MarkerName>(
26  "marker", "The marker name to decide whether to carsen or refine elements.");
27  params.addClassDescription("Marks elements for refinement or coarsening based on the provided "
28  "marker value, while preserving the given boundary.");
29  return params;
30 }
31 
33  : Marker(parameters),
34  _marker_name(parameters.get<MarkerName>("marker")),
35  _marker(&getMarkerValue(_marker_name))
36 {
38  BoundaryName boundary_name = getParam<BoundaryName>("preserved_boundary");
39  auto boundary_ids = MooseMeshUtils::getBoundaryIDs(_mesh, {boundary_name}, true);
40  mooseAssert(boundary_ids.size() == 1, "Boundary does not exist");
41  _preserved_boundary = boundary_ids[0];
42 }
43 
44 bool
45 BoundaryPreservedMarker::preserveBoundary(const Elem * const & current_elem)
46 {
47  auto & elem_side_bnd_ids = _mesh.getMesh().get_boundary_info().get_sideset_map();
48 
49  // Do not coarsen the elements when they are connected to the preserved boundary
50  for (const auto & pr : as_range(elem_side_bnd_ids.equal_range(current_elem)))
51  if (pr.second.second == _preserved_boundary)
52  return true;
53 
54  return false;
55 }
56 
59 {
60  MarkerValue marker_value = static_cast<MarkerValue>((*_marker)[0]);
61  if (marker_value == COARSEN && preserveBoundary(_current_elem))
62  return DO_NOTHING;
63  else
64  return marker_value;
65 }
static InputParameters validParams()
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:1155
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
bool preserveBoundary(const Elem *const &_current_elem)
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...
void errorIfDistributedMesh(std::string name) const
Generate a unified error message if the underlying libMesh mesh is a DistributedMesh.
Definition: MooseMesh.C:3617
MooseMesh & _mesh
Reference to the mesh, obtained from the subproblem.
Definition: Marker.h:125
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:3448
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
const std::string & type() const
Get the type of this class.
Definition: MooseBase.h:89
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.
virtual MarkerValue computeElementMarker() override
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...
BoundaryPreservedMarker(const InputParameters &parameters)
static InputParameters validParams()
Definition: Marker.C:19
registerMooseObject("MooseApp", BoundaryPreservedMarker)