https://mooseframework.inl.gov
Loading...
Searching...
No Matches
UnsignedDistanceToSurfaceMesh.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
11#include "MooseError.h"
13
15
18{
20 params.addRequiredParam<UserObjectName>(
21 "builder", "SBMSurfaceMeshBuilder that provides KDTree, elem_id_map, and boundary elements.");
22
24 "Returns unsigned distance to a surface mesh using KDTree nearest neighbor search. "
25 "The gradient returns the unit vector pointing from boundary to query point.");
26 return params;
27}
28
33
34void
36{
37 const auto builder = &getUserObject<SBMSurfaceMeshBuilder>("builder");
38
39 if (!builder->hasKDTree())
40 mooseError("UnsignedDistanceToSurfaceMesh '",
41 name(),
42 "' requires SBMSurfaceMeshBuilder '",
43 builder->name(),
44 "' to be configured with 'build_kd_tree = true'.");
45
46 _kd_tree = &builder->getKDTree();
47 _boundary_elements = &builder->getBoundaryElements();
48}
49
52{
53 // KDTree nearest neighbor search
54 std::vector<std::size_t> ret_index(1);
55 _kd_tree->neighborSearch(p, 1, ret_index);
56
57 return *_boundary_elements->at(ret_index.front()).get();
58}
59
60RealVectorValue
62{
64 return elem.distanceFrom(p);
65}
66
67Real
68UnsignedDistanceToSurfaceMesh::value(Real /*t*/, const Point & p) const
69{
70 return distanceVectorToSurface(p).norm();
71}
72
73RealGradient
74UnsignedDistanceToSurfaceMesh::gradient(Real /*t*/, const Point & p) const
75{
76 const RealVectorValue dv = distanceVectorToSurface(p);
77 const Real dist = dv.norm();
78
79 if (dist <= libMesh::TOLERANCE)
80 return RealGradient(0, 0, 0);
81
82 // dv points from the query point toward the nearest surface, so -dv points away from it.
83 // The gradient of a distance field points toward increasing distance (away from the surface),
84 // matching the signed-distance gradient convention used by SBMUtils::distanceVectorFromFunction.
85 return -dv / dist;
86}
87
88RealVectorValue
90{
92
93 RealVectorValue n = elem.normal();
94 const Real n_norm = n.norm();
95
96 return n / n_norm;
97}
const Real p
registerMooseObject("ShiftedBoundaryMethodApp", UnsignedDistanceToSurfaceMesh)
static InputParameters validParams()
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void neighborSearch(const Point &query_point, unsigned int patch_size, std::vector< std::size_t > &return_index)
const std::string & name() const
void mooseError(Args &&... args) const
Base class for SBM boundary elements.
virtual Point distanceFrom(const Point &pt) const
Compute the distance vector from an arbitrary point to this boundary element.
const Point & normal() const
Getter for the normal vector.
Computes the unsigned distance to a surface mesh using KDTree nearest neighbor lookup from SBMSurface...
KDTree * _kd_tree
Cached pointers for speed.
RealVectorValue surfaceNormal(const Point &p) const
Return the true boundary surface normal evaluated at the closest point obtained by projecting the que...
const std::vector< std::unique_ptr< SBMBndElementBase > > * _boundary_elements
const SBMBndElementBase & closestBoundaryElem(const Point &p) const
find closest boundary element using KDTree
Real value(Real t, const Point &p) const override
Return unsigned distance value.
RealGradient gradient(Real t, const Point &p) const override
Return the spatial gradient of the unsigned distance function.
RealVectorValue distanceVectorToSurface(const Point &p) const
find closest boundary element and return its distance vector
UnsignedDistanceToSurfaceMesh(const InputParameters &parameters)
static constexpr Real TOLERANCE