# | Line 43 | Line 43 | |
---|---|---|
43 | #include "primitives/Molecule.hpp" | |
44 | #include "utils/simError.h" | |
45 | #include "io/basic_teebuf.hpp" | |
46 | + | #include "io/gzstream.hpp" |
47 | + | #include "io/Globals.hpp" |
48 | + | |
49 | #ifdef IS_MPI | |
50 | #include <mpi.h> | |
51 | #endif //is_mpi | |
# | Line 51 | Line 54 | namespace oopse { | |
54 | ||
55 | DumpWriter::DumpWriter(SimInfo* info) | |
56 | : info_(info), filename_(info->getDumpFileName()), eorFilename_(info->getFinalConfigFileName()){ | |
57 | + | |
58 | + | Globals* simParams = info->getSimParams(); |
59 | + | needCompression_ = simParams->getCompressDumpFile(); |
60 | + | needForceVector_ = simParams->getOutputForceVector(); |
61 | + | |
62 | + | #ifdef HAVE_LIBZ |
63 | + | if (needCompression_) { |
64 | + | filename_ += ".gz"; |
65 | + | eorFilename_ += ".gz"; |
66 | + | } |
67 | + | #endif |
68 | + | |
69 | #ifdef IS_MPI | |
70 | ||
71 | if (worldRank == 0) { | |
72 | #endif // is_mpi | |
73 | ||
59 | – | dumpFile_.open(filename_.c_str(), std::ios::out | std::ios::trunc); |
74 | ||
75 | + | dumpFile_ = createOStream(filename_); |
76 | + | |
77 | if (!dumpFile_) { | |
78 | sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", | |
79 | filename_.c_str()); | |
# | Line 79 | Line 95 | namespace oopse { | |
95 | ||
96 | DumpWriter::DumpWriter(SimInfo* info, const std::string& filename) | |
97 | : info_(info), filename_(filename){ | |
98 | + | |
99 | + | Globals* simParams = info->getSimParams(); |
100 | + | eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; |
101 | + | |
102 | + | needCompression_ = simParams->getCompressDumpFile(); |
103 | + | needForceVector_ = simParams->getOutputForceVector(); |
104 | + | |
105 | + | #ifdef HAVE_LIBZ |
106 | + | if (needCompression_) { |
107 | + | filename_ += ".gz"; |
108 | + | eorFilename_ += ".gz"; |
109 | + | } |
110 | + | #endif |
111 | + | |
112 | #ifdef IS_MPI | |
113 | ||
114 | if (worldRank == 0) { | |
115 | #endif // is_mpi | |
116 | ||
87 | – | eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; |
88 | – | dumpFile_.open(filename_.c_str(), std::ios::out | std::ios::trunc); |
117 | ||
118 | + | dumpFile_ = createOStream(filename_); |
119 | + | |
120 | if (!dumpFile_) { | |
121 | sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", | |
122 | filename_.c_str()); | |
# | Line 112 | Line 142 | namespace oopse { | |
142 | if (worldRank == 0) { | |
143 | #endif // is_mpi | |
144 | ||
145 | < | dumpFile_.close(); |
145 | > | delete dumpFile_; |
146 | ||
147 | #ifdef IS_MPI | |
148 | ||
# | Line 163 | Line 193 | namespace oopse { | |
193 | Vector3d ji; | |
194 | Vector3d pos; | |
195 | Vector3d vel; | |
196 | + | Vector3d frc; |
197 | + | Vector3d trq; |
198 | ||
199 | Molecule* mol; | |
200 | StuntDouble* integrableObject; | |
# | Line 199 | Line 231 | namespace oopse { | |
231 | q = integrableObject->getQ(); | |
232 | ji = integrableObject->getJ(); | |
233 | ||
234 | < | sprintf(tempBuffer, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
234 | > | sprintf(tempBuffer, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", |
235 | q[0], q[1], q[2], q[3], | |
236 | ji[0], ji[1], ji[2]); | |
237 | strcat(writeLine, tempBuffer); | |
238 | } else { | |
239 | < | strcat(writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n"); |
239 | > | strcat(writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0"); |
240 | } | |
241 | ||
242 | + | if (needForceVector_) { |
243 | + | frc = integrableObject->getFrc(); |
244 | + | trq = integrableObject->getTrq(); |
245 | + | |
246 | + | sprintf(tempBuffer, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", |
247 | + | frc[0], frc[1], frc[2], |
248 | + | trq[0], trq[1], trq[2]); |
249 | + | strcat(writeLine, tempBuffer); |
250 | + | } |
251 | + | |
252 | + | strcat(writeLine, "\n"); |
253 | os << writeLine; | |
254 | ||
255 | } | |
# | Line 256 | Line 299 | namespace oopse { | |
299 | int myPotato; | |
300 | int nProc; | |
301 | int which_node; | |
302 | < | double atomData[13]; |
302 | > | double atomData[19]; |
303 | int isDirectional; | |
304 | char MPIatomTypeString[MINIBUFFERSIZE]; | |
305 | int msgLen; // the length of message actually recieved at master nodes | |
# | Line 331 | Line 374 | namespace oopse { | |
374 | ||
375 | myPotato++; | |
376 | ||
377 | < | MPI_Recv(atomData, 13, MPI_DOUBLE, which_node, myPotato, |
377 | > | MPI_Recv(atomData, 19, MPI_DOUBLE, which_node, myPotato, |
378 | MPI_COMM_WORLD, &istatus); | |
379 | myPotato++; | |
380 | ||
381 | MPI_Get_count(&istatus, MPI_DOUBLE, &msgLen); | |
382 | ||
383 | < | if (msgLen == 13) |
383 | > | if (msgLen == 13 || msgLen == 19) |
384 | isDirectional = 1; | |
385 | else | |
386 | isDirectional = 0; | |
# | Line 352 | Line 395 | namespace oopse { | |
395 | atomData[5]); | |
396 | ||
397 | strcat(writeLine, | |
398 | < | "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n"); |
398 | > | "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0"); |
399 | } else { | |
400 | sprintf(writeLine, | |
401 | < | "%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", |
401 | > | "%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", |
402 | MPIatomTypeString, | |
403 | atomData[0], | |
404 | atomData[1], | |
# | Line 371 | Line 414 | namespace oopse { | |
414 | atomData[11], | |
415 | atomData[12]); | |
416 | } | |
417 | + | |
418 | + | if (needForceVector_) { |
419 | + | if (!isDirectional) { |
420 | + | sprintf(writeLine, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", |
421 | + | atomData[6], |
422 | + | atomData[7], |
423 | + | atomData[8], |
424 | + | atomData[9], |
425 | + | atomData[10], |
426 | + | atomData[11]); |
427 | + | } else { |
428 | + | sprintf(writeLine, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", |
429 | + | atomData[13], |
430 | + | atomData[14], |
431 | + | atomData[15], |
432 | + | atomData[16], |
433 | + | atomData[17], |
434 | + | atomData[18]); |
435 | + | } |
436 | + | } |
437 | ||
438 | + | sprintf(writeLine, "\n"); |
439 | os << writeLine; | |
440 | ||
441 | } // end for(int l =0) | |
# | Line 423 | Line 487 | namespace oopse { | |
487 | atomData[12] = ji[2]; | |
488 | } | |
489 | ||
490 | + | if (needForceVector_) { |
491 | + | frc = integrableObject->getFrc(); |
492 | + | trq = integrableObject->getTrq(); |
493 | + | |
494 | + | if (!isDirectional) { |
495 | + | atomData[6] = frc[0]; |
496 | + | atomData[7] = frc[1]; |
497 | + | atomData[8] = frc[2]; |
498 | + | atomData[9] = trq[0]; |
499 | + | atomData[10] = trq[1]; |
500 | + | atomData[11] = trq[2]; |
501 | + | } else { |
502 | + | atomData[13] = frc[0]; |
503 | + | atomData[14] = frc[1]; |
504 | + | atomData[15] = frc[2]; |
505 | + | atomData[16] = trq[0]; |
506 | + | atomData[17] = trq[1]; |
507 | + | atomData[18] = trq[2]; |
508 | + | } |
509 | + | } |
510 | + | |
511 | // If we've survived to here, format the line: | |
512 | ||
513 | if (!isDirectional) { | |
# | Line 433 | Line 518 | namespace oopse { | |
518 | atomData[5]); | |
519 | ||
520 | strcat(writeLine, | |
521 | < | "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n"); |
521 | > | "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0"); |
522 | } else { | |
523 | sprintf(writeLine, | |
524 | < | "%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", |
524 | > | "%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", |
525 | integrableObject->getType().c_str(), | |
526 | atomData[0], | |
527 | atomData[1], | |
# | Line 453 | Line 538 | namespace oopse { | |
538 | atomData[12]); | |
539 | } | |
540 | ||
541 | + | if (needForceVector_) { |
542 | + | if (!isDirectional) { |
543 | + | sprintf(writeLine, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", |
544 | + | atomData[6], |
545 | + | atomData[7], |
546 | + | atomData[8], |
547 | + | atomData[9], |
548 | + | atomData[10], |
549 | + | atomData[11]); |
550 | + | } else { |
551 | + | sprintf(writeLine, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", |
552 | + | atomData[13], |
553 | + | atomData[14], |
554 | + | atomData[15], |
555 | + | atomData[16], |
556 | + | atomData[17], |
557 | + | atomData[18]); |
558 | + | } |
559 | + | } |
560 | ||
561 | + | sprintf(writeLine, "\n"); |
562 | os << writeLine; | |
563 | ||
564 | } //end for(iter = integrableObject.begin()) | |
# | Line 539 | Line 644 | namespace oopse { | |
644 | atomData[12] = ji[2]; | |
645 | } | |
646 | ||
647 | + | if (needForceVector_) { |
648 | + | frc = integrableObject->getFrc(); |
649 | + | trq = integrableObject->getTrq(); |
650 | + | |
651 | + | if (!isDirectional) { |
652 | + | atomData[6] = frc[0]; |
653 | + | atomData[7] = frc[1]; |
654 | + | atomData[8] = frc[2]; |
655 | + | |
656 | + | atomData[9] = trq[0]; |
657 | + | atomData[10] = trq[1]; |
658 | + | atomData[11] = trq[2]; |
659 | + | } else { |
660 | + | atomData[13] = frc[0]; |
661 | + | atomData[14] = frc[1]; |
662 | + | atomData[15] = frc[2]; |
663 | + | |
664 | + | atomData[16] = trq[0]; |
665 | + | atomData[17] = trq[1]; |
666 | + | atomData[18] = trq[2]; |
667 | + | } |
668 | + | } |
669 | + | |
670 | strncpy(MPIatomTypeString, integrableObject->getType().c_str(), MINIBUFFERSIZE); | |
671 | ||
672 | // null terminate the std::string before sending (just in case): | |
# | Line 549 | Line 677 | namespace oopse { | |
677 | ||
678 | myPotato++; | |
679 | ||
680 | < | if (isDirectional) { |
680 | > | if (isDirectional && needForceVector_) { |
681 | > | MPI_Send(atomData, 19, MPI_DOUBLE, 0, myPotato, |
682 | > | MPI_COMM_WORLD); |
683 | > | } else if (isDirectional) { |
684 | MPI_Send(atomData, 13, MPI_DOUBLE, 0, myPotato, | |
685 | MPI_COMM_WORLD); | |
686 | + | } else if (needForceVector_) { |
687 | + | MPI_Send(atomData, 12, MPI_DOUBLE, 0, myPotato, |
688 | + | MPI_COMM_WORLD); |
689 | } else { | |
690 | MPI_Send(atomData, 6, MPI_DOUBLE, 0, myPotato, | |
691 | MPI_COMM_WORLD); | |
# | Line 572 | Line 706 | namespace oopse { | |
706 | } | |
707 | ||
708 | void DumpWriter::writeDump() { | |
709 | < | writeFrame(dumpFile_); |
576 | < | |
709 | > | writeFrame(*dumpFile_); |
710 | } | |
711 | ||
712 | void DumpWriter::writeEor() { | |
713 | < | std::ofstream eorStream; |
713 | > | std::ostream* eorStream; |
714 | ||
715 | #ifdef IS_MPI | |
716 | if (worldRank == 0) { | |
717 | #endif // is_mpi | |
718 | ||
719 | < | 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 | < | } |
719 | > | eorStream = createOStream(eorFilename_); |
720 | ||
721 | #ifdef IS_MPI | |
722 | } | |
723 | #endif // is_mpi | |
724 | ||
725 | < | writeFrame(eorStream); |
725 | > | writeFrame(*eorStream); |
726 | > | |
727 | > | #ifdef IS_MPI |
728 | > | if (worldRank == 0) { |
729 | > | #endif // is_mpi |
730 | > | delete eorStream; |
731 | > | |
732 | > | #ifdef IS_MPI |
733 | > | } |
734 | > | #endif // is_mpi |
735 | > | |
736 | } | |
737 | ||
738 | ||
739 | void DumpWriter::writeDumpAndEor() { | |
603 | – | std::ofstream eorStream; |
740 | std::vector<std::streambuf*> buffers; | |
741 | + | std::ostream* eorStream; |
742 | #ifdef IS_MPI | |
743 | if (worldRank == 0) { | |
744 | #endif // is_mpi | |
745 | ||
746 | < | buffers.push_back(dumpFile_.rdbuf()); |
746 | > | buffers.push_back(dumpFile_->rdbuf()); |
747 | ||
748 | < | 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 | < | } |
748 | > | eorStream = createOStream(eorFilename_); |
749 | ||
750 | < | buffers.push_back(eorStream.rdbuf()); |
750 | > | buffers.push_back(eorStream->rdbuf()); |
751 | ||
752 | #ifdef IS_MPI | |
753 | } | |
# | Line 626 | Line 757 | namespace oopse { | |
757 | std::ostream os(&tbuf); | |
758 | ||
759 | writeFrame(os); | |
760 | + | |
761 | + | #ifdef IS_MPI |
762 | + | if (worldRank == 0) { |
763 | + | #endif // is_mpi |
764 | + | delete eorStream; |
765 | + | |
766 | + | #ifdef IS_MPI |
767 | + | } |
768 | + | #endif // is_mpi |
769 | ||
770 | } | |
771 | ||
772 | + | std::ostream* DumpWriter::createOStream(const std::string& filename) { |
773 | ||
774 | + | std::ostream* newOStream; |
775 | + | #ifdef HAVE_LIBZ |
776 | + | if (needCompression_) { |
777 | + | newOStream = new ogzstream(filename.c_str()); |
778 | + | } else { |
779 | + | newOStream = new std::ofstream(filename.c_str()); |
780 | + | } |
781 | + | #else |
782 | + | newOStream = new std::ofstream(filename.c_str()); |
783 | + | #endif |
784 | + | return newOStream; |
785 | + | } |
786 | ||
787 | }//end namespace oopse |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |