https://mooseframework.inl.gov
Loading...
Searching...
No Matches
NearestNodeThread.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 "NearestNodeThread.h"
11#include "MooseMesh.h"
12
13#include "libmesh/threads.h"
14#include "libmesh/node.h"
15
16#include <cmath>
17
19 const MooseMesh & mesh, std::map<dof_id_type, std::vector<dof_id_type>> & neighbor_nodes)
20 : _max_patch_percentage(0.0), _mesh(mesh), _neighbor_nodes(neighbor_nodes)
21{
22}
23
24// Splitting Constructor
26 : _max_patch_percentage(x._max_patch_percentage),
27 _mesh(x._mesh),
28 _neighbor_nodes(x._neighbor_nodes)
29{
30}
31
38void
40{
41 for (const auto & node_id : range)
42 {
43 const Node & node = _mesh.nodeRef(node_id);
44
45 const Node * closest_node = NULL;
46 Real closest_distance = std::numeric_limits<Real>::max();
47
48 const std::vector<dof_id_type> & neighbor_nodes = _neighbor_nodes[node_id];
49
50 unsigned int n_neighbor_nodes = neighbor_nodes.size();
51
52 for (unsigned int k = 0; k < n_neighbor_nodes; k++)
53 {
54 const Node * cur_node = &_mesh.nodeRef(neighbor_nodes[k]);
55 Real distance = ((*cur_node) - node).norm();
56
57 if (distance < closest_distance)
58 {
59 Real patch_percentage = static_cast<Real>(k) / static_cast<Real>(n_neighbor_nodes);
60
61 // Save off the maximum we had to go through the patch to find the closes node
62 if (patch_percentage > _max_patch_percentage)
63 _max_patch_percentage = patch_percentage;
64
65 closest_distance = distance;
66 closest_node = cur_node;
67 }
68 }
69
70 if (closest_distance == std::numeric_limits<Real>::max())
71 {
72 for (unsigned int k = 0; k < n_neighbor_nodes; k++)
73 {
74 const Node * cur_node = &_mesh.nodeRef(neighbor_nodes[k]);
75 if (std::isnan((*cur_node)(0)) || std::isinf((*cur_node)(0)) ||
76 std::isnan((*cur_node)(1)) || std::isinf((*cur_node)(1)) ||
77 std::isnan((*cur_node)(2)) || std::isinf((*cur_node)(2)))
78 throw MooseException(
79 "Failure in NearestNodeThread because solution contains inf or not-a-number "
80 "entries. This is likely due to a failed factorization of the Jacobian "
81 "matrix.");
82 }
83 mooseError("Unable to find nearest node!");
84 }
85
87
88 info._nearest_node = closest_node;
89 info._distance = closest_distance;
90 }
91}
92
93void
95{
96 // Did the other one go further through the patch than this one?
99
100 _nearest_node_info.insert(other._nearest_node_info.begin(), other._nearest_node_info.end());
101}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Provides a way for users to bail out of the current solve.
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition MooseMesh.h:95
virtual const Node & nodeRef(const dof_id_type i) const
Definition MooseMesh.C:841
Data structure used to hold nearest node info.
std::map< dof_id_type, std::vector< dof_id_type > > & _neighbor_nodes
const MooseMesh & _mesh
void operator()(const NodeIdRange &range)
Save a patch of nodes that are close to each of the secondary nodes to speed the search algorithm TOD...
NearestNodeThread(const MooseMesh &mesh, std::map< dof_id_type, std::vector< dof_id_type > > &neighbor_nodes)
void join(const NearestNodeThread &other)
std::map< dof_id_type, NearestNodeLocator::NearestNodeInfo > _nearest_node_info
MeshBase & mesh
Real distance(const Point &p)