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 
25  "11/30/2019 00:00",
27 
28 template <>
31 {
33 
34  params.addClassDescription("Adds sidesets to the entire mesh based on unique normals");
35 
36  return params;
37 }
38 
40  : AddSideSetsBase(parameters)
41 {
42 }
43 
44 void
46 {
47  setup();
48 
49  if (!_mesh_ptr)
50  mooseError("_mesh_ptr must be initialized before calling AddAllSideSetsByNormals::modify()!");
51 
52  // We can't call this in the constructor, it appears that _mesh_ptr is always NULL there.
53  _mesh_ptr->errorIfDistributedMesh("AddAllSideSetsByNormals");
54 
55  // Get the current list of boundaries so we can generate new ones that won't conflict
57 
58  // Create the map object that will be owned by MooseMesh
59  using map_type = std::map<BoundaryID, RealVectorValue>;
60  std::unique_ptr<map_type> boundary_map = libmesh_make_unique<map_type>();
61 
62  _visited.clear();
63 
64  // We'll need to loop over all of the elements to find ones that match this normal.
65  // We can't rely on flood catching them all here...
66  for (const auto & elem : _mesh_ptr->getMesh().element_ptr_range())
67  for (unsigned int side = 0; side < elem->n_sides(); ++side)
68  {
69  if (elem->neighbor_ptr(side))
70  continue;
71 
72  _fe_face->reinit(elem, side);
73  const std::vector<Point> & normals = _fe_face->get_normals();
74 
75  {
76  // See if we've seen this normal before (linear search)
77  const map_type::value_type * item = nullptr;
78  for (const auto & id_pair : *boundary_map)
79  if (std::abs(1.0 - id_pair.second * normals[0]) < 1e-5)
80  {
81  item = &id_pair;
82  break;
83  }
84 
85  if (item)
86  flood(elem, normals[0], item->first);
87  else
88  {
90  (*boundary_map)[id] = normals[0];
91  flood(elem, normals[0], id);
92  }
93  }
94  }
95 
96  finalize();
97 
98  // Transfer ownership of the boundary map and boundary ID set.
99  _mesh_ptr->setBoundaryToNormalMap(std::move(boundary_map));
101 }
102 
105 {
106  std::set<BoundaryID>::iterator it;
107  BoundaryID next_id = 1;
108 
109  while ((it = _mesh_boundary_ids.find(next_id)) != _mesh_boundary_ids.end())
110  ++next_id;
111 
112  _mesh_boundary_ids.insert(next_id);
113 
114  return next_id;
115 }
MooseMesh::setBoundaryToNormalMap
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:2368
AddSideSetsBase::finalize
void finalize()
This method finalizes the object, setting names back in the boundary_info object and releasing memory...
Definition: AddSideSetsBase.C:64
AddAllSideSetsByNormals
This class will add sidesets to the entire mesh based on unique normals.
Definition: AddAllSideSetsByNormals.h:26
MooseMesh.h
AllSideSetsByNormalsGenerator
This class will add sidesets to the entire mesh based on unique normals.
Definition: AllSideSetsByNormalsGenerator.h:25
Parser.h
MooseObject::mooseError
void mooseError(Args &&... args) const
Definition: MooseObject.h:141
AddAllSideSetsByNormals::getNextBoundaryID
BoundaryID getNextBoundaryID()
Definition: AddAllSideSetsByNormals.C:104
std::abs
MetaPhysicL::DualNumber< T, D > abs(const MetaPhysicL::DualNumber< T, D > &in)
AddSideSetsBase::setup
void setup()
This method is used to construct the FE object so we can compute normals of faces.
Definition: AddSideSetsBase.C:48
AddAllSideSetsByNormals.h
AddAllSideSetsByNormals::_mesh_boundary_ids
std::set< BoundaryID > _mesh_boundary_ids
A pointer to the Mesh's boundary set, this datastructure will be modified through this modifier.
Definition: AddAllSideSetsByNormals.h:40
AddSideSetsBase::_visited
std::map< BoundaryID, std::set< const Elem * > > _visited
Definition: AddSideSetsBase.h:66
validParams< AddSideSetsBase >
InputParameters validParams< AddSideSetsBase >()
Definition: AddSideSetsBase.C:25
InputParameters
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Definition: InputParameters.h:53
AddAllSideSetsByNormals::AddAllSideSetsByNormals
AddAllSideSetsByNormals(const InputParameters &parameters)
Definition: AddAllSideSetsByNormals.C:39
MeshModifier::_mesh_ptr
MooseMesh * _mesh_ptr
Pointer to the mesh.
Definition: MeshModifier.h:68
InputParameters.h
AddSideSetsBase::flood
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...
Definition: AddSideSetsBase.C:71
MooseMesh::getMesh
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2599
BoundaryID
boundary_id_type BoundaryID
Definition: AutomaticMortarGeneration.h:47
InputParameters::addClassDescription
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.
Definition: InputParameters.C:70
MooseMesh::meshBoundaryIds
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:2344
validParams< AddAllSideSetsByNormals >
InputParameters validParams< AddAllSideSetsByNormals >()
Definition: AddAllSideSetsByNormals.C:30
AddSideSetsBase
Definition: AddSideSetsBase.h:33
AddAllSideSetsByNormals::modify
virtual void modify() override
Pure virtual modify function MUST be overridden by children classes.
Definition: AddAllSideSetsByNormals.C:45
AddSideSetsBase::_fe_face
std::unique_ptr< FEBase > _fe_face
Definition: AddSideSetsBase.h:64
registerMooseObjectReplaced
registerMooseObjectReplaced("MooseApp", AddAllSideSetsByNormals, "11/30/2019 00:00", AllSideSetsByNormalsGenerator)
MooseMesh::errorIfDistributedMesh
void errorIfDistributedMesh(std::string name) const
Generate a unified error message if the underlying libMesh mesh is a DistributedMesh.
Definition: MooseMesh.C:2717
MooseMesh::setMeshBoundaryIDs
void setMeshBoundaryIDs(std::set< BoundaryID > boundary_IDs)
Sets the set of BoundaryIDs Is called by AddAllSideSetsByNormals.
Definition: MooseMesh.C:2362