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...
 

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
 
Real _max_patch_percentage
 

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...
 

Protected Attributes

SubProblem_subproblem
 
MooseMesh_mesh
 
NodeIdRange_slave_node_range
 

Detailed Description

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

Definition at line 29 of file NearestNodeLocator.h.

Constructor & Destructor Documentation

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

Definition at line 39 of file NearestNodeLocator.C.

43  : Restartable(_boundaryFuser(boundary1, boundary2), "NearestNodeLocator", subproblem, 0),
44  _subproblem(subproblem),
45  _mesh(mesh),
46  _slave_node_range(NULL),
47  _boundary1(boundary1),
48  _boundary2(boundary2),
49  _first(true)
50 {
51  /*
52  //sanity check on boundary ids
53  const std::set<BoundaryID>& bids=_mesh.getBoundaryIDs();
54  std::set<BoundaryID>::const_iterator sit;
55  sit=bids.find(_boundary1);
56  if (sit == bids.end())
57  mooseError("NearestNodeLocator being created for boundaries ", _boundary1, " and ", _boundary2,
58  ", but boundary ", _boundary1, " does not exist");
59  sit=bids.find(_boundary2);
60  if (sit == bids.end())
61  mooseError("NearestNodeLocator being created for boundaries ", _boundary1, " and ", _boundary2,
62  ", but boundary ", _boundary2, " does not exist");
63  */
64 }
Restartable(const InputParameters &parameters, std::string system_name, SubProblem *subproblem=NULL)
Class constructor Populates the SubProblem and MooseMesh pointers.
Definition: Restartable.C:20
std::string _boundaryFuser(BoundaryID boundary1, BoundaryID boundary2)
NodeIdRange * _slave_node_range
SubProblem & _subproblem
NearestNodeLocator::~NearestNodeLocator ( )

Definition at line 66 of file NearestNodeLocator.C.

66 { delete _slave_node_range; }
NodeIdRange * _slave_node_range

Member Function Documentation

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 224 of file Restartable.h.

225 {
226  return declareRestartableDataWithContext<T>(data_name, NULL);
227 }
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 231 of file Restartable.h.

232 {
233  return declareRestartableDataWithContext<T>(data_name, init_value, NULL);
234 }
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 238 of file Restartable.h.

239 {
241  mooseError("No valid SubProblem found for ", _restartable_system_name, "/", _restartable_name);
242 
243  std::string full_name = _restartable_system_name + "/" + _restartable_name + "/" + data_name;
244  RestartableData<T> * data_ptr = new RestartableData<T>(full_name, context);
245 
247 
248  return data_ptr->get();
249 }
std::string _restartable_system_name
The system name this object is in.
Definition: Restartable.h:202
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
std::string _restartable_name
The name of the object.
Definition: Restartable.h:196
void registerRestartableDataOnSubProblem(std::string name, RestartableDataValue *data, THREAD_ID tid)
Helper function so we don&#39;t have to include SubProblem in the header.
Definition: Restartable.C:49
Concrete definition of a parameter value for a specified type.
SubProblem * _restartable_subproblem
Pointer to the SubProblem class.
Definition: Restartable.h:208
THREAD_ID _restartable_tid
The thread ID for this object.
Definition: Restartable.h:205
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 253 of file Restartable.h.

256 {
258  mooseError("No valid SubProblem found for ", _restartable_system_name, "/", _restartable_name);
259 
260  std::string full_name = _restartable_system_name + "/" + _restartable_name + "/" + data_name;
261  RestartableData<T> * data_ptr = new RestartableData<T>(full_name, context);
262 
263  data_ptr->set() = init_value;
264 
266 
267  return data_ptr->get();
268 }
std::string _restartable_system_name
The system name this object is in.
Definition: Restartable.h:202
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
std::string _restartable_name
The name of the object.
Definition: Restartable.h:196
void registerRestartableDataOnSubProblem(std::string name, RestartableDataValue *data, THREAD_ID tid)
Helper function so we don&#39;t have to include SubProblem in the header.
Definition: Restartable.C:49
Concrete definition of a parameter value for a specified type.
SubProblem * _restartable_subproblem
Pointer to the SubProblem class.
Definition: Restartable.h:208
THREAD_ID _restartable_tid
The thread ID for this object.
Definition: Restartable.h:205
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 204 of file NearestNodeLocator.C.

Referenced by NearestNodeDistanceAux::computeValue().

205 {
206  return _nearest_node_info[node_id]._distance;
207 }
std::map< dof_id_type, NearestNodeInfo > _nearest_node_info
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 69 of file NearestNodeLocator.C.

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

70 {
71  Moose::perf_log.push("NearestNodeLocator::findNodes()", "Execution");
76  if (_first)
77  {
78  _first = false;
79 
80  // Trial slave nodes are all the nodes on the slave 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 slave node
84  std::vector<dof_id_type> trial_slave_nodes;
85  std::vector<dof_id_type> trial_master_nodes;
86 
87  // Build a bounding box. No reason to consider nodes outside of our inflated BB
88  BoundingBox * my_inflated_box = NULL;
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  Real distance_x = 0;
98  Real distance_y = 0;
99  Real distance_z = 0;
100 
101  distance_x = inflation[0];
102 
103  if (inflation.size() > 1)
104  distance_y = inflation[1];
105 
106  if (inflation.size() > 2)
107  distance_z = inflation[2];
108 
109  my_inflated_box = new BoundingBox(Point(my_box.first(0) - distance_x,
110  my_box.first(1) - distance_y,
111  my_box.first(2) - distance_z),
112  Point(my_box.second(0) + distance_x,
113  my_box.second(1) + distance_y,
114  my_box.second(2) + distance_z));
115  }
116 
117  // Data structures to hold the Nodal Boundary conditions
119  for (const auto & bnode : bnd_nodes)
120  {
121  BoundaryID boundary_id = bnode->_bnd_id;
122  dof_id_type node_id = bnode->_node->id();
123 
124  // If we have a BB only consider saving this node if it's in our inflated BB
125  if (!my_inflated_box || (my_inflated_box->contains_point(*bnode->_node)))
126  {
127  if (boundary_id == _boundary1)
128  trial_master_nodes.push_back(node_id);
129  else if (boundary_id == _boundary2)
130  trial_slave_nodes.push_back(node_id);
131  }
132  }
133 
134  // don't need the BB anymore
135  delete my_inflated_box;
136 
137  const std::map<dof_id_type, std::vector<dof_id_type>> & node_to_elem_map =
139 
140  // Convert trial master nodes to a vector of Points. This would be used to
141  // construct the Kdtree.
142  std::vector<Point> master_points(trial_master_nodes.size());
143  for (unsigned int i = 0; i < trial_master_nodes.size(); ++i)
144  {
145  const Node & node = _mesh.nodeRef(trial_master_nodes[i]);
146  for (unsigned int j = 0; j < LIBMESH_DIM; ++j)
147  master_points[i](j) = node(j);
148  }
149 
150  // Create object kd_tree of class KDTree using the coordinates of trial
151  // master nodes. Maximum number of points in each leaf of the Kd tree is set
152  // using max_leaf_size.
153  unsigned int max_leaf_size = 10;
154  KDTree kd_tree(master_points, max_leaf_size);
155 
156  NodeIdRange trial_slave_node_range(trial_slave_nodes.begin(), trial_slave_nodes.end(), 1);
157 
159  _mesh, trial_master_nodes, node_to_elem_map, _mesh.getPatchSize(), kd_tree);
160 
161  Threads::parallel_reduce(trial_slave_node_range, snt);
162 
163  _slave_nodes = snt._slave_nodes;
164  _neighbor_nodes = snt._neighbor_nodes;
165 
166  for (const auto & dof : snt._ghosted_elems)
168 
169  // Cache the slave_node_range so we don't have to build it each time
170  _slave_node_range = new NodeIdRange(_slave_nodes.begin(), _slave_nodes.end(), 1);
171  }
172 
173  _nearest_node_info.clear();
174 
176 
177  Threads::parallel_reduce(*_slave_node_range, nnt);
178 
179  _max_patch_percentage = nnt._max_patch_percentage;
180 
181  _nearest_node_info = nnt._nearest_node_info;
182 
183  Moose::perf_log.pop("NearestNodeLocator::findNodes()", "Execution");
184 }
std::map< dof_id_type, std::vector< dof_id_type > > _neighbor_nodes
Definition: KDTree.h:23
StoredRange< std::vector< dof_id_type >::iterator, dof_id_type > NodeIdRange
Definition: MooseTypes.h:81
std::map< dof_id_type, NearestNodeInfo > _nearest_node_info
const std::vector< Real > & getGhostedBoundaryInflation() const
Return a writable reference to the _ghosted_boundaries_inflation vector.
Definition: MooseMesh.C:2179
std::vector< dof_id_type > _slave_nodes
PerfLog perf_log
Perflog to be used by applications.
NodeIdRange * _slave_node_range
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
virtual const Node & nodeRef(const dof_id_type i) const
Definition: MooseMesh.C:398
unsigned int getPatchSize() const
Getter for the patch_size parameter.
Definition: MooseMesh.C:2314
StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > ConstBndNodeRange
Some useful StoredRange typedefs.
Definition: MooseMesh.h:1184
StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > * getBoundaryNodeRange()
Definition: MooseMesh.C:724
boundary_id_type BoundaryID
Definition: MooseTypes.h:75
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:642
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 210 of file NearestNodeLocator.C.

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

211 {
212  return _nearest_node_info[node_id]._nearest_node;
213 }
std::map< dof_id_type, NearestNodeInfo > _nearest_node_info
void NearestNodeLocator::reinit ( )

Completely redo the search from scratch.

Most likely called because of mesh adaptivity.

Definition at line 187 of file NearestNodeLocator.C.

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

188 {
189  // Reset all data
190  delete _slave_node_range;
191  _slave_node_range = NULL;
192  _nearest_node_info.clear();
193 
194  _first = true;
195 
196  _slave_nodes.clear();
197  _neighbor_nodes.clear();
198 
199  // Redo the search
200  findNodes();
201 }
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
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 69 of file NearestNodeLocator.h.

Referenced by PenetrationLocator::detectPenetration().

69 { return *_slave_node_range; }
NodeIdRange * _slave_node_range
std::vector<dof_id_type>& NearestNodeLocator::slaveNodes ( )
inline

Returns the list of slave nodes this Locator is tracking.

Definition at line 63 of file NearestNodeLocator.h.

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

Member Data Documentation

BoundaryID NearestNodeLocator::_boundary1

Definition at line 93 of file NearestNodeLocator.h.

Referenced by findNodes().

BoundaryID NearestNodeLocator::_boundary2

Definition at line 94 of file NearestNodeLocator.h.

Referenced by findNodes().

bool NearestNodeLocator::_first

Definition at line 96 of file NearestNodeLocator.h.

Referenced by findNodes(), and reinit().

Real NearestNodeLocator::_max_patch_percentage

Definition at line 105 of file NearestNodeLocator.h.

Referenced by findNodes(), and GeometricSearchData::maxPatchPercentage().

MooseMesh& NearestNodeLocator::_mesh
protected

Definition at line 86 of file NearestNodeLocator.h.

Referenced by findNodes().

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

Definition at line 91 of file NearestNodeLocator.h.

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

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

Definition at line 99 of file NearestNodeLocator.h.

Referenced by findNodes(), and reinit().

const unsigned int NearestNodeLocator::_patch_size
static

Definition at line 102 of file NearestNodeLocator.h.

NodeIdRange* NearestNodeLocator::_slave_node_range
protected

Definition at line 88 of file NearestNodeLocator.h.

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

std::vector<dof_id_type> NearestNodeLocator::_slave_nodes
SubProblem& NearestNodeLocator::_subproblem
protected

Definition at line 84 of file NearestNodeLocator.h.

Referenced by findNodes().


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