NAMD
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
GridforceGrid Class Referenceabstract

#include <GridForceGrid.h>

Inheritance diagram for GridforceGrid:
GridforceFullMainGrid GridforceLiteGrid

Public Types

enum  GridforceGridType { GridforceGridTypeUndefined = 0, GridforceGridTypeFull, GridforceGridTypeLite }
 

Public Member Functions

virtual ~GridforceGrid ()
 
virtual void initialize (char *potfilename, SimParameters *simParams, MGridforceParams *mgridParams)=0
 
virtual void reinitialize (SimParameters *simParams, MGridforceParams *mgridParams)=0
 
virtual Position get_center (void) const =0
 
virtual Position get_origin (void) const =0
 
virtual Tensor get_e (void) const =0
 
virtual Tensor get_inv (void) const =0
 
virtual Vector get_scale (void) const =0
 
virtual Bool get_checksize (void) const =0
 
virtual int get_k0 (void) const =0
 
virtual int get_k1 (void) const =0
 
virtual int get_k2 (void) const =0
 
virtual int get_total_grids (void) const =0
 
virtual long int get_all_gridvals (float **all_gridvals) const =0
 
virtual void set_all_gridvals (float *all_gridvals, long int sz)=0
 
virtual void set_scale (Vector s)=0
 
Position wrap_position (const Position &pos, const Lattice &lattice)
 
bool fits_lattice (const Lattice &lattice)
 
int compute_VdV (Position pos, float &V, Vector &dV) const
 
GridforceGridType get_grid_type (void)
 

Static Public Member Functions

static GridforceGridnew_grid (int gridnum, char *potfilename, SimParameters *simParams, MGridforceParams *mgridParams)
 
static void pack_grid (GridforceGrid *grid, MOStream *msg)
 
static GridforceGridunpack_grid (int gridnum, MIStream *msg)
 

Protected Member Functions

virtual void pack (MOStream *msg) const =0
 
virtual void unpack (MIStream *msg)=0
 
Position get_corner (int idx)
 
 GridforceGrid ()
 

Protected Attributes

GridforceGridType type
 
int mygridnum
 

Detailed Description

Definition at line 28 of file GridForceGrid.h.

Member Enumeration Documentation

Enumerator
GridforceGridTypeUndefined 
GridforceGridTypeFull 
GridforceGridTypeLite 

Definition at line 59 of file GridForceGrid.h.

Constructor & Destructor Documentation

GridforceGrid::~GridforceGrid ( )
virtual

Definition at line 48 of file GridForceGrid.C.

48 { ; }
GridforceGrid::GridforceGrid ( )
inlineprotected

Member Function Documentation

int GridforceGrid::compute_VdV ( Position  pos,
float &  V,
Vector dV 
) const
inline

Definition at line 54 of file GridForceGrid.h.

54 { return -1; }
bool GridforceGrid::fits_lattice ( const Lattice lattice)

Definition at line 84 of file GridForceGrid.C.

References DebugM, endi(), get_center(), get_corner(), and wrap_position().

Referenced by ComputeGridForce::doForce(), and GridforceFullMainGrid::initialize().

85 {
86  // Idea: Go through each grid corner and wrap it to the grid center;
87  // if the position moves, then the grid is too big and we return false
88  DebugM(4, "Checking whether grid fits periodic cell\n");
89  Position center = get_center();
90  for (int i = 0; i < 8; i++) {
91  Position pos = get_corner(i);
92  Position pos_wrapped = wrap_position(pos, lattice);
93  if ((pos - pos_wrapped).length() > 1.) {
94  DebugM(5, "(" << pos << ") != (" << pos_wrapped << ")\n" << endi);
95  return false;
96  }
97  }
98  return true;
99 }
Definition: Vector.h:64
#define DebugM(x, y)
Definition: Debug.h:59
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
virtual Position get_center(void) const =0
Position get_corner(int idx)
Position wrap_position(const Position &pos, const Lattice &lattice)
virtual long int GridforceGrid::get_all_gridvals ( float **  all_gridvals) const
pure virtual
virtual Position GridforceGrid::get_center ( void  ) const
pure virtual
virtual Bool GridforceGrid::get_checksize ( void  ) const
pure virtual
Position GridforceGrid::get_corner ( int  idx)
protected

Definition at line 101 of file GridForceGrid.C.

References DebugM, endi(), get_e(), get_k0(), get_k1(), get_k2(), and get_origin().

Referenced by fits_lattice().

102 {
103  // idx -> (x,y,z) (cell basis coordinates)
104  // 0 -> (0,0,0)
105  // 1 -> (1,0,0)
106  // 2 -> (0,1,0)
107  // 3 -> (1,1,0)
108  // 4 -> (0,0,1)
109  // 5 -> (1,0,1)
110  // 6 -> (0,1,1)
111  // 7 -> (1,1,1)
112  Position pos;
113  if (idx >= 8 || idx < 0) {
114  // invalid index
115  pos = Vector(); // default value of Vector() is strange enough to be a decent "undefined" value (-99999, -99999, -999999)
116  } else if (corners[idx] != Vector()) {
117  // use cached value if possible
118  pos = corners[idx];
119  } else {
120  // must calculate
121  Tensor e = get_e();
122  pos = get_origin();
123  if (idx & (1 << 0)) pos += e * Vector(get_k0()-1, 0, 0);
124  if (idx & (1 << 1)) pos += e * Vector(0, get_k1()-1, 0);
125  if (idx & (1 << 2)) pos += e * Vector(0, 0, get_k2()-1);
126  corners[idx] = pos; // cache for future use
127  DebugM(4, "corner " << idx << " = " << pos << "\n" << endi);
128  }
129  return pos;
130 }
Definition: Vector.h:64
virtual Position get_origin(void) const =0
#define DebugM(x, y)
Definition: Debug.h:59
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
virtual int get_k2(void) const =0
Definition: Tensor.h:15
virtual int get_k0(void) const =0
virtual int get_k1(void) const =0
virtual Tensor get_e(void) const =0
virtual Tensor GridforceGrid::get_e ( void  ) const
pure virtual
GridforceGridType GridforceGrid::get_grid_type ( void  )
inline

Definition at line 65 of file GridForceGrid.h.

References type.

Referenced by ComputeGridForce::doForce(), and pack_grid().

65 { return type; }
GridforceGridType type
Definition: GridForceGrid.h:74
virtual Tensor GridforceGrid::get_inv ( void  ) const
pure virtual
virtual int GridforceGrid::get_k0 ( void  ) const
pure virtual

Implemented in GridforceLiteGrid, and GridforceFullMainGrid.

Referenced by get_corner().

virtual int GridforceGrid::get_k1 ( void  ) const
pure virtual

Implemented in GridforceLiteGrid, and GridforceFullMainGrid.

Referenced by get_corner().

virtual int GridforceGrid::get_k2 ( void  ) const
pure virtual

Implemented in GridforceLiteGrid, and GridforceFullMainGrid.

Referenced by get_corner().

virtual Position GridforceGrid::get_origin ( void  ) const
pure virtual

Implemented in GridforceLiteGrid, and GridforceFullMainGrid.

Referenced by get_corner().

virtual Vector GridforceGrid::get_scale ( void  ) const
pure virtual
virtual int GridforceGrid::get_total_grids ( void  ) const
pure virtual
virtual void GridforceGrid::initialize ( char *  potfilename,
SimParameters simParams,
MGridforceParams mgridParams 
)
pure virtual

Implemented in GridforceLiteGrid, and GridforceFullMainGrid.

Referenced by new_grid().

GridforceGrid * GridforceGrid::new_grid ( int  gridnum,
char *  potfilename,
SimParameters simParams,
MGridforceParams mgridParams 
)
static

Definition at line 34 of file GridForceGrid.C.

References MGridforceParams::gridforceLite, and initialize().

Referenced by Molecule::build_gridforce_params().

35 {
36  GridforceGrid *grid = NULL;
37  if (mgridParams->gridforceLite) {
38  grid = new GridforceLiteGrid(gridnum);
39  } else {
40  grid = new GridforceFullMainGrid(gridnum);
41  }
42 
43  grid->initialize(potfilename, simParams, mgridParams);
44 
45  return grid;
46 }
virtual void initialize(char *potfilename, SimParameters *simParams, MGridforceParams *mgridParams)=0
virtual void GridforceGrid::pack ( MOStream msg) const
protectedpure virtual

Implemented in GridforceLiteGrid, and GridforceFullMainGrid.

Referenced by pack_grid().

void GridforceGrid::pack_grid ( GridforceGrid grid,
MOStream msg 
)
static

Definition at line 50 of file GridForceGrid.C.

References get_grid_type(), pack(), and MOStream::put().

Referenced by Node::reloadGridforceGrid(), and Molecule::send_Molecule().

51 {
52  // Abstract interface for packing a grid into a message. This
53  // could easily be a non-static function as it was before, but is
54  // static to make it similar to unpack_grid below, which does need
55  // to be static since it creates a GridforceGrid object.
56  msg->put(grid->get_grid_type());
57  grid->pack(msg);
58 }
virtual void pack(MOStream *msg) const =0
MOStream * put(char data)
Definition: MStream.h:112
GridforceGridType get_grid_type(void)
Definition: GridForceGrid.h:65
virtual void GridforceGrid::reinitialize ( SimParameters simParams,
MGridforceParams mgridParams 
)
pure virtual
virtual void GridforceGrid::set_all_gridvals ( float *  all_gridvals,
long int  sz 
)
pure virtual
virtual void GridforceGrid::set_scale ( Vector  s)
pure virtual
virtual void GridforceGrid::unpack ( MIStream msg)
protectedpure virtual

Implemented in GridforceLiteGrid, and GridforceFullMainGrid.

Referenced by unpack_grid().

GridforceGrid * GridforceGrid::unpack_grid ( int  gridnum,
MIStream msg 
)
static

Definition at line 60 of file GridForceGrid.C.

References MIStream::get(), GridforceGridTypeFull, GridforceGridTypeLite, NAMD_bug(), type, and unpack().

Referenced by Molecule::receive_Molecule(), and Node::reloadGridforceGrid().

61 {
62  // Abstract interface for unpacking a grid from a message.
63  GridforceGrid *grid = NULL;
64  int type;
65 
66  msg->get(type);
67 
68  switch (type) {
70  grid = new GridforceFullMainGrid(gridnum);
71  break;
73  grid = new GridforceLiteGrid(gridnum);
74  break;
75  default:
76  NAMD_bug("GridforceGrid::unpack_grid called with unknown grid type!");
77  }
78 
79  grid->unpack(msg);
80 
81  return grid;
82 }
MIStream * get(char &data)
Definition: MStream.h:29
void NAMD_bug(const char *err_msg)
Definition: common.C:129
GridforceGridType type
Definition: GridForceGrid.h:74
virtual void unpack(MIStream *msg)=0
Position GridforceGrid::wrap_position ( const Position pos,
const Lattice lattice 
)
inline

Definition at line 463 of file GridForceGrid.inl.

References get_center(), Lattice::origin(), and Lattice::wrap_delta().

Referenced by fits_lattice().

464 {
465  // Wrap 'pos' about grid center, using periodic cell information in 'lattice'
466  // Position pos_wrapped = pos;
467  // Position center = get_center();
468  // pos_wrapped += lattice.wrap_delta(pos);
469  // pos_wrapped += lattice.delta(pos_wrapped, center) - (pos_wrapped - center);
470 
471  Position pos_wrapped = pos + lattice.wrap_delta(pos - get_center() + lattice.origin());
472 
473  return pos_wrapped;
474 }
Definition: Vector.h:64
Vector wrap_delta(const Position &pos1) const
Definition: Lattice.h:206
Vector origin() const
Definition: Lattice.h:262
virtual Position get_center(void) const =0

Member Data Documentation

int GridforceGrid::mygridnum
protected
GridforceGridType GridforceGrid::type
protected

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