https://mooseframework.inl.gov
Classes | Public Member Functions | Static 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 > & secondaryNodes ()
 Returns the list of secondary nodes this Locator is tracking. More...
 
NodeIdRangesecondaryNodeRange ()
 Returns the NodeIdRange of secondary nodes to be used for calling threaded functions operating on the secondary nodes. More...
 
void updatePatch (std::vector< dof_id_type > &secondary_nodes)
 Reconstructs the KDtree, updates the patch for the nodes in secondary_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 iteration patch update strategy. More...
 
PerfGraphperfGraph ()
 Get the PerfGraph. More...
 

Static Public Member Functions

static InputParameters validParams ()
 

Public Attributes

std::map< dof_id_type, NearestNodeInfo_nearest_node_info
 
BoundaryID _boundary1
 
BoundaryID _boundary2
 
bool _first
 
bool _reinit_iteration
 
std::vector< dof_id_type_secondary_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
 

Static Public Attributes

static const unsigned int _patch_size
 

Protected Member Functions

template<typename T , typename... Args>
T & declareRestartableData (const std::string &data_name, Args &&... args)
 Declare a piece of data as "restartable" and initialize it. More...
 
template<typename T , typename... Args>
ManagedValue< T > declareManagedRestartableDataWithContext (const std::string &data_name, void *context, Args &&... args)
 Declares a piece of "managed" restartable data and initialize it. More...
 
template<typename T , typename... Args>
const T & getRestartableData (const std::string &data_name) const
 Declare a piece of data as "restartable" and initialize it Similar to declareRestartableData but returns a const reference to the object. More...
 
template<typename T , typename... Args>
T & declareRestartableDataWithContext (const std::string &data_name, void *context, Args &&... args)
 Declare a piece of data as "restartable" and initialize it. More...
 
template<typename T , typename... Args>
T & declareRecoverableData (const std::string &data_name, Args &&... args)
 Declare a piece of data as "recoverable" and initialize it. More...
 
template<typename T , typename... Args>
T & declareRestartableDataWithObjectName (const std::string &data_name, const std::string &object_name, Args &&... args)
 Declare a piece of data as "restartable". More...
 
template<typename T , typename... Args>
T & declareRestartableDataWithObjectNameWithContext (const std::string &data_name, const std::string &object_name, void *context, Args &&... args)
 Declare a piece of data as "restartable". More...
 
std::string restartableName (const std::string &data_name) const
 Gets the name of a piece of restartable data given a data name, adding the system name and object name prefix. More...
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level) const
 Call to register a named section for timing. More...
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level, const std::string &live_message, const bool print_dots=true) const
 Call to register a named section for timing. More...
 
std::string timedSectionName (const std::string &section_name) const
 

Protected Attributes

SubProblem_subproblem
 
MooseMesh_mesh
 
std::unique_ptr< NodeIdRange_secondary_node_range
 
MooseApp_restartable_app
 Reference to the application. More...
 
const std::string _restartable_system_name
 The system name this object is in. More...
 
const THREAD_ID _restartable_tid
 The thread ID for this object. More...
 
const bool _restartable_read_only
 Flag for toggling read only status (see ReporterData) More...
 
MooseApp_pg_moose_app
 The MooseApp that owns the PerfGraph. More...
 
const 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 24 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  _boundary1(boundary1),
40  _boundary2(boundary2),
41  _first(true),
42  _reinit_iteration(true),
44 {
45  /*
46  //sanity check on boundary ids
47  const std::set<BoundaryID>& bids=_mesh.getBoundaryIDs();
48  std::set<BoundaryID>::const_iterator sit;
49  sit=bids.find(_boundary1);
50  if (sit == bids.end())
51  mooseError("NearestNodeLocator being created for boundaries ", _boundary1, " and ", _boundary2,
52  ", but boundary ", _boundary1, " does not exist");
53  sit=bids.find(_boundary2);
54  if (sit == bids.end())
55  mooseError("NearestNodeLocator being created for boundaries ", _boundary1, " and ", _boundary2,
56  ", but boundary ", _boundary2, " does not exist");
57  */
58 
59  // Request the nodeToElem map upfront
61 }
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
Definition: MooseBase.h:87
const Moose::PatchUpdateType _patch_update_strategy
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:64
Restartable(const MooseObject *moose_object, const std::string &system_name)
Class constructor.
Definition: Restartable.C:18
SubProblem & _subproblem
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:3540
PerfGraph & perfGraph()
Get the PerfGraph for this app.
Definition: MooseApp.h:178
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:1201

◆ ~NearestNodeLocator()

NearestNodeLocator::~NearestNodeLocator ( )
default

Member Function Documentation

◆ declareManagedRestartableDataWithContext()

template<typename T , typename... Args>
Restartable::ManagedValue< T > Restartable::declareManagedRestartableDataWithContext ( const std::string &  data_name,
void context,
Args &&...  args 
)
protectedinherited

Declares a piece of "managed" restartable data and initialize it.

Here, "managed" restartable data means that the caller can destruct this data upon destruction of the return value of this method. Therefore, this ManagedValue<T> wrapper should survive after the final calls to dataStore() for it. That is... at the very end.

This is needed for objects whose destruction ordering is important, and enables natural c++ destruction in reverse construction order of the object that declares it.

See delcareRestartableData and declareRestartableDataWithContext for more information.

Definition at line 283 of file Restartable.h.

286 {
287  auto & data_ptr =
288  declareRestartableDataHelper<T>(data_name, context, std::forward<Args>(args)...);
289  return Restartable::ManagedValue<T>(data_ptr);
290 }
Wrapper class for restartable data that is "managed.
Definition: Restartable.h:42

◆ declareRecoverableData()

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

Declare a piece of data as "recoverable" 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)
argsArguments to forward to the constructor of the data

Definition at line 358 of file Restartable.h.

359 {
360  const auto full_name = restartableName(data_name);
361 
363 
364  return declareRestartableDataWithContext<T>(data_name, nullptr, std::forward<Args>(args)...);
365 }
std::string restartableName(const std::string &data_name) const
Gets the name of a piece of restartable data given a data name, adding the system name and object nam...
Definition: Restartable.C:78
void registerRestartableNameWithFilterOnApp(const std::string &name, Moose::RESTARTABLE_FILTER filter)
Helper function for actually registering the restartable data.
Definition: Restartable.C:71

◆ declareRestartableData()

template<typename T , typename... Args>
T & Restartable::declareRestartableData ( const std::string &  data_name,
Args &&...  args 
)
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)
argsArguments to forward to the constructor of the data

Definition at line 276 of file Restartable.h.

277 {
278  return declareRestartableDataWithContext<T>(data_name, nullptr, std::forward<Args>(args)...);
279 }

◆ declareRestartableDataWithContext()

template<typename T , typename... Args>
T & Restartable::declareRestartableDataWithContext ( const std::string &  data_name,
void context,
Args &&...  args 
)
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)
contextContext pointer that will be passed to the load and store functions
argsArguments to forward to the constructor of the data

Definition at line 301 of file Restartable.h.

304 {
305  return declareRestartableDataHelper<T>(data_name, context, std::forward<Args>(args)...).set();
306 }

◆ declareRestartableDataWithObjectName()

template<typename T , typename... Args>
T & Restartable::declareRestartableDataWithObjectName ( const std::string &  data_name,
const std::string &  object_name,
Args &&...  args 
)
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.
argsArguments to forward to the constructor of the data

Definition at line 330 of file Restartable.h.

333 {
334  return declareRestartableDataWithObjectNameWithContext<T>(
335  data_name, object_name, nullptr, std::forward<Args>(args)...);
336 }

◆ declareRestartableDataWithObjectNameWithContext()

template<typename T , typename... Args>
T & Restartable::declareRestartableDataWithObjectNameWithContext ( const std::string &  data_name,
const std::string &  object_name,
void context,
Args &&...  args 
)
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
argsArguments to forward to the constructor of the data

Definition at line 340 of file Restartable.h.

344 {
345  std::string old_name = _restartable_name;
346 
347  _restartable_name = object_name;
348 
349  T & value = declareRestartableDataWithContext<T>(data_name, context, std::forward<Args>(args)...);
350 
351  _restartable_name = old_name;
352 
353  return value;
354 }
std::string _restartable_name
The name of the object.
Definition: Restartable.h:250
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

◆ 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 236 of file NearestNodeLocator.C.

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

237 {
238  return _nearest_node_info[node_id]._distance;
239 }
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 secondary nodes. This will speed searching later.

Definition at line 66 of file NearestNodeLocator.C.

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

67 {
68  TIME_SECTION("findNodes", 3, "Finding Nearest Nodes");
69 
74  const std::map<dof_id_type, std::vector<dof_id_type>> & node_to_elem_map = _mesh.nodeToElemMap();
75 
77  {
78  _first = false;
79 
80  // Trial secondary nodes are all the nodes on the secondary side
81  // We only keep the ones that are either on this processor or are likely
82  // to interact with elements on this processor (ie nodes owned by this processor
83  // are in the "neighborhood" of the secondary node
84  std::vector<dof_id_type> trial_secondary_nodes;
85  std::vector<dof_id_type> trial_primary_nodes;
86 
87  // Build a bounding box. No reason to consider nodes outside of our inflated BB
88  std::unique_ptr<BoundingBox> my_inflated_box = nullptr;
89 
90  const std::vector<Real> & inflation = _mesh.getGhostedBoundaryInflation();
91 
92  // This means there was a user specified inflation... so we can build a BB
93  if (inflation.size() > 0)
94  {
95  BoundingBox my_box = MeshTools::create_local_bounding_box(_mesh);
96 
97  Point distance;
98  for (unsigned int i = 0; i < inflation.size(); ++i)
99  distance(i) = inflation[i];
100 
101  my_inflated_box =
102  std::make_unique<BoundingBox>(my_box.first - distance, my_box.second + distance);
103  }
104 
105  // Data structures to hold the boundary nodes
107  for (const auto & bnode : bnd_nodes)
108  {
109  BoundaryID boundary_id = bnode->_bnd_id;
110  dof_id_type node_id = bnode->_node->id();
111 
112  // If we have a BB only consider saving this node if it's in our inflated BB
113  if (!my_inflated_box || (my_inflated_box->contains_point(*bnode->_node)))
114  {
115  if (boundary_id == _boundary1)
116  trial_primary_nodes.push_back(node_id);
117  else if (boundary_id == _boundary2)
118  trial_secondary_nodes.push_back(node_id);
119  }
120  }
121 
122  // Convert trial primary nodes to a vector of Points. This will be used to
123  // construct the Kdtree.
124  std::vector<Point> primary_points(trial_primary_nodes.size());
125  for (unsigned int i = 0; i < trial_primary_nodes.size(); ++i)
126  {
127  const Node & node = _mesh.nodeRef(trial_primary_nodes[i]);
128  primary_points[i] = node;
129  }
130 
131  // Create object kd_tree of class KDTree using the coordinates of trial
132  // primary nodes.
133  KDTree kd_tree(primary_points, _mesh.getMaxLeafSize());
134 
135  NodeIdRange trial_secondary_node_range(
136  trial_secondary_nodes.begin(), trial_secondary_nodes.end(), 1);
137 
139  _mesh, trial_primary_nodes, node_to_elem_map, _mesh.getPatchSize(), kd_tree);
140 
141  Threads::parallel_reduce(trial_secondary_node_range, snt);
142 
143  _secondary_nodes = snt._secondary_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  // secondary and neighboring primary nodes.
152  {
153  SecondaryNeighborhoodThread snt_ghosting(
154  _mesh, trial_primary_nodes, node_to_elem_map, _mesh.getGhostingPatchSize(), kd_tree);
155 
156  Threads::parallel_reduce(trial_secondary_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 secondary_node_range so we don't have to build it each time
169  std::make_unique<NodeIdRange>(_secondary_nodes.begin(), _secondary_nodes.end(), 1);
170  }
171 
172  _nearest_node_info.clear();
173 
175 
177 
178  _max_patch_percentage = nnt._max_patch_percentage;
179 
180  _nearest_node_info = nnt._nearest_node_info;
181 
183  {
184  // Get the set of elements that are currently being ghosted
185  std::set<dof_id_type> ghost = _subproblem.ghostedElems();
186 
187  for (const auto & node_id : *_secondary_node_range)
188  {
189  const Node * nearest_node = _nearest_node_info[node_id]._nearest_node;
190 
191  // Check if the elements attached to the nearest node are within the ghosted
192  // set of elements. If not produce an error.
193  auto node_to_elem_pair = node_to_elem_map.find(nearest_node->id());
194 
195  if (node_to_elem_pair != node_to_elem_map.end())
196  {
197  const std::vector<dof_id_type> & elems_connected_to_node = node_to_elem_pair->second;
198  for (const auto & dof : elems_connected_to_node)
199  if (std::find(ghost.begin(), ghost.end(), dof) == ghost.end() &&
200  _mesh.elemPtr(dof)->processor_id() != _mesh.processor_id())
201  mooseError("Error in NearestNodeLocator: The nearest neighbor lies outside the "
202  "ghosted set of elements. Increase the ghosting_patch_size parameter in the "
203  "mesh block and try again.");
204  }
205  }
206  }
207 }
std::map< dof_id_type, std::vector< dof_id_type > > _neighbor_nodes
KOKKOS_INLINE_FUNCTION const T * find(const T &target, const T *const begin, const T *const end)
Find a value in an array.
Definition: KokkosUtils.h:40
virtual Elem * elemPtr(const dof_id_type i)
Definition: MooseMesh.C:3240
Definition: KDTree.h:28
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
unsigned int getGhostingPatchSize() const
Getter for the ghosting_patch_size parameter.
Definition: MooseMesh.h:637
void parallel_reduce(const Range &range, Body &body, const Partitioner &, unsigned int n_threads=libMesh::n_threads())
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:3374
virtual const Node & nodeRef(const dof_id_type i) const
Definition: MooseMesh.C:834
libMesh::BoundingBox create_local_bounding_box(const MeshBase &mesh)
std::map< dof_id_type, NearestNodeInfo > _nearest_node_info
std::unique_ptr< NodeIdRange > _secondary_node_range
std::vector< dof_id_type > _secondary_nodes
boundary_id_type BoundaryID
unsigned int getMaxLeafSize() const
Getter for the maximum leaf size parameter.
Definition: MooseMesh.h:642
const Moose::PatchUpdateType _patch_update_strategy
virtual std::set< dof_id_type > & ghostedElems()
Return the list of elements that should have their DoFs ghosted to this processor.
Definition: SubProblem.h:672
unsigned int getPatchSize() const
Getter for the patch_size parameter.
Definition: MooseMesh.C:3528
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
processor_id_type processor_id() const
libMesh::StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > * getBoundaryNodeRange()
Definition: MooseMesh.C:1312
uint8_t dof_id_type
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:1201

◆ getRestartableData()

template<typename T , typename... Args>
const T & Restartable::getRestartableData ( const std::string &  data_name) const
protectedinherited

Declare a piece of data as "restartable" and initialize it Similar to declareRestartableData but returns a const reference to the object.

Forwarded arguments are not allowed in this case because we assume that the object is restarted and we won't need different constructors to initialize it.

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

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

Definition at line 294 of file Restartable.h.

295 {
296  return declareRestartableDataHelper<T>(data_name, nullptr).get();
297 }

◆ 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 242 of file NearestNodeLocator.C.

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

243 {
244  const Node * returnval = _nearest_node_info[node_id]._nearest_node;
245  libmesh_assert(_mesh.getMesh().get_boundary_info().has_boundary_id(returnval, _boundary1));
246  return returnval;
247 }
std::map< dof_id_type, NearestNodeInfo > _nearest_node_info
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:3575
libmesh_assert(ctx)

◆ perfGraph()

PerfGraph & PerfGraphInterface::perfGraph ( )
inherited

Get the PerfGraph.

Definition at line 86 of file PerfGraphInterface.C.

Referenced by CommonOutputAction::act(), PerfGraphData::finalize(), PerfGraphReporter::finalize(), and PerfGraphOutput::output().

87 {
88  return _pg_moose_app.perfGraph();
89 }
MooseApp & _pg_moose_app
The MooseApp that owns the PerfGraph.
PerfGraph & perfGraph()
Get the PerfGraph for this app.
Definition: MooseApp.h:178

◆ registerTimedSection() [1/2]

PerfID PerfGraphInterface::registerTimedSection ( const std::string &  section_name,
const unsigned int  level 
) const
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 61 of file PerfGraphInterface.C.

63 {
64  const auto timed_section_name = timedSectionName(section_name);
65  if (!moose::internal::getPerfGraphRegistry().sectionExists(timed_section_name))
66  return moose::internal::getPerfGraphRegistry().registerSection(timed_section_name, level);
67  else
68  return moose::internal::getPerfGraphRegistry().sectionID(timed_section_name);
69 }
PerfID registerSection(const std::string &section_name, const unsigned int level)
Call to register a named section for timing.
std::string timedSectionName(const std::string &section_name) const
PerfID sectionID(const std::string &section_name) const
Given a name return the PerfID The name of the section.
PerfGraphRegistry & getPerfGraphRegistry()
Get the global PerfGraphRegistry singleton.

◆ registerTimedSection() [2/2]

PerfID PerfGraphInterface::registerTimedSection ( const std::string &  section_name,
const unsigned int  level,
const std::string &  live_message,
const bool  print_dots = true 
) const
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)
live_messageThe message to be printed to the screen during execution
print_dotsWhether or not progress dots should be printed for this section
Returns
The ID of the section - use when starting timing

Definition at line 72 of file PerfGraphInterface.C.

76 {
77  const auto timed_section_name = timedSectionName(section_name);
78  if (!moose::internal::getPerfGraphRegistry().sectionExists(timed_section_name))
80  timedSectionName(section_name), level, live_message, print_dots);
81  else
82  return moose::internal::getPerfGraphRegistry().sectionID(timed_section_name);
83 }
PerfID registerSection(const std::string &section_name, const unsigned int level)
Call to register a named section for timing.
std::string timedSectionName(const std::string &section_name) const
PerfID sectionID(const std::string &section_name) const
Given a name return the PerfID The name of the section.
PerfGraphRegistry & getPerfGraphRegistry()
Get the global PerfGraphRegistry singleton.

◆ reinit()

void NearestNodeLocator::reinit ( )

Completely redo the search from scratch.

Most likely called because of mesh adaptivity.

Definition at line 210 of file NearestNodeLocator.C.

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

211 {
212  TIME_SECTION("reinit", 3, "Reinitializing Nearest Node Search");
213 
214  // Reset all data
215  _secondary_node_range.reset();
216  _nearest_node_info.clear();
217 
218  _first = true;
219 
220  _secondary_nodes.clear();
221  _neighbor_nodes.clear();
222 
223  _new_ghosted_elems.clear();
224 
225  // After a call from system reinit, mesh has been updated with initial adaptivity.
226  // Moose::Iteration relies on data generated for ghosting (i.e. trial_primary_nodes)
227  _reinit_iteration = true;
228 
229  // Redo the search
230  findNodes();
231 
232  _reinit_iteration = false;
233 }
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::unique_ptr< NodeIdRange > _secondary_node_range
std::vector< dof_id_type > _secondary_nodes
std::vector< dof_id_type > _new_ghosted_elems

◆ restartableName()

std::string Restartable::restartableName ( const std::string &  data_name) const
protectedinherited

Gets the name of a piece of restartable data given a data name, adding the system name and object name prefix.

This should only be used in this interface and in testing.

Definition at line 78 of file Restartable.C.

Referenced by Restartable::declareRecoverableData(), and Restartable::declareRestartableDataHelper().

79 {
80  return _restartable_system_name + "/" + _restartable_name + "/" + data_name;
81 }
std::string _restartable_name
The name of the object.
Definition: Restartable.h:250
const std::string _restartable_system_name
The system name this object is in.
Definition: Restartable.h:237

◆ secondaryNodeRange()

NodeIdRange& NearestNodeLocator::secondaryNodeRange ( )
inline

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

Definition at line 64 of file NearestNodeLocator.h.

Referenced by PenetrationLocator::detectPenetration().

64 { return *_secondary_node_range; }
std::unique_ptr< NodeIdRange > _secondary_node_range

◆ secondaryNodes()

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

Returns the list of secondary nodes this Locator is tracking.

Definition at line 58 of file NearestNodeLocator.h.

58 { return _secondary_nodes; }
std::vector< dof_id_type > _secondary_nodes

◆ timedSectionName()

std::string PerfGraphInterface::timedSectionName ( const std::string &  section_name) const
protectedinherited
Returns
The name of the timed section with the name section_name.

Optionally adds a prefix if one is defined.

Definition at line 55 of file PerfGraphInterface.C.

Referenced by PerfGraphInterface::registerTimedSection().

56 {
57  return _prefix.empty() ? "" : (_prefix + "::") + section_name;
58 }
const std::string _prefix
A prefix to use for all sections.

◆ updateGhostedElems()

void NearestNodeLocator::updateGhostedElems ( )

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

Definition at line 363 of file NearestNodeLocator.C.

Referenced by GeometricSearchData::updateGhostedElems().

364 {
365  TIME_SECTION("updateGhostedElems", 5, "Updating Nearest Node Search Because of Ghosting");
366 
367  // When 'iteration' patch update strategy is used, add the elements in
368  // _new_ghosted_elems, which were accumulated in the nonlinear iterations
369  // during the previous time step, to the list of ghosted elements. Also clear
370  // the _new_ghosted_elems array for storing the ghosted elements from the
371  // nonlinear iterations in the current time step.
372 
373  for (const auto & dof : _new_ghosted_elems)
375 
376  _new_ghosted_elems.clear();
377 }
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 > &  secondary_nodes)

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

Definition at line 250 of file NearestNodeLocator.C.

Referenced by PenetrationLocator::detectPenetration().

251 {
252  TIME_SECTION("updatePatch", 3, "Updating Nearest Node Search Patch");
253 
254  std::vector<dof_id_type> trial_primary_nodes;
255 
256  // Build a bounding box. No reason to consider nodes outside of our inflated BB
257  std::unique_ptr<BoundingBox> my_inflated_box = nullptr;
258 
259  const std::vector<Real> & inflation = _mesh.getGhostedBoundaryInflation();
260 
261  // This means there was a user specified inflation... so we can build a BB
262  if (inflation.size() > 0)
263  {
264  BoundingBox my_box = MeshTools::create_local_bounding_box(_mesh);
265 
266  Point distance;
267  for (unsigned int i = 0; i < inflation.size(); ++i)
268  distance(i) = inflation[i];
269 
270  my_inflated_box =
271  std::make_unique<BoundingBox>(my_box.first - distance, my_box.second + distance);
272  }
273 
274  // Data structures to hold the boundary nodes
276  for (const auto & bnode : bnd_nodes)
277  {
278  BoundaryID boundary_id = bnode->_bnd_id;
279  dof_id_type node_id = bnode->_node->id();
280 
281  // If we have a BB only consider saving this node if it's in our inflated BB
282  if (!my_inflated_box || (my_inflated_box->contains_point(*bnode->_node)))
283  {
284  if (boundary_id == _boundary1)
285  trial_primary_nodes.push_back(node_id);
286  }
287  }
288 
289  // Convert trial primary nodes to a vector of Points. This will be used to construct the KDTree.
290  std::vector<Point> primary_points(trial_primary_nodes.size());
291  for (unsigned int i = 0; i < trial_primary_nodes.size(); ++i)
292  {
293  const Node & node = _mesh.nodeRef(trial_primary_nodes[i]);
294  primary_points[i] = node;
295  }
296 
297  const std::map<dof_id_type, std::vector<dof_id_type>> & node_to_elem_map = _mesh.nodeToElemMap();
298 
299  // Create object kd_tree of class KDTree using the coordinates of trial
300  // primary nodes.
301  KDTree kd_tree(primary_points, _mesh.getMaxLeafSize());
302 
303  NodeIdRange secondary_node_range(secondary_nodes.begin(), secondary_nodes.end(), 1);
304 
306  _mesh, trial_primary_nodes, node_to_elem_map, _mesh.getPatchSize(), kd_tree);
307 
308  Threads::parallel_reduce(secondary_node_range, snt);
309 
310  // Calculate new ghosting patch for the secondary_node_range
311  SecondaryNeighborhoodThread snt_ghosting(
312  _mesh, trial_primary_nodes, node_to_elem_map, _mesh.getGhostingPatchSize(), kd_tree);
313 
314  Threads::parallel_reduce(secondary_node_range, snt_ghosting);
315 
316  // Add the new set of elements that need to be ghosted into _new_ghosted_elems
317  for (const auto & dof : snt_ghosting._ghosted_elems)
318  _new_ghosted_elems.push_back(dof);
319 
320  std::vector<dof_id_type> tracked_secondary_nodes = snt._secondary_nodes;
321 
322  // Update the neighbor nodes (patch) for these tracked secondary nodes
323  for (const auto & node_id : tracked_secondary_nodes)
324  _neighbor_nodes[node_id] = snt._neighbor_nodes[node_id];
325 
326  NodeIdRange tracked_secondary_node_range(
327  tracked_secondary_nodes.begin(), tracked_secondary_nodes.end(), 1);
328 
329  NearestNodeThread nnt(_mesh, snt._neighbor_nodes);
330 
331  Threads::parallel_reduce(tracked_secondary_node_range, nnt);
332 
333  _max_patch_percentage = nnt._max_patch_percentage;
334 
335  // Get the set of elements that are currently being ghosted
336  std::set<dof_id_type> ghost = _subproblem.ghostedElems();
337 
338  // Update the nearest node information corresponding to these tracked secondary nodes
339  for (const auto & node_id : tracked_secondary_node_range)
340  {
341  _nearest_node_info[node_id] = nnt._nearest_node_info[node_id];
342 
343  // Check if the elements attached to the nearest node are within the ghosted
344  // set of elements. If not produce an error.
345  const Node * nearest_node = nnt._nearest_node_info[node_id]._nearest_node;
346 
347  auto node_to_elem_pair = node_to_elem_map.find(nearest_node->id());
348 
349  if (node_to_elem_pair != node_to_elem_map.end())
350  {
351  const std::vector<dof_id_type> & elems_connected_to_node = node_to_elem_pair->second;
352  for (const auto & dof : elems_connected_to_node)
353  if (std::find(ghost.begin(), ghost.end(), dof) == ghost.end() &&
354  _mesh.elemPtr(dof)->processor_id() != _mesh.processor_id())
355  mooseError("Error in NearestNodeLocator: The nearest neighbor lies outside the ghosted "
356  "set of elements. Increase the ghosting_patch_size parameter in the mesh "
357  "block and try again.");
358  }
359  }
360 }
std::map< dof_id_type, std::vector< dof_id_type > > _neighbor_nodes
KOKKOS_INLINE_FUNCTION const T * find(const T &target, const T *const begin, const T *const end)
Find a value in an array.
Definition: KokkosUtils.h:40
virtual Elem * elemPtr(const dof_id_type i)
Definition: MooseMesh.C:3240
Definition: KDTree.h:28
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
unsigned int getGhostingPatchSize() const
Getter for the ghosting_patch_size parameter.
Definition: MooseMesh.h:637
void parallel_reduce(const Range &range, Body &body, const Partitioner &, unsigned int n_threads=libMesh::n_threads())
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:3374
virtual const Node & nodeRef(const dof_id_type i) const
Definition: MooseMesh.C:834
libMesh::BoundingBox create_local_bounding_box(const MeshBase &mesh)
std::map< dof_id_type, NearestNodeInfo > _nearest_node_info
boundary_id_type BoundaryID
unsigned int getMaxLeafSize() const
Getter for the maximum leaf size parameter.
Definition: MooseMesh.h:642
virtual std::set< dof_id_type > & ghostedElems()
Return the list of elements that should have their DoFs ghosted to this processor.
Definition: SubProblem.h:672
unsigned int getPatchSize() const
Getter for the patch_size parameter.
Definition: MooseMesh.C:3528
SubProblem & _subproblem
std::vector< dof_id_type > _new_ghosted_elems
processor_id_type processor_id() const
libMesh::StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > * getBoundaryNodeRange()
Definition: MooseMesh.C:1312
uint8_t dof_id_type
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:1201

◆ validParams()

InputParameters PerfGraphInterface::validParams ( )
staticinherited

Definition at line 16 of file PerfGraphInterface.C.

Referenced by Convergence::validParams().

17 {
19  return params;
20 }
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
InputParameters emptyInputParameters()

Member Data Documentation

◆ _boundary1

BoundaryID NearestNodeLocator::_boundary1

◆ _boundary2

BoundaryID NearestNodeLocator::_boundary2

Definition at line 101 of file NearestNodeLocator.h.

Referenced by findNodes().

◆ _first

bool NearestNodeLocator::_first

Definition at line 103 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 93 of file NearestNodeLocator.h.

Referenced by findNodes(), nearestNode(), NearestNodeLocator(), and updatePatch().

◆ _nearest_node_info

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

Definition at line 98 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 112 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 124 of file NearestNodeLocator.h.

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

◆ _patch_size

const unsigned int NearestNodeLocator::_patch_size
static

Definition at line 115 of file NearestNodeLocator.h.

◆ _patch_update_strategy

const Moose::PatchUpdateType NearestNodeLocator::_patch_update_strategy

Definition at line 118 of file NearestNodeLocator.h.

Referenced by findNodes().

◆ _pg_moose_app

MooseApp& PerfGraphInterface::_pg_moose_app
protectedinherited

The MooseApp that owns the PerfGraph.

Definition at line 135 of file PerfGraphInterface.h.

Referenced by PerfGraphInterface::perfGraph().

◆ _prefix

const std::string PerfGraphInterface::_prefix
protectedinherited

A prefix to use for all sections.

Definition at line 138 of file PerfGraphInterface.h.

Referenced by PerfGraphInterface::timedSectionName().

◆ _reinit_iteration

bool NearestNodeLocator::_reinit_iteration

Definition at line 108 of file NearestNodeLocator.h.

Referenced by findNodes(), and reinit().

◆ _restartable_app

MooseApp& Restartable::_restartable_app
protectedinherited

Reference to the application.

Definition at line 234 of file Restartable.h.

Referenced by Restartable::registerRestartableDataOnApp(), and Restartable::registerRestartableNameWithFilterOnApp().

◆ _restartable_read_only

const bool Restartable::_restartable_read_only
protectedinherited

Flag for toggling read only status (see ReporterData)

Definition at line 243 of file Restartable.h.

Referenced by Restartable::registerRestartableDataOnApp().

◆ _restartable_system_name

const std::string Restartable::_restartable_system_name
protectedinherited

The system name this object is in.

Definition at line 237 of file Restartable.h.

Referenced by Restartable::restartableName().

◆ _restartable_tid

const THREAD_ID Restartable::_restartable_tid
protectedinherited

The thread ID for this object.

Definition at line 240 of file Restartable.h.

Referenced by Restartable::declareRestartableDataHelper().

◆ _secondary_node_range

std::unique_ptr<NodeIdRange> NearestNodeLocator::_secondary_node_range
protected

Definition at line 95 of file NearestNodeLocator.h.

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

◆ _secondary_nodes

std::vector<dof_id_type> NearestNodeLocator::_secondary_nodes

◆ _subproblem

SubProblem& NearestNodeLocator::_subproblem
protected

Definition at line 91 of file NearestNodeLocator.h.

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


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