www.mooseframework.org
SideSetsFromPointsGenerator.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 
11 #include "Parser.h"
12 #include "InputParameters.h"
13 #include "MooseMeshUtils.h"
14 #include "CastUniquePointer.h"
15 
16 #include "libmesh/mesh_generation.h"
17 #include "libmesh/mesh.h"
18 #include "libmesh/string_to_enum.h"
19 #include "libmesh/quadrature_gauss.h"
20 #include "libmesh/point_locator_base.h"
21 #include "libmesh/enum_point_locator_type.h"
22 #include "libmesh/distributed_mesh.h"
23 #include "libmesh/elem.h"
24 #include "libmesh/fe_base.h"
25 
26 #include <typeinfo>
27 
29 
30 template <>
33 {
35 
36  params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
37  params.addClassDescription("Adds a new sideset starting at the specified point containing all "
38  "connected element faces with the same normal.");
39  params.addRequiredParam<std::vector<BoundaryName>>("new_boundary",
40  "The name of the boundary to create");
41  params.addRequiredParam<std::vector<Point>>(
42  "points", "A list of points from which to start painting sidesets");
43 
44  return params;
45 }
46 
48  : SideSetsGeneratorBase(parameters),
49  _input(getMesh("input")),
50  _boundary_names(getParam<std::vector<BoundaryName>>("new_boundary")),
51  _points(getParam<std::vector<Point>>("points"))
52 {
53  if (typeid(_input).name() == typeid(std::unique_ptr<DistributedMesh>).name())
54  mooseError("GenerateAllSideSetsByNormals only works with ReplicatedMesh.");
55 
56  if (_points.size() != _boundary_names.size())
57  mooseError("point list and boundary list are not the same length");
58 }
59 
60 std::unique_ptr<MeshBase>
62 {
63  std::unique_ptr<MeshBase> mesh = std::move(_input);
64 
65  // Get the BoundaryIDs from the mesh
66  std::vector<BoundaryID> boundary_ids =
68 
69  setup(*mesh);
70 
71  _visited.clear();
72 
73  std::unique_ptr<PointLocatorBase> pl = PointLocatorBase::build(TREE, *mesh);
74 
75  for (unsigned int i = 0; i < boundary_ids.size(); ++i)
76  {
77  const Elem * elem = (*pl)(_points[i]);
78 
79  for (unsigned int side = 0; side < elem->n_sides(); ++side)
80  {
81  if (elem->neighbor_ptr(side))
82  continue;
83 
84  // See if this point is on this side
85  std::unique_ptr<const Elem> elem_side = elem->side_ptr(side);
86 
87  if (elem_side->contains_point(_points[i]))
88  {
89  // This is the side that we want to paint our sideset with
90  // First get the normal
91  _fe_face->reinit(elem, side);
92  const std::vector<Point> & normals = _fe_face->get_normals();
93 
94  flood(elem, normals[0], boundary_ids[i], *mesh);
95  }
96  }
97  }
98 
99  finalize();
100 
101  for (unsigned int i = 0; i < boundary_ids.size(); ++i)
102  mesh->get_boundary_info().sideset_name(boundary_ids[i]) = _boundary_names[i];
103 
104  return dynamic_pointer_cast<MeshBase>(mesh);
105 }
std::unique_ptr< MeshBase > & _input
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::unique_ptr< T_DEST, T_DELETER > dynamic_pointer_cast(std::unique_ptr< T_SRC, T_DELETER > &src)
These are reworked from https://stackoverflow.com/a/11003103.
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
registerMooseObject("MooseApp", SideSetsFromPointsGenerator)
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
SideSetsFromPointsGenerator(const InputParameters &parameters)
std::unique_ptr< FEBase > _fe_face
void flood(const Elem *elem, Point normal, boundary_id_type side_id, MeshBase &mesh)
This method implements a recursive flood routine to paint a sideset of mesh to neighboring faces give...
void finalize()
This method finalizes the object, setting names back in the boundary_info object and releasing memory...
InputParameters validParams< SideSetsGeneratorBase >()
std::vector< libMesh::boundary_id_type > getBoundaryIDs(const libMesh::MeshBase &mesh, const std::vector< BoundaryName > &boundary_name, bool generate_unknown)
std::vector< BoundaryName > _boundary_names
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:59
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...
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
std::map< boundary_id_type, std::set< const Elem * > > _visited
void setup(MeshBase &mesh)
This method is used to construct the FE object so we can compute normals of faces.
InputParameters validParams< SideSetsFromPointsGenerator >()