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 "MoveNodesToGeometryModifierBase.h" 11 : #include "MooseMesh.h" 12 : #include "libmesh/mesh_base.h" 13 : 14 : InputParameters 15 28582 : MoveNodesToGeometryModifierBase::validParams() 16 : { 17 28582 : InputParameters params = GeneralUserObject::validParams(); 18 28582 : params.addClassDescription( 19 : "Snap refined nodes on a given boundary or block to a given geometry."); 20 28582 : params.addParam<std::vector<BoundaryName>>( 21 : "boundary", {}, "List of boundaries whose nodes are snapped to a given geometry"); 22 28582 : params.addParam<std::vector<SubdomainName>>( 23 : "block", {}, "List of blocks whose nodes are snapped to a given geometry"); 24 : 25 : // By default don't execute 26 28582 : params.set<ExecFlagEnum>("execute_on") = "NONE"; 27 : 28 28582 : return params; 29 0 : } 30 : 31 26 : MoveNodesToGeometryModifierBase::MoveNodesToGeometryModifierBase(const InputParameters & parameters) 32 : : GeneralUserObject(parameters), 33 52 : _mesh(_subproblem.mesh()), 34 26 : _boundary_ids(_mesh.getBoundaryIDs(getParam<std::vector<BoundaryName>>("boundary"))), 35 52 : _subdomain_ids(_mesh.getSubdomainIDs(getParam<std::vector<SubdomainName>>("block"))) 36 : { 37 26 : } 38 : 39 : void 40 0 : MoveNodesToGeometryModifierBase::initialize() 41 : { 42 0 : } 43 : 44 : void 45 0 : MoveNodesToGeometryModifierBase::execute() 46 : { 47 0 : snapNodes(); 48 0 : } 49 : 50 : void 51 0 : MoveNodesToGeometryModifierBase::finalize() 52 : { 53 0 : } 54 : 55 : void 56 72 : MoveNodesToGeometryModifierBase::meshChanged() 57 : { 58 72 : snapNodes(); 59 72 : } 60 : 61 : void 62 72 : MoveNodesToGeometryModifierBase::snapNodes() 63 : { 64 72 : auto & mesh = _mesh.getMesh(); 65 : 66 : // go over boundaries 67 216 : for (auto & boundary_id : _boundary_ids) 68 : { 69 144 : auto node_ids = _mesh.getNodeList(boundary_id); 70 940 : for (auto & node_id : node_ids) 71 : { 72 796 : auto & node = mesh.node_ref(node_id); 73 : 74 796 : snapNode(node); 75 : } 76 144 : } 77 : 78 : // go over blocks 79 72 : MeshBase::node_iterator node = mesh.active_nodes_begin(); 80 72 : MeshBase::node_iterator node_end = mesh.active_nodes_end(); 81 4040 : for (; node != node_end; ++node) 82 : { 83 : // check if node is part of any of the selected blocks 84 1984 : const auto & node_blocks = _mesh.getNodeBlockIds(**node); 85 1984 : for (const auto subdomain_id : _subdomain_ids) 86 646 : if (node_blocks.count(subdomain_id)) 87 : { 88 646 : snapNode(**node); 89 646 : break; 90 : } 91 : } 92 72 : }