Index

NAME

ArrayGenSel(Type) - subset of general array with arithmetic oper­
ations


INCLUDE

include "ArrayGenSel_Type.h"

SYNTAX

 //-----------------------------------------------------------------------------
 class ArrayGenSel(Type) : public ArrayGen(Type)
 {
   // recall: virtual base classes VecSimplest(Type) and VecSimple(Type)

 private:

   // Index sets defining the computational domain (active nodes)

   Handle(IndexSet) Ind;

 protected:

   void reset ();

 public:

   // --- Constructors & destructor ---

   ArrayGenSel(Type) ();
   ArrayGenSel(Type) (int n1);
   ArrayGenSel(Type) (int n1, int n2);
   ArrayGenSel(Type) (int n1, int n2, int n3);
   ArrayGenSel(Type) (const Ptv(int)& n);         // multiple index
   ArrayGenSel(Type) (const IndexSet& I, int offset);
   ArrayGenSel(Type) (const IndexSet& I, const Ptv(int)& offset);
   ArrayGenSel(Type) (const ArrayGenSel(Type)& X);
   ArrayGenSel(Type) (const Vector_prm(Type)& pm);
  ~ArrayGenSel(Type) ();


   // --- Miscanellous utilities ---

   virtual int  getNoEntries () const;

   bool      hasIndexSet () const;
   IndexSet& getIndexSet () const;  // can be called if hasIndexSet is true

   // checks if the index set is compatible with the current array size :

   bool compatible(const IndexSet& I) const;

   // compatible bellow just checks the length of the array,
   // not individual dimensions

   bool compatible (const Vec(Type)& a)
   { return ArrayGen(Type)::compatible(a); }
   bool compatible (const ArrayGen(Type)& a)
   { return ArrayGen(Type)::compatible(a); }
   bool compatible (const ArrayGenSel(Type)& a)
   { return ArrayGen(Type)::compatible((Vec(Type)&)a); }


   // --- Reallocation ---

   void attach (ArrayGen(Type)& values);  // borrow the values
   void pureCopy(const ArrayGen(Type)& values); // allocate (safer than attach)
   void activate ();                      // all entries marked active
   void activate (const IndexSet& I);     // the entries with the indices given
                                          // by I are marked as active

   bool redim   (int n1);
   bool redim   (int n1, int n2);
   bool redim   (int n1, int n2, int n3);
   bool redim   (const Ptv(int)& n);
   bool redim   (const IndexSet& I, int offset=0);
   bool redim   (const IndexSet& I, const Ptv(int)& offset);
   virtual bool redim   (const Vector_prm(Type)& pm);

   virtual bool makeItSimilar (Handle(Vector(Type))& v) const;


   // --- Assignments ---

   virtual void fill (const Vector(Type)& X) { Vec(Type)::fill(X); }
   virtual void fill (const Type& a) { VecSimple(Type)::fill(a); }
   void fill (Type start, Type stop) { Vec(Type)::fill(start,stop); }

   ArrayGenSel(Type)& operator = (const ArrayGenSel(Type)& X);
   ArrayGenSel(Type)& operator = (const ArrayGen(Type)& X);
   ArrayGenSel(Type)& operator = (const Type& a)
   { VecSimple(Type)::fill(a); return *this; }


   void fillSel (const IndexSet& I, Type a);  // fill the elements given
                                              // by the index set with the
                                              // value 'a'

   // --- Numerical operations ---

   virtual void add (const Vector(Type)& yb, const Vector(Type)& zb);
   virtual void add (const Vector(Type)& yb, char s, const Vector(Type)& zb);
   virtual void add (const Vector(Type)& yb, Type b, const Vector(Type)& zb);
   virtual void add
          (Type a, const Vector(Type)& yb, Type b, const Vector(Type)& zb);
   virtual void add (const Vector(Type)& y, int power, Type front_factor);
   virtual void add (Type value);

   virtual void apply (Func(Type) f);
   virtual void mult  (Type value);

   virtual Type inner (const Vector(Type)& yb) const;

   virtual real norm (Norm_type lp = l2) const;
   virtual real normDiff (const Vector(Type)& y, Norm_type lp = l2) const;


   // --- I/O interface ---

   virtual void printSel (Os os, const char* header = NULL,
                         int nentries_per_line = 3) const;
   virtual void printSelAscii  (Os os, const char* header = NULL) const;

   void print(Os os, const char* header = NULL,
              int nentries_per_line = 3) const
   { ArrayGen(Type)::print(os,header,nentries_per_line); }

   // (all entries of the array are read by scan)
   virtual void scan  (Is is);

   friend Os& operator << (Os& os, const Vec(Type)& x);
   friend Is& operator >> (Is& is , Vec(Type)& x);

   CLASS_INFO

   VIRTUAL_CAST(ArrayGenSel(Type))

 private:

   // avoid function "hiding" warnings:
   bool compatible (const VecSimplest(Type)& X) const
   { return ArrayGenSimplest(Type)::compatible (X); }
   bool compatible (const ArrayGenSimplest(Type)& a,
                    bool error_message = true)
   { return ArrayGenSimplest(Type)::compatible(a,error_message); }


   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



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  through  inheritance  from  class  Array­
Gen(Type).  The  bases  of  the  indices  can be arbitrary. It is
assumed that the entries in the array can be used  in  arithmetic
operations  like  +,  -, *  and /. In contrast to ArrayGen(Type),
the current class can mark a subset of the  total  collection  of
vector entries as active.

In  terms of finite difference stencils, this option allows us to
disable nodes close to the grid borders. That  is,  these  points
will not contribute to arithmetic operations such as vector addi­
tions and inner products. The information  needed  for  disabling
nodes  is extracted from a set of indicies, the index set must be
represented by a class  derived  from  the  abstract  base  class
IndexSet.  The  index  set  will  mark  corresponding  entries as
active.  Please note that the subset mechanism does not influence
vector  assignments  in  terms  of  operators of member functions
(e.g. randomize).



CONSTRUCTORS AND INITIALIZATION

There are several constructors, besides the specialized construc­
tor  with an index set as argument, the documentation of the con­
structors are found within  the  documentation  of  class  Array­
Gen(Type) and class ArrayGenSimplest(Type).  The constructor with
the argument of an index set I and an integer offset allocates an
array,  using  the size of I. The offset size is appended to each
end of the spatial dimension and  the  indices  given  by  I  are
marked as active.



MEMBER FUNCTIONS

In   addition   to  the  member  functions  described  for  class
ArrayGen(Type) and class ArrayGenSimplest(Type), we have the fol­
lowing functionality:



getNoEntries  - return the number of active vector entries.

getIndexSet  - return the index set (class IndexSet) contained by
the class.

compatible  - the version with an index set  argument  checks  if
the  indices  are  well  defined corresponding to the size of the
array.  If so true is returned, otherwise false is returned.  The
other versions checks compability with different vector types and
compatibility requires that  the  memomory  segments  have  equal
length  (the  case  where  an  ArrayGenSel object, neglecting the
ghost boundary, is mathematically  compatible  with  an  ArrayGen
object is not treated).

redim  - reallocates the array, c.f. the construcors.

attach   - borrow the values of a ArrayGen object.  This function
is not  completely  safe  since  the  borrowed  object  might  be
deleted. Use the function with care!

pureCopy   -   make  a  pure copy of an ArrayGen object, that is,
allocated the vector and copy the values.

activate  - make it possible to mark selected  array  entries  as
active (others are then non-active in computations).  If no argu­
ment is present all the array entries are marked,  otherwise  the
index set given as argument is used to mark active entries.

makeItSimilar   -  as  in  the  other  classes  derived from Vec­
tor(Type),  this  function  reinitializes  an   existing   Array­
GenSel(Type)  object  or  allocates a new one. In both cases, the
handle v refers to an object with the same attributes as the cur­
rent  one.  In particular, the referenced object will inherit the
present marking of active entries. Please note that this function
does not copy the actual vector entries.

operator  =   and   fill  - these assignments will affect all the
elements of the array.

fillSel  - the elements corresponding to the  index  set  in  the
argument is assigned to a given value.

add   -  vector  additions  use  only  entries that are marked as
active. This is also true for other  arithmetic  operations  like
apply, mult, inner, norm and normDiff.

randomize   - this assignment will affect all the elements of the
array (inherited from class ArrayGen(Type)).





EXAMPLE

#include <Arrays_real.h>
#include <IndexSetBox.h>

void main()
{
  Ptv(int) b(1,1), t(5,5);

  IndexSetBox box(b,t);        // box shaped indexset
  ArrayGenSel(real) x(box,1); // allocates  an  array  with  base
(0,0)
                              // and upper index (6,6)
  s_o<< x.getNoEntries();     // number of marked elements
  ArrayGenSel(real) y(x);     // copy constructor
  x = 1; y = 2;               // all elements are initialized
  y.add(x,y);                 // y = x + y , note that only the
                              // marked elements of y are added
  y.print(s_o,"y=");          // print, only marked elements  are
printed
}



SEE ALSO

class ArrayGen(Type), class ArrayGenSimplest(Type).


DEVELOPED BY

SINTEF Applied Mathematics, Oslo, Norway, and University of Oslo,
Dept. of Mathematics, Norway


AUTHOR

Are Magnus Bruaset, SINTEF Applied Mathematics.

Modified  an extended by Johan Berge, SINTEF Applied Mathematics.