Inheritance diagram for ComputeExtMgr:

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