www.mooseframework.org
AddSideSetsBase.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 
10 #include "AddSideSetsBase.h"
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 
23 template <>
26 {
28  params.addParam<Real>(
29  "variance", 0.10, "The variance [0.0 - 1.0] allowed when comparing normals");
30  params.addParam<bool>("fixed_normal",
31  false,
32  "This Boolean determines whether we fix our normal "
33  "or allow it to vary to \"paint\" around curves");
34 
35  return params;
36 }
37 
39  : MeshModifier(parameters),
40  _variance(getParam<Real>("variance")),
41  _fixed_normal(getParam<bool>("fixed_normal"))
42 {
43 }
44 
46 
47 void
49 {
50  mooseAssert(_mesh_ptr, "Mesh pointer is NULL");
51  mooseAssert(_fe_face == nullptr, "FE Face has already been initialized");
52 
53  unsigned int dim = _mesh_ptr->dimension();
54 
55  // Setup the FE Object so we can calculate normals
56  FEType fe_type(Utility::string_to_enum<Order>("CONSTANT"),
57  Utility::string_to_enum<FEFamily>("MONOMIAL"));
58  _fe_face = FEBase::build(dim, fe_type);
59  _qface = libmesh_make_unique<QGauss>(dim - 1, FIRST);
60  _fe_face->attach_quadrature_rule(_qface.get());
61 }
62 
63 void
65 {
66  _qface.reset();
67  _fe_face.reset();
68 }
69 
70 void
71 AddSideSetsBase::flood(const Elem * elem, Point normal, BoundaryID side_id)
72 {
73  if (elem == nullptr || (_visited[side_id].find(elem) != _visited[side_id].end()))
74  return;
75 
76  _visited[side_id].insert(elem);
77  for (unsigned int side = 0; side < elem->n_sides(); ++side)
78  {
79  if (elem->neighbor_ptr(side))
80  continue;
81 
82  _fe_face->reinit(elem, side);
83  const std::vector<Point> normals = _fe_face->get_normals();
84 
85  // We'll just use the normal of the first qp
86  if (std::abs(1.0 - normal * normals[0]) <= _variance)
87  {
88  _mesh_ptr->getMesh().get_boundary_info().add_side(elem, side, side_id);
89  for (unsigned int neighbor = 0; neighbor < elem->n_sides(); ++neighbor)
90  {
91  // Flood to the neighboring elements using the current matching side normal from this
92  // element.
93  // This will allow us to tolerate small changes in the normals so we can "paint" around a
94  // curve.
95  flood(elem->neighbor_ptr(neighbor), _fixed_normal ? normal : normals[0], side_id);
96  }
97  }
98  }
99 }
MetaPhysicL::DualNumber< T, D > abs(const MetaPhysicL::DualNumber< T, D > &in)
std::unique_ptr< FEBase > _fe_face
MeshModifiers are objects that can modify or add to an existing mesh.
Definition: MeshModifier.h:25
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
AddSideSetsBase(const InputParameters &parameters)
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:68
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2567
virtual unsigned int dimension() const
Returns MeshBase::mesh_dimsension(), (not MeshBase::spatial_dimension()!) of the underlying libMesh m...
Definition: MooseMesh.C:2133
boundary_id_type BoundaryID
virtual ~AddSideSetsBase()
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...
std::unique_ptr< QGauss > _qface
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
InputParameters validParams< MeshModifier >()
Definition: MeshModifier.C:15
void setup()
This method is used to construct the FE object so we can compute normals of faces.