www.mooseframework.org
AddAllSideSetsByNormals.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 "MooseMesh.h"
14 
15 #include "libmesh/fe_base.h"
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/elem.h"
22 
24 
25 template <>
28 {
30  return params;
31 }
32 
34  : AddSideSetsBase(parameters)
35 {
36 }
37 
38 void
40 {
41  setup();
42 
43  if (!_mesh_ptr)
44  mooseError("_mesh_ptr must be initialized before calling AddAllSideSetsByNormals::modify()!");
45 
46  // We can't call this in the constructor, it appears that _mesh_ptr is always NULL there.
47  _mesh_ptr->errorIfDistributedMesh("AddAllSideSetsByNormals");
48 
49  // Get the current list of boundaries so we can generate new ones that won't conflict
51 
52  // Create the map object that will be owned by MooseMesh
53  using map_type = std::map<BoundaryID, RealVectorValue>;
54  std::unique_ptr<map_type> boundary_map = libmesh_make_unique<map_type>();
55 
56  _visited.clear();
57 
58  // We'll need to loop over all of the elements to find ones that match this normal.
59  // We can't rely on flood catching them all here...
60  for (const auto & elem : _mesh_ptr->getMesh().element_ptr_range())
61  for (unsigned int side = 0; side < elem->n_sides(); ++side)
62  {
63  if (elem->neighbor_ptr(side))
64  continue;
65 
66  _fe_face->reinit(elem, side);
67  const std::vector<Point> & normals = _fe_face->get_normals();
68 
69  {
70  // See if we've seen this normal before (linear search)
71  const map_type::value_type * item = nullptr;
72  for (const auto & id_pair : *boundary_map)
73  if (std::abs(1.0 - id_pair.second * normals[0]) < 1e-5)
74  {
75  item = &id_pair;
76  break;
77  }
78 
79  if (item)
80  flood(elem, normals[0], item->first);
81  else
82  {
84  (*boundary_map)[id] = normals[0];
85  flood(elem, normals[0], id);
86  }
87  }
88  }
89 
90  finalize();
91 
92  // Transfer ownership of the boundary map and boundary ID set.
93  _mesh_ptr->setBoundaryToNormalMap(std::move(boundary_map));
95 }
96 
99 {
100  std::set<BoundaryID>::iterator it;
101  BoundaryID next_id = 1;
102 
103  while ((it = _mesh_boundary_ids.find(next_id)) != _mesh_boundary_ids.end())
104  ++next_id;
105 
106  _mesh_boundary_ids.insert(next_id);
107 
108  return next_id;
109 }
InputParameters validParams< AddAllSideSetsByNormals >()
MetaPhysicL::DualNumber< T, D > abs(const MetaPhysicL::DualNumber< T, D > &in)
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
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 setMeshBoundaryIDs(std::set< BoundaryID > boundary_IDs)
Sets the set of BoundaryIDs Is called by AddAllSideSetsByNormals.
Definition: MooseMesh.C:2340
void finalize()
This method finalizes the object, setting names back in the boundary_info object and releasing memory...
This class will add sidesets to the entire mesh based on unique normals.
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:2322
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
boundary_id_type BoundaryID
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:2346
virtual void modify() override
Pure virtual modify function MUST be overridden by children classes.
registerMooseObject("MooseApp", AddAllSideSetsByNormals)
void setup()
This method is used to construct the FE object so we can compute normals of faces.