OOF2: The Manual

Name

ElementNodeIterator — Iterate over Nodes in an Element

Synopses

C++ Synopsis

#include "engine/elementnodeiterator.h"
class ElementNodeIterator {
  Node* node() const;
  ElementNodeIterator& operator++();
  virtual bool end() const;
  virtual void set_start();
  const MasterCoord& mastercoord() const;
}

Python Synopsis

from oof2.SWIG.engine import elementnodeiterator
class ElementNodeIterator:
  def node(self)
  def increment(self)
  def end(self)
  def set_start(self)
  def __getitem__(self, dummyindex)

Source Files

  • SRC/engine/elementnodeiterator.C: C++ source code
  • SRC/engine/elementnodeiterator.h: C++ header
  • SRC/engine/elementnodeiterator.swg: swig source code
  • SRC/engine/elementnodeiterator.spy: Python code included in swig output

Description

An ElementNodeIterator is used to loop over all of the Nodes of an Element. ElementNodeIterators should be created by calling Element::node_iterator, rather than calling the ElementNodeIterator constructor directly.

Here's how to iterate over Nodes in C++:

Element *element; // assume this has been set
for(ElementNodeIterator iter=element->node_iterator(); !iter.end(); ++iter) {
  Node *node = iter.node();
  // do something with node
} 

and here's one way to do it in Python:

for nodeiter in element.node_iterator():
   node = nodeiter.node()
   // do something with node 

Here's an uglier way to do it in Python, which might be useful in some circumstances:
nodeiter = element.node_iterator()
while not nodeiter.end():
    node = nodeiter.node()
    // do something with node
    nodeiter.increment()

Methods

Only those methods useful to authors of OOF2 extensions are discussed here.

Node* node() const

node returns a pointer to the iterator's current Node.

ElementNodeIterator& operator++(), increment()

The C++ function operator++ and the Python function increment both advance the iterator to the next Node. The nodes are visited in an arbitrary order.

operator++ returns a reference to the iterator. increment returns None.

bool end() const

end returns true if the iterator has visited all of the Nodes of the Element.

void set_start()

Sometimes it's useful to look for a particular Node in an Elementand then to loop over all of the other Nodes. This can be done by iterating until the desired Node is found, and then calling the iterator's set_start method. This reinitializes the iterator without changing its current position. The end flag won't be set until the iterator returns to its current position.

const MasterCoord& mastercoord() const

mastercoord returns the master coordinate space position of the Node that the iterator currently points to. It's not possible to get this information directly from the Node, because a single Node can be in many Elements, and have a different master space position in each. ElementNodeIterators don't have this problem, because they know which Element they're looping over.

__getitem__(dummy)

__getitem__ is defined for the Python verison of ElementNodeIterator so that it's possible to use the syntax

for node in element.node_iterator():

to loop over the nodes in an Element. The argument isn't used.[66]



[66] Yes, we know that doing it this way is ugly. It should be rewritten using Python generators.