www.mooseframework.org
SideSetsFromNormals.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 "SideSetsFromNormals.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(
32  "Adds a new named sideset to the mesh for all faces matching the specified normal.");
33  params.addRequiredParam<std::vector<BoundaryName>>("new_boundary",
34  "The name of the boundary to create");
35  params.addRequiredParam<std::vector<Point>>(
36  "normals", "A list of normals for which to start painting sidesets");
37  return params;
38 }
39 
41  : AddSideSetsBase(parameters), _normals(getParam<std::vector<Point>>("normals"))
42 {
43 
44  // Get the BoundaryIDs from the mesh
45  _boundary_names = getParam<std::vector<BoundaryName>>("new_boundary");
46 
47  if (_normals.size() != _boundary_names.size())
48  mooseError("normal list and boundary list are not the same length");
49 
50  // Make sure that the normals are normalized
51  for (auto & normal : _normals)
52  {
53  mooseAssert(normal.norm() >= 1e-5, "Normal is zero");
54  normal /= normal.norm();
55  }
56 }
57 
58 void
60 {
61  if (!_mesh_ptr)
62  mooseError("_mesh_ptr must be initialized before calling SideSetsFromNormals::modify()!");
63 
64  // We can't call this in the constructor, it appears that _mesh_ptr is always NULL there.
65  _mesh_ptr->errorIfDistributedMesh("SideSetsFromNormals");
66 
67  std::vector<BoundaryID> boundary_ids = _mesh_ptr->getBoundaryIDs(_boundary_names, true);
68 
69  setup();
70 
71  _visited.clear();
72 
73  // We'll need to loop over all of the elements to find ones that match this normal.
74  // We can't rely on flood catching them all here...
75  for (const auto & elem : _mesh_ptr->getMesh().element_ptr_range())
76  for (unsigned int side = 0; side < elem->n_sides(); ++side)
77  {
78  if (elem->neighbor_ptr(side))
79  continue;
80 
81  _fe_face->reinit(elem, side);
82  const std::vector<Point> & normals = _fe_face->get_normals();
83 
84  for (unsigned int i = 0; i < boundary_ids.size(); ++i)
85  {
86  if (std::abs(1.0 - _normals[i] * normals[0]) < 1e-5)
87  flood(elem, _normals[i], boundary_ids[i]);
88  }
89  }
90 
91  finalize();
92 
93  BoundaryInfo & boundary_info = _mesh_ptr->getMesh().get_boundary_info();
94  for (unsigned int i = 0; i < boundary_ids.size(); ++i)
95  boundary_info.sideset_name(boundary_ids[i]) = _boundary_names[i];
96 }
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
std::unique_ptr< FEBase > _fe_face
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...
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...
virtual void modify() override
Pure virtual modify function MUST be overridden by children classes.
MooseMesh * _mesh_ptr
Pointer to the mesh.
Definition: MeshModifier.h:74
std::vector< BoundaryName > _boundary_names
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2355
std::vector< Point > _normals
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...
InputParameters validParams< SideSetsFromNormals >()
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
SideSetsFromNormals(const InputParameters &parameters)
void setup()
This method is used to construct the FE object so we can compute normals of faces.