Line data Source code
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 "BoundaryPreservedMarker.h" 11 : #include "MooseMeshUtils.h" 12 : #include "MooseMesh.h" 13 : 14 : #include "libmesh/error_vector.h" 15 : 16 : registerMooseObject("MooseApp", BoundaryPreservedMarker); 17 : 18 : InputParameters 19 14349 : BoundaryPreservedMarker::validParams() 20 : { 21 14349 : InputParameters params = Marker::validParams(); 22 14349 : params.addRequiredParam<BoundaryName>( 23 : "preserved_boundary", 24 : "The name of the boundary to be preserved. Will try to preserve the boundary during AMR"); 25 14349 : params.addRequiredParam<MarkerName>( 26 : "marker", "The marker name to decide whether to carsen or refine elements."); 27 14349 : params.addClassDescription("Marks elements for refinement or coarsening based on the provided " 28 : "marker value, while preserving the given boundary."); 29 14349 : return params; 30 0 : } 31 : 32 44 : BoundaryPreservedMarker::BoundaryPreservedMarker(const InputParameters & parameters) 33 : : Marker(parameters), 34 44 : _marker_name(parameters.get<MarkerName>("marker")), 35 88 : _marker(&getMarkerValue(_marker_name)) 36 : { 37 44 : _mesh.errorIfDistributedMesh(type()); 38 44 : BoundaryName boundary_name = getParam<BoundaryName>("preserved_boundary"); 39 88 : auto boundary_ids = MooseMeshUtils::getBoundaryIDs(_mesh, {boundary_name}, true); 40 : mooseAssert(boundary_ids.size() == 1, "Boundary does not exist"); 41 44 : _preserved_boundary = boundary_ids[0]; 42 88 : } 43 : 44 : bool 45 32158 : BoundaryPreservedMarker::preserveBoundary(const Elem * const & current_elem) 46 : { 47 32158 : 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 42700 : for (const auto & pr : as_range(elem_side_bnd_ids.equal_range(current_elem))) 51 11172 : if (pr.second.second == _preserved_boundary) 52 630 : return true; 53 : 54 31528 : return false; 55 : } 56 : 57 : Marker::MarkerValue 58 119868 : BoundaryPreservedMarker::computeElementMarker() 59 : { 60 119868 : MarkerValue marker_value = static_cast<MarkerValue>((*_marker)[0]); 61 119868 : if (marker_value == COARSEN && preserveBoundary(_current_elem)) 62 630 : return DO_NOTHING; 63 : else 64 119238 : return marker_value; 65 : }