Changeset efc80e for src


Ignore:
Timestamp:
Jul 3, 2017, 3:07:28 PM (7 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
ForceAnnealing_oldresults, IndependentFragmentGrids_IntegrationTest
Children:
ef8667
Parents:
95b64f
git-author:
Frederik Heber <frederik.heber@…> (06/17/17 21:31:42)
git-committer:
Frederik Heber <frederik.heber@…> (07/03/17 15:07:28)
Message:

TremoloParser::load() can deal with multiple time steps.

  • TESTS: Added regression test case.
  • ATOMDATA needs to be the same. Check by regression test case.
  • TESTS: set to XFAIL for the moment due to missing save() implementation for multiple time steps.
Location:
src/Parser
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/TremoloParser.cpp

    r95b64f refc80e  
    143143  molecule *newmol = World::getInstance().createMolecule();
    144144  newmol->ActiveFlag = true;
     145  usedFields_t usedFields_temp;
     146  size_t timestep = 0;
     147  atom *addedatom = NULL;
     148  std::vector<atom *> addedatoms;
     149  std::vector<atom *>::iterator atomiter = addedatoms.begin();
    145150  while (file->good()) {
    146151    std::getline(*file, line, '\n');
    147152    // we only parse in the first ATOMDATA line
    148     if (usedFields_load.empty()) {
    149       location = line.find("ATOMDATA", 0);
    150       if (location != string::npos) {
    151        parseAtomDataKeysLine(line, location + 8, usedFields_load);
     153    location = line.find("ATOMDATA", 0);
     154    if (location != string::npos) {
     155      parseAtomDataKeysLine(line, location + 8, usedFields_temp);
     156      if (usedFields_load.empty()) {
     157        // first ATOMDATA: use this line
     158        usedFields_load.insert(usedFields_load.end(), usedFields_temp.begin(), usedFields_temp.end());
     159        usedFields_temp.clear();
     160        LOG(3, "DEBUG: Local usedFields is: " << usedFields_load);
     161      } else {
     162        // following ATOMDATA: check against present
     163        LOG(3, "DEBUG: Parsed check usedFields is: " << usedFields_temp);
     164        if (usedFields_load != usedFields_temp) {
     165          ELOG(1, "File contains multiple time steps with differing ATOMDATA line, parsing only first time step.");
     166          break;
     167        } else {
     168          // update time step
     169          ++timestep;
     170          atomiter = addedatoms.begin();
     171        }
     172      }
     173    } else {
     174      if (line.length() > 0 && line.at(0) != '#') {
     175        if (timestep != 0) {
     176          ASSERT( atomiter != addedatoms.end(),
     177              "FormatParser< tremolo >::load() - timesteps contains more atoms than first one.");
     178          addedatom = *atomiter++;
     179        }
     180        readAtomDataLine(line, newmol, timestep, addedatom);
     181        if (timestep == 0)
     182          addedatoms.push_back(addedatom);
    152183      }
    153184    }
    154     if (line.length() > 0 && line.at(0) != '#') {
    155       readAtomDataLine(line, newmol);
    156     }
    157   }
    158   LOG(3, "DEBUG: Local usedFields is: " << usedFields_load);
     185  }
     186  ASSERT( addedatoms.size() == newmol->size(),
     187      "FormatParser< tremolo >::load() - number of atoms in mol and addedatoms differ.");
    159188
    160189  // refresh atom::nr and atom::name
     
    692721 * \param line to parse as an atom
    693722 * \param *newmol molecule to add atom to
    694  */
    695 void FormatParser< tremolo >::readAtomDataLine(const std::string &line, molecule *newmol) {
     723 * \param _timestep time step to parse to
     724 * \param _addedatom ref to added atom
     725 */
     726void FormatParser< tremolo >::readAtomDataLine(
     727    const std::string &line,
     728    molecule *newmol,
     729    const size_t _timestep,
     730    atom *&_addedatoms)
     731{
    696732  std::stringstream lineStream;
    697   atom* newAtom = World::getInstance().createAtom();
    698   const atomId_t atomid = newAtom->getId();
    699   additionalAtomData[atomid] = TremoloAtomInfoContainer(); // fill with default values
     733  atom* newAtom = NULL;
     734  atomId_t atomid = -1;
     735  if (_timestep == 0) {
     736    newAtom = World::getInstance().createAtom();
     737    _addedatoms = newAtom;
     738    atomid = newAtom->getId();
     739    additionalAtomData[atomid] = TremoloAtomInfoContainer(); // fill with default values
     740  } else {
     741    newAtom = _addedatoms;
     742    atomid = newAtom->getId();
     743  }
    700744  TremoloAtomInfoContainer *atomInfo = &additionalAtomData[atomid];
    701745  TremoloKey::atomDataKey currentField;
     
    727771        for (int i=0;i<NDIM;i++) {
    728772          ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for x["+toString(i)+"]!");
    729           LOG(4, "INFO: Parsing key " << keyName << " with next token " << word);
    730           newAtom->set(i, toDouble(word));
     773          LOG(4, "INFO: Parsing key " << keyName << " with next token " << word << " on step " << _timestep);
     774          newAtom->setAtStep(i, _timestep, toDouble(word));
    731775          tok_iter++;
    732776        }
     
    736780        for (int i=0;i<NDIM;i++) {
    737781          ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for u["+toString(i)+"]!");
    738           LOG(4, "INFO: Parsing key " << keyName << " with next token " << word);
     782          LOG(4, "INFO: Parsing key " << keyName << " with next token " << word << " on step " << _timestep);
    739783          tempVector[i] = toDouble(word);
    740784          tok_iter++;
    741785        }
    742         newAtom->setAtomicVelocity(tempVector);
     786        newAtom->setAtomicVelocityAtStep(_timestep, tempVector);
    743787        break;
    744788      case TremoloKey::F :
     
    746790        for (int i=0;i<NDIM;i++) {
    747791          ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for F["+toString(i)+"]!");
    748           LOG(4, "INFO: Parsing key " << keyName << " with next token " << word);
     792          LOG(4, "INFO: Parsing key " << keyName << " with next token " << word << " on step " << _timestep);
    749793          tempVector[i] = toDouble(word);
    750794          tok_iter++;
    751795        }
    752         newAtom->setAtomicForce(tempVector);
     796        newAtom->setAtomicForceAtStep(_timestep, tempVector);
    753797        break;
    754798      case TremoloKey::type :
    755799      {
    756800        ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!");
    757         LOG(4, "INFO: Parsing key " << keyName << " with next token " << word);
     801        LOG(4, "INFO: Parsing key " << keyName << " with next token " << word << " on step " << _timestep);
    758802        std::string elementname;
    759803        const element * elem = NULL;
     
    787831      case TremoloKey::Id :
    788832        ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!");
    789         LOG(4, "INFO: Parsing key " << keyName << " with next token " << word);
    790         associateLocaltoGlobalId(toInt(word), atomid);
     833        LOG(4, "INFO: Parsing key " << keyName << " with next token " << word << " on step " << _timestep);
     834        if (_timestep == 0) {
     835          associateLocaltoGlobalId(toInt(word), atomid);
     836        } else {
     837          // check association is the same
     838          ASSERT( (atomId_t)getGlobalId(toInt(word)) == atomid,
     839              "FormatParser< tremolo >::readAtomDataLine() - differing global id "+toString(atomid)
     840              +" on timestep "+toString(_timestep));
     841          ASSERT( getLocalId(atomid) == toInt(word),
     842              "FormatParser< tremolo >::readAtomDataLine() - differing local id "+toString(toInt(word))
     843              +" on timestep "+toString(_timestep));
     844        }
    791845        tok_iter++;
    792846        break;
    793847      case TremoloKey::neighbors :
    794848        for (int i=0;i<atoi(it->substr(it->find("=") + 1, 1).c_str());i++) {
    795           ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!");
    796           LOG(4, "INFO: Parsing key " << keyName << " with next token " << word);
     849          ASSERT(tok_iter != tokens.end(),
     850              "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!");
     851          if (_timestep == 0)
     852            LOG(4, "INFO: Parsing key " << keyName << " with next token " << word << " on step " << _timestep);
    797853          lineStream << word << "\t";
    798854          tok_iter++;
    799855        }
    800         readNeighbors(&lineStream,
    801             atoi(it->substr(it->find("=") + 1, 1).c_str()), atomid);
     856        if (_timestep == 0) {
     857          readNeighbors(&lineStream,
     858              atoi(it->substr(it->find("=") + 1, 1).c_str()), atomid);
     859        }
    802860        break;
    803861      case TremoloKey::charge :
    804862        ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!");
    805         LOG(4, "INFO: Parsing key " << keyName << " with next token " << word);
    806         atomInfo->set(currentField, word);
    807         newAtom->setCharge(boost::lexical_cast<double>(word));
     863        if (_timestep == 0) {
     864          LOG(4, "INFO: Parsing key " << keyName << " with next token " << word << " on step " << _timestep);
     865          atomInfo->set(currentField, word);
     866          newAtom->setCharge(boost::lexical_cast<double>(word));
     867        }
    808868        tok_iter++;
    809869        break;
    810870      default :
    811871        ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!");
    812         LOG(4, "INFO: Parsing key " << keyName << " with next token " << word);
    813         atomInfo->set(currentField, word);
     872        if (_timestep == 0) {
     873          LOG(4, "INFO: Parsing key " << keyName << " with next token " << word << " on step " << _timestep);
     874          atomInfo->set(currentField, word);
     875        }
    814876        tok_iter++;
    815877        break;
  • src/Parser/TremoloParser.hpp

    r95b64f refc80e  
    8080  typedef std::vector<std::string> usedFields_t;
    8181
    82   void readAtomDataLine(const std::string &line, molecule *newmol);
     82  void readAtomDataLine(
     83      const std::string &line,
     84      molecule *newmol,
     85      const size_t _timestep,
     86      atom *&_addedatoms);
    8387  void parseAtomDataKeysLine(const std::string &line, const int offset, usedFields_t &fields);
    8488  static bool testParseAtomDataKeysLine(const std::string &line);
Note: See TracChangeset for help on using the changeset viewer.