00001 #ifdef CH_LANG_CC
00002
00003
00004
00005
00006
00007
00008
00009 #endif
00010
00011 #ifndef _REALVECT_H_
00012 #define _REALVECT_H_
00013
00014 #include <cstddef>
00015 #include <cstdlib>
00016 #include <cstring>
00017 #include <iostream>
00018
00019 #include "SPACE.H"
00020 #include "Misc.H"
00021 #include "REAL.H"
00022 #include "SPACE.H"
00023 #include "IntVect.H"
00024 #include "Vector.H"
00025 #include "SPMD.H"
00026 #include "NamespaceHeader.H"
00027
00028 template<typename T, int n>
00029 class IndexTM;
00030
00032
00040 class RealVect
00041 {
00042 public:
00043
00048
00050
00053 RealVect ();
00054
00055 explicit RealVect (const Vector<Real>&);
00056
00058
00063 RealVect (D_DECL6(Real i, Real j, Real k,
00064 Real l, Real m, Real n));
00065
00067
00070 RealVect (const RealVect& rhs);
00071
00072
00074
00077 RealVect(const IndexTM<Real,CH_SPACEDIM>& a_tm);
00078
00080
00084 RealVect (const IntVect & iv){
00085 for(int d=0 ; d<SpaceDim ; ++d ){ vect[d] = (Real)iv[d] ; }
00086 }
00088
00091 RealVect& operator= (const RealVect& rhs);
00092
00094
00098 inline
00099 Real& operator[] (int i);
00100
00102
00105 inline
00106 const Real& operator[] (int i) const;
00107
00114
00116
00120 bool operator== (const RealVect& p) const;
00121
00123
00127 bool operator!= (const RealVect& p) const;
00128
00130
00137 bool operator< (const RealVect& p) const;
00138
00140
00147 bool operator<= (const RealVect& p) const;
00148
00150
00157 bool operator> (const RealVect& p) const;
00158
00160
00168 bool operator>= (const RealVect& p) const;
00169
00176
00178
00181 RealVect& operator+= (Real s);
00182
00184
00187 RealVect& operator+= (const RealVect& p);
00188
00190
00194 RealVect& operator-= (Real s);
00195
00197
00200 RealVect& operator-= (const RealVect& p);
00201
00203
00207 RealVect operator- (Real s) const;
00208
00210
00213 RealVect& operator*= (Real s);
00214
00216
00219 Real dotProduct(const RealVect& a_rhs) const;
00220
00222
00225 RealVect& operator*= (const RealVect& p);
00226
00227
00228
00229
00230
00231
00232
00234
00238 RealVect operator* (Real s) const;
00239
00241
00244 RealVect& operator/= (Real s);
00245
00247
00250 RealVect& operator/= (const RealVect& p);
00251
00252
00253
00254
00255
00256
00257
00259
00263 RealVect operator/ (Real s) const;
00264
00266
00269 RealVect& scale (Real s);
00270
00277
00279
00283 RealVect& min (const RealVect& p);
00284
00286
00290 friend inline RealVect min (const RealVect& p1,
00291 const RealVect& p2);
00292
00294
00298 RealVect& max (const RealVect& p);
00299
00301
00305 friend inline RealVect max (const RealVect& p1,
00306 const RealVect& p2);
00307
00314
00316
00319 RealVect operator+ () const;
00320
00322
00325 RealVect operator- () const;
00326
00328
00331 Real sum () const;
00332
00334
00337 Real vectorLength() const;
00338
00340
00343 Real product () const;
00344
00346
00350 int minDir(const bool& a_doAbs) const;
00351
00353
00357 int maxDir(const bool& a_doAbs) 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 #include "NamespaceFooter.H"
00508
00509 #include "BaseNamespaceHeader.H"
00510
00511 #include "NamespaceVar.H"
00512
00513
00514 template < >
00515 int linearSize(const CH_XDIR::RealVect& vindex);
00516
00517
00518 template < >
00519 void linearIn(CH_XDIR::RealVect& a_outputT, const void* const inBuf);
00520
00521
00522 template < >
00523 void linearOut(void* const a_outBuf, const CH_XDIR::RealVect& a_inputT);
00524
00525 #include "BaseNamespaceFooter.H"
00526
00527 #include "NamespaceHeader.H"
00528
00529 inline Real& RealVect::operator[] (int i)
00530 {
00531 CH_assert(i>=0 && i < SpaceDim);
00532 return vect[i];
00533 }
00534
00535 inline const Real& RealVect::operator[] (int i) const
00536 {
00537 CH_assert(i>=0 && i < SpaceDim);
00538 return vect[i];
00539 }
00540
00541 inline RealVect::RealVect (const RealVect &iv)
00542 {
00543 D_EXPR6(vect[0]=iv.vect[0], vect[1]=iv.vect[1], vect[2]=iv.vect[2],
00544 vect[3]=iv.vect[3], vect[4]=iv.vect[4], vect[5]=iv.vect[5]);
00545 }
00546
00547
00548 inline
00549 RealVect&
00550 RealVect::operator-= (Real s)
00551 {
00552 D_EXPR6(vect[0] -= s, vect[1] -= s, vect[2] -= s,
00553 vect[3] -= s, vect[4] -= s, vect[5] -= s);
00554 return *this;
00555 }
00556
00557 inline
00558 RealVect&
00559 RealVect::operator-= (const RealVect& p)
00560 {
00561 D_EXPR6(vect[0] -= p[0], vect[1] -= p[1], vect[2] -= p[2],
00562 vect[3] -= p[3], vect[4] -= p[4], vect[5] -= p[5]);
00563 return *this;
00564 }
00565
00566 inline
00567 RealVect
00568 RealVect::operator+ () const
00569 {
00570 return RealVect(*this);
00571 }
00572
00573 inline
00574 RealVect
00575 RealVect::operator- () const
00576 {
00577 return RealVect(D_DECL6(-vect[0], -vect[1], -vect[2],
00578 -vect[3], -vect[4], -vect[5] ));
00579 }
00580
00581 inline
00582 RealVect&
00583 RealVect::scale (Real s)
00584 {
00585 D_EXPR6(vect[0] *= s, vect[1] *= s, vect[2] *= s,
00586 vect[3] *= s, vect[4] *= s, vect[5] *= s);
00587 return *this;
00588 }
00589
00590 inline
00591 Real
00592 RealVect::sum () const
00593 {
00594 return D_TERM6(vect[0], + vect[1], + vect[2], +
00595 vect[3], + vect[4], + vect[5]);
00596 }
00597
00598 inline
00599 Real
00600 RealVect::vectorLength () const
00601 {
00602 Real len = 0;
00603 for(int idir = 0; idir < SpaceDim; idir++)
00604 {
00605 len = len + vect[idir]*vect[idir];
00606 }
00607 len = sqrt(len);
00608
00609 return len;
00610 }
00611
00612 inline
00613 Real
00614 RealVect::product () const
00615 {
00616 return D_TERM6(vect[0], * vect[1], * vect[2], *
00617 vect[3], * vect[4], * vect[5]);
00618 }
00619
00620 inline
00621 RealVect
00622 scale (const RealVect& p,
00623 Real s)
00624 {
00625 return RealVect(D_DECL6(s * p[0], s * p[1], s * p[2],
00626 s * p[3], s * p[4], s * p[5]));
00627 }
00628
00629 inline
00630 bool
00631 RealVect::operator< (const RealVect& p) const
00632 {
00633 return D_TERM6(vect[0] < p[0], && vect[1] < p[1], && vect[2] < p[2],
00634 && vect[3] < p[3], && vect[4] < p[4], && vect[5] < p[5]);
00635 }
00636
00637 inline
00638 bool
00639 RealVect::operator<= (const RealVect& p) const
00640 {
00641 return D_TERM6(vect[0] <= p[0], && vect[1] <= p[1], && vect[2] <= p[2],
00642 && vect[3] <= p[3], && vect[4] <= p[4], && vect[5] <= p[5]);
00643 }
00644
00645
00646 inline
00647 bool
00648 RealVect::operator> (const RealVect& p) const
00649 {
00650 return D_TERM6(vect[0] > p[0], && vect[1] > p[1], && vect[2] > p[2],
00651 && vect[3] > p[3], && vect[4] > p[4], && vect[5] > p[5]);
00652 }
00653
00654 inline
00655 bool
00656 RealVect::operator>= (const RealVect& p) const
00657 {
00658 return D_TERM6(vect[0] >= p[0], && vect[1] >= p[1], && vect[2] >= p[2],
00659 && vect[3] >= p[3], && vect[4] >= p[4], && vect[5] >= p[5]);
00660 }
00661
00662 inline
00663 RealVect&
00664 RealVect::min (const RealVect& p)
00665 {
00666 D_EXPR6(vect[0] = Min(vect[0], p.vect[0]),
00667 vect[1] = Min(vect[1], p.vect[1]),
00668 vect[2] = Min(vect[2], p.vect[2]),
00669 vect[3] = Min(vect[3], p.vect[3]),
00670 vect[4] = Min(vect[4], p.vect[4]),
00671 vect[5] = Min(vect[5], p.vect[5]));
00672 return *this;
00673 }
00674
00675 inline
00676 RealVect&
00677 RealVect::max (const RealVect& p)
00678 {
00679 D_EXPR6(vect[0] = Max(vect[0], p.vect[0]),
00680 vect[1] = Max(vect[1], p.vect[1]),
00681 vect[2] = Max(vect[2], p.vect[2]),
00682 vect[3] = Max(vect[3], p.vect[3]),
00683 vect[4] = Max(vect[4], p.vect[4]),
00684 vect[5] = Max(vect[5], p.vect[5]));
00685 return *this;
00686 }
00687
00688 inline
00689 RealVect
00690 min (const RealVect& p1,
00691 const RealVect& p2)
00692 {
00693 RealVect p(p1);
00694 return p.min(p2);
00695 }
00696
00697 inline
00698 RealVect
00699 max (const RealVect& p1,
00700 const RealVect& p2)
00701 {
00702 RealVect p(p1);
00703 return p.max(p2);
00704 }
00705
00706 extern RealVect BASISREALV(int idir);
00707
00708
00709 #include "NamespaceFooter.H"
00710 #endif