https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Attributes | List of all members
SecondaryNeighborhoodThread Class Reference

#include <SecondaryNeighborhoodThread.h>

Public Member Functions

 SecondaryNeighborhoodThread (const MooseMesh &mesh, const std::vector< dof_id_type > &trial_primary_nodes, const std::unordered_map< dof_id_type, std::vector< dof_id_type > > &node_to_elem_map, const unsigned int patch_size, KDTree &_kd_tree)
 
 SecondaryNeighborhoodThread (SecondaryNeighborhoodThread &x, Threads::split split)
 Splitting Constructor.
 
void operator() (const NodeIdRange &range)
 Save a patch of nodes that are close to each of the secondary nodes to speed the search algorithm TODO: This needs to be updated at some point in time.
 
void join (const SecondaryNeighborhoodThread &other)
 

Public Attributes

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

Protected Attributes

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

Detailed Description

Definition at line 22 of file SecondaryNeighborhoodThread.h.

Constructor & Destructor Documentation

◆ SecondaryNeighborhoodThread() [1/2]

SecondaryNeighborhoodThread::SecondaryNeighborhoodThread ( const MooseMesh mesh,
const std::vector< dof_id_type > &  trial_primary_nodes,
const std::unordered_map< dof_id_type, std::vector< dof_id_type > > &  node_to_elem_map,
const unsigned int  patch_size,
KDTree _kd_tree 
)

Definition at line 19 of file SecondaryNeighborhoodThread.C.

25 : _kd_tree(kd_tree),
26 _mesh(mesh),
27 _trial_primary_nodes(trial_primary_nodes),
28 _node_to_elem_map(node_to_elem_map),
29 _patch_size(patch_size)
30{
31}
const std::vector< dof_id_type > & _trial_primary_nodes
Nodes to search against.
const std::unordered_map< dof_id_type, std::vector< dof_id_type > > & _node_to_elem_map
Node to elem map.
unsigned int _patch_size
The number of nodes to keep.

◆ SecondaryNeighborhoodThread() [2/2]

SecondaryNeighborhoodThread::SecondaryNeighborhoodThread ( SecondaryNeighborhoodThread x,
Threads::split  split 
)

Splitting Constructor.

Definition at line 34 of file SecondaryNeighborhoodThread.C.

Member Function Documentation

◆ join()

void SecondaryNeighborhoodThread::join ( const SecondaryNeighborhoodThread other)

Definition at line 175 of file SecondaryNeighborhoodThread.C.

176{
177 _secondary_nodes.insert(
178 _secondary_nodes.end(), other._secondary_nodes.begin(), other._secondary_nodes.end());
179 _ghosted_elems.insert(other._ghosted_elems.begin(), other._ghosted_elems.end());
180 _neighbor_nodes.insert(other._neighbor_nodes.begin(), other._neighbor_nodes.end());
181}
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 > _secondary_nodes
List of the secondary nodes we're actually going to keep track of.

◆ operator()()

void SecondaryNeighborhoodThread::operator() ( const NodeIdRange range)

Save a patch of nodes that are close to each of the secondary 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 secondary coordinates and patch_size as input and finds the k (=patch_size) nearest neighbors to the secondary node from the trial primary 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 secondary and it's neighbors We're going to see if this processor owns the secondary, 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 secondary node and the neighborhood nodes to this processor. This is a very conservative approach that we might revisit later.

Definition at line 51 of file SecondaryNeighborhoodThread.C.

52{
53 unsigned int patch_size =
54 std::min(_patch_size, static_cast<unsigned int>(_trial_primary_nodes.size()));
55
56 std::vector<std::size_t> return_index(patch_size);
57
58 for (const auto & node_id : range)
59 {
60 const Node & node = _mesh.nodeRef(node_id);
61 Point query_pt;
62 for (const auto i : make_range(Moose::dim))
63 query_pt(i) = node(i);
64
75 _kd_tree.neighborSearch(query_pt, patch_size, return_index);
76
77 std::vector<dof_id_type> neighbor_nodes(return_index.size());
78 for (unsigned int i = 0; i < return_index.size(); ++i)
79 neighbor_nodes[i] = _trial_primary_nodes[return_index[i]];
80
81 processor_id_type processor_id = _mesh.processor_id();
82
91 bool need_to_track = false;
92
93 if (_mesh.nodeRef(node_id).processor_id() == processor_id)
94 need_to_track = true;
95 else
96 {
97 {
98 auto node_to_elem_pair = _node_to_elem_map.find(node_id);
99 if (node_to_elem_pair != _node_to_elem_map.end())
100 {
101 const std::vector<dof_id_type> & elems_connected_to_node = node_to_elem_pair->second;
102
103 // See if we own any of the elements connected to the secondary node
104 for (const auto & dof : elems_connected_to_node)
105 if (_mesh.elemPtr(dof)->processor_id() == processor_id)
106 {
107 need_to_track = true;
108 break; // Break out of element loop
109 }
110 }
111 }
112
113 if (!need_to_track)
114 { // Now check the neighbor nodes to see if we own any of them
115 for (const auto & neighbor_node_id : neighbor_nodes)
116 {
117 if (_mesh.nodeRef(neighbor_node_id).processor_id() == processor_id)
118 need_to_track = true;
119 else // Now see if we own any of the elements connected to the neighbor nodes
120 {
121 auto node_to_elem_pair = _node_to_elem_map.find(neighbor_node_id);
122 mooseAssert(node_to_elem_pair != _node_to_elem_map.end(),
123 "Missing entry in node to elem map");
124 const std::vector<dof_id_type> & elems_connected_to_node = node_to_elem_pair->second;
125
126 for (const auto & dof : elems_connected_to_node)
127 if (_mesh.elemPtr(dof)->processor_id() == processor_id)
128 {
129 need_to_track = true;
130 break; // Break out of element loop
131 }
132 }
133
134 if (need_to_track)
135 break; // Breaking out of neighbor loop
136 }
137 }
138 }
139
140 if (need_to_track)
141 {
142 // Add this node as a secondary node to search in the future
143 _secondary_nodes.push_back(node_id);
144
145 // Set it's neighbors
146 _neighbor_nodes[node_id] = neighbor_nodes;
147
148 { // Add the elements connected to the secondary node to the ghosted list
149 auto node_to_elem_pair = _node_to_elem_map.find(node_id);
150
151 if (node_to_elem_pair != _node_to_elem_map.end())
152 {
153 const std::vector<dof_id_type> & elems_connected_to_node = node_to_elem_pair->second;
154
155 for (const auto & dof : elems_connected_to_node)
156 _ghosted_elems.insert(dof);
157 }
158 }
159 // Now add elements connected to the neighbor nodes to the ghosted list
160 for (unsigned int neighbor_it = 0; neighbor_it < neighbor_nodes.size(); neighbor_it++)
161 {
162 auto node_to_elem_pair = _node_to_elem_map.find(neighbor_nodes[neighbor_it]);
163 mooseAssert(node_to_elem_pair != _node_to_elem_map.end(),
164 "Missing entry in node to elem map");
165 const std::vector<dof_id_type> & elems_connected_to_node = node_to_elem_pair->second;
166
167 for (const auto & dof : elems_connected_to_node)
168 _ghosted_elems.insert(dof);
169 }
170 }
171 }
172}
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
unsigned int dim
void neighborSearch(const Point &query_point, unsigned int patch_size, std::vector< std::size_t > &return_index)
Definition KDTree.C:38
virtual const Node & nodeRef(const dof_id_type i) const
Definition MooseMesh.C:841
processor_id_type processor_id() const
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
uint8_t processor_id_type
IntRange< T > make_range(T beg, T end)

Member Data Documentation

◆ _ghosted_elems

std::set<dof_id_type> SecondaryNeighborhoodThread::_ghosted_elems

Elements that we need to ghost.

Definition at line 48 of file SecondaryNeighborhoodThread.h.

Referenced by NearestNodeLocator::findNodes(), join(), operator()(), and NearestNodeLocator::updatePatch().

◆ _kd_tree

KDTree& SecondaryNeighborhoodThread::_kd_tree

Definition at line 25 of file SecondaryNeighborhoodThread.h.

Referenced by operator()().

◆ _mesh

const MooseMesh& SecondaryNeighborhoodThread::_mesh
protected

The Mesh.

Definition at line 52 of file SecondaryNeighborhoodThread.h.

Referenced by operator()().

◆ _neighbor_nodes

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

The neighborhood nodes associated with each node.

Definition at line 45 of file SecondaryNeighborhoodThread.h.

Referenced by NearestNodeLocator::findNodes(), join(), operator()(), and NearestNodeLocator::updatePatch().

◆ _node_to_elem_map

const std::unordered_map<dof_id_type, std::vector<dof_id_type> >& SecondaryNeighborhoodThread::_node_to_elem_map
protected

Node to elem map.

Definition at line 58 of file SecondaryNeighborhoodThread.h.

Referenced by operator()().

◆ _patch_size

unsigned int SecondaryNeighborhoodThread::_patch_size
protected

The number of nodes to keep.

Definition at line 61 of file SecondaryNeighborhoodThread.h.

Referenced by operator()().

◆ _secondary_nodes

std::vector<dof_id_type> SecondaryNeighborhoodThread::_secondary_nodes

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

Definition at line 42 of file SecondaryNeighborhoodThread.h.

Referenced by NearestNodeLocator::findNodes(), join(), operator()(), and NearestNodeLocator::updatePatch().

◆ _trial_primary_nodes

const std::vector<dof_id_type>& SecondaryNeighborhoodThread::_trial_primary_nodes
protected

Nodes to search against.

Definition at line 55 of file SecondaryNeighborhoodThread.h.

Referenced by operator()().


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