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

Finds the nearest node to each node in boundary1 to each node in boundary2 and the other way around. More...

#include <NearestNodeLocator.h>

Inheritance diagram for NearestNodeLocator:
[legend]

Classes

class  NearestNodeInfo
 Data structure used to hold nearest node info. More...
 

Public Member Functions

 NearestNodeLocator (SubProblem &subproblem, MooseMesh &mesh, BoundaryID boundary1, BoundaryID boundary2)
 
 ~NearestNodeLocator ()
 
void findNodes ()
 This is the main method that is going to start the search. More...
 
void reinit ()
 Completely redo the search from scratch. More...
 
Real distance (dof_id_type node_id)
 Valid to call this after findNodes() has been called to get the distance to the nearest node. More...
 
const Node * nearestNode (dof_id_type node_id)
 Valid to call this after findNodes() has been called to get a pointer to the nearest node. More...
 
std::vector< dof_id_type > & slaveNodes ()
 Returns the list of slave nodes this Locator is tracking. More...
 
NodeIdRangeslaveNodeRange ()
 Returns the NodeIdRange of slave nodes to be used for calling threaded functions operating on the slave nodes. More...
 
void updatePatch (std::vector< dof_id_type > &slave_nodes)
 Reconstructs the KDtree, updates the patch for the nodes in slave_nodes, and updates the closest neighbor for these nodes in nearest node info. More...
 
void updateGhostedElems ()
 Updates the ghosted elements at the start of the time step for iterion patch update strategy. More...
 

Public Attributes

std::map< dof_id_type, NearestNodeInfo_nearest_node_info
 
BoundaryID _boundary1
 
BoundaryID _boundary2
 
bool _first
 
std::vector< dof_id_type > _slave_nodes
 
std::map< dof_id_type, std::vector< dof_id_type > > _neighbor_nodes
 
const Moose::PatchUpdateType _patch_update_strategy
 
Real _max_patch_percentage
 
std::vector< dof_id_type > _new_ghosted_elems
 
PerfID _find_nodes_timer
 
PerfID _update_patch_timer
 
PerfID _reinit_timer
 
PerfID _update_ghosted_elems_timer
 

Static Public Attributes

static const unsigned int _patch_size
 

Protected Member Functions

template<typename T >
T & declareRestartableData (std::string data_name)
 Declare a piece of data as "restartable". More...
 
template<typename T >
T & declareRestartableData (std::string data_name, const T &init_value)
 Declare a piece of data as "restartable" and initialize it. More...
 
template<typename T >
T & declareRestartableDataWithContext (std::string data_name, void *context)
 Declare a piece of data as "restartable". More...
 
template<typename T >
T & declareRestartableDataWithContext (std::string data_name, const T &init_value, void *context)
 Declare a piece of data as "restartable" and initialize it. More...
 
template<typename T >
T & declareRecoverableData (std::string data_name)
 Declare a piece of data as "recoverable". More...
 
template<typename T >
T & declareRecoverableData (std::string data_name, const T &init_value)
 Declare a piece of data as "restartable" and initialize it. More...
 
template<typename T >
T & declareRestartableDataWithObjectName (std::string data_name, std::string object_name)
 Declare a piece of data as "restartable". More...
 
template<typename T >
T & declareRestartableDataWithObjectNameWithContext (std::string data_name, std::string object_name, void *context)
 Declare a piece of data as "restartable". More...
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level)
 Call to register a named section for timing. More...
 

Protected Attributes

SubProblem_subproblem
 
MooseMesh_mesh
 
NodeIdRange_slave_node_range
 
const InputParameters_pg_params
 Params. More...
 
PerfGraph_perf_graph
 The performance graph to add to. More...
 
std::string _prefix
 A prefix to use for all sections. More...
 

Detailed Description

Finds the nearest node to each node in boundary1 to each node in boundary2 and the other way around.

Definition at line 25 of file NearestNodeLocator.h.

Constructor & Destructor Documentation

◆ NearestNodeLocator()

NearestNodeLocator::NearestNodeLocator ( SubProblem subproblem,
MooseMesh mesh,
BoundaryID  boundary1,
BoundaryID  boundary2 
)

Definition at line 26 of file NearestNodeLocator.C.

30  : Restartable(subproblem.getMooseApp(),
31  Moose::stringify(boundary1) + Moose::stringify(boundary2),
32  "NearestNodeLocator",
33  0),
35  "NearestNodeLocator_" + Moose::stringify(boundary1) + "_" +
36  Moose::stringify(boundary2)),
37  _subproblem(subproblem),
38  _mesh(mesh),
39  _slave_node_range(NULL),
40  _boundary1(boundary1),
41  _boundary2(boundary2),
42  _first(true),
44  _find_nodes_timer(registerTimedSection("findNodes", 3)),
45  _update_patch_timer(registerTimedSection("updatePatch", 3)),
46  _reinit_timer(registerTimedSection("reinit", 3)),
47  _update_ghosted_elems_timer(registerTimedSection("updateGhostedElems", 5))
48 {
49  /*
50  //sanity check on boundary ids
51  const std::set<BoundaryID>& bids=_mesh.getBoundaryIDs();
52  std::set<BoundaryID>::const_iterator sit;
53  sit=bids.find(_boundary1);
54  if (sit == bids.end())
55  mooseError("NearestNodeLocator being created for boundaries ", _boundary1, " and ", _boundary2,
56  ", but boundary ", _boundary1, " does not exist");
57  sit=bids.find(_boundary2);
58  if (sit == bids.end())
59  mooseError("NearestNodeLocator being created for boundaries ", _boundary1, " and ", _boundary2,
60  ", but boundary ", _boundary2, " does not exist");
61  */
62 }
PerfID registerTimedSection(const std::string &section_name, const unsigned int level)
Call to register a named section for timing.
const Moose::PatchUpdateType _patch_update_strategy
NodeIdRange * _slave_node_range
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:58
Restartable(const MooseObject *moose_object, const std::string &system_name)
Class constructor.
Definition: Restartable.C:17
SubProblem & _subproblem
MooseApp & getMooseApp() const
Get the MooseApp this object is associated with.
Definition: MooseObject.h:86
PerfGraphInterface(const MooseObject *moose_object)
For objects that are MooseObjects with a default prefix of type()
const Moose::PatchUpdateType & getPatchUpdateStrategy() const
Get the current patch update strategy.
Definition: MooseMesh.C:2483
PerfGraph & perfGraph()
Get the PerfGraph for this app.
Definition: MooseApp.h:97

◆ ~NearestNodeLocator()

NearestNodeLocator::~NearestNodeLocator ( )

Definition at line 64 of file NearestNodeLocator.C.

64 { delete _slave_node_range; }
NodeIdRange * _slave_node_range

Member Function Documentation

◆ declareRecoverableData() [1/2]

template<typename T >
T & Restartable::declareRecoverableData ( std::string  data_name)
protectedinherited

Declare a piece of data as "recoverable".

This means that in the event of a recovery this piece of data will be restored back to its previous value.

Note - this data will NOT be restored on Restart!

NOTE: This returns a reference! Make sure you store it in a reference!

Parameters
data_nameThe name of the data (usually just use the same name as the member variable)

Definition at line 269 of file Restartable.h.

270 {
271  std::string full_name = _restartable_system_name + "/" + _restartable_name + "/" + data_name;
272 
273  registerRecoverableDataOnApp(full_name);
274 
275  return declareRestartableDataWithContext<T>(data_name, nullptr);
276 }
std::string _restartable_system_name
The system name this object is in.
Definition: Restartable.h:194
std::string _restartable_name
The name of the object.
Definition: Restartable.h:191
void registerRecoverableDataOnApp(std::string name)
Helper function for actually registering the restartable data.
Definition: Restartable.C:54

◆ declareRecoverableData() [2/2]

template<typename T >
T & Restartable::declareRecoverableData ( std::string  data_name,
const T &  init_value 
)
protectedinherited

Declare a piece of data as "restartable" and initialize it.

This means that in the event of a restart this piece of data will be restored back to its previous value.

Note - this data will NOT be restored on Restart!

NOTE: This returns a reference! Make sure you store it in a reference!

Parameters
data_nameThe name of the data (usually just use the same name as the member variable)
init_valueThe initial value of the data

Definition at line 280 of file Restartable.h.

281 {
282  std::string full_name = _restartable_system_name + "/" + _restartable_name + "/" + data_name;
283 
284  registerRecoverableDataOnApp(full_name);
285 
286  return declareRestartableDataWithContext<T>(data_name, init_value, nullptr);
287 }
std::string _restartable_system_name
The system name this object is in.
Definition: Restartable.h:194
std::string _restartable_name
The name of the object.
Definition: Restartable.h:191
void registerRecoverableDataOnApp(std::string name)
Helper function for actually registering the restartable data.
Definition: Restartable.C:54

◆ declareRestartableData() [1/2]

template<typename T >
T & Restartable::declareRestartableData ( std::string  data_name)
protectedinherited

Declare a piece of data as "restartable".

This means that in the event of a restart this piece of data will be restored back to its previous value.

NOTE: This returns a reference! Make sure you store it in a reference!

Parameters
data_nameThe name of the data (usually just use the same name as the member variable)

Definition at line 202 of file Restartable.h.

203 {
204  return declareRestartableDataWithContext<T>(data_name, nullptr);
205 }

◆ declareRestartableData() [2/2]

template<typename T >
T & Restartable::declareRestartableData ( std::string  data_name,
const T &  init_value 
)
protectedinherited

Declare a piece of data as "restartable" and initialize it.

This means that in the event of a restart this piece of data will be restored back to its previous value.

NOTE: This returns a reference! Make sure you store it in a reference!

Parameters
data_nameThe name of the data (usually just use the same name as the member variable)
init_valueThe initial value of the data

Definition at line 209 of file Restartable.h.

210 {
211  return declareRestartableDataWithContext<T>(data_name, init_value, nullptr);
212 }

◆ declareRestartableDataWithContext() [1/2]

template<typename T >
T & Restartable::declareRestartableDataWithContext ( std::string  data_name,
void *  context 
)
protectedinherited

Declare a piece of data as "restartable".

This means that in the event of a restart this piece of data will be restored back to its previous value.

NOTE: This returns a reference! Make sure you store it in a reference!

Parameters
data_nameThe name of the data (usually just use the same name as the member variable)
contextContext pointer that will be passed to the load and store functions

Definition at line 216 of file Restartable.h.

217 {
218  std::string full_name = _restartable_system_name + "/" + _restartable_name + "/" + data_name;
219  auto data_ptr = libmesh_make_unique<RestartableData<T>>(full_name, context);
220  T & restartable_data_ref = data_ptr->get();
221 
222  registerRestartableDataOnApp(full_name, std::move(data_ptr), _restartable_tid);
223 
224  return restartable_data_ref;
225 }
std::string _restartable_system_name
The system name this object is in.
Definition: Restartable.h:194
std::string _restartable_name
The name of the object.
Definition: Restartable.h:191
THREAD_ID _restartable_tid
The thread ID for this object.
Definition: Restartable.h:197
void registerRestartableDataOnApp(std::string name, std::unique_ptr< RestartableDataValue > data, THREAD_ID tid)
Helper function for actually registering the restartable data.
Definition: Restartable.C:46

◆ declareRestartableDataWithContext() [2/2]

template<typename T >
T & Restartable::declareRestartableDataWithContext ( std::string  data_name,
const T &  init_value,
void *  context 
)
protectedinherited

Declare a piece of data as "restartable" and initialize it.

This means that in the event of a restart this piece of data will be restored back to its previous value.

NOTE: This returns a reference! Make sure you store it in a reference!

Parameters
data_nameThe name of the data (usually just use the same name as the member variable)
init_valueThe initial value of the data
contextContext pointer that will be passed to the load and store functions

Definition at line 229 of file Restartable.h.

232 {
233  std::string full_name = _restartable_system_name + "/" + _restartable_name + "/" + data_name;
234  auto data_ptr = libmesh_make_unique<RestartableData<T>>(full_name, context);
235  data_ptr->set() = init_value;
236 
237  T & restartable_data_ref = data_ptr->get();
238  registerRestartableDataOnApp(full_name, std::move(data_ptr), _restartable_tid);
239 
240  return restartable_data_ref;
241 }
std::string _restartable_system_name
The system name this object is in.
Definition: Restartable.h:194
std::string _restartable_name
The name of the object.
Definition: Restartable.h:191
THREAD_ID _restartable_tid
The thread ID for this object.
Definition: Restartable.h:197
void registerRestartableDataOnApp(std::string name, std::unique_ptr< RestartableDataValue > data, THREAD_ID tid)
Helper function for actually registering the restartable data.
Definition: Restartable.C:46

◆ declareRestartableDataWithObjectName()

template<typename T >
T & Restartable::declareRestartableDataWithObjectName ( std::string  data_name,
std::string  object_name 
)
protectedinherited

Declare a piece of data as "restartable".

This means that in the event of a restart this piece of data will be restored back to its previous value.

NOTE: This returns a reference! Make sure you store it in a reference!

Parameters
data_nameThe name of the data (usually just use the same name as the member variable)
object_nameA supplied name for the object that is declaring this data.

Definition at line 245 of file Restartable.h.

246 {
247  return declareRestartableDataWithObjectNameWithContext<T>(data_name, object_name, nullptr);
248 }

◆ declareRestartableDataWithObjectNameWithContext()

template<typename T >
T & Restartable::declareRestartableDataWithObjectNameWithContext ( std::string  data_name,
std::string  object_name,
void *  context 
)
protectedinherited

Declare a piece of data as "restartable".

This means that in the event of a restart this piece of data will be restored back to its previous value.

NOTE: This returns a reference! Make sure you store it in a reference!

Parameters
data_nameThe name of the data (usually just use the same name as the member variable)
object_nameA supplied name for the object that is declaring this data.
contextContext pointer that will be passed to the load and store functions

Definition at line 252 of file Restartable.h.

255 {
256  std::string old_name = _restartable_name;
257 
258  _restartable_name = object_name;
259 
260  T & value = declareRestartableDataWithContext<T>(data_name, context);
261 
262  _restartable_name = old_name;
263 
264  return value;
265 }
std::string _restartable_name
The name of the object.
Definition: Restartable.h:191

◆ distance()

Real NearestNodeLocator::distance ( dof_id_type  node_id)

Valid to call this after findNodes() has been called to get the distance to the nearest node.

Definition at line 230 of file NearestNodeLocator.C.

Referenced by NearestNodeDistanceAux::computeValue(), findNodes(), and updatePatch().

231 {
232  return _nearest_node_info[node_id]._distance;
233 }
std::map< dof_id_type, NearestNodeInfo > _nearest_node_info

◆ findNodes()

void NearestNodeLocator::findNodes ( )

This is the main method that is going to start the search.

If this is the first time through we're going to build up a "neighborhood" of nodes surrounding each of the slave nodes. This will speed searching later.

Definition at line 67 of file NearestNodeLocator.C.

Referenced by reinit(), and GeometricSearchData::update().

68 {
69  TIME_SECTION(_find_nodes_timer);
70 
75  const std::map<dof_id_type, std::vector<dof_id_type>> & node_to_elem_map = _mesh.nodeToElemMap();
76 
77  if (_first)
78  {
79  _first = false;
80 
81  // Trial slave nodes are all the nodes on the slave side
82  // We only keep the ones that are either on this processor or are likely
83  // to interact with elements on this processor (ie nodes owned by this processor
84  // are in the "neighborhood" of the slave node
85  std::vector<dof_id_type> trial_slave_nodes;
86  std::vector<dof_id_type> trial_master_nodes;
87 
88  // Build a bounding box. No reason to consider nodes outside of our inflated BB
89  std::unique_ptr<BoundingBox> my_inflated_box = nullptr;
90 
91  const std::vector<Real> & inflation = _mesh.getGhostedBoundaryInflation();
92 
93  // This means there was a user specified inflation... so we can build a BB
94  if (inflation.size() > 0)
95  {
96  BoundingBox my_box = MeshTools::create_local_bounding_box(_mesh);
97 
98  Point distance;
99  for (unsigned int i = 0; i < inflation.size(); ++i)
100  distance(i) = inflation[i];
101 
102  my_inflated_box =
103  libmesh_make_unique<BoundingBox>(my_box.first - distance, my_box.second + distance);
104  }
105 
106  // Data structures to hold the boundary nodes
108  for (const auto & bnode : bnd_nodes)
109  {
110  BoundaryID boundary_id = bnode->_bnd_id;
111  dof_id_type node_id = bnode->_node->id();
112 
113  // If we have a BB only consider saving this node if it's in our inflated BB
114  if (!my_inflated_box || (my_inflated_box->contains_point(*bnode->_node)))
115  {
116  if (boundary_id == _boundary1)
117  trial_master_nodes.push_back(node_id);
118  else if (boundary_id == _boundary2)
119  trial_slave_nodes.push_back(node_id);
120  }
121  }
122 
123  // Convert trial master nodes to a vector of Points. This will be used to
124  // construct the Kdtree.
125  std::vector<Point> master_points(trial_master_nodes.size());
126  for (unsigned int i = 0; i < trial_master_nodes.size(); ++i)
127  {
128  const Node & node = _mesh.nodeRef(trial_master_nodes[i]);
129  master_points[i] = node;
130  }
131 
132  // Create object kd_tree of class KDTree using the coordinates of trial
133  // master nodes.
134  KDTree kd_tree(master_points, _mesh.getMaxLeafSize());
135 
136  NodeIdRange trial_slave_node_range(trial_slave_nodes.begin(), trial_slave_nodes.end(), 1);
137 
139  _mesh, trial_master_nodes, node_to_elem_map, _mesh.getPatchSize(), kd_tree);
140 
141  Threads::parallel_reduce(trial_slave_node_range, snt);
142 
143  _slave_nodes = snt._slave_nodes;
144  _neighbor_nodes = snt._neighbor_nodes;
145 
146  // If 'iteration' patch update strategy is used, a second neighborhood
147  // search using the ghosting_patch_size, which is larger than the regular
148  // patch_size used for contact search, is conducted. The ghosted element set
149  // given by this search is used for ghosting the elements connected to the
150  // slave and neighboring master nodes.
152  {
153  SlaveNeighborhoodThread snt_ghosting(
154  _mesh, trial_master_nodes, node_to_elem_map, _mesh.getGhostingPatchSize(), kd_tree);
155 
156  Threads::parallel_reduce(trial_slave_node_range, snt_ghosting);
157 
158  for (const auto & dof : snt_ghosting._ghosted_elems)
160  }
161  else
162  {
163  for (const auto & dof : snt._ghosted_elems)
165  }
166 
167  // Cache the slave_node_range so we don't have to build it each time
168  _slave_node_range = new NodeIdRange(_slave_nodes.begin(), _slave_nodes.end(), 1);
169  }
170 
171  _nearest_node_info.clear();
172 
174 
175  Threads::parallel_reduce(*_slave_node_range, nnt);
176 
177  _max_patch_percentage = nnt._max_patch_percentage;
178 
179  _nearest_node_info = nnt._nearest_node_info;
180 
182  {
183  // Get the set of elements that are currently being ghosted
184  std::set<dof_id_type> ghost = _subproblem.ghostedElems();
185 
186  for (const auto & node_id : *_slave_node_range)
187  {
188  const Node * nearest_node = _nearest_node_info[node_id]._nearest_node;
189 
190  // Check if the elements attached to the nearest node are within the ghosted
191  // set of elements. If not produce an error.
192  auto node_to_elem_pair = node_to_elem_map.find(nearest_node->id());
193 
194  if (node_to_elem_pair != node_to_elem_map.end())
195  {
196  const std::vector<dof_id_type> & elems_connected_to_node = node_to_elem_pair->second;
197  for (const auto & dof : elems_connected_to_node)
198  if (std::find(ghost.begin(), ghost.end(), dof) == ghost.end() &&
199  _mesh.elemPtr(dof)->processor_id() != _mesh.processor_id())
200  mooseError("Error in NearestNodeLocator : The nearest neighbor lies outside the "
201  "ghosted set of elements. Increase the ghosting_patch_size parameter in the "
202  "mesh block and try again.");
203  }
204  }
205  }
206 }
std::map< dof_id_type, std::vector< dof_id_type > > _neighbor_nodes
virtual Elem * elemPtr(const dof_id_type i)
Definition: MooseMesh.C:2219
Definition: KDTree.h:20
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
StoredRange< std::vector< dof_id_type >::iterator, dof_id_type > NodeIdRange
Definition: MooseTypes.h:101
unsigned int getGhostingPatchSize() const
Getter for the ghosting_patch_size parameter.
Definition: MooseMesh.h:440
Real distance(dof_id_type node_id)
Valid to call this after findNodes() has been called to get the distance to the nearest node...
const std::vector< Real > & getGhostedBoundaryInflation() const
Return a writable reference to the _ghosted_boundaries_inflation vector.
Definition: MooseMesh.C:2336
virtual const Node & nodeRef(const dof_id_type i) const
Definition: MooseMesh.C:478
std::map< dof_id_type, NearestNodeInfo > _nearest_node_info
std::vector< dof_id_type > _slave_nodes
unsigned int getMaxLeafSize() const
Getter for the maximum leaf size parameter.
Definition: MooseMesh.h:445
const Moose::PatchUpdateType _patch_update_strategy
NodeIdRange * _slave_node_range
virtual std::set< dof_id_type > & ghostedElems()
Return the list of elements that should have their DoFs ghosted to this processor.
Definition: SubProblem.h:493
unsigned int getPatchSize() const
Getter for the patch_size parameter.
Definition: MooseMesh.C:2471
virtual void addGhostedElem(dof_id_type elem_id)=0
Will make sure that all dofs connected to elem_id are ghosted to this processor.
SubProblem & _subproblem
StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > ConstBndNodeRange
Some useful StoredRange typedefs.
Definition: MooseMesh.h:1243
StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > * getBoundaryNodeRange()
Definition: MooseMesh.C:830
boundary_id_type BoundaryID
Definition: MooseTypes.h:93
const std::map< dof_id_type, std::vector< dof_id_type > > & nodeToElemMap()
If not already created, creates a map from every node to all elements to which they are connected...
Definition: MooseMesh.C:732

◆ nearestNode()

const Node * NearestNodeLocator::nearestNode ( dof_id_type  node_id)

Valid to call this after findNodes() has been called to get a pointer to the nearest node.

Definition at line 236 of file NearestNodeLocator.C.

Referenced by NearestNodeValueAux::computeValue(), and PenetrationThread::operator()().

237 {
238  return _nearest_node_info[node_id]._nearest_node;
239 }
std::map< dof_id_type, NearestNodeInfo > _nearest_node_info

◆ registerTimedSection()

PerfID PerfGraphInterface::registerTimedSection ( const std::string &  section_name,
const unsigned int  level 
)
protectedinherited

Call to register a named section for timing.

Parameters
section_nameThe name of the code section to be timed
levelThe importance of the timer - lower is more important (0 will always come out)
Returns
The ID of the section - use when starting timing

Definition at line 50 of file PerfGraphInterface.C.

51 {
52  if (_prefix != "")
53  return _perf_graph.registerSection(_prefix + "::" + section_name, level);
54  else
55  return _perf_graph.registerSection(section_name, level);
56 }
PerfGraph & _perf_graph
The performance graph to add to.
std::string _prefix
A prefix to use for all sections.
PerfID registerSection(const std::string &section_name, unsigned int level)
Registers a named section of code.
Definition: PerfGraph.C:41

◆ reinit()

void NearestNodeLocator::reinit ( )

Completely redo the search from scratch.

Most likely called because of mesh adaptivity.

Definition at line 209 of file NearestNodeLocator.C.

Referenced by GeometricSearchData::clearNearestNodeLocators(), and GeometricSearchData::reinit().

210 {
211  TIME_SECTION(_reinit_timer);
212 
213  // Reset all data
214  delete _slave_node_range;
215  _slave_node_range = NULL;
216  _nearest_node_info.clear();
217 
218  _first = true;
219 
220  _slave_nodes.clear();
221  _neighbor_nodes.clear();
222 
223  _new_ghosted_elems.clear();
224 
225  // Redo the search
226  findNodes();
227 }
std::map< dof_id_type, std::vector< dof_id_type > > _neighbor_nodes
void findNodes()
This is the main method that is going to start the search.
std::map< dof_id_type, NearestNodeInfo > _nearest_node_info
std::vector< dof_id_type > _slave_nodes
NodeIdRange * _slave_node_range
std::vector< dof_id_type > _new_ghosted_elems

◆ slaveNodeRange()

NodeIdRange& NearestNodeLocator::slaveNodeRange ( )
inline

Returns the NodeIdRange of slave nodes to be used for calling threaded functions operating on the slave nodes.

Definition at line 65 of file NearestNodeLocator.h.

Referenced by PenetrationLocator::detectPenetration().

65 { return *_slave_node_range; }
NodeIdRange * _slave_node_range

◆ slaveNodes()

std::vector<dof_id_type>& NearestNodeLocator::slaveNodes ( )
inline

Returns the list of slave nodes this Locator is tracking.

Definition at line 59 of file NearestNodeLocator.h.

59 { return _slave_nodes; }
std::vector< dof_id_type > _slave_nodes

◆ updateGhostedElems()

void NearestNodeLocator::updateGhostedElems ( )

Updates the ghosted elements at the start of the time step for iterion patch update strategy.

Definition at line 354 of file NearestNodeLocator.C.

Referenced by GeometricSearchData::updateGhostedElems().

355 {
356  TIME_SECTION(_update_ghosted_elems_timer);
357 
358  // When 'iteration' patch update strategy is used, add the elements in
359  // _new_ghosted_elems, which were accumulated in the nonlinear iterations
360  // during the previous time step, to the list of ghosted elements. Also clear
361  // the _new_ghosted_elems array for storing the ghosted elements from the
362  // nonlinear iterations in the current time step.
363 
364  for (const auto & dof : _new_ghosted_elems)
366 
367  _new_ghosted_elems.clear();
368 }
virtual void addGhostedElem(dof_id_type elem_id)=0
Will make sure that all dofs connected to elem_id are ghosted to this processor.
SubProblem & _subproblem
std::vector< dof_id_type > _new_ghosted_elems

◆ updatePatch()

void NearestNodeLocator::updatePatch ( std::vector< dof_id_type > &  slave_nodes)

Reconstructs the KDtree, updates the patch for the nodes in slave_nodes, and updates the closest neighbor for these nodes in nearest node info.

Definition at line 242 of file NearestNodeLocator.C.

Referenced by PenetrationLocator::detectPenetration().

243 {
244  TIME_SECTION(_update_patch_timer);
245 
246  std::vector<dof_id_type> trial_master_nodes;
247 
248  // Build a bounding box. No reason to consider nodes outside of our inflated BB
249  std::unique_ptr<BoundingBox> my_inflated_box = nullptr;
250 
251  const std::vector<Real> & inflation = _mesh.getGhostedBoundaryInflation();
252 
253  // This means there was a user specified inflation... so we can build a BB
254  if (inflation.size() > 0)
255  {
256  BoundingBox my_box = MeshTools::create_local_bounding_box(_mesh);
257 
258  Point distance;
259  for (unsigned int i = 0; i < inflation.size(); ++i)
260  distance(i) = inflation[i];
261 
262  my_inflated_box =
263  libmesh_make_unique<BoundingBox>(my_box.first - distance, my_box.second + distance);
264  }
265 
266  // Data structures to hold the boundary nodes
268  for (const auto & bnode : bnd_nodes)
269  {
270  BoundaryID boundary_id = bnode->_bnd_id;
271  dof_id_type node_id = bnode->_node->id();
272 
273  // If we have a BB only consider saving this node if it's in our inflated BB
274  if (!my_inflated_box || (my_inflated_box->contains_point(*bnode->_node)))
275  {
276  if (boundary_id == _boundary1)
277  trial_master_nodes.push_back(node_id);
278  }
279  }
280 
281  // Convert trial master nodes to a vector of Points. This will be used to construct the KDTree.
282  std::vector<Point> master_points(trial_master_nodes.size());
283  for (unsigned int i = 0; i < trial_master_nodes.size(); ++i)
284  {
285  const Node & node = _mesh.nodeRef(trial_master_nodes[i]);
286  master_points[i] = node;
287  }
288 
289  const std::map<dof_id_type, std::vector<dof_id_type>> & node_to_elem_map = _mesh.nodeToElemMap();
290 
291  // Create object kd_tree of class KDTree using the coordinates of trial
292  // master nodes.
293  KDTree kd_tree(master_points, _mesh.getMaxLeafSize());
294 
295  NodeIdRange slave_node_range(slave_nodes.begin(), slave_nodes.end(), 1);
296 
298  _mesh, trial_master_nodes, node_to_elem_map, _mesh.getPatchSize(), kd_tree);
299 
300  Threads::parallel_reduce(slave_node_range, snt);
301 
302  // Calculate new ghosting patch for the slave_node_range
303  SlaveNeighborhoodThread snt_ghosting(
304  _mesh, trial_master_nodes, node_to_elem_map, _mesh.getGhostingPatchSize(), kd_tree);
305 
306  Threads::parallel_reduce(slave_node_range, snt_ghosting);
307 
308  // Add the new set of elements that need to be ghosted into _new_ghosted_elems
309  for (const auto & dof : snt_ghosting._ghosted_elems)
310  _new_ghosted_elems.push_back(dof);
311 
312  std::vector<dof_id_type> tracked_slave_nodes = snt._slave_nodes;
313 
314  // Update the neighbor nodes (patch) for these tracked slave nodes
315  for (const auto & node_id : tracked_slave_nodes)
316  _neighbor_nodes[node_id] = snt._neighbor_nodes[node_id];
317 
318  NodeIdRange tracked_slave_node_range(tracked_slave_nodes.begin(), tracked_slave_nodes.end(), 1);
319 
320  NearestNodeThread nnt(_mesh, snt._neighbor_nodes);
321 
322  Threads::parallel_reduce(tracked_slave_node_range, nnt);
323 
324  _max_patch_percentage = nnt._max_patch_percentage;
325 
326  // Get the set of elements that are currently being ghosted
327  std::set<dof_id_type> ghost = _subproblem.ghostedElems();
328 
329  // Update the nearest node information corresponding to these tracked slave nodes
330  for (const auto & node_id : tracked_slave_node_range)
331  {
332  _nearest_node_info[node_id] = nnt._nearest_node_info[node_id];
333 
334  // Check if the elements attached to the nearest node are within the ghosted
335  // set of elements. If not produce an error.
336  const Node * nearest_node = nnt._nearest_node_info[node_id]._nearest_node;
337 
338  auto node_to_elem_pair = node_to_elem_map.find(nearest_node->id());
339 
340  if (node_to_elem_pair != node_to_elem_map.end())
341  {
342  const std::vector<dof_id_type> & elems_connected_to_node = node_to_elem_pair->second;
343  for (const auto & dof : elems_connected_to_node)
344  if (std::find(ghost.begin(), ghost.end(), dof) == ghost.end() &&
345  _mesh.elemPtr(dof)->processor_id() != _mesh.processor_id())
346  mooseError("Error in NearestNodeLocator : The nearest neighbor lies outside the ghosted "
347  "set of elements. Increase the ghosting_patch_size parameter in the mesh "
348  "block and try again.");
349  }
350  }
351 }
std::map< dof_id_type, std::vector< dof_id_type > > _neighbor_nodes
virtual Elem * elemPtr(const dof_id_type i)
Definition: MooseMesh.C:2219
Definition: KDTree.h:20
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
StoredRange< std::vector< dof_id_type >::iterator, dof_id_type > NodeIdRange
Definition: MooseTypes.h:101
unsigned int getGhostingPatchSize() const
Getter for the ghosting_patch_size parameter.
Definition: MooseMesh.h:440
Real distance(dof_id_type node_id)
Valid to call this after findNodes() has been called to get the distance to the nearest node...
const std::vector< Real > & getGhostedBoundaryInflation() const
Return a writable reference to the _ghosted_boundaries_inflation vector.
Definition: MooseMesh.C:2336
virtual const Node & nodeRef(const dof_id_type i) const
Definition: MooseMesh.C:478
std::map< dof_id_type, NearestNodeInfo > _nearest_node_info
unsigned int getMaxLeafSize() const
Getter for the maximum leaf size parameter.
Definition: MooseMesh.h:445
virtual std::set< dof_id_type > & ghostedElems()
Return the list of elements that should have their DoFs ghosted to this processor.
Definition: SubProblem.h:493
unsigned int getPatchSize() const
Getter for the patch_size parameter.
Definition: MooseMesh.C:2471
SubProblem & _subproblem
std::vector< dof_id_type > _new_ghosted_elems
StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > ConstBndNodeRange
Some useful StoredRange typedefs.
Definition: MooseMesh.h:1243
StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > * getBoundaryNodeRange()
Definition: MooseMesh.C:830
boundary_id_type BoundaryID
Definition: MooseTypes.h:93
const std::map< dof_id_type, std::vector< dof_id_type > > & nodeToElemMap()
If not already created, creates a map from every node to all elements to which they are connected...
Definition: MooseMesh.C:732

Member Data Documentation

◆ _boundary1

BoundaryID NearestNodeLocator::_boundary1

Definition at line 101 of file NearestNodeLocator.h.

Referenced by findNodes(), and updatePatch().

◆ _boundary2

BoundaryID NearestNodeLocator::_boundary2

Definition at line 102 of file NearestNodeLocator.h.

Referenced by findNodes().

◆ _find_nodes_timer

PerfID NearestNodeLocator::_find_nodes_timer

Definition at line 122 of file NearestNodeLocator.h.

Referenced by findNodes().

◆ _first

bool NearestNodeLocator::_first

Definition at line 104 of file NearestNodeLocator.h.

Referenced by findNodes(), and reinit().

◆ _max_patch_percentage

Real NearestNodeLocator::_max_patch_percentage

◆ _mesh

MooseMesh& NearestNodeLocator::_mesh
protected

Definition at line 94 of file NearestNodeLocator.h.

Referenced by findNodes(), and updatePatch().

◆ _nearest_node_info

std::map<dof_id_type, NearestNodeInfo> NearestNodeLocator::_nearest_node_info

Definition at line 99 of file NearestNodeLocator.h.

Referenced by distance(), findNodes(), nearestNode(), reinit(), and updatePatch().

◆ _neighbor_nodes

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

Definition at line 107 of file NearestNodeLocator.h.

Referenced by findNodes(), reinit(), and updatePatch().

◆ _new_ghosted_elems

std::vector<dof_id_type> NearestNodeLocator::_new_ghosted_elems

Definition at line 119 of file NearestNodeLocator.h.

Referenced by reinit(), updateGhostedElems(), and updatePatch().

◆ _patch_size

const unsigned int NearestNodeLocator::_patch_size
static

Definition at line 110 of file NearestNodeLocator.h.

◆ _patch_update_strategy

const Moose::PatchUpdateType NearestNodeLocator::_patch_update_strategy

Definition at line 113 of file NearestNodeLocator.h.

Referenced by findNodes().

◆ _perf_graph

PerfGraph& PerfGraphInterface::_perf_graph
protectedinherited

The performance graph to add to.

Definition at line 66 of file PerfGraphInterface.h.

Referenced by PerfGraphData::getValue(), and PerfGraphInterface::registerTimedSection().

◆ _pg_params

const InputParameters* PerfGraphInterface::_pg_params
protectedinherited

Params.

Definition at line 63 of file PerfGraphInterface.h.

◆ _prefix

std::string PerfGraphInterface::_prefix
protectedinherited

A prefix to use for all sections.

Definition at line 69 of file PerfGraphInterface.h.

Referenced by PerfGraphInterface::registerTimedSection().

◆ _reinit_timer

PerfID NearestNodeLocator::_reinit_timer

Definition at line 124 of file NearestNodeLocator.h.

Referenced by reinit().

◆ _slave_node_range

NodeIdRange* NearestNodeLocator::_slave_node_range
protected

Definition at line 96 of file NearestNodeLocator.h.

Referenced by findNodes(), reinit(), slaveNodeRange(), and ~NearestNodeLocator().

◆ _slave_nodes

std::vector<dof_id_type> NearestNodeLocator::_slave_nodes

◆ _subproblem

SubProblem& NearestNodeLocator::_subproblem
protected

Definition at line 92 of file NearestNodeLocator.h.

Referenced by findNodes(), updateGhostedElems(), and updatePatch().

◆ _update_ghosted_elems_timer

PerfID NearestNodeLocator::_update_ghosted_elems_timer

Definition at line 125 of file NearestNodeLocator.h.

Referenced by updateGhostedElems().

◆ _update_patch_timer

PerfID NearestNodeLocator::_update_patch_timer

Definition at line 123 of file NearestNodeLocator.h.

Referenced by updatePatch().


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