ComputeExtMgr Class Reference

List of all members.

Public Member Functions

 ComputeExtMgr ()
 ~ComputeExtMgr ()
void setCompute (ComputeExt *c)
void recvCoord (ExtCoordMsg *)
void recvForce (ExtForceMsg *)

Detailed Description

Definition at line 54 of file ComputeExt.C.


Constructor & Destructor Documentation

ComputeExtMgr::ComputeExtMgr (  ) 

Definition at line 77 of file ComputeExt.C.

00077                              :
00078   extProxy(thisgroup), extCompute(0), numSources(0), numArrived(0),
00079   coordMsgs(0), coord(0), force(0), oldmsg(0), numAtoms(0) {
00080   CkpvAccess(BOCclass_group).computeExtMgr = thisgroup;
00081 }

ComputeExtMgr::~ComputeExtMgr (  ) 

Definition at line 83 of file ComputeExt.C.

00083                               {
00084   for ( int i=0; i<numSources; ++i ) { delete coordMsgs[i]; }
00085   delete [] coordMsgs;
00086   delete [] coord;
00087   delete [] force;
00088   delete oldmsg;
00089 }


Member Function Documentation

void ComputeExtMgr::recvCoord ( ExtCoordMsg  ) 

Definition at line 168 of file ComputeExt.C.

References Lattice::a(), Lattice::a_p(), Lattice::b(), Lattice::b_p(), Lattice::c(), Lattice::c_p(), ComputeExtAtom::charge, ExtCoordMsg::coord, ExtForceMsg::energy, ExtForceMsg::force, ExtForce::force, ComputeExtAtom::id, j, ExtCoordMsg::lattice, Node::molecule, NAMD_die(), ExtCoordMsg::numAtoms, Molecule::numAtoms, Node::Object(), PatchMap::Object(), ComputeExtAtom::position, ExtForce::replace, Node::simParameters, simParams, ExtForceMsg::virial, Vector::x, x, Vector::y, y, Vector::z, and z.

00168                                               {
00169   if ( ! numSources ) {
00170     numSources = (PatchMap::Object())->numNodesWithPatches();
00171     coordMsgs = new ExtCoordMsg*[numSources];
00172     for ( int i=0; i<numSources; ++i ) { coordMsgs[i] = 0; }
00173     numArrived = 0;
00174     numAtoms = Node::Object()->molecule->numAtoms;
00175     coord = new ComputeExtAtom[numAtoms];
00176     force = new ExtForce[numAtoms];
00177   }
00178 
00179   int i;
00180   for ( i=0; i < msg->numAtoms; ++i ) {
00181     coord[msg->coord[i].id] = msg->coord[i];
00182   }
00183 
00184   coordMsgs[numArrived] = msg;
00185   ++numArrived;
00186 
00187   if ( numArrived < numSources ) return;
00188   numArrived = 0;
00189 
00190   // ALL DATA ARRIVED --- CALCULATE FORCES
00191   Lattice lattice = msg->lattice;
00192   SimParameters *simParams = Node::Object()->simParameters;
00193   FILE *file;
00194   int iret;
00195 
00196   // write coordinates to file
00197   //iout << "writing to file " << simParams->extCoordFilename << "\n" << endi;
00198   file = fopen(simParams->extCoordFilename,"w");
00199   if ( ! file ) { NAMD_die(strerror(errno)); }
00200   for ( i=0; i<numAtoms; ++i ) {
00201     int id = coord[i].id + 1;
00202     double charge = coord[i].charge;
00203     double x = coord[i].position.x;
00204     double y = coord[i].position.y;
00205     double z = coord[i].position.z;
00206     iret = fprintf(file,"%d %f %f %f %f\n",id,charge,x,y,z);
00207     if ( iret < 0 ) { NAMD_die(strerror(errno)); }
00208   }
00209   // write periodic cell lattice (0 0 0 if non-periodic)
00210   Vector a = lattice.a();  if ( ! lattice.a_p() ) a = Vector(0,0,0);
00211   Vector b = lattice.b();  if ( ! lattice.b_p() ) b = Vector(0,0,0);
00212   Vector c = lattice.c();  if ( ! lattice.c_p() ) c = Vector(0,0,0);
00213   iret = fprintf(file,"%f %f %f\n%f %f %f\n%f %f %f\n",
00214                  a.x, a.y, a.z, b.x, b.y, b.z, c.x, c.y, c.z);
00215   if ( iret < 0 ) { NAMD_die(strerror(errno)); }
00216   fclose(file);
00217 
00218   // run user-specified command
00219   //iout << "running command " << simParams->extForcesCommand << "\n" << endi;
00220   iret = system(simParams->extForcesCommand);
00221   if ( iret == -1 ) { NAMD_die(strerror(errno)); }
00222   if ( iret ) { NAMD_die("Error running command for external forces."); }
00223 
00224   // remove coordinate file
00225   iret = remove(simParams->extCoordFilename);
00226   if ( iret ) { NAMD_die(strerror(errno)); }
00227 
00228   // read forces from file (overwrite positions)
00229   //iout << "reading from file " << simParams->extForceFilename << "\n" << endi;
00230   file = fopen(simParams->extForceFilename,"r");
00231   if ( ! file ) { NAMD_die(strerror(errno)); }
00232   for ( i=0; i<numAtoms; ++i ) {
00233     int id, replace;
00234     double x, y, z;
00235     iret = fscanf(file,"%d %d %lf %lf %lf\n", &id, &replace, &x, &y, &z);
00236     if ( iret != 5 ) { NAMD_die("Error reading external forces file."); }
00237     if ( id != i + 1 ) { NAMD_die("Atom ID error in external forces file."); }
00238     force[i].force.x = x; force[i].force.y = y; force[i].force.z = z;
00239     force[i].replace = replace;
00240   }
00241   // read energy and virial if they are present
00242   // virial used by NAMD is -'ve of normal convention, so reverse it!
00243   // virial[i][j] in file should be sum of -1 * f_i * r_j
00244   double energy;
00245   double virial[3][3];
00246   iret = fscanf(file,"%lf\n", &energy);
00247   if ( iret != 1 ) {
00248     energy = 0;
00249     for ( int k=0; k<3; ++k ) for ( int l=0; l<3; ++l ) virial[k][l] = 0;
00250   } else {
00251     iret = fscanf(file,"%lf %lf %lf\n%lf %lf %lf\n%lf %lf %lf\n",
00252       &virial[0][0], &virial[0][1], &virial[0][2],
00253       &virial[1][0], &virial[1][1], &virial[1][2],
00254       &virial[2][0], &virial[2][1], &virial[2][2]);
00255     if ( iret != 9 ) {
00256       for ( int k=0; k<3; ++k ) for ( int l=0; l<3; ++l ) virial[k][l] = 0;
00257     } else {
00258       // virial used by NAMD is -'ve of normal convention, so reverse it!
00259       for ( int k=0; k<3; ++k ) for ( int l=0; l<3; ++l ) virial[k][l] *= -1.0;
00260     }
00261   }
00262   fclose(file);
00263 
00264   // remove force file
00265   iret = remove(simParams->extForceFilename);
00266   if ( iret ) { NAMD_die(strerror(errno)); }
00267 
00268   // distribute forces
00269 
00270   for ( int j=0; j < numSources; ++j ) {
00271     ExtCoordMsg *cmsg = coordMsgs[j];
00272     coordMsgs[j] = 0;
00273     ExtForceMsg *fmsg = new (cmsg->numAtoms, 0) ExtForceMsg;
00274     for ( int i=0; i < cmsg->numAtoms; ++i ) {
00275       fmsg->force[i] = force[cmsg->coord[i].id];
00276     }
00277     if ( ! j ) {
00278       fmsg->energy = energy;
00279       for ( int k=0; k<3; ++k ) for ( int l=0; l<3; ++l )
00280         fmsg->virial[k][l] = virial[k][l];
00281     } else {
00282       fmsg->energy = 0;
00283       for ( int k=0; k<3; ++k ) for ( int l=0; l<3; ++l )
00284         fmsg->virial[k][l] = 0;
00285     }
00286     extProxy[cmsg->sourceNode].recvForce(fmsg);
00287     delete cmsg;
00288   }
00289 
00290 }

void ComputeExtMgr::recvForce ( ExtForceMsg  ) 

Definition at line 292 of file ComputeExt.C.

References ComputeExt::saveResults().

00292                                               {
00293   extCompute->saveResults(msg);
00294   delete oldmsg;
00295   oldmsg = msg;
00296 }

void ComputeExtMgr::setCompute ( ComputeExt c  )  [inline]

Definition at line 59 of file ComputeExt.C.

00059 { extCompute = c; }


The documentation for this class was generated from the following file:
Generated on Thu Nov 23 01:17:16 2017 for NAMD by  doxygen 1.4.7