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.

00160                                     {
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 }

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().

00170                                            {
00171   if (approx >= 0 && approx < NELEMS(ApproxName)) {
00172     return ApproxName[approx];
00173   }
00174   else return NULL;
00175 }

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:
pm  the MSM solver object
felec  electrostatic forces x/y/z for each atom
uelec  electrostatic potential energy
atom  positions and charge x/y/z/q for each atom
natoms  number 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().

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 }

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:
pm  the MSM solver object
felec_f  electrostatic forces x/y/z for each atom
uelec_f  electrostatic potential energy
atom_f  positions and charge x/y/z/q for each atom
natoms  number 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().

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 }

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:

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:
pm  the MSM solver object
gridspacing  grid spacing for first grid level
approx  which approximation method
split  which splitting
nlevels  number 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, and NL_Msm_t::split.

Referenced by ComputeMsmSerialMgr::recvCoord().

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 }

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().

00006                             {
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 }

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().

00028                                 {
00029   NL_msm_cleanup(pm);
00030   wkf_timer_destroy(pm->timer);
00031   wkf_timer_destroy(pm->timer_longrng);
00032   free(pm);
00033 }

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.

00210                                    {
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 }

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, and SplitName.

Referenced by print_status().

00220                                          {
00221   if (split >= 0 && split < NELEMS(SplitName)) {
00222     return SplitName[split];
00223   }
00224   else return NULL;
00225 }


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().


Generated on Sat Nov 18 01:17:17 2017 for NAMD by  doxygen 1.4.7