Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

FArrayBox.H

Go to the documentation of this file.
00001 /* _______              __
00002   / ___/ /  ___  __ _  / /  ___
00003  / /__/ _ \/ _ \/  ' \/ _ \/ _ \
00004  \___/_//_/\___/_/_/_/_.__/\___/ 
00005 */
00006 //
00007 // This software is copyright (C) by the Lawrence Berkeley
00008 // National Laboratory.  Permission is granted to reproduce
00009 // this software for non-commercial purposes provided that
00010 // this notice is left intact.
00011 // 
00012 // It is acknowledged that the U.S. Government has rights to
00013 // this software under Contract DE-AC03-765F00098 between
00014 // the U.S.  Department of Energy and the University of
00015 // California.
00016 //
00017 // This software is provided as a professional and academic
00018 // contribution for joint exchange. Thus it is experimental,
00019 // is provided ``as is'', with no warranties of any kind
00020 // whatsoever, no support, no promise of updates, or printed
00021 // documentation. By using this software, you acknowledge
00022 // that the Lawrence Berkeley National Laboratory and
00023 // Regents of the University of California shall have no
00024 // liability with respect to the infringement of other
00025 // copyrights by any part of this software.
00026 //
00027 
00028 #ifndef CH_FARRAYBOX_H
00029 #define CH_FARRAYBOX_H
00030 
00031 //
00032 // $Id: FArrayBox.H,v 1.4 2002/03/29 19:23:55 bvs Exp $
00033 //
00034 
00035 #ifndef WRAPPER
00036 #include <iostream>
00037 
00038 //#include <Pointers.H>
00039 #include "Box.H"
00040 #include "BaseFab.H"
00041 #endif
00042 
00043 #include "REAL.H"
00044 #include "SPACE.H"
00045 
00046 
00047 
00048 //@Man:
00049 //@Memo: A Fortran Array of Reals
00050 /*@Doc: 
00051 
00052   Fortran Array Boxes (generally called FABs) are objects constructed
00053   to interface with arrays in Fortran.  Useful operations can be performed
00054   upon FABs in C++, and they provide a convenient interface to
00055   Fortran when it is necessary to retreat into that language for
00056   doing arithmetic operations when performance matters.
00057 
00058   FArrayBox is derived from BaseFab<Real>.
00059   FArrayBox adds additional useful capabilities which make sense
00060   for Real types, such as I/O and L**p norms.
00061 
00062   The C pre-processor macro `CH\_SPACEDIM' must be defined to use
00063   this class.  The internal precision of FArrayBox objects is
00064   set by defining either `CH\_USE\_FLOAT' or `CH\_USE\_DOUBLE' 
00065 
00066   This class does NOT provide a copy constructor or assignment operator.  */
00067 
00068 
00069 class FArrayBox 
00070 : public BaseFab<Real>
00071 {
00072 
00073 
00074 public:
00075 
00077 
00079 
00082   FArrayBox ();
00083 
00084   /*@ManDoc: Constructs an initial FArrayBox with the data space
00085     allocated but not inititialized. ncomp is the number of components
00086     (variables) at each data point in the Box.  
00087 
00088 */
00089   FArrayBox (const Box& b, int ncomp);
00090   void define(const Box& b, int ncomp) {resize(b, ncomp);}
00091 
00093 
00096   explicit FArrayBox (std::istream& is);
00097 
00099 
00102   virtual ~FArrayBox ();
00103 
00105 
00106   /*@ManDoc: Returns the Lp-norm of this FAB using components
00107     (comp : comp+numcomp-1).  p < 0  -> ERROR.
00108     p = 0  -> infinity norm (max norm).
00109     p = 1  -> sum of ABS(FAB)
00110     p > 1  -> Lp-norm
00111   */
00112   virtual Real norm (int p=2,
00113                      int comp=0,
00114                      int numcomp=1) const;
00115 
00116   /*@ManDoc: Returns the Lp-norm of this FAB using components (comp :
00117     comp+numcomp-1) and within the subbox.  p < 0 -> ERROR.  p = 0 ->
00118     infinity norm (max norm).  p = 1 -> sum of ABS(FAB) p > 1 ->
00119     Lp-norm 
00120 */
00121   virtual Real norm (const Box& subbox,
00122                      int        p=2,
00123                      int        comp=0,
00124                      int        numcomp=1) const;
00125 
00131   virtual Real sumPow(const Box& subbox,
00132                      int        p=2,
00133                      int        comp=0,
00134                      int        numcomp=1) const;
00135 
00137 
00139 
00142   Real min (int comp = 0) const;
00143 
00145 
00150   Real min (const Box& subbox,
00151             int        comp = 0) const;
00152 
00154 
00157   Real max (int comp = 0) const;
00158 
00160 
00165   Real max (const Box& subbox,
00166             int        comp = 0) const;
00167 
00169 
00172   IntVect minIndex (int comp = 0) const;
00173 
00174   /*@ManDoc: Returns location of minimum value in given component  of this FArrayBox in
00175     given subbox.
00176   */
00177   IntVect minIndex (const Box& subbox,
00178                     int        comp = 0) const;
00180 
00183   IntVect maxIndex (int comp = 0) const;
00184 
00185   /*@ManDoc: Returns location of maximum value in given component of
00186     this FArrayBox in given subbox.  
00187 
00188 */
00189   IntVect maxIndex (const Box& subbox,
00190                     int        comp = 0) const;
00191 
00193 
00195 
00201   int maskLT (BaseFab<int>& mask,
00202               Real             val,
00203               int           comp = 0) const;
00204 
00206 
00213   int maskLE (BaseFab<int>& mask,
00214               Real             val,
00215               int           comp = 0) const;
00217 
00223   int maskEQ (BaseFab<int>& mask,
00224               Real             val,
00225               int           comp = 0) const;
00227 
00233   int maskGT (BaseFab<int>& mask,
00234               Real             val,
00235               int           comp = 0) const;
00236 
00238 
00245   int maskGE (BaseFab<int>& mask,
00246               Real             val,
00247               int           comp = 0) const;
00248 
00249 
00251 
00253 
00257   void abs ();
00258 
00260 
00265   void abs (int comp,
00266             int numcomp=1);
00267 
00269 
00274   void abs (const Box& subbox,
00275             int        comp = 0,
00276             int        numcomp=1);
00277 
00279 
00282   Real sum (int comp,
00283             int numcomp = 1) const;
00284 
00285   /*@ManDoc: Returns sum of component of this FArrayBox in given
00286     subbox.  
00287 
00288 */
00289   Real sum (const Box& subbox,
00290             int        comp,
00291             int        numcomp = 1) const;
00292 
00294 
00298   FArrayBox& invert (Real v);
00300 
00305   FArrayBox& invert (Real          v,
00306                      const Box& subbox,
00307                      int        comp=0,
00308                      int        numcomp=1);
00310 
00315   FArrayBox& invert (Real   v,
00316                      int comp,
00317                      int numcomp=1);
00318 
00319 
00320 
00322 
00327   FArrayBox& negate (const Box& subbox,
00328                      int        comp=0,
00329                      int        numcomp=1);
00331 
00336   FArrayBox& negate (int comp,
00337                      int numcomp=1);
00339 
00344   FArrayBox& negate ();
00345 
00347 
00352   FArrayBox& plus (Real          r,
00353                    const Box& b,
00354                    int        comp=0,
00355                    int        numcomp=1);
00356 
00358 
00363   FArrayBox& plus (Real   r,
00364                    int comp,
00365                    int numcomp=1);
00366 
00367 
00369 
00373   FArrayBox& operator+= (Real r);
00374 
00376 
00382    FArrayBox& operator+= (const FArrayBox& f);
00383 
00385 
00391   FArrayBox& plus (const FArrayBox& src);
00392 
00394 
00398   FArrayBox& plus (Real r);
00399   FArrayBox& plus_real (Real r) {return this->plus(r);}
00401 
00407   FArrayBox& plus (const FArrayBox& src, const Real& scale);
00409 
00414   FArrayBox& plus (const FArrayBox& src, const Real& scale, 
00415                    int                srccomp,
00416                    int                destcomp,
00417                    int                numcomp=1);
00418 
00419   /*@ManDoc: Modifies this FArrayBox by pointwise addition of values
00420     in the argument FArrayBox.  Adds src's components
00421     (srccomp:srccomp+numcomp-1) to this FArrayBox's components
00422     (destcomp:destcomp+numcomp-1) where the domains of the two
00423     FArrayBoxes intersect.  
00424 
00425 */
00426   FArrayBox& plus (const FArrayBox& src,
00427                    int                srccomp,
00428                    int                destcomp,
00429                    int                numcomp=1);
00430 
00431   /*@ManDoc: Modifies this FArrayBox by pointwise addition of values
00432     in the argument FArrayBox.  Adds src's components
00433     (srccomp:srccomp+numcomp-1) to this FArrayBox's components
00434     (destcomp:destcomp+numcomp-1) where the domain of this FArrayBox
00435     intersects the subbox.  NOTE: subbox must be contained in this
00436     FAB.  
00437 
00438 */
00439   FArrayBox& plus (const FArrayBox& src,
00440                    const Box&         subbox,
00441                    int                srccomp,
00442                    int                destcomp,
00443                    int                numcomp=1);
00444 
00445   /*@ManDoc: Modifies this FArrayBox by pointwise addition of values
00446                in the argument FArrayBox.  Adds src's components
00447                (srccomp:srccomp+numcomp-1) in the Box srcbox to this
00448                FArrayBox's components (destcomp:destcomp+numcomp-1) in
00449                the Box destbox.  Corresponding locations within the
00450                two FArrayBoxes are indexed relative to srcbox and
00451                destbox, and will in general not be the same.  The
00452                srcbox and destbox must be same size.  The results are
00453                UNDEFINED if the src and dest FArrayBoxes are the same
00454                and the srcbox and destbox overlap.
00455 
00456   */
00457   FArrayBox& plus (const FArrayBox& src,
00458                    const Box&         srcbox,
00459                    const Box&         destbox,
00460                    int                srccomp,
00461                    int                destcomp,
00462                    int                numcomp=1);
00463 
00465 
00469   FArrayBox& operator-= (Real r);
00470 
00472 
00478   FArrayBox& operator-= (const FArrayBox& f);
00479 
00481 
00487   FArrayBox& minus (const FArrayBox& src);
00488 
00489   /*@ManDoc: Modifies this FArrayBox by pointwise subtraction of values
00490     in the argument FArrayBox.  Subtracts src's components
00491     (srccomp:srccomp+numcomp-1) from this FArrayBox's components
00492     (destcomp:destcomp+numcomp-1) where the domains of the two
00493     FArrayBoxes intersect.  
00494 
00495 */
00496   FArrayBox& minus (const FArrayBox& src,
00497                     int                srccomp,
00498                     int                destcomp,
00499                     int                numcomp=1);
00500 
00501   /*@ManDoc: Modifies this FArrayBox by pointwise subtraction of values
00502     in the argument FArrayBox.  Subtracts src's components
00503     (srccomp:srccomp+numcomp-1) from this FArrayBox's components
00504     (destcomp:destcomp+numcomp-1) where the domain of this FArrayBox
00505     intersects the subbox.  NOTE: subbox must be contained in this
00506     FAB.  
00507 
00508 */
00509   FArrayBox& minus (const FArrayBox& src,
00510                     const Box&         subbox,
00511                     int                srccomp,
00512                     int                destcomp,
00513                     int                numcomp=1);
00514 
00515   /*@ManDoc: Modifies this FArrayBox by pointwise subtraction of values
00516                in the argument FArrayBox.  Subtracts src's components
00517                (srccomp:srccomp+numcomp-1) in the Box srcbox from this
00518                FArrayBox's components (destcomp:destcomp+numcomp-1) in
00519                the Box destbox.  Corresponding locations within the
00520                two FArrayBoxes are indexed relative to srcbox and
00521                destbox, and will in general not be the same.  The
00522                srcbox and destbox must be same size.  The results are
00523                UNDEFINED if the src and dest FArrayBoxes are the same
00524                and the srcbox and destbox overlap.
00525 
00526   */
00527   FArrayBox& minus (const FArrayBox& src,
00528                     const Box&         srcbox,
00529                     const Box&         destbox,
00530                     int                srccomp,
00531                     int                destcomp,
00532                     int                numcomp=1);
00533 
00535 
00538   FArrayBox& operator*= (Real r);
00539 
00541 
00544   FArrayBox& mult (Real r);
00545 
00547 
00552   FArrayBox& mult (Real   r,
00553                    int comp,
00554                    int numcomp=1);
00555 
00557 
00562   FArrayBox& mult (Real          r,
00563                    const Box& b,
00564                    int        comp=0,
00565                    int        numcomp=1);
00566 
00568 
00574   FArrayBox& operator*= (const FArrayBox& f);
00575 
00577 
00583   FArrayBox& mult (const FArrayBox& src);
00584 
00585   /*@ManDoc: Modifies this FArrayBox by pointwise multiplication by values
00586     in the argument FArrayBox.  Multiplies src's components
00587     (srccomp:srccomp+numcomp-1) by this FArrayBox's components
00588     (destcomp:destcomp+numcomp-1) where the domains of the two
00589     FArrayBoxes intersect.  
00590 
00591 */
00592   FArrayBox& mult (const FArrayBox& src,
00593                    int                srccomp,
00594                    int                destcomp,
00595                    int                numcomp=1);
00596 
00597   /*@ManDoc: Modifies this FArrayBox by pointwise multiplication by values
00598     in the argument FArrayBox.  Multiplies src's components
00599     (srccomp:srccomp+numcomp-1) by this FArrayBox's components
00600     (destcomp:destcomp+numcomp-1) where the domain of this FArrayBox
00601     intersects the subbox.  NOTE: subbox must be contained in this
00602     FAB.  
00603 
00604 */
00605   FArrayBox& mult (const FArrayBox& src,
00606                    const Box&         subbox,
00607                    int                srccomp,
00608                    int                destcomp,
00609                    int                numcomp=1);
00610 
00611   /*@ManDoc: Modifies this FArrayBox by pointwise multiplication by values
00612                in the argument FArrayBox.  Multiplies src's components
00613                (srccomp:srccomp+numcomp-1) in the Box srcbox by this
00614                FArrayBox's components (destcomp:destcomp+numcomp-1) in
00615                the Box destbox.  Corresponding locations within the
00616                two FArrayBoxes are indexed relative to srcbox and
00617                destbox, and will in general not be the same.  The
00618                srcbox and destbox must be same size.  The results are
00619                UNDEFINED if the src and dest FArrayBoxes are the same
00620                and the srcbox and destbox overlap.
00621 
00622   */
00623   FArrayBox& mult (const FArrayBox& src,
00624                    const Box&         srcbox,
00625                    const Box&         destbox,
00626                    int                srccomp,
00627                    int                destcomp,
00628                    int                numcomp=1);
00629 
00631 
00634   FArrayBox& operator/= (Real r);
00635 
00637 
00640   FArrayBox& divide (Real r);
00641 
00643 
00647   FArrayBox& divide (Real   r,
00648                      int comp,
00649                      int numcomp=1);
00650 
00652 
00657   FArrayBox& divide (Real          r,
00658                      const Box& b,
00659                      int        comp=0,
00660                      int        numcomp=1);
00661 
00663 
00669   FArrayBox& operator/= (const FArrayBox& src);
00670 
00672 
00678   FArrayBox& divide (const FArrayBox& src);
00679 
00680   /*@ManDoc: Modifies this FArrayBox by pointwise division by values
00681     in the argument FArrayBox.  Divides this FArrayBox's components
00682     (destcomp:destcomp+numcomp-1) by src's components
00683     (srccomp:srccomp+numcomp-1) where the domains of the two
00684     FArrayBoxes intersect.  
00685 
00686 */
00687   FArrayBox& divide (const FArrayBox& src,
00688                      int                srccomp,
00689                      int                destcomp,
00690                      int                numcomp=1);
00691 
00692   /*@ManDoc: Modifies this FArrayBox by pointwise division by values
00693     in the argument FArrayBox.  Divides this FArrayBox's components
00694     (destcomp:destcomp+numcomp-1) by src's components
00695     (srccomp:srccomp+numcomp-1) where the domain of this FArrayBox
00696     intersects the subbox.  NOTE: subbox must be contained in this
00697     FAB.  
00698 
00699 */
00700   FArrayBox& divide (const FArrayBox& src,
00701                      const Box&         subbox,
00702                      int                srccomp,
00703                      int                destcomp,
00704                      int                numcomp=1);
00705 
00706   /*@ManDoc: Modifies this FArrayBox by pointwise division by values
00707                in the argument FArrayBox.  Divides this FArrayBox's
00708                components (destcomp:destcomp+numcomp-1) in the Box
00709                destbox by src's components (srccomp:srccomp+numcomp-1)
00710                in the Box srcbox.  Corresponding locations within the
00711                two FArrayBoxes are indexed relative to srcbox and
00712                destbox, and will in general not be the same.  The
00713                srcbox and destbox must be same size.  The results are
00714                UNDEFINED if the src and dest FArrayBoxes are the same
00715                and the srcbox and destbox overlap.
00716 
00717   */
00718   FArrayBox& divide (const FArrayBox& src,
00719                      const Box&         srcbox,
00720                      const Box&         destbox,
00721                      int                srccomp,
00722                      int                destcomp,
00723                      int                numcomp=1);
00724 
00725   Real get(const IntVect& iv, int comp) const { return this->operator()(iv, comp);}
00726   void set(const IntVect& iv, int comp, Real val) {  this->operator()(iv, comp) = val;}
00727 
00728 protected:
00729 
00730   virtual void performCopy (const BaseFab<Real>& src,
00731                             const Box&        srcbox,
00732                             int               srccomp,
00733                             const Box&        destbox,
00734                             int               destcomp,
00735                             int               numcomp);
00736 
00737 private:
00738   //
00739   // These are disallowed.
00740   //
00741   FArrayBox (const FArrayBox&);
00742   FArrayBox& operator= (const FArrayBox&);
00743 };
00744 
00745 
00746 #endif /*CH_FARRAYBOX_H*/

Generated on Thu Aug 29 11:05:44 2002 for Chombo&INS by doxygen1.2.16