www.mooseframework.org
GeometryBase.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "GeometryBase.h"
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  return params;
25 }
26 
28  : GeneralUserObject(parameters),
29  _mesh(_subproblem.mesh()),
30  _boundary_ids(_mesh.getBoundaryIDs(getParam<std::vector<BoundaryName>>("boundary"))),
31  _subdomain_ids(_mesh.getSubdomainIDs(getParam<std::vector<SubdomainName>>("block")))
32 {
33 }
34 
35 void
37 {
38 }
39 
40 void
42 {
43 }
44 
45 void
47 {
48 }
49 
50 void
52 {
53  auto & mesh = _mesh.getMesh();
54 
55  // go over boundaries
56  for (auto & boundary_id : _boundary_ids)
57  {
58  auto node_ids = _mesh.getNodeList(boundary_id);
59  for (auto & node_id : node_ids)
60  {
61  auto & node = mesh.node_ref(node_id);
62 
63  snapNode(node);
64  }
65  }
66 
67  // go over blocks
68  MeshBase::node_iterator node = mesh.active_nodes_begin();
69  MeshBase::node_iterator node_end = mesh.active_nodes_end();
70  for (; node != node_end; ++node)
71  {
72  // check if node is part of any of the selected blocks
73  const auto & node_blocks = _mesh.getNodeBlockIds(**node);
74  for (const auto subdomain_id : _subdomain_ids)
75  if (node_blocks.count(subdomain_id))
76  {
77  snapNode(**node);
78  break;
79  }
80  }
81 }
GeometryBase(const InputParameters &parameters)
Definition: GeometryBase.C:27
virtual void initialize() final
Called before execute() is ever called so that data can be cleared.
Definition: GeometryBase.C:36
virtual void execute() final
Execute method.
Definition: GeometryBase.C:41
const std::vector< BoundaryID > _boundary_ids
List of boundaries (or node sets) that will be snapped to a geometry.
Definition: GeometryBase.h:43
static InputParameters validParams()
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:1281
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.
static InputParameters validParams()
Definition: GeometryBase.C:15
const std::vector< SubdomainID > _subdomain_ids
List of blocks (likely lower D blocks) that will be snapped to a geometry.
Definition: GeometryBase.h:46
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:3199
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:3221
virtual void finalize() final
Finalize.
Definition: GeometryBase.C:46
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 void meshChanged() final
Called on this object when the mesh changes.
Definition: GeometryBase.C:51
MooseMesh & _mesh
Reference to the current simulation mesh.
Definition: GeometryBase.h:40
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...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
virtual void snapNode(Node &node)=0
Override this method in derived classes to implement a specific geometry.