Changeset 9861d0 for src


Ignore:
Timestamp:
Apr 10, 2018, 6:43:30 AM (7 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
AutomationFragmentation_failures, Candidate_v1.6.1, ChemicalSpaceEvaluator, Exclude_Hydrogens_annealWithBondGraph, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_contraction-expansion, Gui_displays_atomic_force_velocity, PythonUI_with_named_parameters, StoppableMakroAction, TremoloParser_IncreasedPrecision
Children:
825d33
Parents:
2f3905
git-author:
Frederik Heber <frederik.heber@…> (06/29/17 14:40:12)
git-committer:
Frederik Heber <frederik.heber@…> (04/10/18 06:43:30)
Message:

BondVectors now return subset of BondVectors for a given atom.

  • functionality extracted from ForceAnnealing::annealWithBondgraph().
  • also the mapped_t type is now kept up-to-date internally as we need it for returning the subset efficiently over a number of atoms, e.g. all in the given range.
  • also moved a few simple implementations over to _impl module.
Location:
src/Dynamics
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Dynamics/BondVectors.cpp

    r2f3905 r9861d0  
    4141#include <iterator>
    4242
     43#include "CodePatterns/Assert.hpp"
     44#include "CodePatterns/Log.hpp"
     45
    4346#include "Atom/atom.hpp"
     47#include "Bond/bond.hpp"
    4448
    45 BondVectors::mapped_t BondVectors::getBondVectorsAtStep(
     49void BondVectors::recalculateBondVectorsAtStep(
    4650    const size_t &_step) const
    4751{
    48   mapped_t returnlist;
     52  current_mapped_vectors.clear();
    4953
    5054  ASSERT( !container.empty(),
     
    5660        - current_bond->rightatom->getPositionAtStep(_step);
    5761    BondVector.Normalize();
    58     returnlist.insert( std::make_pair(current_bond, BondVector) );
     62    current_mapped_vectors.insert( std::make_pair(current_bond, BondVector) );
    5963  }
    60   ASSERT( returnlist.size() == container.size(),
     64  ASSERT( current_mapped_vectors.size() == container.size(),
    6165      "BondVectors::getBondVectors() - not same amount of bond vectors as bonds?");
    6266
    63   return returnlist;
     67  map_is_dirty = false;
     68  current_step_for_map = _step;
    6469}
    6570
     
    7681}
    7782
     83std::vector<Vector> BondVectors::getAtomsBondVectorsAtStep(
     84    const atom &_walker,
     85    const size_t &_step) const
     86{
     87  if (map_is_dirty || (current_step_for_map != _step))
     88    recalculateBondVectorsAtStep(_step);
     89
     90  std::vector<Vector> BondVectors;
     91  // gather subset of BondVectors for the current atom
     92  const BondList& ListOfBonds = _walker.getListOfBonds();
     93  for(BondList::const_iterator bonditer = ListOfBonds.begin();
     94      bonditer != ListOfBonds.end(); ++bonditer) {
     95    const bond::ptr &current_bond = *bonditer;
     96    const BondVectors::mapped_t::const_iterator bviter =
     97        current_mapped_vectors.find(current_bond);
     98    ASSERT( bviter != current_mapped_vectors.end(),
     99        "ForceAnnealing() - cannot find current_bond ?");
     100    ASSERT( bviter != current_mapped_vectors.end(),
     101        "ForceAnnealing - cannot find current bond "+toString(*current_bond)
     102        +" in bonds.");
     103    BondVectors.push_back(bviter->second);
     104  }
     105  LOG(4, "DEBUG: BondVectors for atom #" << _walker.getId() << ": " << BondVectors);
     106
     107  return BondVectors;
     108}
  • src/Dynamics/BondVectors.hpp

    r2f3905 r9861d0  
    3737  typedef std::map<bond::ptr, Vector> mapped_t;
    3838
     39  /** Default cstor for class BondVectors.
     40   *
     41   */
     42  BondVectors();
     43
    3944  /** Prepares the internal container from the bonds of a range of atoms.
    4045   *
     
    5358   * \return const ref to internal container
    5459   */
    55   const container_t& getSorted() const
    56   {
    57     ASSERT( !container.empty(),
    58         "BondVectors::getSorted() - empty internal container, not set properly?");
    59     return container;
    60   }
     60  const container_t& getSorted() const;
    6161
    62   /** Calculates the bond vector for each bond in the internal container and
    63    * returns them in same order as the internal container.
     62  /** Getter for the Bondvectors.
    6463   *
    6564   * \param _step time step for which the bond vector is request
    6665   * \return a map from bond to bond vector
    6766   */
    68   mapped_t getBondVectorsAtStep(const size_t &_step) const;
     67  const mapped_t& getBondVectorsAtStep(const size_t &_step) const;
    6968
    7069  /** Get the position in the internal container for a specific bond.
     
    7574  size_t getIndexForBond(const bond::ptr &_bond) const;
    7675
     76  /** Gather the subset of BondVectors for the given atom.
     77   *
     78   * \param _walker atom to get BondVectors for
     79   * \param _step time step for which the bond vector is request
     80   */
     81  std::vector<Vector> getAtomsBondVectorsAtStep(
     82      const atom &_walker,
     83      const size_t &_step) const;
     84
     85private:
     86  /** Calculates the bond vector for each bond in the internal container.
     87   *
     88   * \param _step time step for which the bond vector is request
     89   */
     90  void recalculateBondVectorsAtStep(const size_t &_step) const;
     91
    7792private:
    7893  //!> internal container for sorted bonds
    7994  container_t container;
     95
     96  //!> states whether map needs update or not
     97  mutable bool map_is_dirty;
     98
     99  //!> contains the step for which the map was calculated
     100  mutable size_t current_step_for_map;
     101
     102  //!> internal map for bond Bondvector association
     103  mutable mapped_t current_mapped_vectors;
    80104};
    81105
  • src/Dynamics/BondVectors_impl.hpp

    r2f3905 r9861d0  
    2121#include "Atom/atom.hpp"
    2222
     23BondVectors::BondVectors() :
     24  map_is_dirty(false),
     25  current_step_for_map((size_t)-1)
     26{}
     27
    2328template <class T>
    2429void BondVectors::setFromAtomRange(
     
    3641  std::sort(container.begin(), container.end());
    3742  container.erase(std::unique(container.begin(), container.end()), container.end());
     43  map_is_dirty = true;
    3844}
    3945
     46const BondVectors::mapped_t&
     47BondVectors::getBondVectorsAtStep(const size_t &_step) const
     48{
     49  if (map_is_dirty || (current_step_for_map != _step))
     50    recalculateBondVectorsAtStep(_step);
     51  return current_mapped_vectors;
     52}
     53
     54const BondVectors::container_t&
     55BondVectors::getSorted() const
     56{
     57  ASSERT( !container.empty(),
     58      "BondVectors::getSorted() - empty internal container, not set properly?");
     59  return container;
     60}
    4061
    4162#endif /* DYNAMICS_BONDVECTORS_IMPL_HPP_ */
  • src/Dynamics/ForceAnnealing.hpp

    r2f3905 r9861d0  
    301301          << ", and CurrentStep is " << CurrentStep);
    302302
    303       // get all bond vectors for this time step (from the perspective of the
    304       // bonds taken from the currentStep)
    305       const BondVectors::mapped_t bondvectors = bv.getBondVectorsAtStep(CurrentStep);
    306 
    307303      for(typename AtomSetMixin<T>::const_iterator iter = AtomicForceManipulator<T>::atoms.begin();
    308304          iter != AtomicForceManipulator<T>::atoms.end(); ++iter) {
     
    317313
    318314          // gather subset of BondVectors for the current atom
    319           std::vector<Vector> BondVectors;
    320           for(BondList::const_iterator bonditer = ListOfBonds.begin();
    321               bonditer != ListOfBonds.end(); ++bonditer) {
    322             const bond::ptr &current_bond = *bonditer;
    323             const BondVectors::mapped_t::const_iterator bviter =
    324                 bondvectors.find(current_bond);
    325             ASSERT( bviter != bondvectors.end(),
    326                 "ForceAnnealing() - cannot find current_bond ?");
    327             ASSERT( bviter != bondvectors.end(),
    328                 "ForceAnnealing - cannot find current bond "+toString(*current_bond)
    329                 +" in bonds.");
    330             BondVectors.push_back(bviter->second);
    331           }
    332           LOG(4, "DEBUG: BondVectors for atom #" << walker.getId() << ": " << BondVectors);
     315          std::vector<Vector> BondVectors = bv.getAtomsBondVectorsAtStep(walker, CurrentStep);
    333316
    334317          // go through all its bonds and calculate what magnitude is represented
Note: See TracChangeset for help on using the changeset viewer.