NAMD
Functions | Variables
msm.c File Reference
#include "msm_defn.h"

Go to the source code of this file.

Functions

NL_MsmNL_msm_create (void)
 
void NL_msm_destroy (NL_Msm *pm)
 
int NL_msm_configure (NL_Msm *pm, double gridspacing, int approx, int split, int nlevels)
 
int NL_msm_compute_force (NL_Msm *pm, double *felec, double *uelec, const double *atom, int natoms)
 
int NL_msm_compute_force_sprec (NL_Msm *pm, float *felec_f, float *uelec_f, const float *atom_f, int natoms)
 
int NL_msm_approx (const char *name)
 
const char * NL_msm_approx_name (int approx)
 
int NL_msm_split (const char *name)
 
const char * NL_msm_split_name (int split)
 

Variables

static const char * ApproxName []
 
static const char * SplitName []
 

Function Documentation

int NL_msm_approx ( const char *  name)

Helper function to determine APPROX enum constant from string name.

Definition at line 160 of file msm.c.

References ApproxName, and NELEMS.

160  {
161  int i;
162  if (name) {
163  for (i = 0; i < NELEMS(ApproxName); i++) {
164  if (strcasecmp(name, ApproxName[i]) == 0) return i;
165  }
166  }
167  return -1;
168 }
#define NELEMS(arr)
Definition: msm_defn.h:39
static const char * ApproxName[]
Definition: msm.c:149
const char* NL_msm_approx_name ( int  approx)

Helper function returning string name for APPROX enum constant.

Definition at line 170 of file msm.c.

References ApproxName, and NELEMS.

Referenced by print_status().

170  {
171  if (approx >= 0 && approx < NELEMS(ApproxName)) {
172  return ApproxName[approx];
173  }
174  else return NULL;
175 }
#define NELEMS(arr)
Definition: msm_defn.h:39
static const char * ApproxName[]
Definition: msm.c:149
int NL_msm_compute_force ( NL_Msm msm,
double *  felec,
double *  uelec,
const double *  atom,
int  natoms 
)

Compute the electrostatic forces and potential energy for the array of atoms. The felec array and the location pointed to by uelec is expected to be initialized before the call. As stated, the atoms must be within the defined cell.

Parameters
pmthe MSM solver object
felecelectrostatic forces x/y/z for each atom
uelecelectrostatic potential energy
atompositions and charge x/y/z/q for each atom
natomsnumber of atoms

Definition at line 56 of file msm.c.

References NL_Msm_t::atom, NL_Msm_t::felec, NL_Msm_t::msmflags, NL_MSM_COMPUTE_LONG_RANGE, NL_msm_compute_long_range(), NL_MSM_COMPUTE_SHORT_RANGE, NL_msm_compute_short_range(), NL_MSM_COMPUTE_SPREC, NL_MSM_ERROR_PARAM, NL_Msm_t::numatoms, NL_Msm_t::report_timings, NL_Msm_t::timer, NL_Msm_t::uelec, wkf_timer_start(), wkf_timer_stop(), and wkf_timer_time().

Referenced by ComputeMsmSerialMgr::recvCoord().

62  {
63  int rc;
64  double time_delta;
65 
66  if (pm->msmflags & NL_MSM_COMPUTE_SPREC) {
67  return NL_MSM_ERROR_PARAM;
68  }
69 
70  /* store buffer pointers from caller */
71  pm->felec = felec;
72  pm->atom = atom;
73  pm->numatoms = natoms;
74  pm->uelec = 0;
75 
79  if (rc) return rc;
80  wkf_timer_stop(pm->timer);
81  time_delta = wkf_timer_time(pm->timer);
82  if (pm->report_timings) {
83  printf("MSM short-range part: %6.3f sec\n", time_delta);
84  }
85  }
89  if (rc) return rc;
90  wkf_timer_stop(pm->timer);
91  time_delta = wkf_timer_time(pm->timer);
92  if (pm->report_timings) {
93  printf("MSM long-range part: %6.3f sec\n", time_delta);
94  }
95  }
96  *uelec += pm->uelec; /* add to caller's potential */
97 
98  return 0;
99 }
double wkf_timer_time(wkf_timerhandle v)
Definition: wkfutils.c:134
int msmflags
Definition: msm_defn.h:590
double * felec
Definition: msm_defn.h:568
wkf_timerhandle timer
Definition: msm_defn.h:684
int numatoms
Definition: msm_defn.h:599
void wkf_timer_stop(wkf_timerhandle v)
Definition: wkfutils.c:129
double uelec
Definition: msm_defn.h:566
int NL_msm_compute_short_range(NL_Msm *pm)
Definition: msm_shortrng.c:37
int NL_msm_compute_long_range(NL_Msm *pm)
Definition: msm_longrng.c:52
const double * atom
Definition: msm_defn.h:569
void wkf_timer_start(wkf_timerhandle v)
Definition: wkfutils.c:124
int report_timings
Definition: msm_defn.h:683
int NL_msm_compute_force_sprec ( NL_Msm msm,
float *  felec,
float *  uelec,
const float *  atom,
int  natoms 
)

Same as NL_msm_compute_force() except for single precision calculation. Call this only if NL_MSM_COMPUTE_SPREC flag was selected.

Parameters
pmthe MSM solver object
felec_felectrostatic forces x/y/z for each atom
uelec_felectrostatic potential energy
atom_fpositions and charge x/y/z/q for each atom
natomsnumber of atoms

Definition at line 102 of file msm.c.

References NL_Msm_t::atom_f, NL_Msm_t::felec_f, NL_Msm_t::msmflags, NL_MSM_COMPUTE_LONG_RANGE, NL_msm_compute_long_range_sprec(), NL_MSM_COMPUTE_SHORT_RANGE, NL_msm_compute_short_range_sprec(), NL_MSM_COMPUTE_SPREC, NL_MSM_ERROR_PARAM, NL_Msm_t::numatoms, NL_Msm_t::report_timings, NL_Msm_t::timer, NL_Msm_t::uelec, wkf_timer_start(), wkf_timer_stop(), and wkf_timer_time().

108  {
109  int rc;
110  double time_delta;
111 
112  if ((pm->msmflags & NL_MSM_COMPUTE_SPREC) == 0) {
113  return NL_MSM_ERROR_PARAM;
114  }
115 
116  /* store buffer pointers from caller */
117  pm->felec_f = felec_f;
118  pm->atom_f = atom_f;
119  pm->numatoms = natoms;
120  pm->uelec = 0;
121 
123  wkf_timer_start(pm->timer);
125  if (rc) return rc;
126  wkf_timer_stop(pm->timer);
127  time_delta = wkf_timer_time(pm->timer);
128  if (pm->report_timings) {
129  printf("MSM short-range part: %6.3f sec\n", time_delta);
130  }
131  }
133  wkf_timer_start(pm->timer);
135  if (rc) return rc;
136  wkf_timer_stop(pm->timer);
137  time_delta = wkf_timer_time(pm->timer);
138  if (pm->report_timings) {
139  printf("MSM long-range part: %6.3f sec\n", time_delta);
140  }
141  }
142  *uelec_f += (float) pm->uelec; /* add to caller's potential */
143 
144  return 0;
145 }
double wkf_timer_time(wkf_timerhandle v)
Definition: wkfutils.c:134
int msmflags
Definition: msm_defn.h:590
wkf_timerhandle timer
Definition: msm_defn.h:684
const float * atom_f
Definition: msm_defn.h:572
int numatoms
Definition: msm_defn.h:599
void wkf_timer_stop(wkf_timerhandle v)
Definition: wkfutils.c:129
double uelec
Definition: msm_defn.h:566
int NL_msm_compute_short_range_sprec(NL_Msm *pm)
int NL_msm_compute_long_range_sprec(NL_Msm *pm)
float * felec_f
Definition: msm_defn.h:571
void wkf_timer_start(wkf_timerhandle v)
Definition: wkfutils.c:124
int report_timings
Definition: msm_defn.h:683
int NL_msm_configure ( NL_Msm msm,
double  gridspacing,
int  approx,
int  split,
int  nlevels 
)

Advanced configuration of MSM. The ratio of cutoff / gridspacing is generally kept between about 2.5 and 6. For atomic lengths in Angstroms, good results are demonstrated for a cutoff distance between 8 and 12 A and the default grid spacing of 2.5 A.

The optimal pairings of approx and split have been demonstrated to be:

  • CUBIC with TAYLOR2 (the default),
  • QUINTIC with TAYLOR3,
  • SEPTIC with TAYLOR4,
  • NONIC with TAYLOR5.

Use QUINTIC2, SEPTIC3, NONIC4 paired with the same splitting functions above if greater continuity is desired.

Set "nlevels" to 0 (the default) to fully adapt the number of grid levels to the system cell size.

Parameters
pmthe MSM solver object
gridspacinggrid spacing for first grid level
approxwhich approximation method
splitwhich splitting
nlevelsnumber of grid levels to use

Definition at line 36 of file msm.c.

References NL_Msm_t::approx, NL_Msm_t::gridspacing, NL_MSM_APPROX_END, NL_MSM_ERROR_PARAM, NL_MSM_SPLIT_END, NL_MSM_SUCCESS, NL_Msm_t::nlevels, split(), and NL_Msm_t::split.

Referenced by ComputeMsmSerialMgr::recvCoord().

42  {
43  if (gridspacing > 0) pm->gridspacing = gridspacing;
44  else if (gridspacing < 0) return NL_MSM_ERROR_PARAM;
45  if (approx >= 0 && approx < NL_MSM_APPROX_END) pm->approx = approx;
46  else return NL_MSM_ERROR_PARAM;
47  if (split >= 0 && split < NL_MSM_SPLIT_END) pm->split = split;
48  else return NL_MSM_ERROR_PARAM;
49  if (nlevels >= 0) pm->nlevels = nlevels;
50  else return NL_MSM_ERROR_PARAM;
51 
52  return NL_MSM_SUCCESS;
53 }
int approx
Definition: msm_defn.h:642
std::vector< std::string > split(const std::string &text, std::string delimiter)
Definition: MoleculeQM.C:73
double gridspacing
Definition: msm_defn.h:633
int split
Definition: msm_defn.h:643
int nlevels
Definition: msm_defn.h:645
NL_Msm* NL_msm_create ( void  )

Allocate MSM solver.

Definition at line 6 of file msm.c.

References NL_Msm_t::approx, NL_Msm_t::binfill, DEFAULT_APPROX, DEFAULT_BINFILL, DEFAULT_DENSITY, DEFAULT_GRIDSPACING, DEFAULT_NBINSLOTS, DEFAULT_NLEVELS, DEFAULT_SPLIT, NL_Msm_t::density, NL_Msm_t::gridspacing, NL_Msm_t::nbinslots, NL_Msm_t::nlevels, NL_Msm_t::split, NL_Msm_t::timer, NL_Msm_t::timer_longrng, and wkf_timer_create().

Referenced by ComputeMsmSerialMgr::recvCoord().

6  {
7  NL_Msm *pm = (NL_Msm *) calloc(1, sizeof(NL_Msm));
8  if (NULL == pm) return NULL;
9 
10  pm->timer = wkf_timer_create();
11  if (NULL == pm->timer) return NULL;
13  if (NULL == pm->timer) return NULL;
14 
15  /* method parameters are modified with msm_configure() */
17  pm->approx = DEFAULT_APPROX;
18  pm->split = DEFAULT_SPLIT;
20 
24  return pm;
25 }
wkf_timerhandle timer
Definition: msm_defn.h:684
int approx
Definition: msm_defn.h:642
wkf_timerhandle wkf_timer_create(void)
Definition: wkfutils.c:161
#define DEFAULT_APPROX
Definition: msm_defn.h:120
#define DEFAULT_DENSITY
Definition: msm_defn.h:124
double density
Definition: msm_defn.h:605
#define DEFAULT_SPLIT
Definition: msm_defn.h:121
int nbinslots
Definition: msm_defn.h:606
#define DEFAULT_BINFILL
Definition: msm_defn.h:125
#define DEFAULT_GRIDSPACING
Definition: msm_defn.h:119
wkf_timerhandle timer_longrng
Definition: msm_defn.h:685
double binfill
Definition: msm_defn.h:604
double gridspacing
Definition: msm_defn.h:633
int split
Definition: msm_defn.h:643
#define DEFAULT_NLEVELS
Definition: msm_defn.h:122
int nlevels
Definition: msm_defn.h:645
#define DEFAULT_NBINSLOTS
Definition: msm_defn.h:126
void NL_msm_destroy ( NL_Msm )

Free MSM solver.

Definition at line 28 of file msm.c.

References NL_msm_cleanup(), NL_Msm_t::timer, NL_Msm_t::timer_longrng, and wkf_timer_destroy().

Referenced by ComputeMsmSerialMgr::~ComputeMsmSerialMgr().

28  {
29  NL_msm_cleanup(pm);
32  free(pm);
33 }
wkf_timerhandle timer
Definition: msm_defn.h:684
void wkf_timer_destroy(wkf_timerhandle v)
Definition: wkfutils.c:168
wkf_timerhandle timer_longrng
Definition: msm_defn.h:685
void NL_msm_cleanup(NL_Msm *pm)
Definition: msm_setup.c:7
int NL_msm_split ( const char *  name)

Helper function to determine SPLIT enum constant from string name.

Definition at line 210 of file msm.c.

References NELEMS, and SplitName.

210  {
211  int i;
212  if (name) {
213  for (i = 0; i < NELEMS(SplitName); i++) {
214  if (strcasecmp(name, SplitName[i]) == 0) return i;
215  }
216  }
217  return -1;
218 }
#define NELEMS(arr)
Definition: msm_defn.h:39
static const char * SplitName[]
Definition: msm.c:179
const char* NL_msm_split_name ( int  split)

Helper function returning string name for SPLIT enum constant.

Definition at line 220 of file msm.c.

References NELEMS, split(), and SplitName.

Referenced by print_status().

220  {
221  if (split >= 0 && split < NELEMS(SplitName)) {
222  return SplitName[split];
223  }
224  else return NULL;
225 }
#define NELEMS(arr)
Definition: msm_defn.h:39
std::vector< std::string > split(const std::string &text, std::string delimiter)
Definition: MoleculeQM.C:73
static const char * SplitName[]
Definition: msm.c:179

Variable Documentation

const char* ApproxName[]
static
Initial value:
= {
"cubic",
"quintic",
"quintic2",
"septic",
"septic3",
"nonic",
"nonic4",
"bspline",
}

Order must be the same as APPROX enum in msm.h

Definition at line 149 of file msm.c.

Referenced by NL_msm_approx(), and NL_msm_approx_name().

const char* SplitName[]
static
Initial value:
= {
"Taylor2",
"Taylor3",
"Taylor4",
"Taylor5",
"Taylor6",
"Taylor7",
"Taylor8",
"Taylor1",
"sigma2_3",
"sigma3_5",
"sigma4_6",
"sigma4_7",
"sigma5_8",
"sigma5_9",
"sigma6_9",
"sigma6_10",
"sigma6_11",
"sigma7_11",
"sigma7_12",
"sigma7_13",
"sigma8_12",
"sigma8_13",
"sigma8_14",
"sigma8_15",
"sigma2_6",
"switch1_2",
"switch3_4",
"switch7_8",
}

Order must be the same as SPLIT enum in msm.h

Definition at line 179 of file msm.c.

Referenced by NL_msm_split(), and NL_msm_split_name().