www.mooseframework.org
AddAllSideSetsByNormals.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 
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  return params;
32 }
33 
35  : AddSideSetsBase(parameters)
36 {
37 }
38 
39 void
41 {
42  setup();
43 
44  if (!_mesh_ptr)
45  mooseError("_mesh_ptr must be initialized before calling AddAllSideSetsByNormals::modify()!");
46 
47  // We can't call this in the constructor, it appears that _mesh_ptr is always NULL there.
48  _mesh_ptr->errorIfDistributedMesh("AddAllSideSetsByNormals");
49 
50  // Get the current list of boundaries so we can generate new ones that won't conflict
52 
53  // Create the map object that will be owned by MooseMesh
54  using map_type = std::map<BoundaryID, RealVectorValue>;
55  std::unique_ptr<map_type> boundary_map = libmesh_make_unique<map_type>();
56 
57  _visited.clear();
58 
59  // We'll need to loop over all of the elements to find ones that match this normal.
60  // We can't rely on flood catching them all here...
61  for (const auto & elem : _mesh_ptr->getMesh().element_ptr_range())
62  for (unsigned int side = 0; side < elem->n_sides(); ++side)
63  {
64  if (elem->neighbor_ptr(side))
65  continue;
66 
67  _fe_face->reinit(elem, side);
68  const std::vector<Point> & normals = _fe_face->get_normals();
69 
70  {
71  // See if we've seen this normal before (linear search)
72  const map_type::value_type * item = nullptr;
73  for (const auto & id_pair : *boundary_map)
74  if (std::abs(1.0 - id_pair.second * normals[0]) < 1e-5)
75  {
76  item = &id_pair;
77  break;
78  }
79 
80  if (item)
81  flood(elem, normals[0], item->first);
82  else
83  {
85  (*boundary_map)[id] = normals[0];
86  flood(elem, normals[0], id);
87  }
88  }
89  }
90 
91  finalize();
92 
93  // Transfer ownership of the boundary map and boundary ID set.
94  _mesh_ptr->setBoundaryToNormalMap(std::move(boundary_map));
96 }
97 
100 {
101  std::set<BoundaryID>::iterator it;
102  BoundaryID next_id = 1;
103 
104  while ((it = _mesh_boundary_ids.find(next_id)) != _mesh_boundary_ids.end())
105  ++next_id;
106 
107  _mesh_boundary_ids.insert(next_id);
108 
109  return next_id;
110 }
InputParameters validParams< AddAllSideSetsByNormals >()
std::set< BoundaryID > _mesh_boundary_ids
A pointer to the Mesh&#39;s boundary set, this datastructure will be modified through this modifier...
std::unique_ptr< FEBase > _fe_face
const std::set< BoundaryID > & meshBoundaryIds() const
Returns a read-only reference to the set of boundary IDs currently present in the Mesh...
Definition: MooseMesh.C:2110
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void setMeshBoundaryIDs(std::set< BoundaryID > boundary_IDs)
Sets the set of BoundaryIDs Is called by AddAllSideSetsByNormals.
Definition: MooseMesh.C:2128
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...
MooseMesh * _mesh_ptr
Pointer to the mesh.
Definition: MeshModifier.h:74
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2355
AddAllSideSetsByNormals(const InputParameters &parameters)
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 setBoundaryToNormalMap(std::unique_ptr< std::map< BoundaryID, RealVectorValue >> boundary_map)
Sets the mapping between BoundaryID and normal vector Is called by AddAllSideSetsByNormals.
Definition: MooseMesh.C:2134
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
virtual void modify() override
Pure virtual modify function MUST be overridden by children classes.
boundary_id_type BoundaryID
Definition: MooseTypes.h:75
void setup()
This method is used to construct the FE object so we can compute normals of faces.