Changeset b97a60 for src


Ignore:
Timestamp:
Feb 17, 2012, 3:24:18 PM (13 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
7d46e3
Parents:
3867a7
git-author:
Frederik Heber <heber@…> (01/06/12 14:37:36)
git-committer:
Frederik Heber <heber@…> (02/17/12 15:24:18)
Message:

Modified IdPool implementation to give either unique or continuous ids.

  • added two class uniqueId and continuousId that get the id type via a template and contain a getNextId_impl(). Also, contains typedef is is_IdPool_trait:
    • uniqueId always return a greater id.
    • continuousId implements the old way.
  • IdPool is now based on two templates, the second is the template that is inherited and its contained function used in getNextId().
  • for atoms the id is the sole identifier for which we can guarantee uniqueness. For molecules uniqueness does not make sense.
  • updated World's documentation on its id pools.
  • TESTFIX: Filling/FillVoidWithMolecule - both changed because the order of the ids has changed. In one case the bonding id flipped, in the other one atom changed places in .xyz file. (Actually, it's surprising that this is the only glitch occuring due to the changing of the id policy).
Location:
src
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • src/IdPool.hpp

    r3867a7 rb97a60  
    2626 * that stores the id).
    2727 *
     28 * Note that the external class \a idpolicy decides upon how the next id is
     29 * produced, \sa IdPool_policy.hpp.
    2830 */
    29 template <class T>
    30 class IdPool {
     31template <class T, class idpolicy>
     32class IdPool : public idpolicy {
     33  // when trait is not of correct type this will produce an error
     34  typedef typename idpolicy::is_IdPool_policy check_for_IdPool_trait;
    3135public:
    3236  /** Constructor for class IdPool.
     
    4347  ~IdPool();
    4448
    45   /** Returns the next available id.
    46    *
    47    * @return free id that is reserved
    48    */
    49   T getNextId();
    50 
    5149  /** Reserves a specific \a id.
    5250   *
     
    6159   */
    6260  void releaseId(T id);
     61
     62  /** Returns the next available id.
     63   *
     64   * @return free id that is reserved
     65   */
     66  T getNextId();
    6367
    6468private:
  • src/IdPool_impl.hpp

    r3867a7 rb97a60  
    1818#include "CodePatterns/Log.hpp"
    1919
    20 template <class T>
    21 IdPool<T>::IdPool(const T _currId, const unsigned int _max_skips, const unsigned int _max_size) :
     20template <class T, class idpolicy>
     21IdPool<T,idpolicy>::IdPool(const T _currId, const unsigned int _max_skips, const unsigned int _max_size) :
    2222  lastAction(NoAction),
    2323  currId(_currId),
     
    2828{}
    2929
    30 template <class T>
    31 IdPool<T>::~IdPool()
     30template <class T, class idpolicy>
     31IdPool<T,idpolicy>::~IdPool()
    3232{}
    3333
    34 template <class T>
    35 T IdPool<T>::getNextId()
     34template <class T, class idpolicy>
     35T IdPool<T,idpolicy>::getNextId()
    3636{
    3737  setLastAction(reserve);
    38   // try to find an Id in the pool;
    39   if(!pool.empty()) {
    40     typename IdPool_t::iterator iter=pool.begin();
    41     T id = iter->first;
    42     range<T> newRange = makeRange(id+1,iter->last);
    43     // we wont use this iterator anymore, so we don't care about invalidating
    44     pool.erase(iter);
    45     if(newRange.first<newRange.last)
    46       pool.insert(newRange);
    47     return id;
    48   }
    49   // Nothing in the pool... we are out of luck
    50   return currId++;
     38  return idpolicy::getNextId_impl(pool, currId);
    5139}
    5240
    53 template <class T>
    54 void IdPool<T>::releaseId(T id)
     41template <class T, class idpolicy>
     42void IdPool<T,idpolicy>::releaseId(T id)
    5543{
    5644  setLastAction(release);
     
    5947}
    6048
    61 template <class T>
    62 bool IdPool<T>::reserveId(T id)
     49template <class T, class idpolicy>
     50bool IdPool<T,idpolicy>::reserveId(T id)
    6351{
    6452  setLastAction(reserve);
     
    10088}
    10189
    102 template <class T>
    103 void IdPool<T>::defragIdPool()
     90template <class T, class idpolicy>
     91void IdPool<T,idpolicy>::defragIdPool()
    10492{
    10593  // check if the situation is bad enough to make defragging neccessary
     
    142130 * at a chosen place.
    143131 */
    144 #define CONSTRUCT_IDPOOL(name) \
    145     template name IdPool< name >::getNextId(); \
    146     template bool IdPool< name >::reserveId( name ); \
    147     template void IdPool< name >::releaseId( name ); \
    148     template void IdPool< name >::setLastAction(const enum Actions _action); \
    149     template void IdPool< name >::defragIdPool() ;
     132#define CONSTRUCT_IDPOOL(name, idpolicy) \
     133    template name IdPool< name, idpolicy >::getNextId(); \
     134    template bool IdPool< name, idpolicy >::reserveId( name ); \
     135    template void IdPool< name, idpolicy >::releaseId( name ); \
     136    template void IdPool< name, idpolicy >::setLastAction(const enum Actions _action); \
     137    template void IdPool< name, idpolicy >::defragIdPool() ;
    150138
    151139#endif /* IDPOOL_IMPL_HPP_ */
  • src/World.cpp

    r3867a7 rb97a60  
    693693
    694694// moleculeId_t und atomId_t sind gleicher Basistyp, deswegen nur einen von beiden konstruieren
    695 CONSTRUCT_IDPOOL(moleculeId_t)
     695CONSTRUCT_IDPOOL(atomId_t, uniqueId)
     696CONSTRUCT_IDPOOL(moleculeId_t, continuousId)
    696697
    697698CONSTRUCT_SINGLETON(World)
  • src/World.hpp

    r3867a7 rb97a60  
    3232#include "CodePatterns/Observer/ObservedContainer.hpp"
    3333#include "CodePatterns/Range.hpp"
     34#include "IdPool_policy.hpp"
    3435#include "IdPool.hpp"
    3536#include "LinkedCell/LinkedCell_View.hpp"
     
    465466   * The pool contains ranges of free ids in the form [bottom,top).
    466467   */
    467   IdPool<atomId_t> atomIdPool;
     468  IdPool<atomId_t, uniqueId> atomIdPool;
    468469
    469470  MoleculeSet molecules;
     
    474475   * The pool contains ranges of free ids in the form [bottom,top).
    475476   */
    476   IdPool<moleculeId_t> moleculeIdPool;
     477  IdPool<moleculeId_t, continuousId> moleculeIdPool;
    477478
    478479private:
  • src/documentation/constructs/world.dox

    r3867a7 rb97a60  
    112112 * \paragraph world-internals-notes-idpool
    113113 *
    114  * The World has an idpool to manage the ids of atoms and molecules, i.e. such
    115  * that they are:
    116  * -# unique
    117  * -# not loosely spread over the whole range of possible, but tightly packed
     114 * The World has an idpool to manage the ids of atoms and molecules. The IdPool
     115 * inherits policies, such that ids are given in a unique (uniqueId) or
     116 * continuous (continousId) fashion.
     117 * The id of an atom is the sole identifier for which we can guarantee
     118 * uniqueness. Due to undo and redo actions the memory address is not a good
     119 * identifier. This is however required for FormatParser's that need
     120 * to store their additionalAtomData at program exit and have to safely identify
     121 * the data with its atoms. This can only be accomplished via the id. Hence,
     122 * we use the unique policy there.
     123 * The id of a molecule however is more of a convenience, to distinguish it from
     124 * the currently present others. A molecule may change very often and it is also
     125 * a compound structure that may change slightly (when a new bond to another atom
     126 * occurs). Thus, the concept of the id as a unique identifier does not make
     127 * sense. Hence, we use the continuous policy here.
    118128 *
    119  * For the latter to work we have a class IdPool that manages the ids and
     129 * Note that IdPool::reserveId() has to ascertain that we may sweep through ids
     130 * available to (undone) AtomRemoveAction or (redone) AtomAddAction in sublinear
     131 * time. For this to work we have a class IdPool that manages the ids and
    120132 * defragments the pool from time to time by combining ranges of released ids.
    121133 *
    122  * \date 2011-10-31
     134 * \date 2012-01-06
    123135 *
    124136 */
Note: See TracChangeset for help on using the changeset viewer.