https://mooseframework.inl.gov
ShortestDistanceToSurfaceTestAux.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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 
12 #include "SBMSurfaceMeshBuilder.h"
13 #include "Function.h"
14 
15 registerMooseObject("ShiftedBoundaryMethodTestApp", ShortestDistanceToSurfaceTestAux);
16 
19 {
21 
22  params.addRequiredParam<UserObjectName>("distance_to_surface",
23  "ShortestDistanceToSurface user object to query.");
24 
25  MooseEnum methods("true_normal distance_by_index true_normal_by_index "
26  "distance_by_func true_normal_by_func");
28  "method", methods, "Which ShortestDistanceToSurface accessor to call.");
29 
30  MooseEnum components("x y z norm", "norm");
31  params.addParam<MooseEnum>(
32  "component", components, "Vector component returned by computeValue (default: norm).");
33 
34  params.addParam<unsigned int>("index", 0, "Surface index used for the *ByIndex variants.");
35 
36  params.addParam<FunctionName>("function", "Function used for the *ByFunc variants.");
37 
38  params.addParam<Point>(
39  "at_point",
40  "Optional fixed query point. If supplied, the accessor is evaluated at this "
41  "point instead of the current element's centroid (useful for hitting "
42  "zero-distance branches at a surface-mesh node).");
43 
44  params.addParam<UserObjectName>(
45  "builder",
46  "Optional SBMSurfaceMeshBuilder; when supplied, initialSetup queries "
47  "getCentroids() so coverage tests can touch that otherwise-unused getter.");
48 
49  params.addClassDescription("Test-only AuxKernel that exposes ShortestDistanceToSurface accessors "
50  "(trueNormal, *ByIndex, *ByFunc) for coverage testing.");
51 
52  return params;
53 }
54 
56  const InputParameters & parameters)
57  : AuxKernel(parameters),
58  _distance_to_surface(getUserObject<ShortestDistanceToSurface>("distance_to_surface")),
59  _builder(isParamValid("builder") ? &getUserObject<SBMSurfaceMeshBuilder>("builder") : nullptr),
60  _method(getParam<MooseEnum>("method")),
61  _component(getParam<MooseEnum>("component")),
62  _index(getParam<unsigned int>("index")),
63  _function(isParamValid("function") ? &getFunction("function") : nullptr),
64  _use_at_point(isParamValid("at_point")),
65  _at_point(_use_at_point ? getParam<Point>("at_point") : Point())
66 {
67  if (isNodal())
68  paramError("variable", "This AuxKernel only supports Elemental fields");
69 
70  const bool needs_function = _method == "distance_by_func" || _method == "true_normal_by_func";
71  if (needs_function && !_function)
72  paramError("function", "A 'function' parameter is required for the *_by_func methods.");
73 }
74 
75 void
77 {
78  if (_builder && _builder->getCentroids().empty())
79  mooseError("ShortestDistanceToSurfaceTestAux: builder '",
80  _builder->name(),
81  "' returned no centroids.");
82 }
83 
84 Real
86 {
87  const Point pt = _use_at_point ? _at_point : _current_elem->vertex_average();
88 
90  if (_method == "true_normal")
92  else if (_method == "distance_by_index")
94  else if (_method == "true_normal_by_index")
96  else if (_method == "distance_by_func")
98  else
100 
101  if (_component == "x")
102  return v(0);
103  if (_component == "y")
104  return v(1);
105  if (_component == "z")
106  return v(2);
107  return v.norm();
108 }
RealVectorValue trueNormalByFunc(const Point &pt, Real t, const Function *func) const
Compute true normal using a specific distance function.
ShortestDistanceToSurfaceTestAux(const InputParameters &parameters)
void paramError(const std::string &param, Args... args) const
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
registerMooseObject("ShiftedBoundaryMethodTestApp", ShortestDistanceToSurfaceTestAux)
const double v
void addRequiredParam(const std::string &name, const std::string &doc_string)
Test-only AuxKernel that exposes the rarely-called ShortestDistanceToSurface accessors (trueNormal...
const std::string & name() const
const ShortestDistanceToSurface & _distance_to_surface
const std::vector< Point > & getCentroids() const
Get the centroids of the boundary elements.
User object that computes the shortest distance to one or more surfaces defined by function- and/or m...
RealVectorValue distanceVectorByIndex(unsigned int idx, const Point &pt) const
A distance vector from a point pt to a specific surface specified by index idx in the &#39;surfaces&#39; para...
const SBMSurfaceMeshBuilder *const _builder
RealVectorValue trueNormal(const Point &pt) const
Return the true normal vector at the closest point on the boundaries.
RealVectorValue distanceVectorByFunc(const Point &pt, Real t, const Function *func) const
Compute distance vector using a specific distance function.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
RealVectorValue trueNormalByIndex(unsigned int idx, const Point &pt) const
A true normal vector at the projected point of pt onto a specific surface specified by index idx in t...
virtual void initialSetup() override
If a &#39;builder&#39; was supplied, calls SBMSurfaceMeshBuilder::getCentroids() once and verifies it is non-...
void mooseError(Args &&... args) const
const Elem *const & _current_elem
void addClassDescription(const std::string &doc_string)
static InputParameters validParams()
const bool _use_at_point
If set, queries are evaluated at this fixed point instead of the current element centroid.
void ErrorVector unsigned int