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