www.mooseframework.org
SlaveNeighborhoodThread.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 
16 
17 #include "AuxiliarySystem.h"
18 #include "Problem.h"
19 #include "FEProblem.h"
20 #include "MooseMesh.h"
21 
22 #include "libmesh/threads.h"
23 
25  const MooseMesh & mesh,
26  const std::vector<dof_id_type> & trial_master_nodes,
27  const std::map<dof_id_type, std::vector<dof_id_type>> & node_to_elem_map,
28  const unsigned int patch_size,
29  KDTree & kd_tree)
30  : _kd_tree(kd_tree),
31  _mesh(mesh),
32  _trial_master_nodes(trial_master_nodes),
33  _node_to_elem_map(node_to_elem_map),
34  _patch_size(patch_size)
35 {
36 }
37 
38 // Splitting Constructor
40  Threads::split /*split*/)
41  : _kd_tree(x._kd_tree),
42  _mesh(x._mesh),
46 {
47 }
48 
55 void
57 {
58  processor_id_type processor_id = _mesh.processor_id();
59 
60  unsigned int patch_size =
61  std::min(_patch_size, static_cast<unsigned int>(_trial_master_nodes.size()));
62 
63  std::vector<std::size_t> return_index(patch_size);
64 
65  for (const auto & node_id : range)
66  {
67  const Node & node = _mesh.nodeRef(node_id);
68  Point query_pt;
69  for (unsigned int i = 0; i < LIBMESH_DIM; ++i)
70  query_pt(i) = node(i);
71 
82  _kd_tree.neighborSearch(query_pt, patch_size, return_index);
83 
84  std::vector<dof_id_type> neighbor_nodes(patch_size);
85  for (unsigned int i = 0; i < patch_size; ++i)
86  neighbor_nodes[i] = _trial_master_nodes[return_index[i]];
87 
96  bool need_to_track = false;
97 
98  if (_mesh.nodeRef(node_id).processor_id() == processor_id)
99  need_to_track = true;
100  else
101  {
102  {
103  auto node_to_elem_pair = _node_to_elem_map.find(node_id);
104  if (node_to_elem_pair != _node_to_elem_map.end())
105  {
106  const std::vector<dof_id_type> & elems_connected_to_node = node_to_elem_pair->second;
107 
108  // See if we own any of the elements connected to the slave node
109  for (const auto & dof : elems_connected_to_node)
110  if (_mesh.elemPtr(dof)->processor_id() == processor_id)
111  {
112  need_to_track = true;
113  break; // Break out of element loop
114  }
115  }
116  }
117 
118  if (!need_to_track)
119  { // Now check the neighbor nodes to see if we own any of them
120  for (const auto & neighbor_node_id : neighbor_nodes)
121  {
122  if (_mesh.nodeRef(neighbor_node_id).processor_id() == processor_id)
123  need_to_track = true;
124  else // Now see if we own any of the elements connected to the neighbor nodes
125  {
126  auto node_to_elem_pair = _node_to_elem_map.find(neighbor_node_id);
127  mooseAssert(node_to_elem_pair != _node_to_elem_map.end(),
128  "Missing entry in node to elem map");
129  const std::vector<dof_id_type> & elems_connected_to_node = node_to_elem_pair->second;
130 
131  for (const auto & dof : elems_connected_to_node)
132  if (_mesh.elemPtr(dof)->processor_id() == processor_id)
133  {
134  need_to_track = true;
135  break; // Break out of element loop
136  }
137  }
138 
139  if (need_to_track)
140  break; // Breaking out of neighbor loop
141  }
142  }
143  }
144 
145  if (need_to_track)
146  {
147  // Add this node as a slave node to search in the future
148  _slave_nodes.push_back(node_id);
149 
150  // Set it's neighbors
151  _neighbor_nodes[node_id] = neighbor_nodes;
152 
153  { // Add the elements connected to the slave node to the ghosted list
154  auto node_to_elem_pair = _node_to_elem_map.find(node_id);
155 
156  if (node_to_elem_pair != _node_to_elem_map.end())
157  {
158  const std::vector<dof_id_type> & elems_connected_to_node = node_to_elem_pair->second;
159 
160  for (const auto & dof : elems_connected_to_node)
161  _ghosted_elems.insert(dof);
162  }
163  }
164 
165  // Now add elements connected to the neighbor nodes to the ghosted list
166  for (unsigned int neighbor_it = 0; neighbor_it < neighbor_nodes.size(); neighbor_it++)
167  {
168  auto node_to_elem_pair = _node_to_elem_map.find(neighbor_nodes[neighbor_it]);
169  mooseAssert(node_to_elem_pair != _node_to_elem_map.end(),
170  "Missing entry in node to elem map");
171  const std::vector<dof_id_type> & elems_connected_to_node = node_to_elem_pair->second;
172 
173  for (const auto & dof : elems_connected_to_node)
174  _ghosted_elems.insert(dof);
175  }
176  }
177  }
178 }
179 
180 void
182 {
183  _slave_nodes.insert(_slave_nodes.end(), other._slave_nodes.begin(), other._slave_nodes.end());
184  _neighbor_nodes.insert(other._neighbor_nodes.begin(), other._neighbor_nodes.end());
185  _ghosted_elems.insert(other._ghosted_elems.begin(), other._ghosted_elems.end());
186 }
virtual Elem * elemPtr(const dof_id_type i)
Definition: MooseMesh.C:2062
Definition: KDTree.h:23
StoredRange< std::vector< dof_id_type >::iterator, dof_id_type > NodeIdRange
Definition: MooseTypes.h:81
const std::map< dof_id_type, std::vector< dof_id_type > > & _node_to_elem_map
Node to elem map.
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...
void neighborSearch(Point &query_point, unsigned int patch_size, std::vector< std::size_t > &return_index)
Definition: KDTree.C:31
static PetscErrorCode Vec x
std::set< dof_id_type > _ghosted_elems
Elements that we need to ghost.
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
std::map< dof_id_type, std::vector< dof_id_type > > _neighbor_nodes
The neighborhood nodes associated with each node.
SlaveNeighborhoodThread(const MooseMesh &mesh, const std::vector< dof_id_type > &trial_master_nodes, const std::map< dof_id_type, std::vector< dof_id_type >> &node_to_elem_map, const unsigned int patch_size, KDTree &_kd_tree)
virtual const Node & nodeRef(const dof_id_type i) const
Definition: MooseMesh.C:398
void join(const SlaveNeighborhoodThread &other)
std::vector< dof_id_type > _slave_nodes
List of the slave nodes we&#39;re actually going to keep track of.
const std::vector< dof_id_type > & _trial_master_nodes
Nodes to search against.
unsigned int _patch_size
The number of nodes to keep.
const MooseMesh & _mesh
The Mesh.