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

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.

77  :
78  extProxy(thisgroup), extCompute(0), numSources(0), numArrived(0),
79  coordMsgs(0), coord(0), force(0), oldmsg(0), numAtoms(0) {
80  CkpvAccess(BOCclass_group).computeExtMgr = thisgroup;
81 }
ComputeExtMgr::~ComputeExtMgr ( )

Definition at line 83 of file ComputeExt.C.

83  {
84  for ( int i=0; i<numSources; ++i ) { delete coordMsgs[i]; }
85  delete [] coordMsgs;
86  delete [] coord;
87  delete [] force;
88  delete oldmsg;
89 }

Member Function Documentation

void ComputeExtMgr::recvCoord ( ExtCoordMsg msg)

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, charge, ExtCoordMsg::coord, ExtForceMsg::energy, SimParameters::extCoordFilename, SimParameters::extForceFilename, SimParameters::extForcesCommand, ExtForceMsg::force, ExtForce::force, ComputeExtAtom::id, ExtCoordMsg::lattice, Node::molecule, NAMD_die(), ExtCoordMsg::numAtoms, Molecule::numAtoms, PatchMap::Object(), Node::Object(), ComputeExtAtom::position, ExtForce::replace, Node::simParameters, simParams, ExtCoordMsg::sourceNode, ExtForceMsg::virial, Vector::x, x, Vector::y, y, Vector::z, and z.

168  {
169  if ( ! numSources ) {
170  numSources = (PatchMap::Object())->numNodesWithPatches();
171  coordMsgs = new ExtCoordMsg*[numSources];
172  for ( int i=0; i<numSources; ++i ) { coordMsgs[i] = 0; }
173  numArrived = 0;
174  numAtoms = Node::Object()->molecule->numAtoms;
175  coord = new ComputeExtAtom[numAtoms];
176  force = new ExtForce[numAtoms];
177  }
178 
179  int i;
180  for ( i=0; i < msg->numAtoms; ++i ) {
181  coord[msg->coord[i].id] = msg->coord[i];
182  }
183 
184  coordMsgs[numArrived] = msg;
185  ++numArrived;
186 
187  if ( numArrived < numSources ) return;
188  numArrived = 0;
189 
190  // ALL DATA ARRIVED --- CALCULATE FORCES
191  Lattice lattice = msg->lattice;
193  FILE *file;
194  int iret;
195 
196  // write coordinates to file
197  //iout << "writing to file " << simParams->extCoordFilename << "\n" << endi;
198  file = fopen(simParams->extCoordFilename,"w");
199  if ( ! file ) { NAMD_die(strerror(errno)); }
200  for ( i=0; i<numAtoms; ++i ) {
201  int id = coord[i].id + 1;
202  double charge = coord[i].charge;
203  double x = coord[i].position.x;
204  double y = coord[i].position.y;
205  double z = coord[i].position.z;
206  iret = fprintf(file,"%d %f %f %f %f\n",id,charge,x,y,z);
207  if ( iret < 0 ) { NAMD_die(strerror(errno)); }
208  }
209  // write periodic cell lattice (0 0 0 if non-periodic)
210  Vector a = lattice.a(); if ( ! lattice.a_p() ) a = Vector(0,0,0);
211  Vector b = lattice.b(); if ( ! lattice.b_p() ) b = Vector(0,0,0);
212  Vector c = lattice.c(); if ( ! lattice.c_p() ) c = Vector(0,0,0);
213  iret = fprintf(file,"%f %f %f\n%f %f %f\n%f %f %f\n",
214  a.x, a.y, a.z, b.x, b.y, b.z, c.x, c.y, c.z);
215  if ( iret < 0 ) { NAMD_die(strerror(errno)); }
216  fclose(file);
217 
218  // run user-specified command
219  //iout << "running command " << simParams->extForcesCommand << "\n" << endi;
220  iret = system(simParams->extForcesCommand);
221  if ( iret == -1 ) { NAMD_die(strerror(errno)); }
222  if ( iret ) { NAMD_die("Error running command for external forces."); }
223 
224  // remove coordinate file
225  iret = remove(simParams->extCoordFilename);
226  if ( iret ) { NAMD_die(strerror(errno)); }
227 
228  // read forces from file (overwrite positions)
229  //iout << "reading from file " << simParams->extForceFilename << "\n" << endi;
230  file = fopen(simParams->extForceFilename,"r");
231  if ( ! file ) { NAMD_die(strerror(errno)); }
232  for ( i=0; i<numAtoms; ++i ) {
233  int id, replace;
234  double x, y, z;
235  iret = fscanf(file,"%d %d %lf %lf %lf\n", &id, &replace, &x, &y, &z);
236  if ( iret != 5 ) { NAMD_die("Error reading external forces file."); }
237  if ( id != i + 1 ) { NAMD_die("Atom ID error in external forces file."); }
238  force[i].force.x = x; force[i].force.y = y; force[i].force.z = z;
239  force[i].replace = replace;
240  }
241  // read energy and virial if they are present
242  // virial used by NAMD is -'ve of normal convention, so reverse it!
243  // virial[i][j] in file should be sum of -1 * f_i * r_j
244  double energy;
245  double virial[3][3];
246  iret = fscanf(file,"%lf\n", &energy);
247  if ( iret != 1 ) {
248  energy = 0;
249  for ( int k=0; k<3; ++k ) for ( int l=0; l<3; ++l ) virial[k][l] = 0;
250  } else {
251  iret = fscanf(file,"%lf %lf %lf\n%lf %lf %lf\n%lf %lf %lf\n",
252  &virial[0][0], &virial[0][1], &virial[0][2],
253  &virial[1][0], &virial[1][1], &virial[1][2],
254  &virial[2][0], &virial[2][1], &virial[2][2]);
255  if ( iret != 9 ) {
256  for ( int k=0; k<3; ++k ) for ( int l=0; l<3; ++l ) virial[k][l] = 0;
257  } else {
258  // virial used by NAMD is -'ve of normal convention, so reverse it!
259  for ( int k=0; k<3; ++k ) for ( int l=0; l<3; ++l ) virial[k][l] *= -1.0;
260  }
261  }
262  fclose(file);
263 
264  // remove force file
265  iret = remove(simParams->extForceFilename);
266  if ( iret ) { NAMD_die(strerror(errno)); }
267 
268  // distribute forces
269 
270  for ( int j=0; j < numSources; ++j ) {
271  ExtCoordMsg *cmsg = coordMsgs[j];
272  coordMsgs[j] = 0;
273  ExtForceMsg *fmsg = new (cmsg->numAtoms, 0) ExtForceMsg;
274  for ( int i=0; i < cmsg->numAtoms; ++i ) {
275  fmsg->force[i] = force[cmsg->coord[i].id];
276  }
277  if ( ! j ) {
278  fmsg->energy = energy;
279  for ( int k=0; k<3; ++k ) for ( int l=0; l<3; ++l )
280  fmsg->virial[k][l] = virial[k][l];
281  } else {
282  fmsg->energy = 0;
283  for ( int k=0; k<3; ++k ) for ( int l=0; l<3; ++l )
284  fmsg->virial[k][l] = 0;
285  }
286  extProxy[cmsg->sourceNode].recvForce(fmsg);
287  delete cmsg;
288  }
289 
290 }
static Node * Object()
Definition: Node.h:86
char extCoordFilename[NAMD_FILENAME_BUFFER_SIZE]
Lattice lattice
Definition: ComputeExt.C:43
char extForcesCommand[NAMD_FILENAME_BUFFER_SIZE]
static PatchMap * Object()
Definition: PatchMap.h:27
Definition: Vector.h:64
SimParameters * simParameters
Definition: Node.h:178
BigReal z
Definition: Vector.h:66
int replace
Definition: NamdTypes.h:201
char extForceFilename[NAMD_FILENAME_BUFFER_SIZE]
BigReal virial[3][3]
Definition: ComputeExt.C:50
ComputeExtAtom * coord
Definition: ComputeExt.C:44
BigReal energy
Definition: ComputeExt.C:49
gridSize z
BigReal x
Definition: Vector.h:66
int numAtoms
Definition: Molecule.h:557
void NAMD_die(const char *err_msg)
Definition: common.C:85
Force force
Definition: NamdTypes.h:202
int sourceNode
Definition: ComputeExt.C:41
ExtForce * force
Definition: ComputeExt.C:51
#define simParams
Definition: Output.C:127
int numAtoms
Definition: ComputeExt.C:42
BigReal y
Definition: Vector.h:66
Vector b() const
Definition: Lattice.h:253
k< npairi;++k){TABENERGY(const int numtypes=simParams->tableNumTypes;const float table_spacing=simParams->tableSpacing;const int npertype=(int)(namdnearbyint(simParams->tableMaxDist/simParams->tableSpacing)+1);) int table_i=(r2iilist[2 *k] >> 14)+r2_delta_expc;const int j=pairlisti[k];#define p_j BigReal diffa=r2list[k]-r2_table[table_i];#define table_four_i TABENERGY(register const int tabtype=-1-(lj_pars->A< 0?lj_pars->A:0);) BigReal kqq=kq_i *p_j-> charge
gridSize y
int b_p() const
Definition: Lattice.h:274
gridSize x
int a_p() const
Definition: Lattice.h:273
Molecule * molecule
Definition: Node.h:176
Vector a() const
Definition: Lattice.h:252
Vector c() const
Definition: Lattice.h:254
int c_p() const
Definition: Lattice.h:275
Position position
Definition: ComputeExt.C:34
void ComputeExtMgr::recvForce ( ExtForceMsg msg)

Definition at line 292 of file ComputeExt.C.

References ComputeExt::saveResults().

292  {
293  extCompute->saveResults(msg);
294  delete oldmsg;
295  oldmsg = msg;
296 }
void saveResults(ExtForceMsg *)
Definition: ComputeExt.C:298
void ComputeExtMgr::setCompute ( ComputeExt c)
inline

Definition at line 59 of file ComputeExt.C.

59 { extCompute = c; }

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