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.5 2003/03/28 22:21:42 ligocki 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 
00141   Real dotProduct(const FArrayBox& fab2) const;
00142 
00144 
00146 
00149   Real min (int comp = 0) const;
00150 
00152 
00157   Real min (const Box& subbox,
00158             int        comp = 0) const;
00159 
00161 
00164   Real max (int comp = 0) const;
00165 
00167 
00172   Real max (const Box& subbox,
00173             int        comp = 0) const;
00174 
00176 
00179   IntVect minIndex (int comp = 0) const;
00180 
00181   /*@ManDoc: Returns location of minimum value in given component  of this FArrayBox in
00182     given subbox.
00183   */
00184   IntVect minIndex (const Box& subbox,
00185                     int        comp = 0) const;
00187 
00190   IntVect maxIndex (int comp = 0) const;
00191 
00192   /*@ManDoc: Returns location of maximum value in given component of
00193     this FArrayBox in given subbox.  
00194 
00195 */
00196   IntVect maxIndex (const Box& subbox,
00197                     int        comp = 0) const;
00198 
00200 
00202 
00208   int maskLT (BaseFab<int>& mask,
00209               Real             val,
00210               int           comp = 0) const;
00211 
00213 
00220   int maskLE (BaseFab<int>& mask,
00221               Real             val,
00222               int           comp = 0) const;
00224 
00230   int maskEQ (BaseFab<int>& mask,
00231               Real             val,
00232               int           comp = 0) const;
00234 
00240   int maskGT (BaseFab<int>& mask,
00241               Real             val,
00242               int           comp = 0) const;
00243 
00245 
00252   int maskGE (BaseFab<int>& mask,
00253               Real             val,
00254               int           comp = 0) const;
00255 
00256 
00258 
00260 
00264   void abs ();
00265 
00267 
00272   void abs (int comp,
00273             int numcomp=1);
00274 
00276 
00281   void abs (const Box& subbox,
00282             int        comp = 0,
00283             int        numcomp=1);
00284 
00286 
00289   Real sum (int comp,
00290             int numcomp = 1) const;
00291 
00292   /*@ManDoc: Returns sum of component of this FArrayBox in given
00293     subbox.  
00294 
00295 */
00296   Real sum (const Box& subbox,
00297             int        comp,
00298             int        numcomp = 1) const;
00299 
00301 
00305   FArrayBox& invert (Real v);
00307 
00312   FArrayBox& invert (Real          v,
00313                      const Box& subbox,
00314                      int        comp=0,
00315                      int        numcomp=1);
00317 
00322   FArrayBox& invert (Real   v,
00323                      int comp,
00324                      int numcomp=1);
00325 
00326 
00327 
00329 
00334   FArrayBox& negate (const Box& subbox,
00335                      int        comp=0,
00336                      int        numcomp=1);
00338 
00343   FArrayBox& negate (int comp,
00344                      int numcomp=1);
00346 
00351   FArrayBox& negate ();
00352 
00354 
00359   FArrayBox& plus (Real          r,
00360                    const Box& b,
00361                    int        comp=0,
00362                    int        numcomp=1);
00363 
00365 
00370   FArrayBox& plus (Real   r,
00371                    int comp,
00372                    int numcomp=1);
00373 
00374 
00376 
00380   FArrayBox& operator+= (Real r);
00381 
00383 
00389    FArrayBox& operator+= (const FArrayBox& f);
00390 
00392 
00398   FArrayBox& plus (const FArrayBox& src);
00399 
00401 
00405   FArrayBox& plus (Real r);
00406   FArrayBox& plus_real (Real r) {return this->plus(r);}
00408 
00414   FArrayBox& plus (const FArrayBox& src, const Real& scale);
00416 
00421   FArrayBox& plus (const FArrayBox& src, const Real& scale, 
00422                    int                srccomp,
00423                    int                destcomp,
00424                    int                numcomp=1);
00425 
00426   /*@ManDoc: Modifies this FArrayBox by pointwise addition of values
00427     in the argument FArrayBox.  Adds src's components
00428     (srccomp:srccomp+numcomp-1) to this FArrayBox's components
00429     (destcomp:destcomp+numcomp-1) where the domains of the two
00430     FArrayBoxes intersect.  
00431 
00432 */
00433   FArrayBox& plus (const FArrayBox& src,
00434                    int                srccomp,
00435                    int                destcomp,
00436                    int                numcomp=1);
00437 
00438   /*@ManDoc: Modifies this FArrayBox by pointwise addition of values
00439     in the argument FArrayBox.  Adds src's components
00440     (srccomp:srccomp+numcomp-1) to this FArrayBox's components
00441     (destcomp:destcomp+numcomp-1) where the domain of this FArrayBox
00442     intersects the subbox.  NOTE: subbox must be contained in this
00443     FAB.  
00444 
00445 */
00446   FArrayBox& plus (const FArrayBox& src,
00447                    const Box&         subbox,
00448                    int                srccomp,
00449                    int                destcomp,
00450                    int                numcomp=1);
00451 
00452   /*@ManDoc: Modifies this FArrayBox by pointwise addition of values
00453                in the argument FArrayBox.  Adds src's components
00454                (srccomp:srccomp+numcomp-1) in the Box srcbox to this
00455                FArrayBox's components (destcomp:destcomp+numcomp-1) in
00456                the Box destbox.  Corresponding locations within the
00457                two FArrayBoxes are indexed relative to srcbox and
00458                destbox, and will in general not be the same.  The
00459                srcbox and destbox must be same size.  The results are
00460                UNDEFINED if the src and dest FArrayBoxes are the same
00461                and the srcbox and destbox overlap.
00462 
00463   */
00464   FArrayBox& plus (const FArrayBox& src,
00465                    const Box&         srcbox,
00466                    const Box&         destbox,
00467                    int                srccomp,
00468                    int                destcomp,
00469                    int                numcomp=1);
00470 
00472 
00476   FArrayBox& operator-= (Real r);
00477 
00479 
00485   FArrayBox& operator-= (const FArrayBox& f);
00486 
00488 
00494   FArrayBox& minus (const FArrayBox& src);
00495 
00496   /*@ManDoc: Modifies this FArrayBox by pointwise subtraction of values
00497     in the argument FArrayBox.  Subtracts src's components
00498     (srccomp:srccomp+numcomp-1) from this FArrayBox's components
00499     (destcomp:destcomp+numcomp-1) where the domains of the two
00500     FArrayBoxes intersect.  
00501 
00502 */
00503   FArrayBox& minus (const FArrayBox& src,
00504                     int                srccomp,
00505                     int                destcomp,
00506                     int                numcomp=1);
00507 
00508   /*@ManDoc: Modifies this FArrayBox by pointwise subtraction of values
00509     in the argument FArrayBox.  Subtracts src's components
00510     (srccomp:srccomp+numcomp-1) from this FArrayBox's components
00511     (destcomp:destcomp+numcomp-1) where the domain of this FArrayBox
00512     intersects the subbox.  NOTE: subbox must be contained in this
00513     FAB.  
00514 
00515 */
00516   FArrayBox& minus (const FArrayBox& src,
00517                     const Box&         subbox,
00518                     int                srccomp,
00519                     int                destcomp,
00520                     int                numcomp=1);
00521 
00522   /*@ManDoc: Modifies this FArrayBox by pointwise subtraction of values
00523                in the argument FArrayBox.  Subtracts src's components
00524                (srccomp:srccomp+numcomp-1) in the Box srcbox from this
00525                FArrayBox's components (destcomp:destcomp+numcomp-1) in
00526                the Box destbox.  Corresponding locations within the
00527                two FArrayBoxes are indexed relative to srcbox and
00528                destbox, and will in general not be the same.  The
00529                srcbox and destbox must be same size.  The results are
00530                UNDEFINED if the src and dest FArrayBoxes are the same
00531                and the srcbox and destbox overlap.
00532 
00533   */
00534   FArrayBox& minus (const FArrayBox& src,
00535                     const Box&         srcbox,
00536                     const Box&         destbox,
00537                     int                srccomp,
00538                     int                destcomp,
00539                     int                numcomp=1);
00540 
00542 
00545   FArrayBox& operator*= (Real r);
00546 
00548 
00551   FArrayBox& mult (Real r);
00552 
00554 
00559   FArrayBox& mult (Real   r,
00560                    int comp,
00561                    int numcomp=1);
00562 
00564 
00569   FArrayBox& mult (Real          r,
00570                    const Box& b,
00571                    int        comp=0,
00572                    int        numcomp=1);
00573 
00575 
00581   FArrayBox& operator*= (const FArrayBox& f);
00582 
00584 
00590   FArrayBox& mult (const FArrayBox& src);
00591 
00592   /*@ManDoc: Modifies this FArrayBox by pointwise multiplication by values
00593     in the argument FArrayBox.  Multiplies src's components
00594     (srccomp:srccomp+numcomp-1) by this FArrayBox's components
00595     (destcomp:destcomp+numcomp-1) where the domains of the two
00596     FArrayBoxes intersect.  
00597 
00598 */
00599   FArrayBox& mult (const FArrayBox& src,
00600                    int                srccomp,
00601                    int                destcomp,
00602                    int                numcomp=1);
00603 
00604   /*@ManDoc: Modifies this FArrayBox by pointwise multiplication by values
00605     in the argument FArrayBox.  Multiplies src's components
00606     (srccomp:srccomp+numcomp-1) by this FArrayBox's components
00607     (destcomp:destcomp+numcomp-1) where the domain of this FArrayBox
00608     intersects the subbox.  NOTE: subbox must be contained in this
00609     FAB.  
00610 
00611 */
00612   FArrayBox& mult (const FArrayBox& src,
00613                    const Box&         subbox,
00614                    int                srccomp,
00615                    int                destcomp,
00616                    int                numcomp=1);
00617 
00618   /*@ManDoc: Modifies this FArrayBox by pointwise multiplication by values
00619                in the argument FArrayBox.  Multiplies src's components
00620                (srccomp:srccomp+numcomp-1) in the Box srcbox by this
00621                FArrayBox's components (destcomp:destcomp+numcomp-1) in
00622                the Box destbox.  Corresponding locations within the
00623                two FArrayBoxes are indexed relative to srcbox and
00624                destbox, and will in general not be the same.  The
00625                srcbox and destbox must be same size.  The results are
00626                UNDEFINED if the src and dest FArrayBoxes are the same
00627                and the srcbox and destbox overlap.
00628 
00629   */
00630   FArrayBox& mult (const FArrayBox& src,
00631                    const Box&         srcbox,
00632                    const Box&         destbox,
00633                    int                srccomp,
00634                    int                destcomp,
00635                    int                numcomp=1);
00636 
00638 
00641   FArrayBox& operator/= (Real r);
00642 
00644 
00647   FArrayBox& divide (Real r);
00648 
00650 
00654   FArrayBox& divide (Real   r,
00655                      int comp,
00656                      int numcomp=1);
00657 
00659 
00664   FArrayBox& divide (Real          r,
00665                      const Box& b,
00666                      int        comp=0,
00667                      int        numcomp=1);
00668 
00670 
00676   FArrayBox& operator/= (const FArrayBox& src);
00677 
00679 
00685   FArrayBox& divide (const FArrayBox& src);
00686 
00687   /*@ManDoc: Modifies this FArrayBox by pointwise division by values
00688     in the argument FArrayBox.  Divides this FArrayBox's components
00689     (destcomp:destcomp+numcomp-1) by src's components
00690     (srccomp:srccomp+numcomp-1) where the domains of the two
00691     FArrayBoxes intersect.  
00692 
00693 */
00694   FArrayBox& divide (const FArrayBox& src,
00695                      int                srccomp,
00696                      int                destcomp,
00697                      int                numcomp=1);
00698 
00699   /*@ManDoc: Modifies this FArrayBox by pointwise division by values
00700     in the argument FArrayBox.  Divides this FArrayBox's components
00701     (destcomp:destcomp+numcomp-1) by src's components
00702     (srccomp:srccomp+numcomp-1) where the domain of this FArrayBox
00703     intersects the subbox.  NOTE: subbox must be contained in this
00704     FAB.  
00705 
00706 */
00707   FArrayBox& divide (const FArrayBox& src,
00708                      const Box&         subbox,
00709                      int                srccomp,
00710                      int                destcomp,
00711                      int                numcomp=1);
00712 
00713   /*@ManDoc: Modifies this FArrayBox by pointwise division by values
00714                in the argument FArrayBox.  Divides this FArrayBox's
00715                components (destcomp:destcomp+numcomp-1) in the Box
00716                destbox by src's components (srccomp:srccomp+numcomp-1)
00717                in the Box srcbox.  Corresponding locations within the
00718                two FArrayBoxes are indexed relative to srcbox and
00719                destbox, and will in general not be the same.  The
00720                srcbox and destbox must be same size.  The results are
00721                UNDEFINED if the src and dest FArrayBoxes are the same
00722                and the srcbox and destbox overlap.
00723 
00724   */
00725   FArrayBox& divide (const FArrayBox& src,
00726                      const Box&         srcbox,
00727                      const Box&         destbox,
00728                      int                srccomp,
00729                      int                destcomp,
00730                      int                numcomp=1);
00731 
00732   Real get(const IntVect& iv, int comp) const { return this->operator()(iv, comp);}
00733   void set(const IntVect& iv, int comp, Real val) {  this->operator()(iv, comp) = val;}
00734 
00735 protected:
00736 
00737   virtual void performCopy (const BaseFab<Real>& src,
00738                             const Box&        srcbox,
00739                             int               srccomp,
00740                             const Box&        destbox,
00741                             int               destcomp,
00742                             int               numcomp);
00743 
00744 private:
00745   //
00746   // These are disallowed.
00747   //
00748   FArrayBox (const FArrayBox&);
00749   FArrayBox& operator= (const FArrayBox&);
00750 };
00751 
00752 
00753 #endif /*CH_FARRAYBOX_H*/

Generated on Wed Apr 16 14:31:04 2003 for EBChombo by doxygen1.2.16