How to Access Neighbor Nodes and Elements

From KratosWiki
Revision as of 15:25, 26 November 2007 by Rrossi (Talk | contribs)
Jump to: navigation, search

In a finite element context it is often useful to have a fast access ( O(N) time with N number of nodes ) to the objects which are "around" a certain node. This can be achieved by storing on each node the list of all of the nodes and elements which are close to it.


Before proceeding it is useful to clarify the meaning of the word "around". To do so, let's consider the mesh


we will define as "NEIGHBOUR NODES" of node 910 which share at least one element with node 910. To make an example

  • Node 910 has the nodes {968 , 940 , 986 , 850 , 876 , 931 } as neighbours nodes
  • Node 876 has the nodes {910, 850, 820, 843, 898, 931} as neighbours nodes

and the elements

  • {2873, 2960, 2961, 2876, 2875, 2874} as NEIGHBOUR ELEMENTS of node 910
  • {2876, 2877, 2849, 2848, 2865, 2875} as NEIGHBOUR ELEMENTS of node 876

note that the order is NOT guaranteed.

Format and use of the Containers

The list of neighbour elements is stored in Kratos as a list of (Weak) Pointers to the nodes or elements. Given a pointer "pnode" to a Node, the list of its neighbour nodes can be obtained as

  WeakPointerVector< Node<3> >& rneigh = pnode->GetValue(NEIGHBOUR_NODES);

while the neighbour elements list can be accessed by

  WeakPointerVector< Element >& rneigh_el = pnode->GetValue(NEIGHBOUR_ELEMENTS);

The two containers are standard and can be treated as normal stl-style containers. A loop over nodes can thus be done by

  WeakPointerVector< Node<3> >& rneigh = pnode->GetValue(NEIGHBOUR_NODES);
  for( WeakPointerVector<Node<3> >::iterator inode = rneigh.begin(); inode!=rneigh.end(); inode++)
     inode->Id(); //accesses to the Id of the node

the user should note that "Weak" pointers are used instead of "Pointers". This is done to guarantee that if a node or element is removed from the list, it will be automatically set to null (but will not be preserved in the memory as it would happen using "Pointers").

Personal tools