https://mooseframework.inl.gov
MoveNodesToGeometryModifierBase.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 "MooseMesh.h"
12 #include "libmesh/mesh_base.h"
13 
16 {
18  params.addClassDescription(
19  "Snap refined nodes on a given boundary or block to a given geometry.");
20  params.addParam<std::vector<BoundaryName>>(
21  "boundary", {}, "List of boundaries whose nodes are snapped to a given geometry");
22  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  params.set<ExecFlagEnum>("execute_on") = "NONE";
27 
28  return params;
29 }
30 
32  : GeneralUserObject(parameters),
33  _mesh(_subproblem.mesh()),
34  _boundary_ids(_mesh.getBoundaryIDs(getParam<std::vector<BoundaryName>>("boundary"))),
35  _subdomain_ids(_mesh.getSubdomainIDs(getParam<std::vector<SubdomainName>>("block")))
36 {
37 }
38 
39 void
41 {
42 }
43 
44 void
46 {
47  snapNodes();
48 }
49 
50 void
52 {
53 }
54 
55 void
57 {
58  snapNodes();
59 }
60 
61 void
63 {
64  auto & mesh = _mesh.getMesh();
65 
66  // go over boundaries
67  for (auto & boundary_id : _boundary_ids)
68  {
69  auto node_ids = _mesh.getNodeList(boundary_id);
70  for (auto & node_id : node_ids)
71  {
72  auto & node = mesh.node_ref(node_id);
73 
74  snapNode(node);
75  }
76  }
77 
78  // go over blocks
79  MeshBase::node_iterator node = mesh.active_nodes_begin();
80  MeshBase::node_iterator node_end = mesh.active_nodes_end();
81  for (; node != node_end; ++node)
82  {
83  // check if node is part of any of the selected blocks
84  const auto & node_blocks = _mesh.getNodeBlockIds(**node);
85  for (const auto subdomain_id : _subdomain_ids)
86  if (node_blocks.count(subdomain_id))
87  {
88  snapNode(**node);
89  break;
90  }
91  }
92 }
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:21
virtual void snapNode(Node &node)=0
Override this method in derived classes to implement a specific geometry.
static InputParameters validParams()
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
MeshBase & mesh
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const std::set< SubdomainID > & getNodeBlockIds(const Node &node) const
Return list of blocks to which the given node belongs.
Definition: MooseMesh.C:1496
std::vector< subdomain_id_type > getSubdomainIDs(const libMesh::MeshBase &mesh, const std::vector< SubdomainName > &subdomain_name)
Get the associated subdomainIDs for the subdomain names that are passed in.
void snapNodes()
Snap all nodes from the specified block or boundary restriction to the derived-class-defined geometry...
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:3443
const std::vector< dof_id_type > & getNodeList(boundary_id_type nodeset_id) const
Return a writable reference to a vector of node IDs that belong to nodeset_id.
Definition: MooseMesh.C:3465
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.
MooseMesh & _mesh
Reference to the current simulation mesh.
virtual void initialize() final
Called before execute() is ever called so that data can be cleared.
virtual void meshChanged() final
Called on this object when the mesh changes.
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...
MoveNodesToGeometryModifierBase(const InputParameters &parameters)
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...
const std::vector< SubdomainID > _subdomain_ids
List of blocks (likely lower D blocks) from which nodes will be snapped to a geometry.
const std::vector< BoundaryID > _boundary_ids
List of boundaries (or node sets) from which nodes will be snapped to a geometry. ...
virtual void execute() final
Execute method.