45#include "io/ZConsWriter.hpp"
55#include "utils/simError.h"
58 ZConsWriter::ZConsWriter(SimInfo* info,
const std::string& filename) :
65 output_.open(filename.c_str());
68 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
69 "Could not open %s for z constrain output_ \n",
75 output_ <<
"//time(fs)" << std::endl;
76 output_ <<
"//number of fixed z-constrain molecules" << std::endl;
77 output_ <<
"//global Index of molecule\tzconstrain force\tcurrentZPos"
84 ZConsWriter::~ZConsWriter() {
94 void ZConsWriter::writeFZ(
const std::list<ZconstraintMol>& fixedZmols) {
96 output_ << info_->getSnapshotManager()->getCurrentSnapshot()->getTime()
98 output_ << fixedZmols.size() << std::endl;
100 std::list<ZconstraintMol>::const_iterator i;
101 for (i = fixedZmols.begin(); i != fixedZmols.end(); ++i) {
102 output_ << i->mol->getGlobalIndex() <<
"\t" << i->fz <<
"\t" << i->zpos
103 <<
"\t" << i->param.zTargetPos << std::endl;
107 const int primaryNode = 0;
110 MPI_Comm_size(MPI_COMM_WORLD, &nproc);
111 MPI_Comm_rank(MPI_COMM_WORLD, &myNode);
113 std::vector<int> tmpNFixedZmols(nproc, 0);
114 std::vector<int> nFixedZmolsInProc(nproc, 0);
115 tmpNFixedZmols[myNode] = fixedZmols.size();
119 MPI_Allreduce(&tmpNFixedZmols[0], &nFixedZmolsInProc[0], nproc, MPI_INT,
120 MPI_SUM, MPI_COMM_WORLD);
122 MPI_Status* ierr = NULL;
126 if (myNode == primaryNode) {
127 std::vector<ZconsData> zconsData;
129 for (
int i = 0; i < nproc; ++i) {
130 if (i == primaryNode) {
131 std::list<ZconstraintMol>::const_iterator j;
132 for (j = fixedZmols.begin(); j != fixedZmols.end(); ++j) {
133 tmpData.zmolIndex = j->mol->getGlobalIndex();
134 tmpData.zforce = j->fz;
135 tmpData.zpos = j->zpos;
136 tmpData.zconsPos = j->param.zTargetPos;
137 zconsData.push_back(tmpData);
141 for (
int k = 0; k < nFixedZmolsInProc[i]; ++k) {
142 MPI_Recv(&zmolIndex, 1, MPI_INT, i, 0, MPI_COMM_WORLD, ierr);
143 MPI_Recv(data, 3, MPI_REALTYPE, i, 0, MPI_COMM_WORLD, ierr);
144 tmpData.zmolIndex = zmolIndex;
145 tmpData.zforce = data[0];
146 tmpData.zpos = data[1];
147 tmpData.zconsPos = data[2];
148 zconsData.push_back(tmpData);
153 output_ << info_->getSnapshotManager()->getCurrentSnapshot()->getTime()
155 output_ << zconsData.size() << std::endl;
157 std::vector<ZconsData>::iterator l;
158 for (l = zconsData.begin(); l != zconsData.end(); ++l) {
159 output_ << l->zmolIndex <<
"\t" << l->zforce <<
"\t" << l->zpos <<
"\t"
160 << l->zconsPos << std::endl;
164 std::list<ZconstraintMol>::const_iterator j;
165 for (j = fixedZmols.begin(); j != fixedZmols.end(); ++j) {
166 zmolIndex = j->mol->getGlobalIndex();
169 data[2] = j->param.zTargetPos;
170 MPI_Send(&zmolIndex, 1, MPI_INT, primaryNode, 0, MPI_COMM_WORLD);
171 MPI_Send(data, 3, MPI_REALTYPE, primaryNode, 0, MPI_COMM_WORLD);
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.