ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/io/DumpWriter.cpp
(Generate patch)

Comparing:
trunk/src/io/DumpWriter.cpp (file contents), Revision 395 by tim, Thu Mar 3 14:40:20 2005 UTC vs.
branches/development/src/io/DumpWriter.cpp (file contents), Revision 1746 by gezelter, Wed Jun 6 02:18:54 2012 UTC

# Line 1 | Line 1
1 < /*
2 < * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
1 > /*
2 > * Copyright (c) 2009 The University of Notre Dame. All Rights Reserved.
3   *
4   * The University of Notre Dame grants you ("Licensee") a
5   * non-exclusive, royalty free, license to use, modify and
6   * redistribute this software in source and binary code form, provided
7   * that the following conditions are met:
8   *
9 < * 1. Acknowledgement of the program authors must be made in any
10 < *    publication of scientific results based in part on use of the
11 < *    program.  An acceptable form of acknowledgement is citation of
12 < *    the article in which the program was described (Matthew
13 < *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 < *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 < *    Parallel Simulation Engine for Molecular Dynamics,"
16 < *    J. Comput. Chem. 26, pp. 252-271 (2005))
17 < *
18 < * 2. Redistributions of source code must retain the above copyright
9 > * 1. Redistributions of source code must retain the above copyright
10   *    notice, this list of conditions and the following disclaimer.
11   *
12 < * 3. Redistributions in binary form must reproduce the above copyright
12 > * 2. Redistributions in binary form must reproduce the above copyright
13   *    notice, this list of conditions and the following disclaimer in the
14   *    documentation and/or other materials provided with the
15   *    distribution.
# Line 37 | Line 28
28   * arising out of the use of or inability to use software, even if the
29   * University of Notre Dame has been advised of the possibility of
30   * such damages.
31 + *
32 + * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your
33 + * research, please cite the appropriate papers when you publish your
34 + * work.  Good starting points are:
35 + *                                                                      
36 + * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).            
37 + * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).          
38 + * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).          
39 + * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010).
40 + * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41   */
42  
43   #include "io/DumpWriter.hpp"
44   #include "primitives/Molecule.hpp"
45   #include "utils/simError.h"
46   #include "io/basic_teebuf.hpp"
47 + #include "io/gzstream.hpp"
48 + #include "io/Globals.hpp"
49 +
50 +
51   #ifdef IS_MPI
52   #include <mpi.h>
53   #endif //is_mpi
54  
55 < namespace oopse {
55 > using namespace std;
56 > namespace OpenMD {
57  
58 < DumpWriter::DumpWriter(SimInfo* info)
59 <                   : info_(info), filename_(info->getDumpFileName()), eorFilename_(info->getFinalConfigFileName()){
58 >  DumpWriter::DumpWriter(SimInfo* info)
59 >    : info_(info), filename_(info->getDumpFileName()), eorFilename_(info->getFinalConfigFileName()){
60 >
61 >    Globals* simParams = info->getSimParams();
62 >    needCompression_   = simParams->getCompressDumpFile();
63 >    needForceVector_   = simParams->getOutputForceVector();
64 >    needParticlePot_   = simParams->getOutputParticlePotential();
65 >    needFlucQ_         = simParams->getOutputFluctuatingCharges();
66 >    needElectricField_ = simParams->getOutputElectricField();
67 >
68 >    createDumpFile_ = true;
69 > #ifdef HAVE_LIBZ
70 >    if (needCompression_) {
71 >      filename_ += ".gz";
72 >      eorFilename_ += ".gz";
73 >    }
74 > #endif
75 >    
76   #ifdef IS_MPI
77  
78      if (worldRank == 0) {
79   #endif // is_mpi
80 +        
81 +      dumpFile_ = createOStream(filename_);
82  
83 <        dumpFile_.open(filename_.c_str(), std::ios::out | std::ios::trunc);
83 >      if (!dumpFile_) {
84 >        sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n",
85 >                filename_.c_str());
86 >        painCave.isFatal = 1;
87 >        simError();
88 >      }
89  
61        if (!dumpFile_) {
62            sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n",
63                    filename_.c_str());
64            painCave.isFatal = 1;
65            simError();
66        }
67
90   #ifdef IS_MPI
91  
92      }
93  
72    sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n");
73    MPIcheckPoint();
74
94   #endif // is_mpi
95  
96 < }
96 >  }
97  
98  
99 < DumpWriter::DumpWriter(SimInfo* info, const std::string& filename)
100 <                   : info_(info), filename_(filename){
99 >  DumpWriter::DumpWriter(SimInfo* info, const std::string& filename)
100 >    : info_(info), filename_(filename){
101 >
102 >    Globals* simParams = info->getSimParams();
103 >    eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor";    
104 >
105 >    needCompression_   = simParams->getCompressDumpFile();
106 >    needForceVector_   = simParams->getOutputForceVector();
107 >    needParticlePot_   = simParams->getOutputParticlePotential();
108 >    needFlucQ_         = simParams->getOutputFluctuatingCharges();
109 >    needElectricField_ = simParams->getOutputElectricField();
110 >
111 >    createDumpFile_ = true;
112 > #ifdef HAVE_LIBZ
113 >    if (needCompression_) {
114 >      filename_ += ".gz";
115 >      eorFilename_ += ".gz";
116 >    }
117 > #endif
118 >    
119   #ifdef IS_MPI
120  
121      if (worldRank == 0) {
122   #endif // is_mpi
123  
124 <        eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor";
125 <        dumpFile_.open(filename_.c_str(), std::ios::out | std::ios::trunc);
124 >      
125 >      dumpFile_ = createOStream(filename_);
126  
127 <        if (!dumpFile_) {
128 <            sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n",
129 <                    filename_.c_str());
130 <            painCave.isFatal = 1;
131 <            simError();
132 <        }
127 >      if (!dumpFile_) {
128 >        sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n",
129 >                filename_.c_str());
130 >        painCave.isFatal = 1;
131 >        simError();
132 >      }
133  
134   #ifdef IS_MPI
135  
136      }
137  
138 <    sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n");
102 <    MPIcheckPoint();
138 > #endif // is_mpi
139  
140 +  }
141 +  
142 +  DumpWriter::DumpWriter(SimInfo* info, const std::string& filename, bool writeDumpFile)
143 +    : info_(info), filename_(filename){
144 +    
145 +    Globals* simParams = info->getSimParams();
146 +    eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor";    
147 +    
148 +    needCompression_   = simParams->getCompressDumpFile();
149 +    needForceVector_   = simParams->getOutputForceVector();
150 +    needParticlePot_   = simParams->getOutputParticlePotential();
151 +    needFlucQ_         = simParams->getOutputFluctuatingCharges();
152 +    needElectricField_ = simParams->getOutputElectricField();
153 +
154 + #ifdef HAVE_LIBZ
155 +    if (needCompression_) {
156 +      filename_ += ".gz";
157 +      eorFilename_ += ".gz";
158 +    }
159 + #endif
160 +    
161 + #ifdef IS_MPI
162 +    
163 +    if (worldRank == 0) {
164   #endif // is_mpi
165 +      
166 +      createDumpFile_ = writeDumpFile;
167 +      if (createDumpFile_) {
168 +        dumpFile_ = createOStream(filename_);
169 +      
170 +        if (!dumpFile_) {
171 +          sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n",
172 +                  filename_.c_str());
173 +          painCave.isFatal = 1;
174 +          simError();
175 +        }
176 +      }
177 + #ifdef IS_MPI
178 +      
179 +    }
180  
181 < }
181 >    
182 > #endif // is_mpi
183 >    
184 >  }
185  
186 < DumpWriter::~DumpWriter() {
186 >  DumpWriter::~DumpWriter() {
187  
188   #ifdef IS_MPI
189  
190      if (worldRank == 0) {
191   #endif // is_mpi
192 <
193 <        dumpFile_.close();
194 <
192 >      if (createDumpFile_){
193 >        writeClosing(*dumpFile_);
194 >        delete dumpFile_;
195 >      }
196   #ifdef IS_MPI
197  
198      }
199  
200   #endif // is_mpi
201  
202 < }
202 >  }
203  
204 < void DumpWriter::writeCommentLine(std::ostream& os, Snapshot* s) {
204 >  void DumpWriter::writeFrameProperties(std::ostream& os, Snapshot* s) {
205  
206 <    double currentTime;
207 <    Mat3x3d hmat;
208 <    double chi;
209 <    double integralOfChiDt;
210 <    Mat3x3d eta;
206 >    char buffer[1024];
207 >
208 >    os << "    <FrameData>\n";
209 >
210 >    RealType currentTime = s->getTime();
211 >
212 >    if (isinf(currentTime) || isnan(currentTime)) {      
213 >      sprintf( painCave.errMsg,
214 >               "DumpWriter detected a numerical error writing the time");      
215 >      painCave.isFatal = 1;
216 >      simError();
217 >    }
218      
219 <    currentTime = s->getTime();
219 >    sprintf(buffer, "        Time: %.10g\n", currentTime);
220 >    os << buffer;
221 >
222 >    Mat3x3d hmat;
223      hmat = s->getHmat();
224 <    chi = s->getChi();
225 <    integralOfChiDt = s->getIntegralOfChiDt();
226 <    eta = s->getEta();
224 >
225 >    for (unsigned int i = 0; i < 3; i++) {
226 >      for (unsigned int j = 0; j < 3; j++) {
227 >        if (isinf(hmat(i,j)) || isnan(hmat(i,j))) {      
228 >          sprintf( painCave.errMsg,
229 >                   "DumpWriter detected a numerical error writing the box");
230 >          painCave.isFatal = 1;
231 >          simError();
232 >        }        
233 >      }
234 >    }
235      
236 <    os << currentTime << ";\t"
237 <         << hmat(0, 0) << "\t" << hmat(1, 0) << "\t" << hmat(2, 0) << ";\t"
238 <         << hmat(0, 1) << "\t" << hmat(1, 1) << "\t" << hmat(2, 1) << ";\t"
239 <         << hmat(0, 2) << "\t" << hmat(1, 2) << "\t" << hmat(2, 2) << ";\t";
236 >    sprintf(buffer, "        Hmat: {{ %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }}\n",
237 >            hmat(0, 0), hmat(1, 0), hmat(2, 0),
238 >            hmat(0, 1), hmat(1, 1), hmat(2, 1),
239 >            hmat(0, 2), hmat(1, 2), hmat(2, 2));
240 >    os << buffer;
241  
242 <    //write out additional parameters, such as chi and eta
242 >    RealType chi = s->getChi();
243 >    RealType integralOfChiDt = s->getIntegralOfChiDt();
244 >    if (isinf(chi) || isnan(chi) ||
245 >        isinf(integralOfChiDt) || isnan(integralOfChiDt)) {      
246 >      sprintf( painCave.errMsg,
247 >               "DumpWriter detected a numerical error writing the thermostat");
248 >      painCave.isFatal = 1;
249 >      simError();
250 >    }
251 >    sprintf(buffer, "  Thermostat: %.10g , %.10g\n", chi, integralOfChiDt);
252 >    os << buffer;
253  
254 <    os << chi << "\t" << integralOfChiDt << "\t;";
254 >    Mat3x3d eta;
255 >    eta = s->getEta();
256  
257 <    os << eta(0, 0) << "\t" << eta(1, 0) << "\t" << eta(2, 0) << ";\t"
258 <         << eta(0, 1) << "\t" << eta(1, 1) << "\t" << eta(2, 1) << ";\t"
259 <         << eta(0, 2) << "\t" << eta(1, 2) << "\t" << eta(2, 2) << ";";
260 <        
261 <    os << "\n";
262 < }
257 >    for (unsigned int i = 0; i < 3; i++) {
258 >      for (unsigned int j = 0; j < 3; j++) {
259 >        if (isinf(eta(i,j)) || isnan(eta(i,j))) {      
260 >          sprintf( painCave.errMsg,
261 >                   "DumpWriter detected a numerical error writing the barostat");
262 >          painCave.isFatal = 1;
263 >          simError();
264 >        }        
265 >      }
266 >    }
267  
268 < void DumpWriter::writeFrame(std::ostream& os) {
269 <    const int BUFFERSIZE = 2000;
270 <    const int MINIBUFFERSIZE = 100;
268 >    sprintf(buffer, "    Barostat: {{ %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }}\n",
269 >            eta(0, 0), eta(1, 0), eta(2, 0),
270 >            eta(0, 1), eta(1, 1), eta(2, 1),
271 >            eta(0, 2), eta(1, 2), eta(2, 2));
272 >    os << buffer;
273  
274 <    char tempBuffer[BUFFERSIZE];
275 <    char writeLine[BUFFERSIZE];
274 >    os << "    </FrameData>\n";
275 >  }
276  
277 <    Quat4d q;
163 <    Vector3d ji;
164 <    Vector3d pos;
165 <    Vector3d vel;
277 >  void DumpWriter::writeFrame(std::ostream& os) {
278  
279 + #ifdef IS_MPI
280 +    MPI_Status istatus;
281 + #endif
282 +
283      Molecule* mol;
284      StuntDouble* integrableObject;
285      SimInfo::MoleculeIterator mi;
286      Molecule::IntegrableObjectIterator ii;
171  
172    int nTotObjects;    
173    nTotObjects = info_->getNGlobalIntegrableObjects();
287  
288   #ifndef IS_MPI
289 +    os << "  <Snapshot>\n";
290 +
291 +    writeFrameProperties(os, info_->getSnapshotManager()->getCurrentSnapshot());
292  
293 +    os << "    <StuntDoubles>\n";
294 +    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
295  
296 <    os << nTotObjects << "\n";
297 <        
298 <    writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot());
296 >      
297 >      for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;  
298 >           integrableObject = mol->nextIntegrableObject(ii)) {  
299 >          os << prepareDumpLine(integrableObject);
300 >          
301 >      }
302 >    }    
303 >    os << "    </StuntDoubles>\n";
304 >    
305 >    os << "  </Snapshot>\n";
306  
307 +    os.flush();
308 + #else
309 +    //every node prepares the dump lines for integrable objects belong to itself
310 +    std::string buffer;
311      for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
312  
184        for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;
185            integrableObject = mol->nextIntegrableObject(ii)) {
186                
313  
314 <            pos = integrableObject->getPos();
315 <            vel = integrableObject->getVel();
314 >      for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;
315 >           integrableObject = mol->nextIntegrableObject(ii)) {  
316 >          buffer += prepareDumpLine(integrableObject);
317 >      }
318 >    }
319 >    
320 >    const int masterNode = 0;
321 >    int nProc;
322 >    MPI_Comm_size(MPI_COMM_WORLD, &nProc);
323 >    if (worldRank == masterNode) {      
324 >      os << "  <Snapshot>\n";  
325 >      writeFrameProperties(os, info_->getSnapshotManager()->getCurrentSnapshot());
326 >      os << "    <StuntDoubles>\n";
327 >        
328 >      os << buffer;
329  
330 <            sprintf(tempBuffer, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
192 <                    integrableObject->getType().c_str(),
193 <                    pos[0], pos[1], pos[2],
194 <                    vel[0], vel[1], vel[2]);
330 >      for (int i = 1; i < nProc; ++i) {
331  
332 <            strcpy(writeLine, tempBuffer);
332 >        // receive the length of the string buffer that was
333 >        // prepared by processor i
334  
335 <            if (integrableObject->isDirectional()) {
336 <                q = integrableObject->getQ();
337 <                ji = integrableObject->getJ();
338 <
339 <                sprintf(tempBuffer, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
340 <                        q[0], q[1], q[2], q[3],
341 <                        ji[0], ji[1], ji[2]);
342 <                strcat(writeLine, tempBuffer);
343 <            } else {
207 <                strcat(writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n");
208 <            }
209 <
210 <            os << writeLine;
211 <
335 >        MPI_Bcast(&i, 1, MPI_INT,masterNode,MPI_COMM_WORLD);
336 >        int recvLength;
337 >        MPI_Recv(&recvLength, 1, MPI_INT, i, 0, MPI_COMM_WORLD, &istatus);
338 >        char* recvBuffer = new char[recvLength];
339 >        if (recvBuffer == NULL) {
340 >        } else {
341 >          MPI_Recv(recvBuffer, recvLength, MPI_CHAR, i, 0, MPI_COMM_WORLD, &istatus);
342 >          os << recvBuffer;
343 >          delete [] recvBuffer;
344          }
345 +      }
346 +      os << "    </StuntDoubles>\n";
347 +      
348 +      os << "  </Snapshot>\n";
349 +      os.flush();
350 +    } else {
351 +      int sendBufferLength = buffer.size() + 1;
352 +      int myturn = 0;
353 +      for (int i = 1; i < nProc; ++i){
354 +        MPI_Bcast(&myturn,1, MPI_INT,masterNode,MPI_COMM_WORLD);
355 +        if (myturn == worldRank){
356 +          MPI_Send(&sendBufferLength, 1, MPI_INT, masterNode, 0, MPI_COMM_WORLD);
357 +          MPI_Send((void *)buffer.c_str(), sendBufferLength, MPI_CHAR, masterNode, 0, MPI_COMM_WORLD);
358 +        }
359 +      }
360      }
361  
362 <    os.flush();
216 < #else // is_mpi
217 <    /*********************************************************************
218 <     * Documentation?  You want DOCUMENTATION?
219 <     *
220 <     * Why all the potatoes below?  
221 <     *
222 <     * To make a long story short, the original version of DumpWriter
223 <     * worked in the most inefficient way possible.  Node 0 would
224 <     * poke each of the node for an individual atom's formatted data
225 <     * as node 0 worked its way down the global index. This was particularly
226 <     * inefficient since the method blocked all processors at every atom
227 <     * (and did it twice!).
228 <     *
229 <     * An intermediate version of DumpWriter could be described from Node
230 <     * zero's perspective as follows:
231 <     *
232 <     *  1) Have 100 of your friends stand in a circle.
233 <     *  2) When you say go, have all of them start tossing potatoes at
234 <     *     you (one at a time).
235 <     *  3) Catch the potatoes.
236 <     *
237 <     * It was an improvement, but MPI has buffers and caches that could
238 <     * best be described in this analogy as "potato nets", so there's no
239 <     * need to block the processors atom-by-atom.
240 <     *
241 <     * This new and improved DumpWriter works in an even more efficient
242 <     * way:
243 <     *
244 <     *  1) Have 100 of your friend stand in a circle.
245 <     *  2) When you say go, have them start tossing 5-pound bags of
246 <     *     potatoes at you.
247 <     *  3) Once you've caught a friend's bag of potatoes,
248 <     *     toss them a spud to let them know they can toss another bag.
249 <     *
250 <     * How's THAT for documentation?
251 <     *
252 <     *********************************************************************/
253 <    const int masterNode = 0;
362 > #endif // is_mpi
363  
364 <    int * potatoes;
256 <    int myPotato;
257 <    int nProc;
258 <    int which_node;
259 <    double atomData[13];
260 <    int isDirectional;
261 <    char MPIatomTypeString[MINIBUFFERSIZE];
262 <    int msgLen; // the length of message actually recieved at master nodes
263 <    int haveError;
264 <    MPI_Status istatus;
265 <    int nCurObj;
266 <    
267 <    // code to find maximum tag value
268 <    int * tagub;
269 <    int flag;
270 <    int MAXTAG;
271 <    MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &tagub, &flag);
364 >  }
365  
366 <    if (flag) {
367 <        MAXTAG = *tagub;
368 <    } else {
369 <        MAXTAG = 32767;
370 <    }
366 >  std::string DumpWriter::prepareDumpLine(StuntDouble* integrableObject) {
367 >        
368 >    int index = integrableObject->getGlobalIntegrableObjectIndex();
369 >    std::string type("pv");
370 >    std::string line;
371 >    char tempBuffer[4096];
372  
373 <    if (worldRank == masterNode) { //master node (node 0) is responsible for writing the dump file
373 >    Vector3d pos;
374 >    Vector3d vel;
375 >    pos = integrableObject->getPos();
376  
377 <        // Node 0 needs a list of the magic potatoes for each processor;
377 >    if (isinf(pos[0]) || isnan(pos[0]) ||
378 >        isinf(pos[1]) || isnan(pos[1]) ||
379 >        isinf(pos[2]) || isnan(pos[2]) ) {      
380 >      sprintf( painCave.errMsg,
381 >               "DumpWriter detected a numerical error writing the position"
382 >               " for object %d", index);      
383 >      painCave.isFatal = 1;
384 >      simError();
385 >    }
386  
387 <        MPI_Comm_size(MPI_COMM_WORLD, &nProc);
284 <        potatoes = new int[nProc];
387 >    vel = integrableObject->getVel();          
388  
389 <        //write out the comment lines
390 <        for(int i = 0; i < nProc; i++) {
391 <            potatoes[i] = 0;
392 <        }
389 >    if (isinf(vel[0]) || isnan(vel[0]) ||
390 >        isinf(vel[1]) || isnan(vel[1]) ||
391 >        isinf(vel[2]) || isnan(vel[2]) ) {      
392 >      sprintf( painCave.errMsg,
393 >               "DumpWriter detected a numerical error writing the velocity"
394 >               " for object %d", index);      
395 >      painCave.isFatal = 1;
396 >      simError();
397 >    }
398  
399 +    sprintf(tempBuffer, "%18.10g %18.10g %18.10g %13e %13e %13e",
400 +            pos[0], pos[1], pos[2],
401 +            vel[0], vel[1], vel[2]);                    
402 +    line += tempBuffer;
403  
404 <        os << nTotObjects << "\n";
405 <        writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot());
404 >    if (integrableObject->isDirectional()) {
405 >      type += "qj";
406 >      Quat4d q;
407 >      Vector3d ji;
408 >      q = integrableObject->getQ();
409  
410 <        for(int i = 0; i < info_->getNGlobalMolecules(); i++) {
410 >      if (isinf(q[0]) || isnan(q[0]) ||
411 >          isinf(q[1]) || isnan(q[1]) ||
412 >          isinf(q[2]) || isnan(q[2]) ||
413 >          isinf(q[3]) || isnan(q[3]) ) {      
414 >        sprintf( painCave.errMsg,
415 >                 "DumpWriter detected a numerical error writing the quaternion"
416 >                 " for object %d", index);      
417 >        painCave.isFatal = 1;
418 >        simError();
419 >      }
420  
421 <            // Get the Node number which has this atom;
421 >      ji = integrableObject->getJ();
422  
423 <            which_node = info_->getMolToProc(i);
424 <
425 <            if (which_node != masterNode) { //current molecule is in slave node
426 <                if (potatoes[which_node] + 1 >= MAXTAG) {
427 <                    // The potato was going to exceed the maximum value,
428 <                    // so wrap this processor potato back to 0:        
423 >      if (isinf(ji[0]) || isnan(ji[0]) ||
424 >          isinf(ji[1]) || isnan(ji[1]) ||
425 >          isinf(ji[2]) || isnan(ji[2]) ) {      
426 >        sprintf( painCave.errMsg,
427 >                 "DumpWriter detected a numerical error writing the angular"
428 >                 " momentum for object %d", index);      
429 >        painCave.isFatal = 1;
430 >        simError();
431 >      }
432  
433 <                    potatoes[which_node] = 0;
434 <                    MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0,
435 <                             MPI_COMM_WORLD);
436 <                }
433 >      sprintf(tempBuffer, " %13e %13e %13e %13e %13e %13e %13e",
434 >              q[0], q[1], q[2], q[3],
435 >              ji[0], ji[1], ji[2]);
436 >      line += tempBuffer;
437 >    }
438  
439 <                myPotato = potatoes[which_node];
439 >    if (needForceVector_) {
440 >      type += "f";
441 >      Vector3d frc = integrableObject->getFrc();
442 >      if (isinf(frc[0]) || isnan(frc[0]) ||
443 >          isinf(frc[1]) || isnan(frc[1]) ||
444 >          isinf(frc[2]) || isnan(frc[2]) ) {      
445 >        sprintf( painCave.errMsg,
446 >                 "DumpWriter detected a numerical error writing the force"
447 >                 " for object %d", index);      
448 >        painCave.isFatal = 1;
449 >        simError();
450 >      }
451 >      sprintf(tempBuffer, " %13e %13e %13e",
452 >              frc[0], frc[1], frc[2]);
453 >      line += tempBuffer;
454 >      
455 >      if (integrableObject->isDirectional()) {
456 >        type += "t";
457 >        Vector3d trq = integrableObject->getTrq();        
458 >        if (isinf(trq[0]) || isnan(trq[0]) ||
459 >            isinf(trq[1]) || isnan(trq[1]) ||
460 >            isinf(trq[2]) || isnan(trq[2]) ) {      
461 >          sprintf( painCave.errMsg,
462 >                   "DumpWriter detected a numerical error writing the torque"
463 >                   " for object %d", index);      
464 >          painCave.isFatal = 1;
465 >          simError();
466 >        }        
467 >        sprintf(tempBuffer, " %13e %13e %13e",
468 >                trq[0], trq[1], trq[2]);
469 >        line += tempBuffer;
470 >      }      
471 >    }
472  
473 <                //recieve the number of integrableObject in current molecule
474 <                MPI_Recv(&nCurObj, 1, MPI_INT, which_node, myPotato,
475 <                         MPI_COMM_WORLD, &istatus);
476 <                myPotato++;
473 >    if (needParticlePot_) {
474 >      type += "u";
475 >      RealType particlePot = integrableObject->getParticlePot();
476 >      if (isinf(particlePot) || isnan(particlePot)) {      
477 >        sprintf( painCave.errMsg,
478 >                 "DumpWriter detected a numerical error writing the particle "
479 >                 " potential for object %d", index);      
480 >        painCave.isFatal = 1;
481 >        simError();
482 >      }
483 >      sprintf(tempBuffer, " %13e", particlePot);
484 >      line += tempBuffer;
485 >    }
486 >    
487 >    if (needFlucQ_) {
488 >      type += "cw";
489 >      RealType fqPos = integrableObject->getFlucQPos();
490 >      if (isinf(fqPos) || isnan(fqPos) ) {      
491 >        sprintf( painCave.errMsg,
492 >                 "DumpWriter detected a numerical error writing the"
493 >                 " fluctuating charge for object %d", index);      
494 >        painCave.isFatal = 1;
495 >        simError();
496 >      }
497 >      sprintf(tempBuffer, " %13e ", fqPos);
498 >      line += tempBuffer;
499 >    
500 >      RealType fqVel = integrableObject->getFlucQVel();
501 >      if (isinf(fqVel) || isnan(fqVel) ) {      
502 >        sprintf( painCave.errMsg,
503 >                 "DumpWriter detected a numerical error writing the"
504 >                 " fluctuating charge velocity for object %d", index);      
505 >        painCave.isFatal = 1;
506 >        simError();
507 >      }
508 >      sprintf(tempBuffer, " %13e ", fqVel);
509 >      line += tempBuffer;
510  
511 <                for(int l = 0; l < nCurObj; l++) {
512 <                    if (potatoes[which_node] + 2 >= MAXTAG) {
513 <                        // The potato was going to exceed the maximum value,
514 <                        // so wrap this processor potato back to 0:        
511 >      if (needForceVector_) {
512 >        type += "g";
513 >        RealType fqFrc = integrableObject->getFlucQFrc();        
514 >        if (isinf(fqFrc) || isnan(fqFrc) ) {      
515 >          sprintf( painCave.errMsg,
516 >                   "DumpWriter detected a numerical error writing the"
517 >                   " fluctuating charge force for object %d", index);      
518 >          painCave.isFatal = 1;
519 >          simError();
520 >        }
521 >        sprintf(tempBuffer, " %13e ", fqFrc);        
522 >        line += tempBuffer;
523 >      }
524 >    }
525  
526 <                        potatoes[which_node] = 0;
527 <                        MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node,
528 <                                 0, MPI_COMM_WORLD);
529 <                    }
526 >    if (needElectricField_) {
527 >      type += "e";
528 >      Vector3d eField= integrableObject->getElectricField();
529 >      if (isinf(eField[0]) || isnan(eField[0]) ||
530 >          isinf(eField[1]) || isnan(eField[1]) ||
531 >          isinf(eField[2]) || isnan(eField[2]) ) {      
532 >        sprintf( painCave.errMsg,
533 >                 "DumpWriter detected a numerical error writing the electric"
534 >                 " field for object %d", index);      
535 >        painCave.isFatal = 1;
536 >        simError();
537 >      }
538 >      sprintf(tempBuffer, " %13e %13e %13e",
539 >              eField[0], eField[1], eField[2]);
540 >      line += tempBuffer;
541 >    }
542  
543 <                    MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR,
544 <                             which_node, myPotato, MPI_COMM_WORLD,
545 <                             &istatus);
543 >    sprintf(tempBuffer, "%10d %7s %s\n", index, type.c_str(), line.c_str());
544 >    return std::string(tempBuffer);
545 >  }
546  
547 <                    myPotato++;
548 <
549 <                    MPI_Recv(atomData, 13, MPI_DOUBLE, which_node, myPotato,
335 <                             MPI_COMM_WORLD, &istatus);
336 <                    myPotato++;
337 <
338 <                    MPI_Get_count(&istatus, MPI_DOUBLE, &msgLen);
339 <
340 <                    if (msgLen == 13)
341 <                        isDirectional = 1;
342 <                    else
343 <                        isDirectional = 0;
344 <
345 <                    // If we've survived to here, format the line:
346 <
347 <                    if (!isDirectional) {
348 <                        sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
349 <                                MPIatomTypeString, atomData[0],
350 <                                atomData[1], atomData[2],
351 <                                atomData[3], atomData[4],
352 <                                atomData[5]);
353 <
354 <                        strcat(writeLine,
355 <                               "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n");
356 <                    } else {
357 <                        sprintf(writeLine,
358 <                                "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
359 <                                MPIatomTypeString,
360 <                                atomData[0],
361 <                                atomData[1],
362 <                                atomData[2],
363 <                                atomData[3],
364 <                                atomData[4],
365 <                                atomData[5],
366 <                                atomData[6],
367 <                                atomData[7],
368 <                                atomData[8],
369 <                                atomData[9],
370 <                                atomData[10],
371 <                                atomData[11],
372 <                                atomData[12]);
373 <                    }
374 <
375 <                    os << writeLine;
376 <
377 <                } // end for(int l =0)
378 <
379 <                potatoes[which_node] = myPotato;
380 <            } else { //master node has current molecule
381 <
382 <                mol = info_->getMoleculeByGlobalIndex(i);
383 <
384 <                if (mol == NULL) {
385 <                    sprintf(painCave.errMsg, "Molecule not found on node %d!", worldRank);
386 <                    painCave.isFatal = 1;
387 <                    simError();
388 <                }
389 <                
390 <                for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;
391 <                    integrableObject = mol->nextIntegrableObject(ii)) {      
392 <
393 <                    pos = integrableObject->getPos();
394 <                    vel = integrableObject->getVel();
395 <
396 <                    atomData[0] = pos[0];
397 <                    atomData[1] = pos[1];
398 <                    atomData[2] = pos[2];
399 <
400 <                    atomData[3] = vel[0];
401 <                    atomData[4] = vel[1];
402 <                    atomData[5] = vel[2];
403 <
404 <                    isDirectional = 0;
405 <
406 <                    if (integrableObject->isDirectional()) {
407 <                        isDirectional = 1;
408 <
409 <                        q = integrableObject->getQ();
410 <                        ji = integrableObject->getJ();
411 <
412 <                        for(int j = 0; j < 6; j++) {
413 <                            atomData[j] = atomData[j];
414 <                        }
415 <
416 <                        atomData[6] = q[0];
417 <                        atomData[7] = q[1];
418 <                        atomData[8] = q[2];
419 <                        atomData[9] = q[3];
420 <
421 <                        atomData[10] = ji[0];
422 <                        atomData[11] = ji[1];
423 <                        atomData[12] = ji[2];
424 <                    }
425 <
426 <                    // If we've survived to here, format the line:
427 <
428 <                    if (!isDirectional) {
429 <                        sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
430 <                                integrableObject->getType().c_str(), atomData[0],
431 <                                atomData[1], atomData[2],
432 <                                atomData[3], atomData[4],
433 <                                atomData[5]);
547 >  void DumpWriter::writeDump() {
548 >    writeFrame(*dumpFile_);
549 >  }
550  
551 <                        strcat(writeLine,
552 <                               "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n");
553 <                    } else {
554 <                        sprintf(writeLine,
555 <                                "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
556 <                                integrableObject->getType().c_str(),
441 <                                atomData[0],
442 <                                atomData[1],
443 <                                atomData[2],
444 <                                atomData[3],
445 <                                atomData[4],
446 <                                atomData[5],
447 <                                atomData[6],
448 <                                atomData[7],
449 <                                atomData[8],
450 <                                atomData[9],
451 <                                atomData[10],
452 <                                atomData[11],
453 <                                atomData[12]);
454 <                    }
551 >  void DumpWriter::writeEor() {
552 >    std::ostream* eorStream;
553 >    
554 > #ifdef IS_MPI
555 >    if (worldRank == 0) {
556 > #endif // is_mpi
557  
558 +      eorStream = createOStream(eorFilename_);
559  
560 <                    os << writeLine;
458 <
459 <                } //end for(iter = integrableObject.begin())
460 <            }
461 <        } //end for(i = 0; i < mpiSim->getNmol())
462 <
463 <        os.flush();
464 <        
465 <        sprintf(checkPointMsg, "Sucessfully took a dump.\n");
466 <        MPIcheckPoint();
467 <
468 <        delete [] potatoes;
469 <    } else {
470 <
471 <        // worldRank != 0, so I'm a remote node.  
472 <
473 <        // Set my magic potato to 0:
474 <
475 <        myPotato = 0;
476 <
477 <        for(int i = 0; i < info_->getNGlobalMolecules(); i++) {
478 <
479 <            // Am I the node which has this integrableObject?
480 <            int whichNode = info_->getMolToProc(i);
481 <            if (whichNode == worldRank) {
482 <                if (myPotato + 1 >= MAXTAG) {
483 <
484 <                    // The potato was going to exceed the maximum value,
485 <                    // so wrap this processor potato back to 0 (and block until
486 <                    // node 0 says we can go:
487 <
488 <                    MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD,
489 <                             &istatus);
490 <                }
491 <
492 <                mol = info_->getMoleculeByGlobalIndex(i);
493 <
494 <                
495 <                nCurObj = mol->getNIntegrableObjects();
496 <
497 <                MPI_Send(&nCurObj, 1, MPI_INT, 0, myPotato, MPI_COMM_WORLD);
498 <                myPotato++;
499 <
500 <                for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;
501 <                    integrableObject = mol->nextIntegrableObject(ii)) {
502 <
503 <                    if (myPotato + 2 >= MAXTAG) {
504 <
505 <                        // The potato was going to exceed the maximum value,
506 <                        // so wrap this processor potato back to 0 (and block until
507 <                        // node 0 says we can go:
508 <
509 <                        MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD,
510 <                                 &istatus);
511 <                    }
512 <
513 <                    pos = integrableObject->getPos();
514 <                    vel = integrableObject->getVel();
515 <
516 <                    atomData[0] = pos[0];
517 <                    atomData[1] = pos[1];
518 <                    atomData[2] = pos[2];
519 <
520 <                    atomData[3] = vel[0];
521 <                    atomData[4] = vel[1];
522 <                    atomData[5] = vel[2];
523 <
524 <                    isDirectional = 0;
525 <
526 <                    if (integrableObject->isDirectional()) {
527 <                        isDirectional = 1;
528 <
529 <                        q = integrableObject->getQ();
530 <                        ji = integrableObject->getJ();
531 <
532 <                        atomData[6] = q[0];
533 <                        atomData[7] = q[1];
534 <                        atomData[8] = q[2];
535 <                        atomData[9] = q[3];
536 <
537 <                        atomData[10] = ji[0];
538 <                        atomData[11] = ji[1];
539 <                        atomData[12] = ji[2];
540 <                    }
541 <
542 <                    strncpy(MPIatomTypeString, integrableObject->getType().c_str(), MINIBUFFERSIZE);
543 <
544 <                    // null terminate the  std::string before sending (just in case):
545 <                    MPIatomTypeString[MINIBUFFERSIZE - 1] = '\0';
546 <
547 <                    MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0,
548 <                             myPotato, MPI_COMM_WORLD);
549 <
550 <                    myPotato++;
551 <
552 <                    if (isDirectional) {
553 <                        MPI_Send(atomData, 13, MPI_DOUBLE, 0, myPotato,
554 <                                 MPI_COMM_WORLD);
555 <                    } else {
556 <                        MPI_Send(atomData, 6, MPI_DOUBLE, 0, myPotato,
557 <                                 MPI_COMM_WORLD);
558 <                    }
559 <
560 <                    myPotato++;
561 <                }
562 <                    
563 <            }
564 <            
565 <        }
566 <        sprintf(checkPointMsg, "Sucessfully took a dump.\n");
567 <        MPIcheckPoint();
560 > #ifdef IS_MPI
561      }
562 + #endif // is_mpi    
563  
564 < #endif // is_mpi
564 >    writeFrame(*eorStream);
565  
572 }
573
574 void DumpWriter::writeDump() {
575    writeFrame(dumpFile_);
576
577 }
578
579 void DumpWriter::writeEor() {
580    std::ofstream eorStream;
581    
566   #ifdef IS_MPI
567      if (worldRank == 0) {
568   #endif // is_mpi
569 <
570 <        eorStream.open(eorFilename_.c_str());
587 <        if (!eorStream.is_open()) {
588 <            sprintf(painCave.errMsg, "DumpWriter : Could not open \"%s\" for writing.\n",
589 <                    eorFilename_.c_str());
590 <            painCave.isFatal = 1;
591 <            simError();
592 <        }
593 <
569 >      writeClosing(*eorStream);
570 >      delete eorStream;
571   #ifdef IS_MPI
572      }
573 < #endif // is_mpi    
573 > #endif // is_mpi  
574  
575 <    writeFrame(eorStream);
599 < }
575 >  }
576  
577  
578 < void DumpWriter::writeDumpAndEor() {
603 <    std::ofstream eorStream;
578 >  void DumpWriter::writeDumpAndEor() {
579      std::vector<std::streambuf*> buffers;
580 +    std::ostream* eorStream;
581   #ifdef IS_MPI
582      if (worldRank == 0) {
583   #endif // is_mpi
584  
585 <        buffers.push_back(dumpFile_.rdbuf());
585 >      buffers.push_back(dumpFile_->rdbuf());
586  
587 <        eorStream.open(eorFilename_.c_str());
612 <        if (!eorStream.is_open()) {
613 <            sprintf(painCave.errMsg, "DumpWriter : Could not open \"%s\" for writing.\n",
614 <                    eorFilename_.c_str());
615 <            painCave.isFatal = 1;
616 <            simError();
617 <        }
587 >      eorStream = createOStream(eorFilename_);
588  
589 <        buffers.push_back(eorStream.rdbuf());
589 >      buffers.push_back(eorStream->rdbuf());
590          
591   #ifdef IS_MPI
592      }
# Line 626 | Line 596 | void DumpWriter::writeDumpAndEor() {
596      std::ostream os(&tbuf);
597  
598      writeFrame(os);
599 +
600 + #ifdef IS_MPI
601 +    if (worldRank == 0) {
602 + #endif // is_mpi
603 +      writeClosing(*eorStream);
604 +      delete eorStream;
605 + #ifdef IS_MPI
606 +    }
607 + #endif // is_mpi  
608      
609 < }
609 >  }
610  
611 +  std::ostream* DumpWriter::createOStream(const std::string& filename) {
612  
613 +    std::ostream* newOStream;
614 + #ifdef HAVE_LIBZ
615 +    if (needCompression_) {
616 +      newOStream = new ogzstream(filename.c_str());
617 +    } else {
618 +      newOStream = new std::ofstream(filename.c_str());
619 +    }
620 + #else
621 +    newOStream = new std::ofstream(filename.c_str());
622 + #endif
623 +    //write out MetaData first
624 +    (*newOStream) << "<OpenMD version=2>" << std::endl;
625 +    (*newOStream) << "  <MetaData>" << std::endl;
626 +    (*newOStream) << info_->getRawMetaData();
627 +    (*newOStream) << "  </MetaData>" << std::endl;
628 +    return newOStream;
629 +  }
630  
631 < }//end namespace oopse
631 >  void DumpWriter::writeClosing(std::ostream& os) {
632 >
633 >    os << "</OpenMD>\n";
634 >    os.flush();
635 >  }
636 >
637 > }//end namespace OpenMD

Comparing:
trunk/src/io/DumpWriter.cpp (property svn:keywords), Revision 395 by tim, Thu Mar 3 14:40:20 2005 UTC vs.
branches/development/src/io/DumpWriter.cpp (property svn:keywords), Revision 1746 by gezelter, Wed Jun 6 02:18:54 2012 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines