www.mooseframework.org
SideSetsFromPoints.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 "SideSetsFromPoints.h"
11 #include "Parser.h"
12 #include "InputParameters.h"
13 #include "MooseMesh.h"
14 
15 #include "libmesh/mesh_generation.h"
16 #include "libmesh/mesh.h"
17 #include "libmesh/string_to_enum.h"
18 #include "libmesh/quadrature_gauss.h"
19 #include "libmesh/point_locator_base.h"
20 #include "libmesh/enum_point_locator_type.h"
21 #include "libmesh/elem.h"
22 #include "libmesh/fe_base.h"
23 
25 
26 template <>
29 {
31  params.addClassDescription("Adds a new sideset starting at the specified point containing all "
32  "connected element faces with the same normal.");
33  params.addRequiredParam<std::vector<BoundaryName>>("new_boundary",
34  "The name of the boundary to create");
35  params.addRequiredParam<std::vector<Point>>(
36  "points", "A list of points from which to start painting sidesets");
37  return params;
38 }
39 
41  : AddSideSetsBase(parameters),
42  _boundary_names(getParam<std::vector<BoundaryName>>("new_boundary")),
43  _points(getParam<std::vector<Point>>("points"))
44 {
45  if (_points.size() != _boundary_names.size())
46  mooseError("point list and boundary list are not the same length");
47 }
48 
49 void
51 {
52  if (!_mesh_ptr)
53  mooseError("_mesh_ptr must be initialized before calling SideSetsFromPoints::modify()!");
54 
55  // We can't call this in the constructor, it appears that _mesh_ptr is always NULL there.
56  _mesh_ptr->errorIfDistributedMesh("SideSetsFromPoints");
57 
58  // Get the BoundaryIDs from the mesh
59  std::vector<BoundaryID> boundary_ids = _mesh_ptr->getBoundaryIDs(_boundary_names, true);
60 
61  setup();
62 
63  _visited.clear();
64 
65  std::unique_ptr<PointLocatorBase> pl = PointLocatorBase::build(TREE, *_mesh_ptr);
66 
67  for (unsigned int i = 0; i < boundary_ids.size(); ++i)
68  {
69  const Elem * elem = (*pl)(_points[i]);
70 
71  for (unsigned int side = 0; side < elem->n_sides(); ++side)
72  {
73  if (elem->neighbor_ptr(side))
74  continue;
75 
76  // See if this point is on this side
77  std::unique_ptr<const Elem> elem_side = elem->side_ptr(side);
78 
79  if (elem_side->contains_point(_points[i]))
80  {
81  // This is the side that we want to paint our sideset with
82  // First get the normal
83  _fe_face->reinit(elem, side);
84  const std::vector<Point> & normals = _fe_face->get_normals();
85 
86  flood(elem, normals[0], boundary_ids[i]);
87  }
88  }
89  }
90 
91  finalize();
92 
93  for (unsigned int i = 0; i < boundary_ids.size(); ++i)
94  _mesh_ptr->getMesh().boundary_info->sideset_name(boundary_ids[i]) = _boundary_names[i];
95 }
InputParameters validParams< SideSetsFromPoints >()
std::unique_ptr< FEBase > _fe_face
std::vector< BoundaryName > _boundary_names
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
void finalize()
This method finalizes the object, setting names back in the boundary_info object and releasing memory...
SideSetsFromPoints(const InputParameters &parameters)
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...
MooseMesh * _mesh_ptr
Pointer to the mesh.
Definition: MeshModifier.h:68
void errorIfDistributedMesh(std::string name) const
Generate a unified error message if the underlying libMesh mesh is a DistributedMesh.
Definition: MooseMesh.C:2685
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2567
InputParameters validParams< AddSideSetsBase >()
std::map< BoundaryID, std::set< const Elem * > > _visited
void flood(const Elem *elem, Point normal, BoundaryID side_id)
This method implements a recursive flood routine to paint a sideset of mesh to neighboring faces give...
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::vector< BoundaryID > getBoundaryIDs(const Elem *const elem, const unsigned short int side) const
Returns a vector of boundary IDs for the requested element on the requested side. ...
Definition: MooseMesh.C:2153
std::vector< Point > _points
registerMooseObject("MooseApp", SideSetsFromPoints)
void setup()
This method is used to construct the FE object so we can compute normals of faces.
virtual void modify() override
Pure virtual modify function MUST be overridden by children classes.