Index

NAME

FieldPiWisConst  - piecewise const scalar field over materials or
elements


INCLUDE

include "FieldPiWisConst.h"

SYNTAX

 class FieldPiWisConst : public FieldWithPtValues
 {
   friend class FieldsPiWisConst;

   Handle(GridFE)        mesh;
   Handle(Vec(NUMT))     subdomain_values;
   bool                  elementsRsubdomains;

   HandleElmDefs         elmdef;  // help quantity for void point
   Mat(real)             coor;    // help quantity for void point

   bool reallocate
     (const GridFE& grid, bool elementsRsubdomains, const char* fieldname);

 public:
   FieldPiWisConst ();
   FieldPiWisConst (const GridFE& grid, bool elementsRsubdomains,
                    const char* fieldname);
   FieldPiWisConst (const GridFE& grid, const Vec(NUMT)& subdomain_values,
                    const char* fieldname);
  ~FieldPiWisConst ();

   bool update ();  // updating/redim due to a mesh change
   bool redim  (const GridFE& grid, bool elementsRsubdomains,
                const char* fieldname);
   bool redim  (const GridFE& grid, const Vec(NUMT)& subdomain_values,
                const char* fieldname);

   const GridFE& grid () const { return mesh(); }
         GridFE& grid ()       { return mesh(); }

   bool piecewiseConstOverElms () const  { return elementsRsubdomains; }

   const Vec(NUMT)& values () const { return *subdomain_values; }
         Vec(NUMT)& values ()       { return *subdomain_values; }

   // setValueElm, setSubDomainValue and setMaterialValue do the same...
   void setValueElm (int e, NUMT value);
   void setSubDomainValue (int material, NUMT value);
   void setMaterialValue (int material, NUMT value)
      { setSubDomainValue(material,value); } // just another name...

   void fill (const Vec(NUMT)& values);
   void operator = (const FieldPiWisConst& f);
   void operator = (const FieldFE& f);  // samples f at the element centroid
   void fill (const FieldsFEatItgPt& f, int component);  // average in each elm

   virtual bool ok () const;
   virtual void minmax (NUMT& min, NUMT& max, GridWithPts* grid =NULL) const;

   void point (Ptv(real)& pt, int element);
   void point (Ptv(real)& pt, int element) const
   { CAST_CONST_AWAY(FieldPiWisConst)->point(pt,element); }

           NUMT  valueElm (int e) const;

   virtual NUMT  valuePt  (const Ptv(real)& x, real t = DUMMY);
   virtual NUMT  valueFEM (const FiniteElement& fe, real t = DUMMY);
   virtual Ptv(NUMT) derivativePt (const Ptv(real)& x, real t = DUMMY);
           void      derivativeElm (Ptv(NUMT)& der, int e);
   virtual void derivativeFEM (Ptv(NUMT)& d, const FiniteElement& fe,
                               real t = DUMMY);

   virtual void fill  (NUMT value);
   virtual void add   (NUMT value);
   virtual void mult  (NUMT value);
   virtual void apply (Func(NUMT) f);
   virtual void add   (Field& field, int power, NUMT front_factor);

   virtual Field&   scale ();
   virtual Field& unscale ();

   virtual void  unloadData (Os os) const;
   virtual void loadData (Is is);
   virtual void  attach (Grid& grid);
   virtual Grid* getGridBase();

   // virtual functions from FieldWithPtValues:

   virtual int   getNoPoints () const  // cannot be made inline
     { return subdomain_values->size(); }

   virtual int   getNoValues () const  // cannot be made inline
     { return subdomain_values->size(); }

   virtual NUMT& valuePoint (int point_no)
     { return subdomain_values()(point_no); }  // virt. & less eff. than valueElm

   virtual NUMT  valuePoint (int point_no) const
    { return subdomain_values()(point_no); }

   virtual Ptv(real) getPt (int point_no) const;

   virtual       GridWithPts& getGridWithPts ();
   virtual const GridWithPts& getGridWithPts () const;

   virtual Vec(NUMT)& valuesVec()
     { return *subdomain_values; }
   virtual const Vec(NUMT)& valuesVec() const
     { return *subdomain_values; }

   CLASS_INFO
   VIRTUAL_CAST(FieldPiWisConst);
   // temporary:
   COPY_CONSTRUCTOR(FieldPiWisConst);

   virtual void print (Os os) const;
           void scan  (Is is);
 };



KEYWORDS

finite element, scalar field, piecewise constants



DESCRIPTION

The FieldPiWisConst class represents a piecewise constant  scalar
field  over  non-overlapping subdomains of a finite element grid.
The subdomains are defined in terms of the "material" concept  in
class GridFE.  (This is different from the "subdomain" concept in
class GridFE; the latter can represent non-overlapping subdomains
for domain decomposition methods and parallel algorithms, whereas
the former reflects distinct physical materials  of  the  domain,
with  possibly  different physical (material) properties.)  There
are two different representations: 1) the field  is  constant  on
each subdomain, where the subdomains are defined in a finite ele­
ment grid, 2) the field is constant on each finite element  (ie.,
the  finite  elements  constitute  the  subdomains).  The  choice
between these two definitions of "subdomain" is given as a param­
eter to the constructor.

It  may  seem  strange that FieldPiWisConst is derived from class
FieldWithPtValues. This derivation is  motivated  by  some  field
generators  (such as stochastic field generators) where one wants
to hide the details of a scattered point  collection,  a  compli­
cated  finite  element  field  or a piecewise constant field. The
"point" associated with a field value in FieldPiWisConst is meant
to  be  the  centroid  of the domain over which the field is con­
stant. When the elements are the subdomains, this point  is  easy
to  compute  since GridFE supports a function for calculating the
centroid. For subdomain consisting of a set of elements, there is
no  implementation  of the "point" concept in the present version
of the class.  However, in this latter case, there is seldom use­
ful to regard FieldPiWisConst as a field with point values.



CONSTRUCTORS AND INITIALIZATION

There  is one constructor taking a finite element grid as parame­
ter. In addition, a boolean variable indicates whether  the  ele­
ments  are  the  subdomain or if the subdomain definitions in the
grid should be used.



MEMBER FUNCTIONS

"redim - each constructor is a  simple  call  to  the  associated
redim function. In other words, we refer to constructing and ini­
tializing the class for more information on the  actions  of  the
redim functions.

update  -redimensions  the  internal data structure in accordance
with the attached grid. useful in adaptive grid methods where the
size of the grid may vary during a simulation. The boolean return
value reflects whether new memory was allocated or not.

grid -returns access to the assocoated grid.

piecewiseConstOverElms - returns a true value if the elements are
the subdomains (otherwise it returns a false value).

setValueElm - sets the value of the field in an element. Requires
that the elements are the subdomains.

setDubDomainValue - sets the field value for the given  subdomain
(to  be  used  when  the elements are not the subdomains, and the
subdomain reflects a material).

setMaterialValue - same as setSubDomainValue, just another  func­
tion name for making some codes easier to read.

fill(const  Vec(NUMT)&  values)  - fill all subdomain values.  If
the elements are the subdomains and one sends  an  ArrayGen(real)
as  argument, one can use this function for initializing a Field­
PiWisConst with values obtained from the cells in a  finite  dif­
ference  grid  (GridLattice). The element and cell numbering will
correspond to each other if the numering conventions of PreproBox
(for  example)  is  followed when constructing the finite element
grid.  If the grid was initialized by a scanLattice function,  or
set  equal  to a GridLattice, the element numering will automati­
cally coincide.  Observe that the length and dimension  sizes  of
the ArrayGen(real) argument is different from the standard Field­
Lattice point values array (in the latter field class, the  point
array reflects values at the nodes in the grid rather than in the
cells).

fill (FieldsFEatItgPt&) - initializes a FieldPiWisConst object at
each  element as the average of the field values of FieldsFEatIt­
gPt (in the same element). If FieldsFEatItgPt contains  only  one
field  value  per  element (at the centroid), the data in Fields­
FEatItgPt  are  just  copied  into  the  present  FieldPiWisConst
object.

values  -  gives  access to a vector with all the subdomain field
values.  The length of the vector depends on the type  of  field,
that  is,  piecewise  constants  over each element or over subdo­
mains.  You can  use  value().size(),  or  better,  piecewiseCon­
stOverElms to test for the field type.

For the rest of the member functions we refer to class FieldFE.



EXAMPLE

Two applications can be found under the directories
$NOR/dp/src/app/class-verify/FieldPiWisConst/permeability
$NOR/dp/src/app/class-verify/FieldPiWisConst/velocity


SEE ALSO

class Field, class GridFE


DEVELOPED BY

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


AUTHOR

Hans Petter Langtangen, SINTEF/UiO