ComputeMsmSerialMgr Class Reference

List of all members.

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.

00081                                          :
00082   msmProxy(thisgroup), msmCompute(0), numSources(0), numArrived(0),
00083   coordMsgs(0), coord(0), force(0), oldmsg(0), numAtoms(0),
00084   msmsolver(0), msmcoord(0), msmforce(0)
00085 {
00086   CkpvAccess(BOCclass_group).computeMsmSerialMgr = thisgroup;
00087 }

ComputeMsmSerialMgr::~ComputeMsmSerialMgr (  ) 

Definition at line 89 of file ComputeMsmSerial.C.

References NL_msm_destroy().

00090 {
00091   for (int i=0;  i < numSources;  i++)  delete coordMsgs[i];
00092   delete [] coordMsgs;
00093   delete [] coord;
00094   delete [] force;
00095   delete oldmsg;
00096   if (msmsolver) NL_msm_destroy(msmsolver);
00097   if (msmcoord) delete[] msmcoord;
00098   if (msmforce) delete[] msmforce;
00099 }


Member Function Documentation

void ComputeMsmSerialMgr::recvCoord ( MsmSerialCoordMsg  ) 

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(), MsmSerialCoordMsg::coord, COULOMB, MsmSerialForceMsg::energy, MsmSerialForceMsg::force, ComputeMsmSerialAtom::id, j, MsmSerialCoordMsg::lattice, Node::molecule, 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, Node::Object(), PatchMap::Object(), Lattice::origin(), ComputeMsmSerialAtom::position, rescale_nonperiodic_cell(), Node::simParameters, simParams, eabffunc::split(), MsmSerialForceMsg::virial, x, Vector::x, Vector::y, and Vector::z.

00308                                                           {
00309   if ( ! numSources ) {
00310     numSources = (PatchMap::Object())->numNodesWithPatches();
00311     coordMsgs = new MsmSerialCoordMsg*[numSources];
00312     for ( int i=0; i<numSources; ++i ) { coordMsgs[i] = 0; }
00313     numArrived = 0;
00314     numAtoms = Node::Object()->molecule->numAtoms;
00315     coord = new ComputeMsmSerialAtom[numAtoms];
00316     force = new MsmSerialForce[numAtoms];
00317   }
00318 
00319   int i;
00320   for ( i=0; i < msg->numAtoms; ++i ) {
00321     coord[msg->coord[i].id] = msg->coord[i];
00322   }
00323 
00324   coordMsgs[numArrived] = msg;
00325   ++numArrived;
00326 
00327   if ( numArrived < numSources ) return;
00328   numArrived = 0;
00329 
00330   // ALL DATA ARRIVED --- CALCULATE FORCES
00331   Lattice lattice = msg->lattice;
00332   SimParameters *simParams = Node::Object()->simParameters;
00333 
00334   double energy = 0;
00335   double virial[3][3];
00336 
00337   int rc = 0;  // return code
00338 
00339   if ( ! msmsolver ) {
00340     //
00341     // setup MSM solver
00342     //
00343     msmsolver = NL_msm_create();
00344     if ( ! msmsolver ) NAMD_die("unable to create MSM solver");
00345     double dielectric = simParams->dielectric;
00346     double cutoff = simParams->cutoff;
00347     double gridspacing = simParams->MSMGridSpacing;
00348     double padding = simParams->MSMPadding;
00349     int approx = simParams->MSMApprox;
00350     int split = simParams->MSMSplit;
00351     int nlevels = simParams->MSMLevels;
00352     int msmflags = 0;
00353     msmflags |= (lattice.a_p() ? NL_MSM_PERIODIC_VEC1 : 0);
00354     msmflags |= (lattice.b_p() ? NL_MSM_PERIODIC_VEC2 : 0);
00355     msmflags |= (lattice.c_p() ? NL_MSM_PERIODIC_VEC3 : 0);
00356     msmflags |= NL_MSM_COMPUTE_LONG_RANGE;  // compute only long-range part
00357     //msmflags |= NL_MSM_COMPUTE_ALL;
00358     //printf("msmflags = %x\n", msmflags);
00359     rc = NL_msm_configure(msmsolver, gridspacing, approx, split, nlevels);
00360     if (rc) NAMD_die("unable to configure MSM solver");
00361     Vector u=lattice.a(), v=lattice.b(), w=lattice.c(), c=lattice.origin();
00362     Vector ru=lattice.a_r(), rv=lattice.b_r(), rw=lattice.c_r();
00363     if ((msmflags & NL_MSM_PERIODIC_ALL) != NL_MSM_PERIODIC_ALL) {
00364       // called only if there is some non-periodic boundary
00365       int isperiodic = (msmflags & NL_MSM_PERIODIC_ALL);
00366       //printf("calling rescale\n");
00367       rescale_nonperiodic_cell(u, v, w, c, ru, rv, rw,
00368           isperiodic, numAtoms, coord, padding, gridspacing);
00369     }
00370     double vec1[3], vec2[3], vec3[3], center[3];
00371     vec1[0] = u.x;
00372     vec1[1] = u.y;
00373     vec1[2] = u.z;
00374     vec2[0] = v.x;
00375     vec2[1] = v.y;
00376     vec2[2] = v.z;
00377     vec3[0] = w.x;
00378     vec3[1] = w.y;
00379     vec3[2] = w.z;
00380     center[0] = c.x;
00381     center[1] = c.y;
00382     center[2] = c.z;
00383 #if 0
00384     printf("dielectric = %g\n", dielectric);
00385     printf("vec1 = %g %g %g\n", vec1[0], vec1[1], vec1[2]);
00386     printf("vec2 = %g %g %g\n", vec2[0], vec2[1], vec2[2]);
00387     printf("vec3 = %g %g %g\n", vec3[0], vec3[1], vec3[2]);
00388     printf("center = %g %g %g\n", center[0], center[1], center[2]);
00389     printf("cutoff = %g\n", cutoff);
00390     printf("numatoms = %d\n", numAtoms);
00391 #endif
00392     rc = NL_msm_setup(msmsolver, cutoff, vec1, vec2, vec3, center, msmflags);
00393     if (rc) NAMD_die("unable to set up MSM solver");
00394     msmcoord = new double[4*numAtoms];
00395     msmforce = new double[3*numAtoms];
00396     if (msmcoord==0 || msmforce==0) NAMD_die("can't allocate MSM atom buffers");
00397     // scale charges - these won't change
00398     double celec = sqrt(COULOMB / simParams->dielectric);
00399     for (i = 0;  i < numAtoms;  i++) {
00400       msmcoord[4*i+3] = celec * coord[i].charge;
00401     }
00402   }
00403 
00404   // evaluate long-range MSM forces
00405   for (i = 0;  i < numAtoms;  i++) {
00406     msmcoord[4*i  ] = coord[i].position.x;
00407     msmcoord[4*i+1] = coord[i].position.y;
00408     msmcoord[4*i+2] = coord[i].position.z;
00409   }
00410   for (i = 0;  i < numAtoms;  i++) {
00411     msmforce[3*i  ] = 0;
00412     msmforce[3*i+1] = 0;
00413     msmforce[3*i+2] = 0;
00414   }
00415   rc = NL_msm_compute_force(msmsolver, msmforce, &energy, msmcoord, numAtoms);
00416   if (rc) NAMD_die("error evaluating MSM forces");
00417   for (i = 0;  i < numAtoms;  i++) {
00418     force[i].x = msmforce[3*i  ];
00419     force[i].y = msmforce[3*i+1];
00420     force[i].z = msmforce[3*i+2];
00421   }
00422   // MSM does not yet calculate virial
00423   for (int k=0;  k < 3;  k++) {
00424     for (int l=0;  l < 3;  l++) {
00425       virial[k][l] = 0;
00426     }
00427   }
00428 
00429   // distribute forces
00430   for (int j=0;  j < numSources;  j++) {
00431     MsmSerialCoordMsg *cmsg = coordMsgs[j];
00432     coordMsgs[j] = 0;
00433     MsmSerialForceMsg *fmsg = new (cmsg->numAtoms, 0) MsmSerialForceMsg;
00434 
00435     for (int i=0;  i < cmsg->numAtoms;  i++) {
00436       fmsg->force[i] = force[cmsg->coord[i].id];
00437     }
00438 
00439     if ( ! j ) {  // set virial and energy only for first message
00440       fmsg->energy = energy;
00441       for (int k=0;  k < 3;  k++) {
00442         for (int l=0;  l < 3;  l++) {
00443           fmsg->virial[k][l] = virial[k][l];
00444         }
00445       }
00446     }
00447     else {  // set other messages to zero, add into reduction only once
00448       fmsg->energy = 0;
00449       for (int k=0;  k < 3;  k++) {
00450         for (int l=0;  l < 3;  l++) {
00451           fmsg->virial[k][l] = 0;
00452         }
00453       }
00454     }
00455 
00456     msmProxy[cmsg->sourceNode].recvForce(fmsg);
00457     delete cmsg;
00458   }
00459 }

void ComputeMsmSerialMgr::recvForce ( MsmSerialForceMsg  ) 

Definition at line 461 of file ComputeMsmSerial.C.

References ComputeMsmSerial::saveResults().

00461                                                           {
00462   msmCompute->saveResults(msg);
00463   delete oldmsg;
00464   oldmsg = msg;
00465 }

void ComputeMsmSerialMgr::setCompute ( ComputeMsmSerial c  )  [inline]

Definition at line 59 of file ComputeMsmSerial.C.

00059 { msmCompute = c; }


The documentation for this class was generated from the following file:
Generated on Mon Sep 25 01:17:17 2017 for NAMD by  doxygen 1.4.7