www.mooseframework.org
SideSetsGeneratorBase.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 "SideSetsGeneratorBase.h"
11 #include "Parser.h"
12 #include "InputParameters.h"
13 #include "MooseMesh.h"
14 
15 #include "libmesh/mesh_generation.h"
16 #include "libmesh/mesh.h"
17 #include "libmesh/string_to_enum.h"
18 #include "libmesh/quadrature_gauss.h"
19 #include "libmesh/point_locator_base.h"
20 #include "libmesh/fe_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  : MeshGenerator(parameters),
40  _variance(getParam<Real>("variance")),
41  _fixed_normal(getParam<bool>("fixed_normal"))
42 {
43 }
44 
46 
47 void
49 {
50  mooseAssert(_fe_face == nullptr, "FE Face has already been initialized");
51 
52  unsigned int dim = mesh.mesh_dimension();
53 
54  // Setup the FE Object so we can calculate normals
55  FEType fe_type(Utility::string_to_enum<Order>("CONSTANT"),
56  Utility::string_to_enum<FEFamily>("MONOMIAL"));
57  _fe_face = FEBase::build(dim, fe_type);
58  _qface = libmesh_make_unique<QGauss>(dim - 1, FIRST);
59  _fe_face->attach_quadrature_rule(_qface.get());
60 }
61 
62 void
64 {
65  _qface.reset();
66  _fe_face.reset();
67 }
68 
69 void
70 SideSetsGeneratorBase::flood(const Elem * elem,
71  Point normal,
72  boundary_id_type side_id,
73  MeshBase & mesh)
74 {
75  if (elem == nullptr || (_visited[side_id].find(elem) != _visited[side_id].end()))
76  return;
77 
78  _visited[side_id].insert(elem);
79  for (unsigned int side = 0; side < elem->n_sides(); ++side)
80  {
81  if (elem->neighbor_ptr(side))
82  continue;
83 
84  _fe_face->reinit(elem, side);
85  const std::vector<Point> normals = _fe_face->get_normals();
86 
87  // We'll just use the normal of the first qp
88  if (std::abs(1.0 - normal * normals[0]) <= _variance)
89  {
90  mesh.get_boundary_info().add_side(elem, side, side_id);
91  for (unsigned int neighbor = 0; neighbor < elem->n_sides(); ++neighbor)
92  {
93  // Flood to the neighboring elements using the current matching side normal from this
94  // element.
95  // This will allow us to tolerate small changes in the normals so we can "paint" around a
96  // curve.
97  flood(elem->neighbor_ptr(neighbor), _fixed_normal ? normal : normals[0], side_id, mesh);
98  }
99  }
100  }
101 }
MetaPhysicL::DualNumber< T, D > abs(const MetaPhysicL::DualNumber< T, D > &in)
SideSetsGeneratorBase(const InputParameters &parameters)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::unique_ptr< QGauss > _qface
std::unique_ptr< FEBase > _fe_face
void flood(const Elem *elem, Point normal, boundary_id_type side_id, MeshBase &mesh)
This method implements a recursive flood routine to paint a sideset of mesh to neighboring faces give...
void finalize()
This method finalizes the object, setting names back in the boundary_info object and releasing memory...
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< MeshGenerator >()
Definition: MeshGenerator.C:16
std::map< boundary_id_type, std::set< const Elem * > > _visited
InputParameters validParams< SideSetsGeneratorBase >()
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:30
void setup(MeshBase &mesh)
This method is used to construct the FE object so we can compute normals of faces.