OOF2: The Manual


IndexP — Generic wrapper for index objects


C++ Synopsis

#include "engine/fieldindex.h"
class IndexP {
  IndexP(FieldIndex* index);
  IndexP(const IndexP& other);
  IndexP cloneIndex() const;
  int integer() const;
  bool in_plane() const;
  operator const FieldIndex&() const;
  void set(const std::vector<int>* components);
  std::vector<int>* components() const;

Python Synopsis

from oof2.SWIG.engine.fieldindex import IndexP
class IndexP:
  def cloneIndex(self)
  def integer(self)
  def in_plane(self)
  def set(self, components)
  def components(self)

Derived Classes

Source Files

  • SRC/engine/fieldindex.h: C++ header
  • SRC/engine/fieldindex.C: C++ source code
  • SRC/engine/fieldindex.swg: SWIG source code
  • SRC/engine/fieldindex.spy: python code included in the swig output


IndexP is a wrapper for the various FieldIndex classes, which are used to refer to components of various kinds of Fields, Fluxes and Equations. The wrapper is a light-weight object that allows a FieldIndex to be used in a generic fashion, while at the same time handling allocation and deallocation of the FieldIndex object. All of the public FieldIndex methods are available in IndexP.

Note that IndexP does not do reference counting. It's not a smart pointer class. It just allows functions that would otherwise have to work with a pointer to work with an object instead.


IndexP(FieldIndex *index)

The IndexP constructor has a single argument, which must be a pointer to a newly constructed instance of a FieldIndex subclass. The IndexP takes over ownership of the FieldIndex and will delete it when necessary.

[Note] Note

The IndexP constructor is not available in Python. It should never be necessary to construct a new IndexP in Python. Most IndexP objects are constructed by calling a C++ method of a Field (or similar) object.

IndexP(const IndexP& other)

The IndexP copy constructor creates a copy of the underlying FieldIndex object as well.

IndexP cloneIndex() const

cloneIndex is just a wrapper for the copy constructor. It's useful to have an explicit name for this operation when it's invoked from IteratorP, which is derived from IndexP.

int integer() const()

Every kind of FieldIndex has a canonical ordering of the indices that it represents. For example, a VectorFieldIndex takes the values x, y, z in that order, and a SymTensorIndex takes the values xx, yy, zz, yz, xz, xy, in that order. IndexP::integer returns the current value's position in the canonical list.

integer is used whenever an IndexP needs to be used to determine a position in a Python list, C++ std::vector, or other linear storage structure. It's also used in some situations where functions weren't designed to accept the more abstract FieldIndex or IndexP objects, for whatever reason.

bool in_plane() const

in_plane indicates whether or not the IndexP refers to an in-plane or out-of-plane index. For vectors, x and y are in-plane. For tensors, any set of indices containing a z is out-of-plane.

operator const FieldIndex&() const

This operator converts an IndexP to a reference to a const FieldIndex. This conversion can only be done in C++.

void set(const std::vector<int>* components)

The set method sets the value of a IndexP and its underlying FieldIndex from a std::vector of ints (in C++) or a list of integers (in Python). The required length of the list depends on the FieldIndex subclass.

std::vector<int>* components() const

components returns the value of the IndexP as a C++ std::vector or Python list of integers. The length of the list depends upon the FieldIndex subclass that the IndexP wraps. This function allocates a new std::vector<int>, which must be deleted explicitly when called from C++.