https://mooseframework.inl.gov
Loading...
Searching...
No Matches
NearestNodeNumberUO.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
10#include "NearestNodeNumberUO.h"
11#include <limits>
12
14
17{
19 params.addRequiredParam<Point>("point", "The point");
20 params.addClassDescription("Finds and outputs the nearest node number to a point");
21 return params;
22}
23
25 : NodalUserObject(parameters),
26 _my_pid(processor_id()),
27 _point(getParam<Point>("point")),
28 _node_found(false),
29 _min_distance(std::numeric_limits<Real>::max()),
30 _closest_node(nullptr),
31 _overall_best_id(0)
32{
33}
34
35void
37{
38 _node_found = false;
39 _min_distance = std::numeric_limits<Real>::max();
40 _min_distance = std::numeric_limits<Real>::max();
41 _closest_node = nullptr;
42}
43
44void
46{
47 if (!_node_found)
48 {
49 _min_distance = std::numeric_limits<Real>::max();
50 _closest_node = nullptr;
51 }
52}
53
54void
56{
57 if (_node_found)
58 return;
59 const Real dist = ((*_current_node) - _point).norm();
60 if (dist < _min_distance || (dist == _min_distance && _current_node->id() < _closest_node->id()))
61 {
62 _min_distance = dist;
64 }
65}
66
67void
69{
70 Real overall_min_distance = _min_distance;
71 gatherMin(overall_min_distance);
72 _overall_best_id = (overall_min_distance == _min_distance)
73 ? _closest_node->id()
74 : std::numeric_limits<dof_id_type>::max();
76 _node_found = true;
77}
78
79dof_id_type
84
85const Node *
87{
88 if (!_closest_node) // probably no evaluation has occurred
89 return nullptr;
90 if (_closest_node->id() == _overall_best_id && _closest_node->processor_id() == _my_pid)
91 return _closest_node;
92 return nullptr;
93}
94
95void
97{
98 const auto & nnn = static_cast<const NearestNodeNumberUO &>(y);
99 if (!nnn._closest_node)
100 return;
101 if (nnn._min_distance < _min_distance ||
102 (nnn._min_distance == _min_distance && nnn._closest_node->id() < _closest_node->id()))
103 {
105 _closest_node = nnn._closest_node;
106 }
107}
registerMooseObject("MooseApp", NearestNodeNumberUO)
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...
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.
Finds the nearest node to a given point.
const Node * _closest_node
Nearest node on this processor.
dof_id_type getClosestNodeId() const
Returns the ID of the nearest node.
virtual void threadJoin(const UserObject &y) override
Must override.
Real _min_distance
Minimum distance for nodes on this processor.
virtual void execute() override
Execute method.
dof_id_type _overall_best_id
Node number of closest node, over the whole mesh.
NearestNodeNumberUO(const InputParameters &parameters)
static InputParameters validParams()
virtual void meshChanged() override
Called on this object when the mesh changes.
bool _node_found
Whether the nearest node on this processor has been found (this is used to reduce unnecessary re-comp...
const Point & _point
The point.
const processor_id_type _my_pid
processor ID of this object
const Node * getClosestNode() const
Returns a const pointer to the closest node over the entire mesh, if that node is owned by this proce...
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
virtual void finalize() override
Finalize.
A user object that runs over all the nodes and does an aggregation step to compute a single value.
const Node *const & _current_node
Reference to current node pointer.
static InputParameters validParams()
void gatherMin(T &value)
Gather the parallel min of the variable passed in.
Base class for user-specific data.
Definition UserObject.h:20