www.mooseframework.org
NearestNodeThread.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "NearestNodeThread.h"
16 #include "MooseMesh.h"
17 
18 #include "libmesh/threads.h"
19 
20 #include <cmath>
21 
23  const MooseMesh & mesh, std::map<dof_id_type, std::vector<dof_id_type>> & neighbor_nodes)
24  : _max_patch_percentage(0.0), _mesh(mesh), _neighbor_nodes(neighbor_nodes)
25 {
26 }
27 
28 // Splitting Constructor
31  _mesh(x._mesh),
33 {
34 }
35 
42 void
44 {
45  for (const auto & node_id : range)
46  {
47  const Node & node = _mesh.nodeRef(node_id);
48 
49  const Node * closest_node = NULL;
50  Real closest_distance = std::numeric_limits<Real>::max();
51 
52  const std::vector<dof_id_type> & neighbor_nodes = _neighbor_nodes[node_id];
53 
54  unsigned int n_neighbor_nodes = neighbor_nodes.size();
55 
56  for (unsigned int k = 0; k < n_neighbor_nodes; k++)
57  {
58  const Node * cur_node = &_mesh.nodeRef(neighbor_nodes[k]);
59  Real distance = ((*cur_node) - node).norm();
60 
61  if (distance < closest_distance)
62  {
63  Real patch_percentage = static_cast<Real>(k) / static_cast<Real>(n_neighbor_nodes);
64 
65  // Save off the maximum we had to go through the patch to find the closes node
66  if (patch_percentage > _max_patch_percentage)
67  _max_patch_percentage = patch_percentage;
68 
69  closest_distance = distance;
70  closest_node = cur_node;
71  }
72  }
73 
74  if (closest_distance == std::numeric_limits<Real>::max())
75  {
76  for (unsigned int k = 0; k < n_neighbor_nodes; k++)
77  {
78  const Node * cur_node = &_mesh.nodeRef(neighbor_nodes[k]);
79  if (std::isnan((*cur_node)(0)) || std::isinf((*cur_node)(0)) ||
80  std::isnan((*cur_node)(1)) || std::isinf((*cur_node)(1)) ||
81  std::isnan((*cur_node)(2)) || std::isinf((*cur_node)(2)))
82  mooseError("Failure in NearestNodeThread because solution contains inf or not-a-number "
83  "entries. This is likely due to a failed factorization of the Jacobian "
84  "matrix.");
85  }
86  mooseError("Unable to find nearest node!");
87  }
88 
90 
91  info._nearest_node = closest_node;
92  info._distance = closest_distance;
93  }
94 }
95 
96 void
98 {
99  // Did the other one go further through the patch than this one?
102 
103  _nearest_node_info.insert(other._nearest_node_info.begin(), other._nearest_node_info.end());
104 }
std::map< dof_id_type, std::vector< dof_id_type > > & _neighbor_nodes
StoredRange< std::vector< dof_id_type >::iterator, dof_id_type > NodeIdRange
Definition: MooseTypes.h:81
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
std::map< dof_id_type, NearestNodeLocator::NearestNodeInfo > _nearest_node_info
void join(const NearestNodeThread &other)
static PetscErrorCode Vec x
Data structure used to hold nearest node info.
const MooseMesh & _mesh
NearestNodeThread(const MooseMesh &mesh, std::map< dof_id_type, std::vector< dof_id_type >> &neighbor_nodes)
void operator()(const NodeIdRange &range)
Save a patch of nodes that are close to each of the slave nodes to speed the search algorithm TODO: T...
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
virtual const Node & nodeRef(const dof_id_type i) const
Definition: MooseMesh.C:437