www.mooseframework.org
Public Member Functions | Public Attributes | Protected Attributes | List of all members
SlaveNeighborhoodThread Class Reference

#include <SlaveNeighborhoodThread.h>

Public Member Functions

 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)
 
 SlaveNeighborhoodThread (SlaveNeighborhoodThread &x, Threads::split split)
 Splitting Constructor. More...
 
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: This needs to be updated at some point in time. More...
 
void join (const SlaveNeighborhoodThread &other)
 

Public Attributes

KDTree_kd_tree
 
std::vector< dof_id_type > _slave_nodes
 List of the slave nodes we're actually going to keep track of. More...
 
std::map< dof_id_type, std::vector< dof_id_type > > _neighbor_nodes
 The neighborhood nodes associated with each node. More...
 
std::set< dof_id_type > _ghosted_elems
 Elements that we need to ghost. More...
 

Protected Attributes

const MooseMesh_mesh
 The Mesh. More...
 
const std::vector< dof_id_type > & _trial_master_nodes
 Nodes to search against. More...
 
const std::map< dof_id_type, std::vector< dof_id_type > > & _node_to_elem_map
 Node to elem map. More...
 
unsigned int _patch_size
 The number of nodes to keep. More...
 

Detailed Description

Definition at line 28 of file SlaveNeighborhoodThread.h.

Constructor & Destructor Documentation

SlaveNeighborhoodThread::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 
)

Definition at line 24 of file SlaveNeighborhoodThread.C.

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 }
const std::map< dof_id_type, std::vector< dof_id_type > > & _node_to_elem_map
Node to elem map.
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.
SlaveNeighborhoodThread::SlaveNeighborhoodThread ( SlaveNeighborhoodThread x,
Threads::split  split 
)

Splitting Constructor.

Definition at line 39 of file SlaveNeighborhoodThread.C.

41  : _kd_tree(x._kd_tree),
42  _mesh(x._mesh),
46 {
47 }
const std::map< dof_id_type, std::vector< dof_id_type > > & _node_to_elem_map
Node to elem map.
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.

Member Function Documentation

void SlaveNeighborhoodThread::join ( const SlaveNeighborhoodThread other)

Definition at line 181 of file SlaveNeighborhoodThread.C.

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 }
std::set< dof_id_type > _ghosted_elems
Elements that we need to ghost.
std::map< dof_id_type, std::vector< dof_id_type > > _neighbor_nodes
The neighborhood nodes associated with each node.
std::vector< dof_id_type > _slave_nodes
List of the slave nodes we&#39;re actually going to keep track of.
void SlaveNeighborhoodThread::operator() ( const NodeIdRange range)

Save a patch of nodes that are close to each of the slave nodes to speed the search algorithm TODO: This needs to be updated at some point in time.

If the hits into this data structure approach "the end" then it may be time to update

neighborSearch function takes the slave coordinates and patch_size as input and finds the k (=patch_size) nearest neighbors to the slave node from the trial master node set. The indices of the nearest neighbors are stored in the array return_index.

Now see if this processor needs to keep track of this slave and it's neighbors We're going to see if this processor owns the slave, any of the neighborhood nodes or any of the elements connected to either set. If it does then we're going to ghost all of the elements connected to the slave node and the neighborhood nodes to this processor. This is a very conservative approach that we might revisit later.

Definition at line 56 of file SlaveNeighborhoodThread.C.

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 }
virtual Elem * elemPtr(const dof_id_type i)
Definition: MooseMesh.C:2115
const std::map< dof_id_type, std::vector< dof_id_type > > & _node_to_elem_map
Node to elem map.
void neighborSearch(Point &query_point, unsigned int patch_size, std::vector< std::size_t > &return_index)
Definition: KDTree.C:31
std::set< dof_id_type > _ghosted_elems
Elements that we need to ghost.
std::map< dof_id_type, std::vector< dof_id_type > > _neighbor_nodes
The neighborhood nodes associated with each node.
virtual const Node & nodeRef(const dof_id_type i) const
Definition: MooseMesh.C:437
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.

Member Data Documentation

std::set<dof_id_type> SlaveNeighborhoodThread::_ghosted_elems

Elements that we need to ghost.

Definition at line 53 of file SlaveNeighborhoodThread.h.

Referenced by join(), and operator()().

KDTree& SlaveNeighborhoodThread::_kd_tree

Definition at line 31 of file SlaveNeighborhoodThread.h.

Referenced by operator()().

const MooseMesh& SlaveNeighborhoodThread::_mesh
protected

The Mesh.

Definition at line 57 of file SlaveNeighborhoodThread.h.

Referenced by operator()().

std::map<dof_id_type, std::vector<dof_id_type> > SlaveNeighborhoodThread::_neighbor_nodes

The neighborhood nodes associated with each node.

Definition at line 50 of file SlaveNeighborhoodThread.h.

Referenced by join(), and operator()().

const std::map<dof_id_type, std::vector<dof_id_type> >& SlaveNeighborhoodThread::_node_to_elem_map
protected

Node to elem map.

Definition at line 63 of file SlaveNeighborhoodThread.h.

Referenced by operator()().

unsigned int SlaveNeighborhoodThread::_patch_size
protected

The number of nodes to keep.

Definition at line 66 of file SlaveNeighborhoodThread.h.

Referenced by operator()().

std::vector<dof_id_type> SlaveNeighborhoodThread::_slave_nodes

List of the slave nodes we're actually going to keep track of.

Definition at line 47 of file SlaveNeighborhoodThread.h.

Referenced by join(), and operator()().

const std::vector<dof_id_type>& SlaveNeighborhoodThread::_trial_master_nodes
protected

Nodes to search against.

Definition at line 60 of file SlaveNeighborhoodThread.h.

Referenced by operator()().


The documentation for this class was generated from the following files: