48#include "io/ZConsWriter.hpp"
58#include "utils/simError.h"
61 ZConsWriter::ZConsWriter(
SimInfo* info,
const std::string& filename) :
68 output_.open(filename.c_str());
71 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
72 "Could not open %s for z constrain output_ \n",
78 output_ <<
"//time(fs)" << std::endl;
79 output_ <<
"//number of fixed z-constrain molecules" << std::endl;
80 output_ <<
"//global Index of molecule\tzconstrain force\tcurrentZPos"
87 ZConsWriter::~ZConsWriter() {
97 void ZConsWriter::writeFZ(
const std::list<ZconstraintMol>& fixedZmols) {
99 output_ << info_->getSnapshotManager()->getCurrentSnapshot()->getTime()
101 output_ << fixedZmols.size() << std::endl;
103 std::list<ZconstraintMol>::const_iterator i;
104 for (i = fixedZmols.begin(); i != fixedZmols.end(); ++i) {
105 output_ << i->mol->getGlobalIndex() <<
"\t" << i->fz <<
"\t" << i->zpos
106 <<
"\t" << i->param.zTargetPos << std::endl;
110 const int primaryNode = 0;
113 MPI_Comm_size(MPI_COMM_WORLD, &nproc);
114 MPI_Comm_rank(MPI_COMM_WORLD, &myNode);
116 std::vector<int> tmpNFixedZmols(nproc, 0);
117 std::vector<int> nFixedZmolsInProc(nproc, 0);
118 tmpNFixedZmols[myNode] = fixedZmols.size();
122 MPI_Allreduce(&tmpNFixedZmols[0], &nFixedZmolsInProc[0], nproc, MPI_INT,
123 MPI_SUM, MPI_COMM_WORLD);
129 if (myNode == primaryNode) {
130 std::vector<ZconsData> zconsData;
132 for (
int i = 0; i < nproc; ++i) {
133 if (i == primaryNode) {
134 std::list<ZconstraintMol>::const_iterator j;
135 for (j = fixedZmols.begin(); j != fixedZmols.end(); ++j) {
136 tmpData.zmolIndex = j->mol->getGlobalIndex();
137 tmpData.zforce = j->fz;
138 tmpData.zpos = j->zpos;
139 tmpData.zconsPos = j->param.zTargetPos;
140 zconsData.push_back(tmpData);
144 for (
int k = 0; k < nFixedZmolsInProc[i]; ++k) {
145 MPI_Recv(&zmolIndex, 1, MPI_INT, i, 0, MPI_COMM_WORLD, &ierr);
146 MPI_Recv(data, 3, MPI_REALTYPE, i, 0, MPI_COMM_WORLD, &ierr);
147 tmpData.zmolIndex = zmolIndex;
148 tmpData.zforce = data[0];
149 tmpData.zpos = data[1];
150 tmpData.zconsPos = data[2];
151 zconsData.push_back(tmpData);
156 output_ << info_->getSnapshotManager()->getCurrentSnapshot()->getTime()
158 output_ << zconsData.size() << std::endl;
160 std::vector<ZconsData>::iterator l;
161 for (l = zconsData.begin(); l != zconsData.end(); ++l) {
162 output_ << l->zmolIndex <<
"\t" << l->zforce <<
"\t" << l->zpos <<
"\t"
163 << l->zconsPos << std::endl;
167 std::list<ZconstraintMol>::const_iterator j;
168 for (j = fixedZmols.begin(); j != fixedZmols.end(); ++j) {
169 zmolIndex = j->mol->getGlobalIndex();
172 data[2] = j->param.zTargetPos;
173 MPI_Send(&zmolIndex, 1, MPI_INT, primaryNode, 0, MPI_COMM_WORLD);
174 MPI_Send(data, 3, MPI_REALTYPE, primaryNode, 0, MPI_COMM_WORLD);
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.