NAMD
Public Member Functions | List of all members
ComputeMsmSerialMgr Class Reference
Inheritance diagram for ComputeMsmSerialMgr:

Public Member Functions

 ComputeMsmSerialMgr ()
 
 ~ComputeMsmSerialMgr ()
 
void setCompute (ComputeMsmSerial *c)
 
void recvCoord (MsmSerialCoordMsg *)
 
void recvForce (MsmSerialForceMsg *)
 

Detailed Description

Definition at line 54 of file ComputeMsmSerial.C.

Constructor & Destructor Documentation

ComputeMsmSerialMgr::ComputeMsmSerialMgr ( )

Definition at line 81 of file ComputeMsmSerial.C.

81  :
82  msmProxy(thisgroup), msmCompute(0), numSources(0), numArrived(0),
83  coordMsgs(0), coord(0), force(0), oldmsg(0), numAtoms(0),
84  msmsolver(0), msmcoord(0), msmforce(0)
85 {
86  CkpvAccess(BOCclass_group).computeMsmSerialMgr = thisgroup;
87 }
ComputeMsmSerialMgr::~ComputeMsmSerialMgr ( )

Definition at line 89 of file ComputeMsmSerial.C.

References NL_msm_destroy().

90 {
91  for (int i=0; i < numSources; i++) delete coordMsgs[i];
92  delete [] coordMsgs;
93  delete [] coord;
94  delete [] force;
95  delete oldmsg;
96  if (msmsolver) NL_msm_destroy(msmsolver);
97  if (msmcoord) delete[] msmcoord;
98  if (msmforce) delete[] msmforce;
99 }
void NL_msm_destroy(NL_Msm *pm)
Definition: msm.c:28

Member Function Documentation

void ComputeMsmSerialMgr::recvCoord ( MsmSerialCoordMsg msg)

Definition at line 308 of file ComputeMsmSerial.C.

References Lattice::a(), Lattice::a_p(), Lattice::a_r(), Lattice::b(), Lattice::b_p(), Lattice::b_r(), Lattice::c(), Lattice::c_p(), Lattice::c_r(), ComputeMsmSerialAtom::charge, MsmSerialCoordMsg::coord, COULOMB, SimParameters::cutoff, SimParameters::dielectric, MsmSerialForceMsg::energy, MsmSerialForceMsg::force, ComputeMsmSerialAtom::id, MsmSerialCoordMsg::lattice, Node::molecule, SimParameters::MSMApprox, SimParameters::MSMGridSpacing, SimParameters::MSMLevels, SimParameters::MSMPadding, SimParameters::MSMSplit, NAMD_die(), NL_msm_compute_force(), NL_MSM_COMPUTE_LONG_RANGE, NL_msm_configure(), NL_msm_create(), NL_MSM_PERIODIC_ALL, NL_MSM_PERIODIC_VEC1, NL_MSM_PERIODIC_VEC2, NL_MSM_PERIODIC_VEC3, NL_msm_setup(), MsmSerialCoordMsg::numAtoms, Molecule::numAtoms, PatchMap::Object(), Node::Object(), Lattice::origin(), ComputeMsmSerialAtom::position, rescale_nonperiodic_cell(), Node::simParameters, simParams, MsmSerialCoordMsg::sourceNode, split(), MsmSerialForceMsg::virial, Vector::x, Vector::y, and Vector::z.

308  {
309  if ( ! numSources ) {
310  numSources = (PatchMap::Object())->numNodesWithPatches();
311  coordMsgs = new MsmSerialCoordMsg*[numSources];
312  for ( int i=0; i<numSources; ++i ) { coordMsgs[i] = 0; }
313  numArrived = 0;
314  numAtoms = Node::Object()->molecule->numAtoms;
315  coord = new ComputeMsmSerialAtom[numAtoms];
316  force = new MsmSerialForce[numAtoms];
317  }
318 
319  int i;
320  for ( i=0; i < msg->numAtoms; ++i ) {
321  coord[msg->coord[i].id] = msg->coord[i];
322  }
323 
324  coordMsgs[numArrived] = msg;
325  ++numArrived;
326 
327  if ( numArrived < numSources ) return;
328  numArrived = 0;
329 
330  // ALL DATA ARRIVED --- CALCULATE FORCES
331  Lattice lattice = msg->lattice;
333 
334  double energy = 0;
335  double virial[3][3];
336 
337  int rc = 0; // return code
338 
339  if ( ! msmsolver ) {
340  //
341  // setup MSM solver
342  //
343  msmsolver = NL_msm_create();
344  if ( ! msmsolver ) NAMD_die("unable to create MSM solver");
345  double dielectric = simParams->dielectric;
346  double cutoff = simParams->cutoff;
347  double gridspacing = simParams->MSMGridSpacing;
348  double padding = simParams->MSMPadding;
349  int approx = simParams->MSMApprox;
350  int split = simParams->MSMSplit;
351  int nlevels = simParams->MSMLevels;
352  int msmflags = 0;
353  msmflags |= (lattice.a_p() ? NL_MSM_PERIODIC_VEC1 : 0);
354  msmflags |= (lattice.b_p() ? NL_MSM_PERIODIC_VEC2 : 0);
355  msmflags |= (lattice.c_p() ? NL_MSM_PERIODIC_VEC3 : 0);
356  msmflags |= NL_MSM_COMPUTE_LONG_RANGE; // compute only long-range part
357  //msmflags |= NL_MSM_COMPUTE_ALL;
358  //printf("msmflags = %x\n", msmflags);
359  rc = NL_msm_configure(msmsolver, gridspacing, approx, split, nlevels);
360  if (rc) NAMD_die("unable to configure MSM solver");
361  Vector u=lattice.a(), v=lattice.b(), w=lattice.c(), c=lattice.origin();
362  Vector ru=lattice.a_r(), rv=lattice.b_r(), rw=lattice.c_r();
363  if ((msmflags & NL_MSM_PERIODIC_ALL) != NL_MSM_PERIODIC_ALL) {
364  // called only if there is some non-periodic boundary
365  int isperiodic = (msmflags & NL_MSM_PERIODIC_ALL);
366  //printf("calling rescale\n");
367  rescale_nonperiodic_cell(u, v, w, c, ru, rv, rw,
368  isperiodic, numAtoms, coord, padding, gridspacing);
369  }
370  double vec1[3], vec2[3], vec3[3], center[3];
371  vec1[0] = u.x;
372  vec1[1] = u.y;
373  vec1[2] = u.z;
374  vec2[0] = v.x;
375  vec2[1] = v.y;
376  vec2[2] = v.z;
377  vec3[0] = w.x;
378  vec3[1] = w.y;
379  vec3[2] = w.z;
380  center[0] = c.x;
381  center[1] = c.y;
382  center[2] = c.z;
383 #if 0
384  printf("dielectric = %g\n", dielectric);
385  printf("vec1 = %g %g %g\n", vec1[0], vec1[1], vec1[2]);
386  printf("vec2 = %g %g %g\n", vec2[0], vec2[1], vec2[2]);
387  printf("vec3 = %g %g %g\n", vec3[0], vec3[1], vec3[2]);
388  printf("center = %g %g %g\n", center[0], center[1], center[2]);
389  printf("cutoff = %g\n", cutoff);
390  printf("numatoms = %d\n", numAtoms);
391 #endif
392  rc = NL_msm_setup(msmsolver, cutoff, vec1, vec2, vec3, center, msmflags);
393  if (rc) NAMD_die("unable to set up MSM solver");
394  msmcoord = new double[4*numAtoms];
395  msmforce = new double[3*numAtoms];
396  if (msmcoord==0 || msmforce==0) NAMD_die("can't allocate MSM atom buffers");
397  // scale charges - these won't change
398  double celec = sqrt(COULOMB / simParams->dielectric);
399  for (i = 0; i < numAtoms; i++) {
400  msmcoord[4*i+3] = celec * coord[i].charge;
401  }
402  }
403 
404  // evaluate long-range MSM forces
405  for (i = 0; i < numAtoms; i++) {
406  msmcoord[4*i ] = coord[i].position.x;
407  msmcoord[4*i+1] = coord[i].position.y;
408  msmcoord[4*i+2] = coord[i].position.z;
409  }
410  for (i = 0; i < numAtoms; i++) {
411  msmforce[3*i ] = 0;
412  msmforce[3*i+1] = 0;
413  msmforce[3*i+2] = 0;
414  }
415  rc = NL_msm_compute_force(msmsolver, msmforce, &energy, msmcoord, numAtoms);
416  if (rc) NAMD_die("error evaluating MSM forces");
417  for (i = 0; i < numAtoms; i++) {
418  force[i].x = msmforce[3*i ];
419  force[i].y = msmforce[3*i+1];
420  force[i].z = msmforce[3*i+2];
421  }
422  // MSM does not yet calculate virial
423  for (int k=0; k < 3; k++) {
424  for (int l=0; l < 3; l++) {
425  virial[k][l] = 0;
426  }
427  }
428 
429  // distribute forces
430  for (int j=0; j < numSources; j++) {
431  MsmSerialCoordMsg *cmsg = coordMsgs[j];
432  coordMsgs[j] = 0;
433  MsmSerialForceMsg *fmsg = new (cmsg->numAtoms, 0) MsmSerialForceMsg;
434 
435  for (int i=0; i < cmsg->numAtoms; i++) {
436  fmsg->force[i] = force[cmsg->coord[i].id];
437  }
438 
439  if ( ! j ) { // set virial and energy only for first message
440  fmsg->energy = energy;
441  for (int k=0; k < 3; k++) {
442  for (int l=0; l < 3; l++) {
443  fmsg->virial[k][l] = virial[k][l];
444  }
445  }
446  }
447  else { // set other messages to zero, add into reduction only once
448  fmsg->energy = 0;
449  for (int k=0; k < 3; k++) {
450  for (int l=0; l < 3; l++) {
451  fmsg->virial[k][l] = 0;
452  }
453  }
454  }
455 
456  msmProxy[cmsg->sourceNode].recvForce(fmsg);
457  delete cmsg;
458  }
459 }
static Node * Object()
Definition: Node.h:86
Vector a_r() const
Definition: Lattice.h:268
BigReal virial[3][3]
static PatchMap * Object()
Definition: PatchMap.h:27
Definition: Vector.h:64
SimParameters * simParameters
Definition: Node.h:178
Vector c_r() const
Definition: Lattice.h:270
#define COULOMB
Definition: common.h:44
BigReal z
Definition: Vector.h:66
ComputeMsmSerialAtom * coord
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
Vector origin() const
Definition: Lattice.h:262
Vector b_r() const
Definition: Lattice.h:269
MsmSerialForce * force
int NL_msm_compute_force(NL_Msm *pm, double *felec, double *uelec, const double *atom, int natoms)
Definition: msm.c:56
BigReal x
Definition: Vector.h:66
int numAtoms
Definition: Molecule.h:556
BigReal MSMGridSpacing
void NAMD_die(const char *err_msg)
Definition: common.C:83
std::vector< std::string > split(const std::string &text, std::string delimiter)
Definition: MoleculeQM.C:73
#define simParams
Definition: Output.C:127
static void rescale_nonperiodic_cell(Vector &u, Vector &v, Vector &w, Vector &c, Vector &ru, Vector &rv, Vector &rw, int isperiodic, int numatoms, const ComputeMsmSerialAtom *coord, double padding, double gridspacing)
BigReal y
Definition: Vector.h:66
Vector b() const
Definition: Lattice.h:253
BigReal dielectric
int b_p() const
Definition: Lattice.h:274
BigReal MSMPadding
int a_p() const
Definition: Lattice.h:273
Molecule * molecule
Definition: Node.h:176
Vector a() const
Definition: Lattice.h:252
int NL_msm_setup(NL_Msm *msm, double cutoff, double cellvec1[3], double cellvec2[3], double cellvec3[3], double cellcenter[3], int msmflags)
Definition: msm_setup.c:62
Vector c() const
Definition: Lattice.h:254
int c_p() const
Definition: Lattice.h:275
void ComputeMsmSerialMgr::recvForce ( MsmSerialForceMsg msg)

Definition at line 461 of file ComputeMsmSerial.C.

References ComputeMsmSerial::saveResults().

461  {
462  msmCompute->saveResults(msg);
463  delete oldmsg;
464  oldmsg = msg;
465 }
void saveResults(MsmSerialForceMsg *)
void ComputeMsmSerialMgr::setCompute ( ComputeMsmSerial c)
inline

Definition at line 59 of file ComputeMsmSerial.C.

59 { msmCompute = c; }

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