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

BaseFab.H

Go to the documentation of this file.
00001 /*   _______              __
00002     / ___/ /  ___  __ _  / /  ___
00003    / /__/ _ \/ _ \/  V \/ _ \/ _ \
00004    \___/_//_/\___/_/_/_/_.__/\___/
00005 */
00006 // CHOMBO Copyright (c) 2000-2004, The Regents of the University of
00007 // California, through Lawrence Berkeley National Laboratory (subject to
00008 // receipt of any required approvals from U.S. Dept. of Energy).  All
00009 // rights reserved.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are met:
00013 //
00014 // (1) Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 // (2) Redistributions in binary form must reproduce the above copyright
00017 // notice, this list of conditions and the following disclaimer in the
00018 // documentation and/or other materials provided with the distribution.
00019 // (3) Neither the name of Lawrence Berkeley National Laboratory, U.S.
00020 // Dept. of Energy nor the names of its contributors may be used to endorse
00021 // or promote products derived from this software without specific prior
00022 // written permission.
00023 //
00024 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00026 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00027 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
00028 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00029 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00030 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00031 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00032 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00033 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00034 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035 //
00036 // You are under no obligation whatsoever to provide any bug fixes,
00037 // patches, or upgrades to the features, functionality or performance of
00038 // the source code ("Enhancements") to anyone; however, if you choose to
00039 // make your Enhancements available either publicly, or directly to
00040 // Lawrence Berkeley National Laboratory, without imposing a separate
00041 // written license agreement for such Enhancements, then you hereby grant
00042 // the following license: a non-exclusive, royalty-free perpetual license
00043 // to install, use, modify, prepare derivative works, incorporate into
00044 // other computer software, distribute, and sublicense such Enhancements or
00045 // derivative works thereof, in binary and source code form.
00046 //
00047 // TRADEMARKS. Product and company names mentioned herein may be the
00048 // trademarks of their respective owners.  Any rights not expressly granted
00049 // herein are reserved.
00050 //
00051 
00052 #ifndef _BASEFAB_H_
00053 #define _BASEFAB_H_
00054 
00055 #include <cstdlib>
00056 #include <assert.h>
00057 #include <string>
00058 #include <typeinfo>
00059 
00060 #include "Box.H"
00061 #include "Arena.H"
00062 #include "Interval.H"
00063 #include "REAL.H"
00064 
00111 extern Real BaseFabRealSetVal;
00112 
00113 template <class T> class BaseFab
00114 {
00115 public:
00117 
00124   BaseFab ();
00125 
00127 
00130   BaseFab(const Box& a_bx,
00131           int        a_n,
00132           T*         a_alias = NULL);
00133 
00147   BaseFab(const Interval& a_comps,
00148           BaseFab<T>&     a_original);
00149 
00151 
00155   virtual ~BaseFab();
00156 
00166   void resize(const Box& a_b,
00167               int        a_n = 1,
00168               T*         a_alias=NULL);
00169 
00174   virtual void define(const Box& a_box,
00175                       int        a_comps,
00176                       T*         a_alias = NULL)
00177   {
00178     resize(a_box, a_comps, a_alias);
00179   }
00180 
00185   virtual void define(const Interval& a_comps,
00186                       BaseFab<T>&     a_original);
00187 
00192   void clear();
00193 
00195 
00197 
00200   int nComp() const;
00201 
00203 
00206   const Box& box() const;
00207 
00212   const int* size() const;
00213 
00217   const IntVect& smallEnd() const;
00218 
00222   const IntVect& bigEnd() const;
00223 
00225 
00228   Interval interval() const
00229   {
00230     return Interval(0, m_nvar-1);
00231   }
00232 
00238   T& operator () (const IntVect& a_p,
00239                   int            a_N);
00240 
00241   T& operator () (const IntVect& a_p);
00242 
00248   const T& operator () (const IntVect& p,
00249                         int            N) const;
00250 
00251   const T& operator () (const IntVect& p) const;
00252 
00258   void getVal(T*             a_data,
00259               const IntVect& a_pos,
00260               int            a_N,
00261               int            a_numcomp) const;
00262 
00268   void getVal(T*             a_data,
00269               const IntVect& a_pos) const;
00270 
00272 
00280   const int* loVect() const;
00281 
00289   const int* hiVect() const;
00290 
00296   const int* nCompPtr() const;
00297 
00307   T* dataPtr(int a_n = 0);
00308 
00318   const T* dataPtr(int a_n = 0) const;
00319 
00321 
00326   bool contains(const BaseFab<T>& a_fab) const;
00327 
00332   bool contains(const Box& a_bx) const;
00333 
00335 
00341   void setVal(T          a_x,
00342               const Box& a_bx,
00343               int        a_nstart,
00344               int        a_numcomp);
00345 
00347 
00351   void setVal(T          a_x,
00352               const Box& a_bx,
00353               int        a_n);
00354 
00356 
00360   void setVal(T   a_x,
00361               int a_n);
00362 
00364 
00368   void setVal(T a_x);
00369 
00385   BaseFab<T>& copy(const BaseFab<T>& a_src,
00386                    const Box&        a_srcbox,
00387                    int               a_srccomp,
00388                    const Box&        a_destbox,
00389                    int               a_destcomp,
00390                    int               a_numcomp);
00391 
00399   BaseFab<T>& copy(const BaseFab<T>& a_src,
00400                    int               a_srccomp,
00401                    int               a_destcomp,
00402                    int               a_numcomp = 1);
00403 
00410   BaseFab<T>& copy(const BaseFab<T>& a_src,
00411                    const Box&        a_destbox);
00412 
00418   BaseFab<T>& copy(const BaseFab<T>& a_src);
00419 
00421 
00426   void copy(const Box&        a_RegionFrom,
00427             const Interval&   a_Cdest,
00428             const Box&        a_RegionTo,
00429             const BaseFab<T>& a_src,
00430             const Interval&   a_Csrc);
00431 
00433 
00435 
00440   BaseFab<T>& shift(const IntVect& a_v);
00441 
00443 
00449   BaseFab<T>& shift(int a_idir,
00450                     int a_ncells);
00451 
00453 
00463   BaseFab<T>& shiftHalf(int a_dir,
00464                         int a_numHalfs);
00465 
00467 
00472   BaseFab<T>& shiftHalf(const IntVect& a_v);
00473 
00475 
00477 
00483   virtual int size(const Box&      a_box,
00484                    const Interval& a_comps) const;
00485 
00487 
00492   virtual void linearOut(void*           a_buf,
00493                          const Box&      a_R,
00494                          const Interval& a_comps) const;
00495 
00497   virtual void linearIn(void*           a_buf,
00498                         const Box&      a_R,
00499                         const Interval& a_comps);
00500 
00502   static int preAllocatable()
00503   {
00504     return 0; // static preAllocatable
00505   }
00506 
00507 
00508 protected:
00509   //
00510   // Allocates memory for the `BaseFab<T>'.
00511   //
00512   void define();
00513 
00514   //
00515   // Deallocates memory for the `BaseFab<T>'.
00516   //
00517   void undefine();
00518 
00519   static std::string name();
00520 
00521   //
00522   // The function called by BaseFab copy operations.
00523   //
00524   virtual void performCopy(const BaseFab<T>& a_src,
00525                            const Box&        a_srcbox,
00526                            int               a_srccomp,
00527                            const Box&        a_destbox,
00528                            int               a_destcomp,
00529                            int               a_numcomp);
00530 
00531   //
00532   // This function is called by the `BaseFab' setVal operations.
00533   //
00534   void performSetVal(T          a_x,
00535                      const Box& a_bx,
00536                      int        a_nstart,
00537                      int        a_numcomp);
00538 
00539   //
00540   // template class static data member.  not sure if this will
00541   // work with all compilers.  It has been in the draft standard
00542   // for some time
00543   //
00544   static Arena* s_Arena;
00545 
00546   Box  m_domain;   // My index space.
00547   int  m_nvar;     // Number components.
00548   long m_numpts;   // Cached number of points in FAB.
00549   long m_truesize; // m_nvar * m_numpts that was allocated on heap
00550                    //   (only if m_aliased == false).
00551   T*   m_dptr;     // The data pointer.
00552   bool m_aliased;  // The BaseFab is not allocated memory, but is an alias. bvs
00553 
00554 private:
00555   //
00556   // These functions are made private to prevent use of the default
00557   // functions provided by the C++ compiler.
00558   //
00559   BaseFab<T>& operator= (const BaseFab<T>&);
00560   BaseFab (const BaseFab<T>&);
00561 };
00562 
00563 #include "BaseFabImplem.H"
00564 
00565 #endif

Generated on Wed Jan 19 17:51:22 2005 for Chombo&INSwithParticles by doxygen1.2.16