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 "BoundaryMarker.h" 11 : #include "MooseMesh.h" 12 : 13 : registerMooseObject("MooseApp", BoundaryMarker); 14 : 15 : InputParameters 16 14386 : BoundaryMarker::validParams() 17 : { 18 14386 : InputParameters params = Marker::validParams(); 19 14386 : params.addClassDescription( 20 : "Marks all elements with sides on a given boundary for refinement/coarsening"); 21 14386 : MooseEnum marker_states = Marker::markerStates(); 22 : 23 14386 : params.addRequiredParam<MooseEnum>( 24 : "mark", marker_states, "How to mark elements adjacent to the boundary."); 25 14386 : params.addRequiredParam<std::vector<BoundaryName>>("next_to", 26 : "Boundaries to refine elements along"); 27 14386 : params.addParam<Real>("distance", 0.0, "Distance from the boundary to refine within"); 28 28772 : return params; 29 14386 : } 30 : 31 61 : BoundaryMarker::BoundaryMarker(const InputParameters & parameters) 32 : : Marker(parameters), 33 61 : _distance(getParam<Real>("distance")), 34 61 : _bnd_elem_ids(_mesh.getBoundariesToActiveSemiLocalElemIds()), 35 61 : _mark(parameters.get<MooseEnum>("mark").getEnum<MarkerValue>()), 36 122 : _boundary_ids(_mesh.getBoundaryIDs(getParam<std::vector<BoundaryName>>("next_to"))) 37 : { 38 61 : if (_mesh.isDistributedMesh() && _distance > 0) 39 0 : 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 61 : } 42 : 43 : Marker::MarkerValue 44 424531 : BoundaryMarker::computeElementMarker() 45 : { 46 424531 : if (_distance == 0.0) 47 : { 48 : // is the current element member of any selected boundary element set? 49 826120 : for (const auto boundary : _boundary_ids) 50 424232 : if (_mesh.isBoundaryElem(_current_elem->id(), boundary)) 51 22048 : return _mark; 52 : 53 401888 : return DONT_MARK; 54 : } 55 : else 56 : { 57 819 : for (const auto boundary : _boundary_ids) 58 : { 59 595 : const auto it = _bnd_elem_ids.find(boundary); 60 595 : if (it != _bnd_elem_ids.end()) 61 2702 : for (const auto id : it->second) 62 : { 63 : // shortcut if we are checing the current element itself 64 2478 : if (id == _current_elem->id()) 65 371 : return _mark; 66 : 67 : // otherwise compute distance to the boundary elements 68 2429 : const auto elem = _mesh.elemPtr(id); 69 2429 : const auto r = _current_elem->vertex_average() - elem->vertex_average(); 70 2429 : if (r.norm() < _distance) 71 322 : return _mark; 72 : } 73 : } 74 224 : return DONT_MARK; 75 : } 76 : }