www.mooseframework.org
PlaneDeletionGenerator.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 "PlaneDeletionGenerator.h"
11 
12 #include "libmesh/type_vector.h"
13 #include "libmesh/point.h"
14 #include "libmesh/elem.h"
15 
17 
20 {
22 
23  params.addClassDescription(
24  "Removes elements lying 'above' the plane (in the direction of the normal).");
25 
26  params.addRequiredParam<Point>("point", "The point that defines the plane");
27  params.addRequiredParam<RealVectorValue>("normal", "The normal that defines the plane");
28 
29  return params;
30 }
31 
33  : ElementDeletionGeneratorBase(parameters),
34  _point(getParam<Point>("point")),
35  _normal(getParam<RealVectorValue>("normal"))
36 {
37  if (!_normal.norm())
38  paramError("normal", "Normal vector must have a size!");
39 
40  // Make sure it's a unit vector
41  _normal /= _normal.norm();
42 }
43 
44 bool
46 {
47  auto centroid = elem->vertex_average();
48 
49  auto vec_from_plane_point = centroid - _point;
50 
51  auto norm = vec_from_plane_point.norm();
52 
53  // If we _perfectly_ hit a centroid... default to deleting the element
54  if (!norm)
55  return true;
56 
57  // Unitize it
58  vec_from_plane_point /= norm;
59 
60  return vec_from_plane_point * _normal > 0;
61 }
RealVectorValue _normal
Normal vector.
const Point & _point
Point defining the plane.
auto norm() const -> decltype(std::norm(Real()))
registerMooseObject("MooseApp", PlaneDeletionGenerator)
This class deletes elements from the mesh data structure after it has been generated or read but befo...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
PlaneDeletionGenerator(const InputParameters &parameters)
static InputParameters validParams()
Deletes elements lying above a plane.
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
auto norm(const T &a) -> decltype(std::abs(a))
virtual bool shouldDelete(const Elem *elem) override
Method that returns a Boolean indicating whether an element should be removed from the mesh...
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...