NAMD
msm.c
Go to the documentation of this file.
1 /* msm.c */
2 
3 #include "msm_defn.h"
4 
5 
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 }
26 
27 
29  NL_msm_cleanup(pm);
32  free(pm);
33 }
34 
35 
37  NL_Msm *pm,
38  double gridspacing,
39  int approx,
40  int split,
41  int nlevels
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 }
54 
55 
57  NL_Msm *pm,
58  double *felec,
59  double *uelec,
60  const double *atom,
61  int natoms
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 }
100 
101 
103  NL_Msm *pm,
104  float *felec_f,
105  float *uelec_f,
106  const float *atom_f,
107  int natoms
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 }
146 
147 
149 static const char *ApproxName[] = {
150  "cubic",
151  "quintic",
152  "quintic2",
153  "septic",
154  "septic3",
155  "nonic",
156  "nonic4",
157  "bspline",
158 };
159 
160 int NL_msm_approx(const char *name) {
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 }
169 
170 const char *NL_msm_approx_name(int approx) {
171  if (approx >= 0 && approx < NELEMS(ApproxName)) {
172  return ApproxName[approx];
173  }
174  else return NULL;
175 }
176 
177 
179 static const char *SplitName[] = {
180  "Taylor2",
181  "Taylor3",
182  "Taylor4",
183  "Taylor5",
184  "Taylor6",
185  "Taylor7",
186  "Taylor8",
187  "Taylor1",
188  "sigma2_3",
189  "sigma3_5",
190  "sigma4_6",
191  "sigma4_7",
192  "sigma5_8",
193  "sigma5_9",
194  "sigma6_9",
195  "sigma6_10",
196  "sigma6_11",
197  "sigma7_11",
198  "sigma7_12",
199  "sigma7_13",
200  "sigma8_12",
201  "sigma8_13",
202  "sigma8_14",
203  "sigma8_15",
204  "sigma2_6",
205  "switch1_2",
206  "switch3_4",
207  "switch7_8",
208 };
209 
210 int NL_msm_split(const char *name) {
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 }
219 
220 const char *NL_msm_split_name(int split) {
221  if (split >= 0 && split < NELEMS(SplitName)) {
222  return SplitName[split];
223  }
224  else return NULL;
225 }
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
const char * NL_msm_split_name(int split)
Definition: msm.c:220
wkf_timerhandle timer
Definition: msm_defn.h:684
int approx
Definition: msm_defn.h:642
void wkf_timer_destroy(wkf_timerhandle v)
Definition: wkfutils.c:168
const float * atom_f
Definition: msm_defn.h:572
int numatoms
Definition: msm_defn.h:599
NL_Msm * NL_msm_create(void)
Definition: msm.c:6
int NL_msm_configure(NL_Msm *pm, double gridspacing, int approx, int split, int nlevels)
Definition: msm.c:36
wkf_timerhandle wkf_timer_create(void)
Definition: wkfutils.c:161
#define DEFAULT_APPROX
Definition: msm_defn.h:120
int NL_msm_approx(const char *name)
Definition: msm.c:160
#define DEFAULT_DENSITY
Definition: msm_defn.h:124
double density
Definition: msm_defn.h:605
void wkf_timer_stop(wkf_timerhandle v)
Definition: wkfutils.c:129
double uelec
Definition: msm_defn.h:566
#define DEFAULT_SPLIT
Definition: msm_defn.h:121
int nbinslots
Definition: msm_defn.h:606
int NL_msm_compute_short_range_sprec(NL_Msm *pm)
int NL_msm_compute_long_range_sprec(NL_Msm *pm)
#define NELEMS(arr)
Definition: msm_defn.h:39
float * felec_f
Definition: msm_defn.h:571
int NL_msm_compute_short_range(NL_Msm *pm)
Definition: msm_shortrng.c:37
static const char * ApproxName[]
Definition: msm.c:149
#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
int NL_msm_compute_force(NL_Msm *pm, double *felec, double *uelec, const double *atom, int natoms)
Definition: msm.c:56
int NL_msm_compute_long_range(NL_Msm *pm)
Definition: msm_longrng.c:52
int NL_msm_split(const char *name)
Definition: msm.c:210
double binfill
Definition: msm_defn.h:604
void NL_msm_cleanup(NL_Msm *pm)
Definition: msm_setup.c:7
const double * atom
Definition: msm_defn.h:569
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
const char * NL_msm_approx_name(int approx)
Definition: msm.c:170
#define DEFAULT_NLEVELS
Definition: msm_defn.h:122
int NL_msm_compute_force_sprec(NL_Msm *pm, float *felec_f, float *uelec_f, const float *atom_f, int natoms)
Definition: msm.c:102
static const char * SplitName[]
Definition: msm.c:179
void wkf_timer_start(wkf_timerhandle v)
Definition: wkfutils.c:124
void NL_msm_destroy(NL_Msm *pm)
Definition: msm.c:28
int nlevels
Definition: msm_defn.h:645
#define DEFAULT_NBINSLOTS
Definition: msm_defn.h:126
int report_timings
Definition: msm_defn.h:683