Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

RealVect.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 _REALVECT_H_
00053 #define _REALVECT_H_
00054 
00055 #include <cstddef>
00056 #include <cstdlib>
00057 #include <cstring>
00058 #include <iostream>
00059 
00060 #include "SPACE.H"
00061 #include "Misc.H"
00062 #include "REAL.H"
00063 #include "SPACE.H"
00064 #include "IntVect.H"
00065 
00067 
00075 class RealVect
00076 {
00077 public:
00078 
00083 
00085 
00088   RealVect ();
00089 
00091 
00096   RealVect (D_DECL(Real i, Real j, Real k));
00097 
00099 
00102   RealVect (const RealVect& rhs);
00103 
00105 
00109   RealVect (const IntVect & iv){
00110     for(int d=0 ; d<SpaceDim ; ++d ){ vect[d] = (Real)iv[d] ; }
00111   }
00113 
00116   RealVect& operator= (const RealVect& rhs);
00117 
00119 
00123   inline
00124   Real& operator[] (int i);
00125 
00127 
00130   inline
00131   const Real& operator[] (int i) const;
00132 
00139 
00141 
00145   bool operator== (const RealVect& p) const;
00146 
00148 
00152   bool operator!= (const RealVect& p) const;
00153 
00155 
00162   bool operator< (const RealVect& p) const;
00163 
00165 
00172   bool operator<= (const RealVect& p) const;
00173 
00175 
00182   bool operator> (const RealVect& p) const;
00183 
00185 
00193   bool operator>= (const RealVect& p) const;
00194 
00196 
00209   bool lexLT (const RealVect& s) const;
00210 
00212 
00225   bool lexGT (const RealVect& s) const;
00226 
00233 
00235 
00238   RealVect& operator+= (Real s);
00239 
00241 
00244   RealVect& operator+= (const RealVect& p);
00245 
00247 
00251   RealVect& operator-= (Real s);
00252 
00254 
00257   RealVect& operator-= (const RealVect& p);
00258 
00260 
00264   RealVect operator- (Real s) const;
00265 
00267 
00270   RealVect& operator*= (Real s);
00271 
00273 
00276   Real dotProduct(const RealVect& a_rhs) const;
00277 
00279 
00282   RealVect& operator*= (const RealVect& p);
00283 
00284 //XXX  ///
00285 //XXX  /**
00286 //XXX     Returns component-wise product of this RealVect and argument.
00287 //XXX  */
00288 //XXX  RealVect operator* (const RealVect& p) const;
00289 
00291 
00295   RealVect operator* (Real s) const;
00296 
00298 
00301   RealVect& operator/= (Real s);
00302 
00304 
00307   RealVect& operator/= (const RealVect& p);
00308 
00309 //XXX  ///
00310 //XXX  /**
00311 //XXX     Returns component-wise quotient of this RealVect by argument.
00312 //XXX  */
00313 //XXX  RealVect operator/ (const RealVect& p) const;
00314 
00316 
00320   RealVect operator/ (Real s) const;
00321 
00323 
00326   RealVect& scale (Real s);
00327 
00334 
00336 
00339   RealVect operator+ () const;
00340 
00342 
00345   RealVect operator- () const;
00346 
00348 
00351   Real sum () const;
00352 
00354 
00357   Real product () const;
00358 
00365 
00367 
00370   const Real* dataPtr() const;
00371 
00373 
00376   Real* dataPtr() ;
00377 
00384 
00386 
00397   friend RealVect BASISREALV(int dir);
00398 
00400 
00403   static const RealVect Zero;
00404 
00406 
00409   static const RealVect Unit;
00410 
00417 
00419 
00423   friend RealVect operator+ (Real            s,
00424                              const RealVect& p);
00425 
00427 
00430   friend RealVect operator- (Real            s,
00431                              const RealVect& p);
00432 
00434 
00438   friend RealVect operator* (Real            s,
00439                              const RealVect& p);
00441 
00445   friend RealVect operator/ (Real            s,
00446                              const RealVect& p);
00447 
00449 
00452   friend RealVect operator+ (const RealVect& s,
00453                              const RealVect& p);
00454 
00456 
00459   friend RealVect operator- (const RealVect& s,
00460                              const RealVect& p);
00461 
00463 
00466   friend RealVect operator* (const RealVect& s,
00467                              const RealVect& p);
00469 
00472   friend RealVect operator/ (const RealVect& s,
00473                              const RealVect& p);
00474 
00475 
00477 
00481   friend inline RealVect scale (const RealVect& p,
00482                                 Real            s);
00483 
00484 
00487 
00488 
00491   friend std::ostream& operator<< (std::ostream& ostr,
00492                                    const RealVect& p);
00493 
00494   friend class HDF5Handle;
00495 
00496   static size_t io_offset;
00497 
00498 protected:
00499 
00503   Real vect[SpaceDim];
00504 
00505 };
00506 
00507 inline Real& RealVect::operator[] (int i)
00508 {
00509  CH_assert(i>=0 && i < SpaceDim);
00510   return vect[i];
00511 }
00512 
00513 inline const Real& RealVect::operator[] (int i) const
00514 {
00515  CH_assert(i>=0 && i < SpaceDim);
00516   return vect[i];
00517 }
00518 
00519 inline RealVect::RealVect (const RealVect &iv)
00520 {
00521   D_EXPR(vect[0]=iv.vect[0], vect[1]=iv.vect[1], vect[2]=iv.vect[2]);
00522 }
00523 
00524 inline 
00525 RealVect&
00526 RealVect::operator-= (const RealVect& p)
00527 {
00528   D_EXPR(vect[0] -= p[0], vect[1] -= p[1], vect[2] -= p[2]);
00529   return *this;
00530 }
00531 
00532 inline
00533 RealVect
00534 RealVect::operator+ () const
00535 {
00536   return RealVect(*this);
00537 }
00538 
00539 inline
00540 RealVect
00541 RealVect::operator- () const
00542 {
00543   return RealVect(D_DECL(-vect[0], -vect[1], -vect[2] ));
00544 }
00545 
00546 inline
00547 RealVect&
00548 RealVect::scale (Real s)
00549 {
00550   D_EXPR(vect[0] *= s, vect[1] *= s, vect[2] *= s);
00551   return *this;
00552 }
00553 
00554 inline
00555 Real
00556 RealVect::sum () const
00557 {
00558   return D_TERM(vect[0], + vect[1], + vect[2]);
00559 }
00560 
00561 inline
00562 Real
00563 RealVect::product () const
00564 {
00565   return D_TERM(vect[0], * vect[1], * vect[2]);
00566 }
00567 
00568 inline
00569 RealVect
00570 scale (const RealVect& p,
00571        Real            s)
00572 {
00573   return RealVect(D_DECL(s * p[0], s * p[1], s * p[2]));
00574 }
00575 
00576 inline
00577 bool
00578 RealVect::operator< (const RealVect& p) const
00579 {
00580   return D_TERM(vect[0] < p[0], && vect[1] < p[1], && vect[2] < p[2]);
00581 }
00582 
00583 inline
00584 bool
00585 RealVect::operator<= (const RealVect& p) const
00586 {
00587   return D_TERM(vect[0] <= p[0], && vect[1] <= p[1], && vect[2] <= p[2]);
00588 }
00589 
00590 
00591 inline
00592 bool
00593 RealVect::operator> (const RealVect& p) const
00594 {
00595   return D_TERM(vect[0] > p[0], && vect[1] > p[1], && vect[2] > p[2]);
00596 }
00597 
00598 inline
00599 bool
00600 RealVect::operator>= (const RealVect& p) const
00601 {
00602   return D_TERM(vect[0] >= p[0], && vect[1] >= p[1], && vect[2] >= p[2]);
00603 }
00604 
00605 inline
00606 bool
00607 RealVect::lexLT (const RealVect &s) const
00608 {
00609 #define LLT0 (vect[0] < s[0])
00610 #define LLT1 ((vect[0] == s[0]) && (vect[1] < s[1]))
00611 #define LLT2 ((vect[1] == s[1]) && (vect[2] < s[2]))
00612 #if   CH_SPACEDIM == 1
00613   return LLT0;
00614 #elif CH_SPACEDIM == 2
00615   return LLT0 || LLT1;
00616 #elif CH_SPACEDIM == 3
00617   return LLT0 || (vect[0]==s[0] && ((vect[1] < s[1] || LLT2)));
00618 #endif
00619 #undef LLT0
00620 #undef LLT1
00621 #undef LLT2
00622 }
00623 
00624 inline
00625 bool
00626 RealVect::lexGT (const RealVect& s) const
00627 {
00628 #define LGT0 (vect[0] > s[0])
00629 #define LGT1 ((vect[0] == s[0]) && (vect[1] > s[1]))
00630 #define LGT2 ((vect[1] == s[1]) && (vect[2] > s[2]))
00631 #if   CH_SPACEDIM == 1
00632   return LGT0;
00633 #elif CH_SPACEDIM == 2
00634   return LGT0 || LGT1;
00635 #elif CH_SPACEDIM == 3
00636   return LGT0 || (vect[0] == s[0] && ((vect[1] > s[1] || LGT2)));
00637 #endif
00638 #undef LGT0
00639 #undef LGT1
00640 #undef LGT2
00641 }
00642 
00643 extern RealVect BASISREALV(int idir);
00644 /*
00645 #include "CH_HDF5.H"
00646 #include "SPMD.H"
00647 
00648 template < >
00649 int linearSize(const RealVect& vindex);
00650 
00651 //VolIndex specialization of linearIn
00652 template < >
00653 void linearIn(RealVect& a_outputT, const void* const inBuf);
00654 
00655 //VolIndex specialization of linearOut
00656 template < >
00657 void linearOut(void* const a_outBuf, const RealVect& a_inputT);
00658 
00659 */
00660 
00661 #endif

Generated on Wed Oct 5 13:52:09 2005 for Chombo&AMRSelfGravity by  doxygen 1.4.1