NAMD
Classes | Public Member Functions | Static Public Member Functions | Friends | List of all members
Output Class Reference

#include <Output.h>

Public Member Functions

 Output ()
 
 ~Output ()
 
void energy (int, BigReal *)
 
void coordinate (int, int, Vector *, FloatVector *, Lattice &)
 
void velocity (int, int, Vector *)
 
void force (int, int, Vector *)
 
void replicaDcdOff ()
 
void setReplicaDcdIndex (int index)
 
void replicaDcdInit (int index, const char *filename)
 
void recvReplicaDcdInit (ReplicaDcdInitMsg *msg)
 
void recvReplicaDcdData (ReplicaDcdDataMsg *msg)
 

Static Public Member Functions

static int coordinateNeeded (int)
 
static int velocityNeeded (int)
 
static int forceNeeded (int)
 

Friends

class SimParameters
 

Detailed Description

Definition at line 43 of file Output.h.

Constructor & Destructor Documentation

Output::Output ( )

Definition at line 168 of file Output.C.

168 : replicaDcdActive(0) { }
Output::~Output ( )

Definition at line 178 of file Output.C.

178 { }

Member Function Documentation

void Output::coordinate ( int  timestep,
int  n,
Vector coor,
FloatVector fcoor,
Lattice lattice 
)

Definition at line 277 of file Output.C.

References SimParameters::dcdFrequency, SimParameters::dcdUnitCell, END_OF_RUN, endi(), EVAL_MEASURE, FILE_OUTPUT, SimParameters::firstTimestep, IMDOutput::gather_coordinates(), Node::getScript(), Node::imd, SimParameters::IMDfreq, SimParameters::IMDon, iout, ScriptTcl::measure(), SimParameters::N, Node::Object(), SimParameters::restartFrequency, Node::simParameters, simParams, and wrap_coor().

Referenced by CollectionMaster::disposePositions().

279 {
281  double coor_wrapped = 0;
282  float fcoor_wrapped = 0;
283 
284  if ( timestep >= 0 ) {
285 
286  // Output a DCD trajectory
287  if ( simParams->dcdFrequency &&
288  ((timestep % simParams->dcdFrequency) == 0) )
289  {
290  wrap_coor(fcoor,lattice,&fcoor_wrapped);
291  output_dcdfile(timestep, n, fcoor,
292  simParams->dcdUnitCell ? &lattice : NULL);
293  }
294 
295  // Output a restart file
296  if ( simParams->restartFrequency &&
297  ((timestep % simParams->restartFrequency) == 0) )
298  {
299  iout << "WRITING COORDINATES TO RESTART FILE AT STEP "
300  << timestep << "\n" << endi;
301  wrap_coor(coor,lattice,&coor_wrapped);
302  output_restart_coordinates(coor, n, timestep);
303  iout << "FINISHED WRITING RESTART COORDINATES\n" <<endi;
304  fflush(stdout);
305  }
306 
307  // Interactive MD
308  if ( simParams->IMDon &&
309  ( ((timestep % simParams->IMDfreq) == 0) ||
310  (timestep == simParams->firstTimestep) ) )
311  {
312  IMDOutput *imd = Node::Object()->imd;
313  wrap_coor(fcoor,lattice,&fcoor_wrapped);
314  if (imd != NULL) imd->gather_coordinates(timestep, n, fcoor);
315  }
316 
317  }
318 
319  if (timestep == EVAL_MEASURE)
320  {
321 #ifdef NAMD_TCL
322  wrap_coor(coor,lattice,&coor_wrapped);
323  Node::Object()->getScript()->measure(coor);
324 #endif
325  }
326 
327  // Output final coordinates
328  if (timestep == FILE_OUTPUT || timestep == END_OF_RUN)
329  {
330  int realstep = ( timestep == FILE_OUTPUT ?
331  simParams->firstTimestep : simParams->N );
332  iout << "WRITING COORDINATES TO OUTPUT FILE AT STEP "
333  << realstep << "\n" << endi;
334  fflush(stdout);
335  wrap_coor(coor,lattice,&coor_wrapped);
336  output_final_coordinates(coor, n, realstep);
337  }
338 
339  // Close trajectory files
340  if (timestep == END_OF_RUN)
341  {
342  if (simParams->dcdFrequency) output_dcdfile(END_OF_RUN,0,0,
343  simParams->dcdUnitCell ? &lattice : NULL);
344  }
345 
346 }
static Node * Object()
Definition: Node.h:86
#define FILE_OUTPUT
Definition: Output.h:25
IMDOutput * imd
Definition: Node.h:183
ScriptTcl * getScript(void)
Definition: Node.h:192
#define EVAL_MEASURE
Definition: Output.h:27
SimParameters * simParameters
Definition: Node.h:178
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
void gather_coordinates(int timestep, int N, FloatVector *coords)
Definition: IMDOutput.C:29
#define iout
Definition: InfoStream.h:51
void wrap_coor(Vector *coor, Lattice &lattice, double *done)
Definition: Output.C:269
#define END_OF_RUN
Definition: Output.h:26
#define simParams
Definition: Output.C:127
void measure(Vector *)
Definition: ScriptTcl.C:1387
int Output::coordinateNeeded ( int  timestep)
static

Definition at line 198 of file Output.C.

References SimParameters::benchTimestep, SimParameters::dcdFrequency, END_OF_RUN, EVAL_MEASURE, FILE_OUTPUT, SimParameters::firstTimestep, SimParameters::IMDfreq, SimParameters::IMDon, Node::Object(), SimParameters::restartFrequency, Node::simParameters, and simParams.

Referenced by Controller::enqueueCollections(), and Sequencer::submitCollections().

199 {
201 
202  if(simParams->benchTimestep) return 0;
203 
204  int positionsNeeded = 0;
205 
206  if ( timestep >= 0 ) {
207 
208  // Output a DCD trajectory
209  if ( simParams->dcdFrequency &&
210  ((timestep % simParams->dcdFrequency) == 0) )
211  { positionsNeeded |= 1; }
212 
213  // Output a restart file
214  if ( simParams->restartFrequency &&
215  ((timestep % simParams->restartFrequency) == 0) )
216  { positionsNeeded |= 2; }
217 
218  // Iteractive MD
219  if ( simParams->IMDon &&
220  ( ((timestep % simParams->IMDfreq) == 0) ||
221  (timestep == simParams->firstTimestep) ) )
222  { positionsNeeded |= 1; }
223 
224  }
225 
226  // Output final coordinates
227  if (timestep == FILE_OUTPUT || timestep == END_OF_RUN ||
228  timestep == EVAL_MEASURE)
229  {
230  positionsNeeded |= 2;
231  }
232 
233  return positionsNeeded;
234 }
static Node * Object()
Definition: Node.h:86
#define FILE_OUTPUT
Definition: Output.h:25
#define EVAL_MEASURE
Definition: Output.h:27
SimParameters * simParameters
Definition: Node.h:178
#define END_OF_RUN
Definition: Output.h:26
#define simParams
Definition: Output.C:127
void Output::energy ( int  ,
BigReal  
)
void Output::force ( int  timestep,
int  n,
Vector frc 
)

Definition at line 486 of file Output.C.

References endi(), SimParameters::firstTimestep, FORCE_OUTPUT, SimParameters::forceDcdFrequency, iout, Node::Object(), Node::simParameters, and simParams.

Referenced by CollectionMaster::disposeForces().

487 {
489 
490  if ( timestep >= 0 ) {
491 
492  // Output force DCD trajectory
493  if ( simParams->forceDcdFrequency &&
494  ((timestep % simParams->forceDcdFrequency) == 0) )
495  {
496  output_forcedcdfile(timestep, n, frc);
497  }
498 
499  }
500 
501  // Output forces
502  if (timestep == FORCE_OUTPUT)
503  {
504  int realstep = simParams->firstTimestep;
505  iout << "WRITING FORCES TO OUTPUT FILE AT STEP "
506  << realstep << "\n" << endi;
507  fflush(stdout);
508  output_forces(realstep, n, frc);
509  }
510 
511  // Trajectory file closed by velocity() above
512 
513 }
static Node * Object()
Definition: Node.h:86
SimParameters * simParameters
Definition: Node.h:178
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
#define iout
Definition: InfoStream.h:51
#define simParams
Definition: Output.C:127
#define FORCE_OUTPUT
Definition: Output.h:28
int Output::forceNeeded ( int  timestep)
static

Definition at line 460 of file Output.C.

References SimParameters::benchTimestep, FORCE_OUTPUT, SimParameters::forceDcdFrequency, Node::Object(), Node::simParameters, and simParams.

Referenced by Controller::enqueueCollections(), and Sequencer::submitCollections().

461 {
463 
464  if(simParams->benchTimestep) return 0;
465 
466  int forcesNeeded = 0;
467 
468  if ( timestep >= 0 ) {
469 
470  // Output a force DCD trajectory
471  if ( simParams->forceDcdFrequency &&
472  ((timestep % simParams->forceDcdFrequency) == 0) )
473  { forcesNeeded |= 1; }
474 
475  }
476 
477  // Output forces
478  if (timestep == FORCE_OUTPUT)
479  {
480  forcesNeeded |= 2;
481  }
482 
483  return forcesNeeded;
484 }
static Node * Object()
Definition: Node.h:86
SimParameters * simParameters
Definition: Node.h:178
#define simParams
Definition: Output.C:127
#define FORCE_OUTPUT
Definition: Output.h:28
void Output::recvReplicaDcdData ( ReplicaDcdDataMsg msg)

Definition at line 700 of file Output.C.

References ReplicaDcdDataMsg::data, DCD_FILEEXISTS, ReplicaDcdDataMsg::dcdIndex, ReplicaDcdDataMsg::DELTA, endi(), iout, NAMD_bug(), NAMD_die(), NAMD_err(), ReplicaDcdDataMsg::NFILE, ReplicaDcdDataMsg::NPRIV, ReplicaDcdDataMsg::NSAVC, ReplicaDcdDataMsg::NSTEP, ReplicaDcdDataMsg::numAtoms, open_dcd_write(), sendReplicaDcdAck(), ReplicaDcdDataMsg::srcPart, ReplicaDcdDataMsg::unitcell, ReplicaDcdDataMsg::with_unitcell, write_dcdheader(), and write_dcdstep().

Referenced by recvReplicaDcdData().

700  {
701  if ( ! replicaDcdFiles.count(msg->dcdIndex) ) {
702  char err_msg[257];
703  sprintf(err_msg, "Unknown replicaDcdFile identifier %d\n", msg->dcdIndex);
704  NAMD_die(err_msg);
705  }
706  replicaDcdFile &f = replicaDcdFiles[msg->dcdIndex];
707 
708  if ( ! f.fileid ) {
709  // Open the DCD file
710  iout << "OPENING REPLICA DCD FILE " << msg->dcdIndex << " " << f.filename.c_str() << "\n" << endi;
711 
712  f.fileid=open_dcd_write(f.filename.c_str());
713 
714  if (f.fileid == DCD_FILEEXISTS) {
715  char err_msg[257];
716  sprintf(err_msg, "DCD file %s already exists!!", f.filename.c_str());
717  NAMD_err(err_msg);
718  } else if (f.fileid < 0) {
719  char err_msg[257];
720  sprintf(err_msg, "Couldn't open DCD file %s", f.filename.c_str());
721  NAMD_err(err_msg);
722  } else if (! f.fileid) {
723  NAMD_bug("Output::recvReplicaDcdData open_dcd_write returned fileid of zero");
724  }
725 
726  // Write out the header
727  int ret_code = write_dcdheader(f.fileid, f.filename.c_str(),
728  msg->numAtoms, msg->NFILE, msg->NPRIV, msg->NSAVC, msg->NSTEP,
729  msg->DELTA, msg->with_unitcell);
730 
731  if (ret_code<0) {
732  NAMD_err("Writing of DCD header failed!!");
733  }
734  }
735 
736  // Write out the values for this timestep
737  iout << "WRITING TO REPLICA DCD FILE " << msg->dcdIndex << " " << f.filename.c_str() << "\n" << endi;
738  float *msgx = (float*) msg->data;
739  float *msgy = msgx + msg->numAtoms;
740  float *msgz = msgy + msg->numAtoms;
741  int ret_code = write_dcdstep(f.fileid, msg->numAtoms, msgx, msgy, msgz,
742  msg->with_unitcell ? msg->unitcell : 0);
743  if (ret_code < 0) NAMD_err("Writing of DCD step failed!!");
744 
745  sendReplicaDcdAck(msg->srcPart, (ReplicaDcdAckMsg*) CmiAlloc(sizeof(ReplicaDcdAckMsg)));
746 }
void NAMD_err(const char *err_msg)
Definition: common.C:106
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
#define iout
Definition: InfoStream.h:51
int open_dcd_write(const char *dcdname)
Definition: dcdlib.C:662
#define DCD_FILEEXISTS
Definition: dcdlib.h:52
void NAMD_bug(const char *err_msg)
Definition: common.C:129
int write_dcdstep(int fd, int N, float *X, float *Y, float *Z, double *cell)
Definition: dcdlib.C:736
void NAMD_die(const char *err_msg)
Definition: common.C:85
int write_dcdheader(int fd, const char *filename, int N, int NFILE, int NPRIV, int NSAVC, int NSTEP, double DELTA, int with_unitcell)
Definition: dcdlib.C:915
void sendReplicaDcdAck(int dstPart, ReplicaDcdAckMsg *msg)
Definition: DataExchanger.C:67
double unitcell[6]
Definition: DataExchanger.h:49
void Output::recvReplicaDcdInit ( ReplicaDcdInitMsg msg)

Definition at line 689 of file Output.C.

References close_dcd_write(), ReplicaDcdInitMsg::data, ReplicaDcdInitMsg::dcdIndex, endi(), iout, sendReplicaDcdAck(), and ReplicaDcdInitMsg::srcPart.

Referenced by recvReplicaDcdInit().

689  {
690  replicaDcdFile &f = replicaDcdFiles[msg->dcdIndex];
691  if ( f.fileid ) {
692  iout << "CLOSING REPLICA DCD FILE " << msg->dcdIndex << " " << f.filename.c_str() << "\n" << endi;
693  close_dcd_write(f.fileid);
694  f.fileid = 0;
695  }
696  f.filename = (const char*) msg->data;
697  sendReplicaDcdAck(msg->srcPart, (ReplicaDcdAckMsg*) CmiAlloc(sizeof(ReplicaDcdAckMsg)));
698 }
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
#define iout
Definition: InfoStream.h:51
void sendReplicaDcdAck(int dstPart, ReplicaDcdAckMsg *msg)
Definition: DataExchanger.C:67
void close_dcd_write(int fd)
Definition: dcdlib.C:1063
void Output::replicaDcdInit ( int  index,
const char *  filename 
)

Definition at line 678 of file Output.C.

References ReplicaDcdInitMsg::data, ReplicaDcdInitMsg::dcdIndex, sendReplicaDcdInit(), and ReplicaDcdInitMsg::srcPart.

678  {
679  replicaDcdActive = 1;
680  replicaDcdIndex = index;
681  int msgsize = sizeof(ReplicaDcdInitMsg) + strlen(filename);
682  ReplicaDcdInitMsg *msg = (ReplicaDcdInitMsg *) CmiAlloc(msgsize);
683  msg->srcPart = CmiMyPartition();
684  msg->dcdIndex = replicaDcdIndex;
685  strcpy(msg->data, filename);
686  sendReplicaDcdInit(abs(replicaDcdIndex) % CmiNumPartitions(), msg, msgsize);
687 }
void sendReplicaDcdInit(int dstPart, ReplicaDcdInitMsg *msg, int msgsize)
Definition: DataExchanger.C:45
void Output::replicaDcdOff ( )
inline

Definition at line 100 of file Output.h.

100 { replicaDcdActive = 0; }
void Output::setReplicaDcdIndex ( int  index)

Definition at line 673 of file Output.C.

673  {
674  replicaDcdActive = 1;
675  replicaDcdIndex = index;
676 }
void Output::velocity ( int  timestep,
int  n,
Vector vel 
)

Definition at line 396 of file Output.C.

References END_OF_RUN, endi(), FILE_OUTPUT, SimParameters::firstTimestep, SimParameters::forceDcdFrequency, iout, SimParameters::N, Node::Object(), SimParameters::restartFrequency, Node::simParameters, simParams, and SimParameters::velDcdFrequency.

Referenced by CollectionMaster::disposeVelocities().

397 {
399 
400  if ( timestep >= 0 ) {
401 
402  // Output velocity DCD trajectory
403  if ( simParams->velDcdFrequency &&
404  ((timestep % simParams->velDcdFrequency) == 0) )
405  {
406  output_veldcdfile(timestep, n, vel);
407  }
408 
409  // Output restart file
410  if ( simParams->restartFrequency &&
411  ((timestep % simParams->restartFrequency) == 0) )
412  {
413  iout << "WRITING VELOCITIES TO RESTART FILE AT STEP "
414  << timestep << "\n" << endi;
415  output_restart_velocities(timestep, n, vel);
416  iout << "FINISHED WRITING RESTART VELOCITIES\n" <<endi;
417  fflush(stdout);
418  }
419 
420  }
421 
422  // Output final velocities
423  if (timestep == FILE_OUTPUT || timestep == END_OF_RUN)
424  {
425  int realstep = ( timestep == FILE_OUTPUT ?
426  simParams->firstTimestep : simParams->N );
427  iout << "WRITING VELOCITIES TO OUTPUT FILE AT STEP "
428  << realstep << "\n" << endi;
429  fflush(stdout);
430  output_final_velocities(realstep, n, vel);
431  }
432 
433  // Close trajectory files
434  if (timestep == END_OF_RUN)
435  {
436  if (simParams->velDcdFrequency) output_veldcdfile(END_OF_RUN,0,0);
437  // close force dcd file here since no final force output below
438  if (simParams->forceDcdFrequency) output_forcedcdfile(END_OF_RUN,0,0);
439  }
440 
441 }
static Node * Object()
Definition: Node.h:86
#define FILE_OUTPUT
Definition: Output.h:25
SimParameters * simParameters
Definition: Node.h:178
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
#define iout
Definition: InfoStream.h:51
#define END_OF_RUN
Definition: Output.h:26
#define simParams
Definition: Output.C:127
int Output::velocityNeeded ( int  timestep)
static

Definition at line 365 of file Output.C.

References SimParameters::benchTimestep, END_OF_RUN, FILE_OUTPUT, Node::Object(), SimParameters::restartFrequency, Node::simParameters, simParams, and SimParameters::velDcdFrequency.

Referenced by Controller::enqueueCollections(), and Sequencer::submitCollections().

366 {
368 
369  if(simParams->benchTimestep) return 0;
370 
371  int velocitiesNeeded = 0;
372 
373  if ( timestep >= 0 ) {
374 
375  // Output a velocity DCD trajectory
376  if ( simParams->velDcdFrequency &&
377  ((timestep % simParams->velDcdFrequency) == 0) )
378  { velocitiesNeeded |= 1; }
379 
380  // Output a restart file
381  if ( simParams->restartFrequency &&
382  ((timestep % simParams->restartFrequency) == 0) )
383  { velocitiesNeeded |= 2; }
384 
385  }
386 
387  // Output final velocities
388  if (timestep == FILE_OUTPUT || timestep == END_OF_RUN)
389  {
390  velocitiesNeeded |= 2;
391  }
392 
393  return velocitiesNeeded;
394 }
static Node * Object()
Definition: Node.h:86
#define FILE_OUTPUT
Definition: Output.h:25
SimParameters * simParameters
Definition: Node.h:178
#define END_OF_RUN
Definition: Output.h:26
#define simParams
Definition: Output.C:127

Friends And Related Function Documentation

friend class SimParameters
friend

Definition at line 48 of file Output.h.


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