www.mooseframework.org
SideSetsFromPoints.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "SideSetsFromPoints.h"
16 #include "Parser.h"
17 #include "InputParameters.h"
18 #include "MooseMesh.h"
19 
20 #include "libmesh/mesh_generation.h"
21 #include "libmesh/mesh.h"
22 #include "libmesh/string_to_enum.h"
23 #include "libmesh/quadrature_gauss.h"
24 #include "libmesh/point_locator_base.h"
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<Elem> elem_side = elem->side(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 }
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:1951
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 errorIfDistributedMesh(std::string name) const
Generate a unified error message if the underlying libMesh mesh is a DistributedMesh.
Definition: MooseMesh.C:2473
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:74
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2355
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...
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
std::vector< Point > _points
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.