NAMD
Public Member Functions | List of all members
msm::Grid< T > Class Template Reference

#include <MsmMap.h>

Inheritance diagram for msm::Grid< T >:
msm::IndexRange

Public Member Functions

 Grid ()
 
void init (const IndexRange &n)
 
void set (int pia, int pni, int pja, int pnj, int pka, int pnk)
 
void setbounds (int pia, int pib, int pja, int pjb, int pka, int pkb)
 
void resize (int n)
 
const T & operator() (int i, int j, int k) const
 
const T & operator() (const Ivec &n) const
 
const T & elem (int i, int j, int k) const
 
T & operator() (int i, int j, int k)
 
T & operator() (const Ivec &n)
 
T & elem (int i, int j, int k)
 
int flatindex (int i, int j, int k) const
 
const Array< T > & data () const
 
Array< T > & data ()
 
void reset (const T &t)
 
void updateLower (const Ivec &n)
 
Grid< T > & operator+= (const Grid< T > &g)
 
void extract (Grid< T > &g)
 
template<int N>
Grid< T > & operator+= (const GridFixed< T, N > &g)
 
template<int N>
void extract (GridFixed< T, N > &g)
 
- Public Member Functions inherited from msm::IndexRange
 IndexRange ()
 
void set (int pia, int pni, int pja, int pnj, int pka, int pnk)
 
void setbounds (int pia, int pib, int pja, int pjb, int pka, int pkb)
 
int ia () const
 
int ib () const
 
int ja () const
 
int jb () const
 
int ka () const
 
int kb () const
 
int ni () const
 
int nj () const
 
int nk () const
 
int nn () const
 
Ivec lower () const
 
Ivec extent () const
 
int operator<= (const IndexRange &n)
 

Additional Inherited Members

- Protected Attributes inherited from msm::IndexRange
Ivec nlower
 
Ivec nextent
 

Detailed Description

template<class T>
class msm::Grid< T >

Definition at line 464 of file MsmMap.h.

Constructor & Destructor Documentation

template<class T>
msm::Grid< T >::Grid ( )
inline

Definition at line 602 of file MsmMap.h.

602 { }

Member Function Documentation

template<class T>
const Array<T>& msm::Grid< T >::data ( ) const
inline
template<class T>
Array<T>& msm::Grid< T >::data ( )
inline

Definition at line 667 of file MsmMap.h.

667 { return gdata; }
template<class T>
const T& msm::Grid< T >::elem ( int  i,
int  j,
int  k 
) const
inline

Definition at line 629 of file MsmMap.h.

Referenced by msm::Grid< Vtype >::operator()().

629  {
630  if (i<ia() || i>ib() || j<ja() || j>jb() || k<ka() || k>kb()) {
631  char msg[200];
632  snprintf(msg, sizeof(msg), "Grid indexing:\n"
633  "ia=%d, ib=%d, i=%d\n"
634  "ja=%d, jb=%d, j=%d\n"
635  "ka=%d, kb=%d, k=%d\n",
636  ia(), ib(), i, ja(), jb(), j, ka(), kb(), k);
637  NAMD_die(msg);
638  }
639  return gdata[flatindex(i,j,k)];
640  }
int ka() const
Definition: MsmMap.h:438
int ia() const
Definition: MsmMap.h:434
int kb() const
Definition: MsmMap.h:439
int jb() const
Definition: MsmMap.h:437
void NAMD_die(const char *err_msg)
Definition: common.C:83
int flatindex(int i, int j, int k) const
Definition: MsmMap.h:663
int ib() const
Definition: MsmMap.h:435
int ja() const
Definition: MsmMap.h:436
template<class T>
T& msm::Grid< T >::elem ( int  i,
int  j,
int  k 
)
inline

Definition at line 651 of file MsmMap.h.

651  {
652  if (i<ia() || i>ib() || j<ja() || j>jb() || k<ka() || k>kb()) {
653  char msg[200];
654  snprintf(msg, sizeof(msg), "Grid indexing:\n"
655  "ia=%d, ib=%d, i=%d\n"
656  "ja=%d, jb=%d, j=%d\n"
657  "ka=%d, kb=%d, k=%d\n",
658  ia(), ib(), i, ja(), jb(), j, ka(), kb(), k);
659  NAMD_die(msg);
660  }
661  return gdata[flatindex(i,j,k)];
662  }
int ka() const
Definition: MsmMap.h:438
int ia() const
Definition: MsmMap.h:434
int kb() const
Definition: MsmMap.h:439
int jb() const
Definition: MsmMap.h:437
void NAMD_die(const char *err_msg)
Definition: common.C:83
int flatindex(int i, int j, int k) const
Definition: MsmMap.h:663
int ib() const
Definition: MsmMap.h:435
int ja() const
Definition: MsmMap.h:436
template<class T>
void msm::Grid< T >::extract ( Grid< T > &  g)
inline

Definition at line 748 of file MsmMap.h.

Referenced by msm::PatchData::sendCharge(), and msm::PatchData::sendChargeC1Hermite().

748  {
749  ASSERT(IndexRange(g) <= IndexRange(*this));
750  int gni = g.nextent.i;
751  int gnj = g.nextent.j;
752  int gnk = g.nextent.k;
753  int index = 0;
754  int ni = nextent.i;
755  int nij = nextent.i * nextent.j;
756  int koff = (g.nlower.k - nlower.k) * nij
757  + (g.nlower.j - nlower.j) * ni + (g.nlower.i - nlower.i);
758  T *gbuf = g.gdata.buffer();
759  const T *buf = gdata.buffer();
760  for (int k = 0; k < gnk; k++) {
761  int jkoff = k * nij + koff;
762  for (int j = 0; j < gnj; j++) {
763  int ijkoff = j * ni + jkoff;
764  for (int i = 0; i < gni; i++, index++) {
765  gbuf[index] = buf[i + ijkoff];
766  }
767  }
768  }
769  }
#define ASSERT(expr)
Definition: MsmMap.h:68
int k
Definition: MsmMap.h:411
int i
Definition: MsmMap.h:411
int j
Definition: MsmMap.h:411
Ivec nextent
Definition: MsmMap.h:459
int ni() const
Definition: MsmMap.h:440
template<class T>
template<int N>
void msm::Grid< T >::extract ( GridFixed< T, N > &  g)
inline

Definition at line 801 of file MsmMap.h.

801  {
802  ASSERT(IndexRange(g) <= IndexRange(*this));
803  int gni = g.nextent.i;
804  int gnj = g.nextent.j;
805  int gnk = g.nextent.k;
806  int index = 0;
807  int ni = nextent.i;
808  int nij = nextent.i * nextent.j;
809  int koff = (g.nlower.k - nlower.k) * nij
810  + (g.nlower.j - nlower.j) * ni + (g.nlower.i - nlower.i);
811  T *gbuf = g.buffer();
812  const T *buf = gdata.buffer();
813  for (int k = 0; k < gnk; k++) {
814  int jkoff = k * nij + koff;
815  for (int j = 0; j < gnj; j++) {
816  int ijkoff = j * ni + jkoff;
817  for (int i = 0; i < gni; i++, index++) {
818  gbuf[index] = buf[i + ijkoff];
819  }
820  }
821  }
822  }
#define ASSERT(expr)
Definition: MsmMap.h:68
int k
Definition: MsmMap.h:411
int i
Definition: MsmMap.h:411
int j
Definition: MsmMap.h:411
Ivec nextent
Definition: MsmMap.h:459
int ni() const
Definition: MsmMap.h:440
template<class T>
int msm::Grid< T >::flatindex ( int  i,
int  j,
int  k 
) const
inline

Definition at line 663 of file MsmMap.h.

Referenced by msm::Grid< Vtype >::elem(), and msm::Grid< Vtype >::operator()().

663  {
664  return ((k-ka())*nj() + (j-ja()))*ni() + (i-ia());
665  }
int ka() const
Definition: MsmMap.h:438
int ia() const
Definition: MsmMap.h:434
int nj() const
Definition: MsmMap.h:441
int ja() const
Definition: MsmMap.h:436
int ni() const
Definition: MsmMap.h:440
template<class T>
void msm::Grid< T >::init ( const IndexRange n)
inline
template<class T>
const T& msm::Grid< T >::operator() ( int  i,
int  j,
int  k 
) const
inline

Definition at line 619 of file MsmMap.h.

Referenced by msm::Grid< Vtype >::operator()().

619  {
620 #ifdef DEBUG_MSM
621  return elem(i,j,k);
622 #else
623  return gdata[flatindex(i,j,k)];
624 #endif
625  }
const T & elem(int i, int j, int k) const
Definition: MsmMap.h:629
int flatindex(int i, int j, int k) const
Definition: MsmMap.h:663
template<class T>
const T& msm::Grid< T >::operator() ( const Ivec n) const
inline

Definition at line 626 of file MsmMap.h.

626  {
627  return this->operator()(n.i, n.j, n.k);
628  }
const T & operator()(int i, int j, int k) const
Definition: MsmMap.h:619
template<class T>
T& msm::Grid< T >::operator() ( int  i,
int  j,
int  k 
)
inline

Definition at line 641 of file MsmMap.h.

641  {
642 #ifdef DEBUG_MSM
643  return elem(i,j,k);
644 #else
645  return gdata[flatindex(i,j,k)];
646 #endif
647  }
const T & elem(int i, int j, int k) const
Definition: MsmMap.h:629
int flatindex(int i, int j, int k) const
Definition: MsmMap.h:663
template<class T>
T& msm::Grid< T >::operator() ( const Ivec n)
inline

Definition at line 648 of file MsmMap.h.

648  {
649  return this->operator()(n.i, n.j, n.k);
650  }
const T & operator()(int i, int j, int k) const
Definition: MsmMap.h:619
template<class T>
Grid<T>& msm::Grid< T >::operator+= ( const Grid< T > &  g)
inline

Definition at line 681 of file MsmMap.h.

681  {
682 #if 1
683  ASSERT(IndexRange(g) <= IndexRange(*this));
684 #else
685  if ( ! (IndexRange(g) <= IndexRange(*this)) ) {
686  Grid<T> tmp = *this;
687  // expand myself to hold sum
688  int ia = nlower.i;
689  if (ia > g.nlower.i) ia = g.nlower.i;
690  int ja = nlower.j;
691  if (ja > g.nlower.j) ja = g.nlower.j;
692  int ka = nlower.k;
693  if (ka > g.nlower.k) ka = g.nlower.k;
694  int ib1 = nlower.i + nextent.i;
695  int gib1 = g.nlower.i + g.nextent.i;
696  if (ib1 < gib1) ib1 = gib1;
697  int jb1 = nlower.j + nextent.j;
698  int gjb1 = g.nlower.j + g.nextent.j;
699  if (jb1 < gjb1) jb1 = gjb1;
700  int kb1 = nlower.k + nextent.k;
701  int gkb1 = g.nlower.k + g.nextent.k;
702  if (kb1 < gkb1) kb1 = gkb1;
703  setbounds(ia, ib1-1, ja, jb1-1, ka, kb1-1);
704  reset(0); // make sure constructor for T accepts "0" as its zero
705  // now copy "tmp" grid elements into my expanded self
706  int index = 0;
707  int ni = nextent.i;
708  int nij = nextent.i * nextent.j;
709  int koff = (tmp.nlower.k - nlower.k) * nij
710  + (tmp.nlower.j - nlower.j) * ni + (tmp.nlower.i - nlower.i);
711  const T *gbuf = tmp.gdata.buffer();
712  T *buf = gdata.buffer();
713  for (int k = 0; k < tmp.nextent.k; k++) {
714  int jkoff = k * nij + koff;
715  for (int j = 0; j < tmp.nextent.j; j++) {
716  int ijkoff = j * ni + jkoff;
717  for (int i = 0; i < tmp.nextent.i; i++, index++) {
718  buf[i + ijkoff] = gbuf[index];
719  }
720  }
721  }
722  }
723 #endif
724  int gni = g.nextent.i;
725  int gnj = g.nextent.j;
726  int gnk = g.nextent.k;
727  int index = 0;
728  int ni = nextent.i;
729  int nij = nextent.i * nextent.j;
730  int koff = (g.nlower.k - nlower.k) * nij
731  + (g.nlower.j - nlower.j) * ni + (g.nlower.i - nlower.i);
732  const T *gbuf = g.gdata.buffer();
733  T *buf = gdata.buffer();
734  for (int k = 0; k < gnk; k++) {
735  int jkoff = k * nij + koff;
736  for (int j = 0; j < gnj; j++) {
737  int ijkoff = j * ni + jkoff;
738  for (int i = 0; i < gni; i++, index++) {
739  buf[i + ijkoff] += gbuf[index];
740  }
741  }
742  }
743  return(*this);
744  }
void reset(const T &t)
Definition: MsmMap.h:670
#define ASSERT(expr)
Definition: MsmMap.h:68
int k
Definition: MsmMap.h:411
int ka() const
Definition: MsmMap.h:438
int i
Definition: MsmMap.h:411
int ia() const
Definition: MsmMap.h:434
void setbounds(int pia, int pib, int pja, int pjb, int pka, int pkb)
Definition: MsmMap.h:612
int j
Definition: MsmMap.h:411
Ivec nextent
Definition: MsmMap.h:459
int ja() const
Definition: MsmMap.h:436
int ni() const
Definition: MsmMap.h:440
template<class T>
template<int N>
Grid<T>& msm::Grid< T >::operator+= ( const GridFixed< T, N > &  g)
inline

Definition at line 774 of file MsmMap.h.

774  {
775  ASSERT(IndexRange(g) <= IndexRange(*this));
776  int gni = g.nextent.i;
777  int gnj = g.nextent.j;
778  int gnk = g.nextent.k;
779  int index = 0;
780  int ni = nextent.i;
781  int nij = nextent.i * nextent.j;
782  int koff = (g.nlower.k - nlower.k) * nij
783  + (g.nlower.j - nlower.j) * ni + (g.nlower.i - nlower.i);
784  const T *gbuf = g.buffer();
785  T *buf = gdata.buffer();
786  for (int k = 0; k < gnk; k++) {
787  int jkoff = k * nij + koff;
788  for (int j = 0; j < gnj; j++) {
789  int ijkoff = j * ni + jkoff;
790  for (int i = 0; i < gni; i++, index++) {
791  buf[i + ijkoff] += gbuf[index];
792  }
793  }
794  }
795  return(*this);
796  }
#define ASSERT(expr)
Definition: MsmMap.h:68
int k
Definition: MsmMap.h:411
int i
Definition: MsmMap.h:411
int j
Definition: MsmMap.h:411
Ivec nextent
Definition: MsmMap.h:459
int ni() const
Definition: MsmMap.h:440
template<class T>
void msm::Grid< T >::reset ( const T &  t)
inline

Definition at line 670 of file MsmMap.h.

Referenced by msm::PatchData::init(), ComputeMsmMgr::initialize(), ComputeMsmMgr::initVirialContrib(), and msm::Grid< Vtype >::operator+=().

670  {
671  T *buf = gdata.buffer();
672  int len = nn();
673  for (int n = 0; n < len; n++) { buf[n] = t; }
674  }
int nn() const
Definition: MsmMap.h:443
template<class T>
void msm::Grid< T >::resize ( int  n)
inline

Definition at line 616 of file MsmMap.h.

Referenced by msm::PatchData::PatchData().

616  { // reserve space but don't set grid indexing
617  gdata.resize(n);
618  }
template<class T>
void msm::Grid< T >::set ( int  pia,
int  pni,
int  pja,
int  pnj,
int  pka,
int  pnk 
)
inline

Definition at line 608 of file MsmMap.h.

Referenced by ComputeMsmMgr::initialize().

608  {
609  IndexRange::set(pia, pni, pja, pnj, pka, pnk);
610  gdata.resize(nn());
611  }
void set(int pia, int pni, int pja, int pnj, int pka, int pnk)
Definition: MsmMap.h:426
int nn() const
Definition: MsmMap.h:443
template<class T>
void msm::Grid< T >::setbounds ( int  pia,
int  pib,
int  pja,
int  pjb,
int  pka,
int  pkb 
)
inline

Definition at line 612 of file MsmMap.h.

Referenced by ComputeMsmMgr::initialize(), and msm::Grid< Vtype >::operator+=().

612  {
613  IndexRange::setbounds(pia, pib, pja, pjb, pka, pkb);
614  gdata.resize(nn());
615  }
void setbounds(int pia, int pib, int pja, int pjb, int pka, int pkb)
Definition: MsmMap.h:431
int nn() const
Definition: MsmMap.h:443
template<class T>
void msm::Grid< T >::updateLower ( const Ivec n)
inline

The documentation for this class was generated from the following file: