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 timestep, int n, Vector *coor, FloatVector *fcoor, Lattice &lattice)
 Produce appropriate coordinate output for the current timestep. More...
 
void velocity (int timestep, int n, Vector *vel, FloatVector *fvel)
 Produce appropriate velocity for the current timestep. More...
 
void force (int timestep, int n, Vector *frc, FloatVector *ffrc)
 Produce appropriate force for the current timestep. More...
 
void replicaDcdOff ()
 
void setReplicaDcdIndex (int index)
 
void replicaDcdInit (int index, const char *filename)
 
void replicaDcdSelectInit (int index, const char *tag, const char *filename)
 
void recvReplicaDcdInit (ReplicaDcdInitMsg *msg)
 
void recvReplicaDcdData (ReplicaDcdDataMsg *msg)
 

Static Public Member Functions

static std::pair< int, int > coordinateNeeded (int timestep)
 Check if the step requires to output the coordinates. More...
 
static int velocityNeeded (int timestep)
 Check if the step requires to output the velocities. More...
 
static int forceNeeded (int timestep)
 Check if the step requires to output the forces. More...
 

Friends

class SimParameters
 

Detailed Description

Definition at line 35 of file Output.h.

Constructor & Destructor Documentation

◆ Output()

Output::Output ( )

Definition at line 171 of file Output.C.

171 : replicaDcdActive(0) { }

◆ ~Output()

Output::~Output ( )

Definition at line 181 of file Output.C.

181 { }

Member Function Documentation

◆ coordinate()

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

Produce appropriate coordinate output for the current timestep.

Parameters
timestepTimestep coordinates were accumulated for
nThe number of coordinates accumulated
coorArray of Vectors containing the coordinates in double precision. If the second bit of the first bitmask of coordinateNeeded is 1, then this parameter shouldn't be nullptr or NULL.
fcoorArray of Vectors containing the coordinates in single precision. If the first bit of the first bitmask of coordinateNeeded is 1, then this parameter shouldn't be nullptr or NULL.
latticeThe PBC box for wrapping the output coordinates

Definition at line 334 of file Output.C.

References Lattice::a(), Lattice::b(), Lattice::c(), Molecule::dcdSelectionParams, END_OF_RUN, endi(), EVAL_MEASURE, FILE_OUTPUT, dcd_params::frequency, IMDOutput::gather_box(), IMDOutput::gather_coordinates(), Molecule::get_dcd_selection_index_from_atom_id(), Molecule::get_dcd_selection_size(), Node::getScript(), Node::imd, IMDv2, IMDv3, iout, ScriptTcl::measure(), Node::molecule, Node::Object(), Node::simParameters, simParams, dcd_params::size, dcd_params::tag, wrap_coor(), wrap_coor_dcd_selection(), Vector::x, Vector::y, and Vector::z.

Referenced by CollectionMaster::disposePositions().

336 {
338  Molecule *molecule = Node::Object()->molecule;
339  double coor_wrapped = 0;
340  float fcoor_wrapped = 0;
341 
342  if ( timestep >= 0 ) {
343 
344  // Output a DCD trajectory
345  if ( simParams->dcdFrequency &&
346  ((timestep % simParams->dcdFrequency) == 0) )
347  {
348  wrap_coor(fcoor,lattice,&fcoor_wrapped);
349  output_dcdfile(timestep, n, fcoor,
350  simParams->dcdUnitCell ? &lattice : NULL, 0);
351  }
352 
353  // Output any DCD selection trajectories that this timestep mods
354  if ( simParams->dcdSelectionOn)
355  {
356  bool needCleanup = false;
357 
358  for(int index=0; index<16;++index)
359  {
360  int frequency=molecule->dcdSelectionParams[index].frequency;
361  uint16 tag=molecule->dcdSelectionParams[index].tag;
362  int size=molecule->dcdSelectionParams[index].size;
363  if(frequency>0 && (timestep % frequency) == 0)
364  {
365  FloatVector *dcdSelectionFcoor = fcoor;
366  int dcdSelectionNpoints = n;
367  if(dcdSelectionNpoints != molecule->get_dcd_selection_size(index))
368  {
369  // on intervals when some other output is also happening, we have
370  // to filter out a copy of the selection from the full
371  // collected output then wrap and output accordingly
372  dcdSelectionNpoints = size;
373  dcdSelectionFcoor = new FloatVector[dcdSelectionNpoints];
374  needCleanup = true;
375  for(int i=0; i<n ;i++)
376  {
377  int offset = molecule->get_dcd_selection_index_from_atom_id(index, i);
378  if(offset >= 0)
379  dcdSelectionFcoor[offset] = fcoor[i];
380  }
381  }
382  else
383  {
384  dcdSelectionFcoor = fcoor;
385  }
386  wrap_coor_dcd_selection(dcdSelectionFcoor, lattice, &fcoor_wrapped, index);
387  output_dcdfile(timestep, dcdSelectionNpoints, dcdSelectionFcoor,
388  simParams->dcdUnitCell ? &lattice : NULL, tag);
389  if(needCleanup)
390  delete [] dcdSelectionFcoor;
391  }
392 
393  }
394  }
395 
396  // Output a restart file
397  if ( simParams->restartFrequency &&
398  ((timestep % simParams->restartFrequency) == 0) )
399  {
400  iout << "WRITING COORDINATES TO RESTART FILE AT STEP "
401  << timestep << "\n" << endi;
402  wrap_coor(coor,lattice,&coor_wrapped);
403  output_restart_coordinates(coor, n, timestep);
404  iout << "FINISHED WRITING RESTART COORDINATES\n" <<endi;
405  fflush(stdout);
406  }
407 
408  // Interactive MD
409  if ( simParams->IMDon &&
410  ( ((timestep % simParams->IMDfreq) == 0) ||
411  (timestep == simParams->firstTimestep) ) )
412  {
413 
414  if ((simParams->IMDversion == IMDversion_t::IMDv3)
415  && (simParams->IMDsendsettings.box_switch == 1))
416  {
417  IMDOutput *imd = NULL;
418 #ifdef NODEGROUP_FORCE_REGISTER
419  if (simParams->CUDASOAintegrate) {
420  CProxy_PatchData cpdata(CkpvAccess(BOCclass_group).patchData);
421  imd = cpdata.ckLocalBranch()->imd;
422  }
423  else
424 #endif
425  {
426  imd = Node::Object()->imd;
427  }
428 
429  IMDBox box = {(float)lattice.a().x, (float)lattice.a().y, (float)lattice.a().z,
430  (float)lattice.b().x, (float)lattice.b().y, (float)lattice.b().z,
431  (float)lattice.c().x, (float)lattice.c().y, (float)lattice.c().z};
432 
433  if (imd != NULL) imd->gather_box(timestep, &box);
434  }
435 
436  if ((simParams->IMDversion == IMDversion_t::IMDv2) || ((simParams->IMDversion == IMDversion_t::IMDv3)
437  && (simParams->IMDsendsettings.fcoords_switch == 1)))
438  {
439  IMDOutput *imd = NULL;
440 #ifdef NODEGROUP_FORCE_REGISTER
441  if (simParams->CUDASOAintegrate) {
442  CProxy_PatchData cpdata(CkpvAccess(BOCclass_group).patchData);
443  imd = cpdata.ckLocalBranch()->imd;
444  }
445  else
446 #endif
447  {
448  imd = Node::Object()->imd;
449  }
450  if ((simParams->IMDversion == IMDversion_t::IMDv2) || ((simParams->IMDversion == IMDversion_t::IMDv3)
451  && (simParams->IMDsendsettings.wrap_switch == 1)))
452  wrap_coor(fcoor,lattice,&fcoor_wrapped);
453  if (imd != NULL) imd->gather_coordinates(timestep, n, fcoor);
454  }
455 
456  }
457 
458  }
459 
460  if (timestep == EVAL_MEASURE)
461  {
462 #ifdef NAMD_TCL
463  wrap_coor(coor,lattice,&coor_wrapped);
464  Node::Object()->getScript()->measure(coor);
465 #endif
466  }
467 
468  // Output final coordinates
469  if (timestep == FILE_OUTPUT || timestep == END_OF_RUN)
470  {
471  int realstep = ( timestep == FILE_OUTPUT ?
472  simParams->firstTimestep : simParams->N );
473  iout << "WRITING COORDINATES TO OUTPUT FILE AT STEP "
474  << realstep << "\n" << endi;
475  fflush(stdout);
476  wrap_coor(coor,lattice,&coor_wrapped);
477  output_final_coordinates(coor, n, realstep);
478  }
479 
480  // Close trajectory files
481  if (timestep == END_OF_RUN)
482  {
483  if (simParams->dcdFrequency) output_dcdfile(END_OF_RUN,0,0,
484  simParams->dcdUnitCell
485  ? &lattice : NULL, 0);
486  if ( simParams->dcdSelectionOn)
487  {
488  for(int dcdSelectionIndex=0; dcdSelectionIndex<16;++dcdSelectionIndex)
489  {
490  int dcdSelectionFrequency = molecule->dcdSelectionParams[dcdSelectionIndex].frequency;
491  int dcdSelectionTag = molecule->dcdSelectionParams[dcdSelectionIndex].tag;
492  if(dcdSelectionFrequency)
493  output_dcdfile(END_OF_RUN,0,0,
494  simParams->dcdUnitCell
495  ? &lattice : NULL, dcdSelectionTag);
496  }
497  }
498  }
499 
500 }
static Node * Object()
Definition: Node.h:86
DCDParams dcdSelectionParams[16]
Definition: Molecule.h:482
int frequency
Definition: common.h:255
NAMD_HOST_DEVICE Vector c() const
Definition: Lattice.h:270
Definition: common.h:275
#define FILE_OUTPUT
Definition: Output.h:25
IMDOutput * imd
Definition: Node.h:186
uint16 tag
Definition: common.h:252
#define EVAL_MEASURE
Definition: Output.h:27
SimParameters * simParameters
Definition: Node.h:181
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
BigReal z
Definition: Vector.h:74
void gather_coordinates(int timestep, int N, FloatVector *coords)
Definition: IMDOutput.C:29
#define iout
Definition: InfoStream.h:51
Molecule stores the structural information for the system.
Definition: Molecule.h:174
uint16_t uint16
Definition: common.h:41
const int get_dcd_selection_size(const int index)
Definition: Molecule.h:893
void wrap_coor(Vector *coor, Lattice &lattice, double *done)
Definition: Output.C:326
Definition: imd.h:55
int get_dcd_selection_index_from_atom_id(const int index, const int atomIndex)
Definition: Molecule.h:888
void wrap_coor_dcd_selection(Vector *coor, Lattice &lattice, double *done, int index)
Definition: Output.C:318
BigReal x
Definition: Vector.h:74
#define END_OF_RUN
Definition: Output.h:26
NAMD_HOST_DEVICE Vector b() const
Definition: Lattice.h:269
void gather_box(int timestep, IMDBox *box)
Definition: IMDOutput.C:56
#define simParams
Definition: Output.C:131
int size
Definition: common.h:259
BigReal y
Definition: Vector.h:74
ScriptTcl * getScript()
Definition: Node.C:1656
Definition: common.h:275
NAMD_HOST_DEVICE Vector a() const
Definition: Lattice.h:268
void measure(Vector *)
Definition: ScriptTcl.C:1400
Molecule * molecule
Definition: Node.h:179

◆ coordinateNeeded()

std::pair< int, int > Output::coordinateNeeded ( int  timestep)
static

Check if the step requires to output the coordinates.

Parameters
timestepThe current step number
Returns
A pair of bitmasks. The first bitmask indicates whether the step requires to output the velocities. If the first returned bitmask is 0, then the coordinates are not required for output. If its first bit is 1, then the single-precision coordinates are required. If its second bit is 1, then the double-precision coordinates are required. If both the first and the second bit are 1, then both precisions are required. XXX TODO: Document the second bitmask (also known as dcdSelectionTag)

Definition at line 185 of file Output.C.

References Molecule::dcdSelectionParams, END_OF_RUN, EVAL_MEASURE, FILE_OUTPUT, dcd_params::frequency, IMDv2, IMDv3, Node::molecule, Node::Object(), Node::simParameters, simParams, and dcd_params::tag.

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

186 {
188 
189  if(simParams->benchTimestep) return std::make_pair(0,0);
190 
191  int positionsNeeded = 0;
192  uint16 dcdSelectionTag = 0;
193  if ( timestep >= 0 ) {
194 
195  // Output a DCD trajectory
196  if ( simParams->dcdFrequency &&
197  ((timestep % simParams->dcdFrequency) == 0) )
198  { positionsNeeded |= 1; }
199 
200  // Output a DCD Selection trajectory
201 
202  if (simParams->dcdSelectionOn)
203  {
204  Molecule *mol = Node::Object()->molecule;
205  int tagCount=0;
206  for(int index=0; index<16;++index)
207  {
208  int frequency=mol->dcdSelectionParams[index].frequency;
209  uint16 tag=mol->dcdSelectionParams[index].tag;
210  if(frequency && (timestep % frequency) == 0)
211  {
212  if(++tagCount>1)
213  positionsNeeded |=1; //multi selection means all positions
214  positionsNeeded |= 4; dcdSelectionTag = tag;
215  }
216  }
217  }
218  // Output a restart file
219  if ( simParams->restartFrequency &&
220  ((timestep % simParams->restartFrequency) == 0) )
221  { positionsNeeded |= 2; }
222 
223  // Iteractive MD
224  if ( simParams->IMDon &&
225  ( ((timestep % simParams->IMDfreq) == 0) ||
226  (timestep == simParams->firstTimestep) ) &&
227  ((simParams->IMDversion == IMDversion_t::IMDv2) || ((simParams->IMDversion == IMDversion_t::IMDv3)
228  && (simParams->IMDsendsettings.fcoords_switch == 1))) )
229  { positionsNeeded |= 1; }
230 
231  }
232 
233  // Output final coordinates
234  if (timestep == FILE_OUTPUT || timestep == END_OF_RUN ||
235  timestep == EVAL_MEASURE)
236  {
237  positionsNeeded |= 2;
238  }
239  return std::make_pair(positionsNeeded,dcdSelectionTag);
240 }
static Node * Object()
Definition: Node.h:86
DCDParams dcdSelectionParams[16]
Definition: Molecule.h:482
int frequency
Definition: common.h:255
Definition: common.h:275
#define FILE_OUTPUT
Definition: Output.h:25
uint16 tag
Definition: common.h:252
#define EVAL_MEASURE
Definition: Output.h:27
SimParameters * simParameters
Definition: Node.h:181
Molecule stores the structural information for the system.
Definition: Molecule.h:174
uint16_t uint16
Definition: common.h:41
#define END_OF_RUN
Definition: Output.h:26
#define simParams
Definition: Output.C:131
Definition: common.h:275
Molecule * molecule
Definition: Node.h:179

◆ energy()

void Output::energy ( int  ,
BigReal  
)

◆ force()

void Output::force ( int  timestep,
int  n,
Vector frc,
FloatVector ffrc 
)

Produce appropriate force for the current timestep.

This function receives the forces accumulated for a given timestep from the Collect object and calls the appropriate output functions. ALL routines used to output force information should be called from here.

Parameters
timestepTimestep forces were accumulated for
nThe number of forces accumulated
frcArray of Vectors containing the forces in double precision. If the second bit of forceNeeded is 1, then this parameter shouldn't be nullptr or NULL.
ffrcArray of Vectors containing the forces in single precision. If the first bit of forceNeeded is 1, then this parameter shouldn't be nullptr or NULL.

Definition at line 646 of file Output.C.

References endi(), FORCE_OUTPUT, IMDOutput::gather_forces(), Node::imd, IMDv2, IMDv3, iout, Node::Object(), Node::simParameters, and simParams.

Referenced by CollectionMaster::disposeForces().

647 {
649 
650  if ( timestep >= 0 ) {
651 
652  // Output force DCD trajectory
653  if ( simParams->forceDcdFrequency &&
654  ((timestep % simParams->forceDcdFrequency) == 0) )
655  {
656  output_forcedcdfile(timestep, n, ffrc);
657  }
658 
659  // Interactive MD
660  if ( simParams->IMDon &&
661  ( ((timestep % simParams->IMDfreq) == 0) ||
662  (timestep == simParams->firstTimestep) ) &&
663  ((simParams->IMDversion == IMDversion_t::IMDv2) || ((simParams->IMDversion == IMDversion_t::IMDv3)
664  && (simParams->IMDsendsettings.forces_switch == 1))) )
665  {
666  IMDOutput *imd = NULL;
667 #ifdef NODEGROUP_FORCE_REGISTER
668  if (simParams->CUDASOAintegrate) {
669  CProxy_PatchData cpdata(CkpvAccess(BOCclass_group).patchData);
670  imd = cpdata.ckLocalBranch()->imd;
671  }
672  else
673 #endif
674  {
675  imd = Node::Object()->imd;
676  }
677  if (imd != NULL) imd->gather_forces(timestep, n, ffrc);
678  }
679 
680  }
681 
682  // Output forces
683  if (timestep == FORCE_OUTPUT)
684  {
685  int realstep = simParams->firstTimestep;
686  iout << "WRITING FORCES TO OUTPUT FILE AT STEP "
687  << realstep << "\n" << endi;
688  fflush(stdout);
689  output_forces(realstep, n, frc);
690  }
691 
692  // Trajectory file closed by velocity() above
693 
694 }
static Node * Object()
Definition: Node.h:86
Definition: common.h:275
IMDOutput * imd
Definition: Node.h:186
SimParameters * simParameters
Definition: Node.h:181
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
#define iout
Definition: InfoStream.h:51
#define simParams
Definition: Output.C:131
void gather_forces(int timestep, int N, FloatVector *forces)
Definition: IMDOutput.C:47
Definition: common.h:275
#define FORCE_OUTPUT
Definition: Output.h:28

◆ forceNeeded()

int Output::forceNeeded ( int  timestep)
static

Check if the step requires to output the forces.

Parameters
timestepThe current step number
Returns
A bitmask indicates whether the step requires to output the forces. If the return value is 0, then forces are not required for output. If the first bit of the return value is 1, then the single-precision forces is required. If the second bit is 1, then the double- precision forces is required. If both the first and the second bit are 1, then both precisions are required.

Definition at line 612 of file Output.C.

References FORCE_OUTPUT, IMDv2, IMDv3, Node::Object(), Node::simParameters, and simParams.

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

613 {
615 
616  if(simParams->benchTimestep) return 0;
617 
618  int forcesNeeded = 0;
619 
620  if ( timestep >= 0 ) {
621 
622  // Output a force DCD trajectory
623  if ( simParams->forceDcdFrequency &&
624  ((timestep % simParams->forceDcdFrequency) == 0) )
625  { forcesNeeded |= 1; }
626 
627  // Iteractive MD
628  if ( simParams->IMDon &&
629  ( ((timestep % simParams->IMDfreq) == 0) ||
630  (timestep == simParams->firstTimestep) ) &&
631  ((simParams->IMDversion == IMDversion_t::IMDv2) || ((simParams->IMDversion == IMDversion_t::IMDv3)
632  && (simParams->IMDsendsettings.forces_switch == 1))) )
633  { forcesNeeded |= 1; }
634 
635  }
636 
637  // Output forces
638  if (timestep == FORCE_OUTPUT)
639  {
640  forcesNeeded |= 2;
641  }
642 
643  return forcesNeeded;
644 }
static Node * Object()
Definition: Node.h:86
Definition: common.h:275
SimParameters * simParameters
Definition: Node.h:181
#define simParams
Definition: Output.C:131
Definition: common.h:275
#define FORCE_OUTPUT
Definition: Output.h:28

◆ recvReplicaDcdData()

void Output::recvReplicaDcdData ( ReplicaDcdDataMsg msg)

Definition at line 925 of file Output.C.

References ReplicaDcdDataMsg::data, DCD_FILEEXISTS, ReplicaDcdDataMsg::dcdIndex, ReplicaDcdDataMsg::dcdSelectIndex, ReplicaDcdDataMsg::DELTA, endi(), iout, NAMD_bug(), NAMD_die(), NAMD_err(), namdMyNode, 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().

925  {
926  Molecule *molecule = namdMyNode->molecule;
927  if ( msg->dcdSelectIndex>=16 && ! replicaDcdFiles.count(msg->dcdIndex) ||
928  ( ! replicaDcdFiles.count(msg->dcdIndex) )) {
929  char err_msg[257];
930  sprintf(err_msg, "Unknown replicaDcdFile identifier %d\n", msg->dcdIndex);
931  NAMD_die(err_msg);
932  }
933  replicaDcdFile &f = (msg->dcdSelectIndex<16) ? replicaDcdSelectFiles[std::make_pair(msg->dcdIndex,msg->dcdSelectIndex)]: replicaDcdFiles[msg->dcdIndex];
934 
935  if ( ! f.fileid ) {
936  // Open the DCD file
937  iout << "OPENING REPLICA DCD FILE " << msg->dcdIndex << " " << f.filename.c_str() << "\n" << endi;
938 
939  f.fileid=open_dcd_write(f.filename.c_str());
940 
941  if (f.fileid == DCD_FILEEXISTS) {
942  char err_msg[257];
943  sprintf(err_msg, "DCD file %s already exists!!", f.filename.c_str());
944  NAMD_err(err_msg);
945  } else if (f.fileid < 0) {
946  char err_msg[257];
947  if(msg->dcdSelectIndex<16)
948  sprintf(err_msg, "Couldn't open DCD Index %d Select Index %d file %s", msg->dcdIndex, msg->dcdSelectIndex, f.filename.c_str());
949  else
950  sprintf(err_msg, "Couldn't open DCD Index %d file %s", msg->dcdIndex, f.filename.c_str());
951  NAMD_err(err_msg);
952  } else if (! f.fileid) {
953  NAMD_bug("Output::recvReplicaDcdData open_dcd_write returned fileid of zero");
954  }
955 
956  // Write out the header
957  int ret_code = write_dcdheader(f.fileid, f.filename.c_str(),
958  msg->numAtoms, msg->NFILE, msg->NPRIV, msg->NSAVC, msg->NSTEP,
959  msg->DELTA, msg->with_unitcell);
960 
961  if (ret_code<0) {
962  NAMD_err("Writing of DCD header failed!!");
963  }
964  }
965 
966  // Write out the values for this timestep
967  iout << "WRITING TO REPLICA DCD FILE " << msg->dcdIndex << " " << f.filename.c_str() << "\n" << endi;
968  float *msgx = (float*) msg->data;
969  float *msgy = msgx + msg->numAtoms;
970  float *msgz = msgy + msg->numAtoms;
971  int ret_code = write_dcdstep(f.fileid, msg->numAtoms, msgx, msgy, msgz,
972  msg->with_unitcell ? msg->unitcell : 0);
973  if (ret_code < 0) NAMD_err("Writing of DCD step failed!!");
974 
975  sendReplicaDcdAck(msg->srcPart, (ReplicaDcdAckMsg*) CmiAlloc(sizeof(ReplicaDcdAckMsg)));
976 }
void NAMD_err(const char *err_msg)
Definition: common.C:170
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
#define iout
Definition: InfoStream.h:51
Molecule stores the structural information for the system.
Definition: Molecule.h:174
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:195
#define namdMyNode
Definition: Output.C:130
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:147
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
uint16_t dcdSelectIndex
Definition: DataExchanger.h:48
double unitcell[6]
Definition: DataExchanger.h:51

◆ recvReplicaDcdInit()

void Output::recvReplicaDcdInit ( ReplicaDcdInitMsg msg)

Definition at line 914 of file Output.C.

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

Referenced by recvReplicaDcdInit().

914  {
915  replicaDcdFile &f = (msg->dcdSelectIndex<16) ? replicaDcdSelectFiles[std::make_pair(msg->dcdIndex,msg->dcdSelectIndex)]: replicaDcdFiles[msg->dcdIndex];
916  if ( f.fileid ) {
917  iout << "CLOSING REPLICA DCD FILE " << msg->dcdIndex << " " << f.filename.c_str() << "\n" << endi;
918  close_dcd_write(f.fileid);
919  f.fileid = 0;
920  }
921  f.filename = (const char*) msg->data;
922  sendReplicaDcdAck(msg->srcPart, (ReplicaDcdAckMsg*) CmiAlloc(sizeof(ReplicaDcdAckMsg)));
923 }
uint16_t dcdSelectIndex
Definition: DataExchanger.h:39
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

◆ replicaDcdInit()

void Output::replicaDcdInit ( int  index,
const char *  filename 
)

Definition at line 888 of file Output.C.

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

888  {
889  replicaDcdActive = 1;
890  replicaDcdIndex = index;
891  int msgsize = sizeof(ReplicaDcdInitMsg) + strlen(filename);
892  ReplicaDcdInitMsg *msg = (ReplicaDcdInitMsg *) CmiAlloc(msgsize);
893  msg->srcPart = CmiMyPartition();
894  msg->dcdIndex = replicaDcdIndex;
895  msg->dcdSelectIndex = 16;
896  strcpy(msg->data, filename);
897  sendReplicaDcdInit(abs(replicaDcdIndex) % CmiNumPartitions(), msg, msgsize);
898 }
uint16_t dcdSelectIndex
Definition: DataExchanger.h:39
void sendReplicaDcdInit(int dstPart, ReplicaDcdInitMsg *msg, int msgsize)
Definition: DataExchanger.C:45

◆ replicaDcdOff()

void Output::replicaDcdOff ( )
inline

Definition at line 173 of file Output.h.

173 { replicaDcdActive = 0; }

◆ replicaDcdSelectInit()

void Output::replicaDcdSelectInit ( int  index,
const char *  tag,
const char *  filename 
)

Definition at line 900 of file Output.C.

References ReplicaDcdInitMsg::data, ReplicaDcdInitMsg::dcdIndex, ReplicaDcdInitMsg::dcdSelectIndex, Molecule::find_or_create_dcd_selection_index(), namdMyNode, sendReplicaDcdInit(), and ReplicaDcdInitMsg::srcPart.

900  {
901  replicaDcdActive = 1;
902  replicaDcdIndex = index;
903  int msgsize = sizeof(ReplicaDcdInitMsg) + strlen(filename);
904  ReplicaDcdInitMsg *msg = (ReplicaDcdInitMsg *) CmiAlloc(msgsize);
905  msg->srcPart = CmiMyPartition();
906  msg->dcdIndex = replicaDcdIndex;
907  Molecule *molecule = namdMyNode->molecule;
909  strcpy(msg->data, filename);
910  sendReplicaDcdInit(abs(replicaDcdIndex) % CmiNumPartitions(), msg, msgsize);
911 }
uint16_t dcdSelectIndex
Definition: DataExchanger.h:39
void sendReplicaDcdInit(int dstPart, ReplicaDcdInitMsg *msg, int msgsize)
Definition: DataExchanger.C:45
Molecule stores the structural information for the system.
Definition: Molecule.h:174
uint16_t find_or_create_dcd_selection_index(const char *keystr)
#define namdMyNode
Definition: Output.C:130

◆ setReplicaDcdIndex()

void Output::setReplicaDcdIndex ( int  index)

Definition at line 883 of file Output.C.

883  {
884  replicaDcdActive = 1;
885  replicaDcdIndex = index;
886 }

◆ velocity()

void Output::velocity ( int  timestep,
int  n,
Vector vel,
FloatVector fvel 
)

Produce appropriate velocity for the current timestep.

This function receives the velocities accumulated for a given timestep from the Collect object and calls the appropriate output functions. ALL routines used to output velocity information should be called from here.

Parameters
timestepTimestep velocities were accumulated for
nThe number of velocities accumulated
velArray of Vectors containing the velocities in double precision. If the second bit of velocityNeeded is 1, then this parameter shouldn't be nullptr or NULL.
fvelArray of Vectors containing the velocities in single precision. If the first bit of velocityNeeded is 1, then this parameter shouldn't be nullptr or NULL.

Definition at line 541 of file Output.C.

References END_OF_RUN, endi(), FILE_OUTPUT, IMDOutput::gather_velocities(), Node::imd, IMDv3, iout, Node::Object(), PDBVELFACTOR, Node::simParameters, and simParams.

Referenced by CollectionMaster::disposeVelocities().

542 {
544 
545  if ( timestep >= 0 ) {
546 
547  // Output velocity DCD trajectory
548  if ( simParams->velDcdFrequency &&
549  ((timestep % simParams->velDcdFrequency) == 0) )
550  {
551  output_veldcdfile(timestep, n, fvel);
552  }
553 
554  // Output restart file
555  if ( simParams->restartFrequency &&
556  ((timestep % simParams->restartFrequency) == 0) )
557  {
558  iout << "WRITING VELOCITIES TO RESTART FILE AT STEP "
559  << timestep << "\n" << endi;
560  output_restart_velocities(timestep, n, vel);
561  iout << "FINISHED WRITING RESTART VELOCITIES\n" <<endi;
562  fflush(stdout);
563  }
564 
565  // Interactive MD
566  if ( simParams->IMDon &&
567  ( ((timestep % simParams->IMDfreq) == 0) ||
568  (timestep == simParams->firstTimestep) ) &&
569  ((simParams->IMDversion == IMDversion_t::IMDv3)
570  && (simParams->IMDsendsettings.velocities_switch == 1)) )
571  {
572  IMDOutput *imd = NULL;
573 #ifdef NODEGROUP_FORCE_REGISTER
574  if (simParams->CUDASOAintegrate) {
575  CProxy_PatchData cpdata(CkpvAccess(BOCclass_group).patchData);
576  imd = cpdata.ckLocalBranch()->imd;
577  }
578  else
579 #endif
580  {
581  imd = Node::Object()->imd;
582  }
583  if (imd != NULL) {
584  scale_fvels(fvel, n, PDBVELFACTOR);
585  imd->gather_velocities(timestep, n, fvel);
586  }
587  }
588 
589  }
590 
591  // Output final velocities
592  if (timestep == FILE_OUTPUT || timestep == END_OF_RUN)
593  {
594  int realstep = ( timestep == FILE_OUTPUT ?
595  simParams->firstTimestep : simParams->N );
596  iout << "WRITING VELOCITIES TO OUTPUT FILE AT STEP "
597  << realstep << "\n" << endi;
598  fflush(stdout);
599  output_final_velocities(realstep, n, vel);
600  }
601 
602  // Close trajectory files
603  if (timestep == END_OF_RUN)
604  {
605  if (simParams->velDcdFrequency) output_veldcdfile(END_OF_RUN,0,0);
606  // close force dcd file here since no final force output below
607  if (simParams->forceDcdFrequency) output_forcedcdfile(END_OF_RUN,0,0);
608  }
609 
610 }
static Node * Object()
Definition: Node.h:86
void gather_velocities(int timestep, int N, FloatVector *velocities)
Definition: IMDOutput.C:38
Definition: common.h:275
#define FILE_OUTPUT
Definition: Output.h:25
IMDOutput * imd
Definition: Node.h:186
SimParameters * simParameters
Definition: Node.h:181
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:131
#define PDBVELFACTOR
Definition: common.h:57

◆ velocityNeeded()

int Output::velocityNeeded ( int  timestep)
static

Check if the step requires to output the velocities.

Parameters
timestepThe current step number
Returns
A bitmask indicates whether the step requires to output the velocities. If the return value is 0, then velocities are not required for output. If the first bit of the return value is 1, then the single-precision velocities are required. If the second bit is 1, then the double- precision velocities are required. If both the first and the second bit are 1, then both precisions are required.

Definition at line 502 of file Output.C.

References END_OF_RUN, FILE_OUTPUT, IMDv3, Node::Object(), Node::simParameters, and simParams.

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

503 {
505 
506  if(simParams->benchTimestep) return 0;
507 
508  int velocitiesNeeded = 0;
509 
510  if ( timestep >= 0 ) {
511 
512  // Output a velocity DCD trajectory
513  if ( simParams->velDcdFrequency &&
514  ((timestep % simParams->velDcdFrequency) == 0) )
515  { velocitiesNeeded |= 1; }
516 
517  // Output a restart file
518  if ( simParams->restartFrequency &&
519  ((timestep % simParams->restartFrequency) == 0) )
520  { velocitiesNeeded |= 2; }
521 
522  // Interactive MD
523  if ( simParams->IMDon &&
524  ( ((timestep % simParams->IMDfreq) == 0) ||
525  (timestep == simParams->firstTimestep) ) &&
526  ((simParams->IMDversion == IMDversion_t::IMDv3)
527  && (simParams->IMDsendsettings.velocities_switch == 1)) )
528  { velocitiesNeeded |= 1; }
529 
530  }
531 
532  // Output final velocities
533  if (timestep == FILE_OUTPUT || timestep == END_OF_RUN)
534  {
535  velocitiesNeeded |= 2;
536  }
537 
538  return velocitiesNeeded;
539 }
static Node * Object()
Definition: Node.h:86
Definition: common.h:275
#define FILE_OUTPUT
Definition: Output.h:25
SimParameters * simParameters
Definition: Node.h:181
#define END_OF_RUN
Definition: Output.h:26
#define simParams
Definition: Output.C:131

Friends And Related Function Documentation

◆ SimParameters

friend class SimParameters
friend

Definition at line 40 of file Output.h.


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