| 42 | 
  | 
#include "io/DumpWriter.hpp" | 
| 43 | 
  | 
#include "primitives/Molecule.hpp" | 
| 44 | 
  | 
#include "utils/simError.h" | 
| 45 | 
< | 
 | 
| 45 | 
> | 
#include "io/basic_teebuf.hpp" | 
| 46 | 
  | 
#ifdef IS_MPI | 
| 47 | 
  | 
#include <mpi.h> | 
| 48 | 
  | 
#endif //is_mpi | 
| 49 | 
  | 
 | 
| 50 | 
  | 
namespace oopse { | 
| 51 | 
+ | 
 | 
| 52 | 
+ | 
DumpWriter::DumpWriter(SimInfo* info)  | 
| 53 | 
+ | 
                   : info_(info), filename_(info->getDumpFileName()), eorFilename_(info->getFinalConfigFileName()){ | 
| 54 | 
+ | 
#ifdef IS_MPI | 
| 55 | 
+ | 
 | 
| 56 | 
+ | 
    if (worldRank == 0) { | 
| 57 | 
+ | 
#endif // is_mpi | 
| 58 | 
+ | 
 | 
| 59 | 
+ | 
        dumpFile_.open(filename_.c_str(), std::ios::out | std::ios::trunc); | 
| 60 | 
+ | 
 | 
| 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 | 
+ | 
 | 
| 68 | 
+ | 
#ifdef IS_MPI | 
| 69 | 
+ | 
 | 
| 70 | 
+ | 
    } | 
| 71 | 
+ | 
 | 
| 72 | 
+ | 
    sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n"); | 
| 73 | 
+ | 
    MPIcheckPoint(); | 
| 74 | 
+ | 
 | 
| 75 | 
+ | 
#endif // is_mpi | 
| 76 | 
+ | 
 | 
| 77 | 
+ | 
} | 
| 78 | 
+ | 
 | 
| 79 | 
  | 
 | 
| 80 | 
  | 
DumpWriter::DumpWriter(SimInfo* info, const std::string& filename)  | 
| 81 | 
  | 
                   : info_(info), filename_(filename){ | 
| 84 | 
  | 
    if (worldRank == 0) { | 
| 85 | 
  | 
#endif // is_mpi | 
| 86 | 
  | 
 | 
| 87 | 
+ | 
        eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; | 
| 88 | 
  | 
        dumpFile_.open(filename_.c_str(), std::ios::out | std::ios::trunc); | 
| 89 | 
  | 
 | 
| 90 | 
  | 
        if (!dumpFile_) { | 
| 149 | 
  | 
         << eta(0, 1) << "\t" << eta(1, 1) << "\t" << eta(2, 1) << ";\t" | 
| 150 | 
  | 
         << eta(0, 2) << "\t" << eta(1, 2) << "\t" << eta(2, 2) << ";"; | 
| 151 | 
  | 
         | 
| 152 | 
< | 
    os << std::endl; | 
| 152 | 
> | 
    os << "\n"; | 
| 153 | 
  | 
} | 
| 154 | 
  | 
 | 
| 155 | 
  | 
void DumpWriter::writeFrame(std::ostream& os) { | 
| 212 | 
  | 
        } | 
| 213 | 
  | 
    } | 
| 214 | 
  | 
 | 
| 215 | 
+ | 
    os.flush(); | 
| 216 | 
  | 
#else // is_mpi | 
| 217 | 
  | 
    /********************************************************************* | 
| 218 | 
  | 
     * Documentation?  You want DOCUMENTATION? | 
| 258 | 
  | 
    int which_node; | 
| 259 | 
  | 
    double atomData[13]; | 
| 260 | 
  | 
    int isDirectional; | 
| 231 | 
– | 
    const char * atomTypeString; | 
| 261 | 
  | 
    char MPIatomTypeString[MINIBUFFERSIZE]; | 
| 262 | 
  | 
    int msgLen; // the length of message actually recieved at master nodes | 
| 263 | 
  | 
    int haveError; | 
| 328 | 
  | 
                    MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, | 
| 329 | 
  | 
                             which_node, myPotato, MPI_COMM_WORLD, | 
| 330 | 
  | 
                             &istatus); | 
| 302 | 
– | 
 | 
| 303 | 
– | 
                    atomTypeString = MPIatomTypeString; | 
| 331 | 
  | 
 | 
| 332 | 
  | 
                    myPotato++; | 
| 333 | 
  | 
 | 
| 346 | 
  | 
 | 
| 347 | 
  | 
                    if (!isDirectional) { | 
| 348 | 
  | 
                        sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", | 
| 349 | 
< | 
                                atomTypeString, atomData[0], | 
| 349 | 
> | 
                                MPIatomTypeString, atomData[0], | 
| 350 | 
  | 
                                atomData[1], atomData[2], | 
| 351 | 
  | 
                                atomData[3], atomData[4], | 
| 352 | 
  | 
                                atomData[5]); | 
| 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 | 
< | 
                                atomTypeString, | 
| 359 | 
> | 
                                MPIatomTypeString, | 
| 360 | 
  | 
                                atomData[0], | 
| 361 | 
  | 
                                atomData[1], | 
| 362 | 
  | 
                                atomData[2], | 
| 388 | 
  | 
                } | 
| 389 | 
  | 
                 | 
| 390 | 
  | 
                for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;  | 
| 391 | 
< | 
                    integrableObject = mol->nextIntegrableObject(ii)) { | 
| 365 | 
< | 
                         | 
| 366 | 
< | 
                    atomTypeString = integrableObject->getType().c_str(); | 
| 391 | 
> | 
                    integrableObject = mol->nextIntegrableObject(ii)) {       | 
| 392 | 
  | 
 | 
| 393 | 
  | 
                    pos = integrableObject->getPos(); | 
| 394 | 
  | 
                    vel = integrableObject->getVel(); | 
| 427 | 
  | 
 | 
| 428 | 
  | 
                    if (!isDirectional) { | 
| 429 | 
  | 
                        sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", | 
| 430 | 
< | 
                                atomTypeString, atomData[0], | 
| 430 | 
> | 
                                integrableObject->getType().c_str(), atomData[0], | 
| 431 | 
  | 
                                atomData[1], atomData[2], | 
| 432 | 
  | 
                                atomData[3], atomData[4], | 
| 433 | 
  | 
                                atomData[5]); | 
| 437 | 
  | 
                    } else { | 
| 438 | 
  | 
                        sprintf(writeLine, | 
| 439 | 
  | 
                                "%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", | 
| 440 | 
< | 
                                atomTypeString, | 
| 440 | 
> | 
                                integrableObject->getType().c_str(), | 
| 441 | 
  | 
                                atomData[0], | 
| 442 | 
  | 
                                atomData[1], | 
| 443 | 
  | 
                                atomData[2], | 
| 461 | 
  | 
        } //end for(i = 0; i < mpiSim->getNmol()) | 
| 462 | 
  | 
 | 
| 463 | 
  | 
        os.flush(); | 
| 464 | 
< | 
        std::cout << "master" << std::endl; | 
| 464 | 
> | 
         | 
| 465 | 
  | 
        sprintf(checkPointMsg, "Sucessfully took a dump.\n"); | 
| 441 | 
– | 
 | 
| 466 | 
  | 
        MPIcheckPoint(); | 
| 467 | 
  | 
 | 
| 468 | 
  | 
        delete [] potatoes; | 
| 510 | 
  | 
                                 &istatus); | 
| 511 | 
  | 
                    } | 
| 512 | 
  | 
 | 
| 489 | 
– | 
                    atomTypeString = integrableObject->getType().c_str(); | 
| 490 | 
– | 
 | 
| 513 | 
  | 
                    pos = integrableObject->getPos(); | 
| 514 | 
  | 
                    vel = integrableObject->getVel(); | 
| 515 | 
  | 
 | 
| 539 | 
  | 
                        atomData[12] = ji[2]; | 
| 540 | 
  | 
                    } | 
| 541 | 
  | 
 | 
| 542 | 
< | 
                    strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE); | 
| 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'; | 
| 563 | 
  | 
            } | 
| 564 | 
  | 
             | 
| 565 | 
  | 
        } | 
| 544 | 
– | 
        std::cout << "slave" << std::endl; | 
| 566 | 
  | 
        sprintf(checkPointMsg, "Sucessfully took a dump.\n"); | 
| 567 | 
  | 
        MPIcheckPoint(); | 
| 568 | 
  | 
    } | 
| 571 | 
  | 
 | 
| 572 | 
  | 
} | 
| 573 | 
  | 
 | 
| 574 | 
+ | 
void DumpWriter::writeDump() { | 
| 575 | 
+ | 
    writeFrame(dumpFile_); | 
| 576 | 
+ | 
 | 
| 577 | 
+ | 
} | 
| 578 | 
+ | 
 | 
| 579 | 
+ | 
void DumpWriter::writeEor() { | 
| 580 | 
+ | 
    std::ofstream eorStream; | 
| 581 | 
+ | 
     | 
| 582 | 
+ | 
#ifdef IS_MPI | 
| 583 | 
+ | 
    if (worldRank == 0) { | 
| 584 | 
+ | 
#endif // is_mpi | 
| 585 | 
+ | 
 | 
| 586 | 
+ | 
        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 | 
+ | 
 | 
| 594 | 
+ | 
#ifdef IS_MPI | 
| 595 | 
+ | 
    } | 
| 596 | 
+ | 
#endif // is_mpi     | 
| 597 | 
+ | 
 | 
| 598 | 
+ | 
    writeFrame(eorStream); | 
| 599 | 
+ | 
} | 
| 600 | 
+ | 
 | 
| 601 | 
+ | 
 | 
| 602 | 
+ | 
void DumpWriter::writeDumpAndEor() { | 
| 603 | 
+ | 
    std::ofstream eorStream; | 
| 604 | 
+ | 
    std::vector<std::streambuf*> buffers; | 
| 605 | 
+ | 
#ifdef IS_MPI | 
| 606 | 
+ | 
    if (worldRank == 0) { | 
| 607 | 
+ | 
#endif // is_mpi | 
| 608 | 
+ | 
 | 
| 609 | 
+ | 
        buffers.push_back(dumpFile_.rdbuf()); | 
| 610 | 
+ | 
 | 
| 611 | 
+ | 
        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 | 
+ | 
        } | 
| 618 | 
+ | 
 | 
| 619 | 
+ | 
        buffers.push_back(eorStream.rdbuf()); | 
| 620 | 
+ | 
         | 
| 621 | 
+ | 
#ifdef IS_MPI | 
| 622 | 
+ | 
    } | 
| 623 | 
+ | 
#endif // is_mpi     | 
| 624 | 
+ | 
 | 
| 625 | 
+ | 
    TeeBuf tbuf(buffers.begin(), buffers.end()); | 
| 626 | 
+ | 
    std::ostream os(&tbuf); | 
| 627 | 
+ | 
 | 
| 628 | 
+ | 
    writeFrame(os); | 
| 629 | 
+ | 
     | 
| 630 | 
+ | 
} | 
| 631 | 
+ | 
 | 
| 632 | 
+ | 
 | 
| 633 | 
+ | 
 | 
| 634 | 
  | 
}//end namespace oopse |