NAME
ArrayGen(Type) - generalized, multi-dimensional array with arith
metic operations (arbitrary base)
INCLUDE
include "ArrayGen_Type.h"
SYNTAX
//-----------------------------------------------------------------------------
class ArrayGen(Type) : public Vec(Type), public ArrayGenSimple(Type)
//-----------------------------------------------------------------------------
{
friend class ArrayGenSel(Type);
// recall: virtual base classes VecSimplest(Type) and VecSimple(Type)
public:
// --- Constructors & destructor ---
ArrayGen(Type) ();
ArrayGen(Type) (int n1);
ArrayGen(Type) (int n1, int n2);
ArrayGen(Type) (int n1, int n2, int n3);
ArrayGen(Type) (const Ptv(int)& n); // multiple index
ArrayGen(Type) (const ArrayGen(Type)& X);
ArrayGen(Type) (const Vector_prm(Type)& pm);
virtual ~ArrayGen(Type) ();
// --- Miscanellous utilities ---
bool compatible (const Vec(Type)& a);
bool compatible (const ArrayGen(Type)& a);
// --- Reallocation ---
virtual bool makeItSimilar (Handle(Vector(Type))& v) const;
virtual bool redim (const Vector_prm(Type)& pm)
{ return Vec(Type)::redim (pm);}
bool redim (int n1)
{ return ArrayGenSimplest(Type)::redim(n1); }
bool redim (int n1, int n2)
{ return ArrayGenSimplest(Type)::redim(n1,n2); }
bool redim (int n1, int n2, int n3)
{ return ArrayGenSimplest(Type)::redim(n1,n2,n3); }
bool redim (const Ptv(int)& n)
{ return ArrayGenSimplest(Type)::redim(n); }
// --- Assignments ---
virtual void fill (const Vector(Type)& X);
virtual void fill (const Type& a);
ArrayGen(Type)& operator = (const ArrayGen(Type)& X)
{ ArrayGenSimple(Type)::operator=(X); return *this; }
ArrayGen(Type)& operator = (const Type& a)
{ VecSimple(Type)::fill(a); return *this; }
ArrayGen(Type)& operator = (const ArrayGenSel(Type)& X);
void fill (Type start, Type stop) { Vec(Type)::fill(start,stop); }
Type& operator () (int i)
{ return ArrayGenSimplest(Type)::operator()(i); }
Type& operator () (int i, int j)
{ return ArrayGenSimplest(Type)::operator()(i,j); }
Type& operator () (int i, int j, int k)
{ return ArrayGenSimplest(Type)::operator()(i,j,k); }
Type& operator () (const Ptv(int)& index)
{ return ArrayGenSimplest(Type)::operator()(index); }
const Type& operator () (int i) const
{ return ArrayGenSimplest(Type)::operator()(i); }
const Type& operator () (int i, int j) const
{ return ArrayGenSimplest(Type)::operator()(i,j); }
const Type& operator () (int i, int j, int k) const
{ return ArrayGenSimplest(Type)::operator()(i,j,k); }
const Type& operator () (const Ptv(int)& index) const
{ return ArrayGenSimplest(Type)::operator()(index); }
// --- Numerical operations ---
// This functionality is inherited from Vec
// --- I/O interface ---
virtual void print (Os os, const char* header = NULL,
int nentries_per_line = 3) const;
virtual void printAscii (Os os, const char* header = NULL) const;
virtual void scan (Is is);
friend Os& operator << (Os& os, const ArrayGen(Type)& x);
friend Is& operator >> (Is& is, ArrayGen(Type)& x);
// save and load inherited from Vec
CLASS_INFO
VIRTUAL_CAST(ArrayGen(Type))
private:
// avoid function "hiding" warnings from Sun compilers
bool compatible (const ArrayGenSimplest(Type)& a,
bool error_message = true)
{ return ArrayGenSimplest(Type)::compatible(a,error_message); }
bool compatible (const VecSimplest(Type)& X) const
{ return VecSimplest(Type)::compatible(X); }
void printAscii (Os os, const char* /*header*/,
int /*nentries_per_line*/) const { printAscii(os,NULL); }
bool redim (Type* a, int n, int base = 0)
{ return ArrayGenSimplest(Type)::redim(a,n,base); }
};
KEYWORDS
finite difference methods, point operator matrix, general array,
multi-dimensional array, array
DESCRIPTION
The class implements a multi-dimensional array in terms of a
standard, one-dimensional C array. The multi-dimensional feature
is created by offering subscript operators for one, two, three
and Ptv(int) indices. The bases of the indices can be arbitrary
(see the example for class ArrayGenSimplest(Type). It is assumed
that the entries in the array can be used in arithmetic opera
tions like +, -, * and /.
Please note that ArrayGen(Type) is simply a standard vector with
the possibility of multi-dimensional indexing.
The present class has class VecSimplest(Type) as a virtual base
class.
CONSTRUCTORS AND INITIALIZATION
With respect to the constructors taking multiple integers or
Ptv(int) arguments, see the documentation for class ArrayGenSim
plest(Type). In addition, there is a copy constructor and a ver
sion based on the parameter class Vector_prm(Type), see class
Vec(Type) for further details.
MEMBER FUNCTIONS
Several member functions are tailored versions of the ones in the
ancestor classes Vec(Type) and ArrayGenSimplest(Type). We refer
to the documentation of these classes for further details. How
ever the following local definitions are made:
compatible - checks compatibility between the input vector and
the current object with respect to the total length.
We note that all functions for arithmetic operations, i.e., add,
norm, normDiff and inner are inherited from class Vec(Type). That
is, in such operations the ArrayGen(Type) entries are viewed as
elements of a standard vector and treated according to the actual
storage sequence.
EXAMPLES
See documentation for class ArrayGenSimplest(Type).
SEE ALSO
class ArrayGenSimplest(Type), class Vec(Type), class Array
GenSel(Type).
DEVELOPED BY
SINTEF Applied Mathematics, Oslo, Norway, and University of Oslo,
Dept. of Mathematics, Norway
AUTHOR
Original code by Hans Petter Langtangen, UiO/SINTEF Applied Math
ematics. Modified and extended by Are Magnus Bruaset, SINTEF
Applied Mathematics.