msm.c

Go to the documentation of this file.
00001 /* msm.c */
00002 
00003 #include "msm_defn.h"
00004 
00005 
00006 NL_Msm *NL_msm_create(void) {
00007   NL_Msm *pm = (NL_Msm *) calloc(1, sizeof(NL_Msm));
00008   if (NULL == pm) return NULL;
00009 
00010   pm->timer = wkf_timer_create();
00011   if (NULL == pm->timer) return NULL;
00012   pm->timer_longrng = wkf_timer_create();
00013   if (NULL == pm->timer) return NULL;
00014 
00015   /* method parameters are modified with msm_configure() */
00016   pm->gridspacing = DEFAULT_GRIDSPACING;
00017   pm->approx = DEFAULT_APPROX;
00018   pm->split = DEFAULT_SPLIT;
00019   pm->nlevels = DEFAULT_NLEVELS;
00020 
00021   pm->density = DEFAULT_DENSITY;
00022   pm->binfill = DEFAULT_BINFILL;
00023   pm->nbinslots = DEFAULT_NBINSLOTS;
00024   return pm;
00025 }
00026 
00027 
00028 void NL_msm_destroy(NL_Msm *pm) {
00029   NL_msm_cleanup(pm);
00030   wkf_timer_destroy(pm->timer);
00031   wkf_timer_destroy(pm->timer_longrng);
00032   free(pm);
00033 }
00034 
00035 
00036 int NL_msm_configure(
00037     NL_Msm *pm,          
00038     double gridspacing,  
00039     int approx,          
00040     int split,           
00041     int nlevels          
00042     ) {
00043   if (gridspacing > 0) pm->gridspacing = gridspacing;
00044   else if (gridspacing < 0) return NL_MSM_ERROR_PARAM;
00045   if (approx >= 0 && approx < NL_MSM_APPROX_END) pm->approx = approx;
00046   else return NL_MSM_ERROR_PARAM;
00047   if (split >= 0 && split < NL_MSM_SPLIT_END) pm->split = split;
00048   else return NL_MSM_ERROR_PARAM;
00049   if (nlevels >= 0) pm->nlevels = nlevels;
00050   else return NL_MSM_ERROR_PARAM;
00051 
00052   return NL_MSM_SUCCESS;
00053 }
00054 
00055 
00056 int NL_msm_compute_force(
00057     NL_Msm *pm,          
00058     double *felec,       
00059     double *uelec,       
00060     const double *atom,  
00061     int natoms           
00062     ) {
00063   int rc;
00064   double time_delta;
00065 
00066   if (pm->msmflags & NL_MSM_COMPUTE_SPREC) {
00067     return NL_MSM_ERROR_PARAM;
00068   }
00069 
00070   /* store buffer pointers from caller */
00071   pm->felec = felec;
00072   pm->atom = atom;
00073   pm->numatoms = natoms;
00074   pm->uelec = 0;
00075 
00076   if (pm->msmflags & NL_MSM_COMPUTE_SHORT_RANGE) {
00077     wkf_timer_start(pm->timer);
00078     rc = NL_msm_compute_short_range(pm);
00079     if (rc) return rc;
00080     wkf_timer_stop(pm->timer);
00081     time_delta = wkf_timer_time(pm->timer);
00082     if (pm->report_timings) {
00083       printf("MSM short-range part:  %6.3f sec\n", time_delta);
00084     }
00085   }
00086   if (pm->msmflags & NL_MSM_COMPUTE_LONG_RANGE) {
00087     wkf_timer_start(pm->timer);
00088     rc = NL_msm_compute_long_range(pm);
00089     if (rc) return rc;
00090     wkf_timer_stop(pm->timer);
00091     time_delta = wkf_timer_time(pm->timer);
00092     if (pm->report_timings) {
00093       printf("MSM long-range part:   %6.3f sec\n", time_delta);
00094     }
00095   }
00096   *uelec += pm->uelec;  /* add to caller's potential */
00097 
00098   return 0;
00099 }
00100 
00101 
00102 int NL_msm_compute_force_sprec(
00103     NL_Msm *pm,          
00104     float *felec_f,      
00105     float *uelec_f,      
00106     const float *atom_f, 
00107     int natoms           
00108     ) {
00109   int rc;
00110   double time_delta;
00111 
00112   if ((pm->msmflags & NL_MSM_COMPUTE_SPREC) == 0) {
00113     return NL_MSM_ERROR_PARAM;
00114   }
00115 
00116   /* store buffer pointers from caller */
00117   pm->felec_f = felec_f;
00118   pm->atom_f = atom_f;
00119   pm->numatoms = natoms;
00120   pm->uelec = 0;
00121 
00122   if (pm->msmflags & NL_MSM_COMPUTE_SHORT_RANGE) {
00123     wkf_timer_start(pm->timer);
00124     rc = NL_msm_compute_short_range_sprec(pm);
00125     if (rc) return rc;
00126     wkf_timer_stop(pm->timer);
00127     time_delta = wkf_timer_time(pm->timer);
00128     if (pm->report_timings) {
00129       printf("MSM short-range part:  %6.3f sec\n", time_delta);
00130     }
00131   }
00132   if (pm->msmflags & NL_MSM_COMPUTE_LONG_RANGE) {
00133     wkf_timer_start(pm->timer);
00134     rc = NL_msm_compute_long_range_sprec(pm);
00135     if (rc) return rc;
00136     wkf_timer_stop(pm->timer);
00137     time_delta = wkf_timer_time(pm->timer);
00138     if (pm->report_timings) {
00139       printf("MSM long-range part:   %6.3f sec\n", time_delta);
00140     }
00141   }
00142   *uelec_f += (float) pm->uelec;  /* add to caller's potential */
00143 
00144   return 0;
00145 }
00146 
00147 
00149 static const char *ApproxName[] = {
00150   "cubic",
00151   "quintic",
00152   "quintic2",
00153   "septic",
00154   "septic3",
00155   "nonic",
00156   "nonic4",
00157   "bspline",
00158 };
00159 
00160 int NL_msm_approx(const char *name) {
00161   int i;
00162   if (name) {
00163     for (i = 0;  i < NELEMS(ApproxName);  i++) {
00164       if (strcasecmp(name, ApproxName[i]) == 0) return i;
00165     }
00166   }
00167   return -1;
00168 }
00169 
00170 const char *NL_msm_approx_name(int approx) {
00171   if (approx >= 0 && approx < NELEMS(ApproxName)) {
00172     return ApproxName[approx];
00173   }
00174   else return NULL;
00175 }
00176 
00177 
00179 static const char *SplitName[] = {
00180   "Taylor2",
00181   "Taylor3",
00182   "Taylor4",
00183   "Taylor5",
00184   "Taylor6",
00185   "Taylor7",
00186   "Taylor8",
00187   "Taylor1",
00188   "sigma2_3",
00189   "sigma3_5",
00190   "sigma4_6",
00191   "sigma4_7",
00192   "sigma5_8",
00193   "sigma5_9",
00194   "sigma6_9",
00195   "sigma6_10",
00196   "sigma6_11",
00197   "sigma7_11",
00198   "sigma7_12",
00199   "sigma7_13",
00200   "sigma8_12",
00201   "sigma8_13",
00202   "sigma8_14",
00203   "sigma8_15",
00204   "sigma2_6",
00205   "switch1_2",
00206   "switch3_4",
00207   "switch7_8",
00208 };
00209 
00210 int NL_msm_split(const char *name) {
00211   int i;
00212   if (name) {
00213     for (i = 0;  i < NELEMS(SplitName);  i++) {
00214       if (strcasecmp(name, SplitName[i]) == 0) return i;
00215     }
00216   }
00217   return -1;
00218 }
00219 
00220 const char *NL_msm_split_name(int split) {
00221   if (split >= 0 && split < NELEMS(SplitName)) {
00222     return SplitName[split];
00223   }
00224   else return NULL;
00225 }

Generated on Tue Sep 19 01:17:13 2017 for NAMD by  doxygen 1.4.7