Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/World.hpp

    r43dad6 rcf0ca1  
    2323#include "Patterns/Cacheable.hpp"
    2424#include "Patterns/Singleton.hpp"
     25#include "Patterns/ObservedContainer.hpp"
    2526
    2627// include config.h
     
    3435class AtomDescriptor_impl;
    3536template<typename T> class AtomsCalculation;
     37class Box;
    3638class config;
    3739class ManipulateAtomsProcess;
     40class Matrix;
    3841class molecule;
    3942class MoleculeDescriptor;
     
    4346class ThermoStatContainer;
    4447
     48
    4549/****************************************** forward declarations *****************************/
    4650
     
    5862friend class MoleculeDescriptor_impl;
    5963friend class MoleculeDescriptor;
     64// coupling with descriptors over selection
     65friend class AtomSelectionDescriptor_impl;
     66friend class MoleculeSelectionDescriptor_impl;
    6067
    6168// Actions, calculations etc associated with the World
     
    6572
    6673  // Types for Atom and Molecule structures
    67   typedef std::map<atomId_t,atom*> AtomSet;
    68   typedef std::map<moleculeId_t,molecule*> MoleculeSet;
     74  typedef ObservedContainer<std::map<atomId_t,atom*> > AtomSet;
     75  typedef ObservedContainer<std::map<moleculeId_t,molecule*> > MoleculeSet;
    6976
    7077  /***** getter and setter *****/
     
    125132   * get the domain size as a symmetric matrix (6 components)
    126133   */
    127   double * getDomain();
     134  Box& getDomain();
     135
     136  /**
     137   * Set the domain size from a matrix object
     138   *
     139   * Matrix needs to be symmetric
     140   */
     141  void setDomain(const Matrix &mat);
    128142
    129143  /**
     
    207221  ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string);
    208222
     223  /****
     224   * Iterators to use internal data structures
     225   * All these iterators are observed to track changes.
     226   * There is a corresponding protected section with unobserved iterators,
     227   * which can be used internally when the extra speed is needed
     228   */
     229
     230  typedef SelectiveIterator<atom*,AtomSet,AtomDescriptor>       AtomIterator;
     231
     232  /**
     233   * returns an iterator over all Atoms matching a given descriptor.
     234   * This iterator is observed, so don't keep it around unnecessary to
     235   * avoid unintended blocking.
     236   */
     237  AtomIterator getAtomIter(AtomDescriptor descr);
     238  AtomIterator getAtomIter();
     239
     240  AtomIterator atomEnd();
     241
     242  typedef SelectiveIterator<molecule*,MoleculeSet,MoleculeDescriptor>   MoleculeIterator;
     243
     244  /**
     245   * returns an iterator over all Molecules matching a given descriptor.
     246   * This iterator is observed, so don't keep it around unnecessary to
     247   * avoid unintended blocking.
     248   */
     249  MoleculeIterator getMoleculeIter(MoleculeDescriptor descr);
     250  MoleculeIterator getMoleculeIter();
     251
     252  MoleculeIterator moleculeEnd();
     253
     254  /******** Selections of molecules and Atoms *************/
     255  void clearAtomSelection();
     256  void selectAtom(atom*);
     257  void selectAtom(atomId_t);
     258  void selectAllAtoms(AtomDescriptor);
     259  void selectAtomsOfMolecule(molecule*);
     260  void selectAtomsOfMolecule(moleculeId_t);
     261  void unselectAtom(atom*);
     262  void unselectAtom(atomId_t);
     263  void unselectAllAtoms(AtomDescriptor);
     264  void unselectAtomsOfMolecule(molecule*);
     265  void unselectAtomsOfMolecule(moleculeId_t);
     266
     267  void clearMoleculeSelection();
     268  void selectMolecule(molecule*);
     269  void selectMolecule(moleculeId_t);
     270  void selectAllMoleculess(MoleculeDescriptor);
     271  void selectMoleculeOfAtom(atom*);
     272  void selectMoleculeOfAtom(atomId_t);
     273  void unselectMolecule(molecule*);
     274  void unselectMolecule(moleculeId_t);
     275  void unselectAllMoleculess(MoleculeDescriptor);
     276  void unselectMoleculeOfAtom(atom*);
     277  void unselectMoleculeOfAtom(atomId_t);
     278
     279  /******************** Iterators to selections *****************/
     280  typedef AtomSet::iterator AtomSelectionIterator;
     281  AtomSelectionIterator beginAtomSelection();
     282  AtomSelectionIterator endAtomSelection();
     283
     284  typedef MoleculeSet::iterator MoleculeSelectionIterator;
     285  MoleculeSelectionIterator beginMoleculeSelection();
     286  MoleculeSelectionIterator endMoleculeSelection();
     287
    209288protected:
    210   /**** Iterators to use internal data structures */
     289  /****
     290   * Iterators to use internal data structures
     291   * All these iterators are unobserved for speed reasons.
     292   * There is a corresponding public section to these methods,
     293   * which produce observed iterators.*/
    211294
    212295  // Atoms
    213   typedef SelectiveIterator<atom*,AtomSet,AtomDescriptor> AtomIterator;
     296  typedef SelectiveIterator<atom*,AtomSet::set_t,AtomDescriptor>        internal_AtomIterator;
    214297
    215298  /**
     
    217300   * used for internal purposes, like AtomProcesses and AtomCalculations.
    218301   */
    219   AtomIterator getAtomIter(AtomDescriptor descr);
     302  internal_AtomIterator getAtomIter_internal(AtomDescriptor descr);
    220303
    221304  /**
     
    225308   * used for internal purposes, like AtomProcesses and AtomCalculations.
    226309   */
    227   AtomIterator atomEnd();
     310  internal_AtomIterator atomEnd_internal();
    228311
    229312  // Molecules
    230 
    231   typedef SelectiveIterator<molecule*,MoleculeSet,MoleculeDescriptor> MoleculeIterator;
     313  typedef SelectiveIterator<molecule*,MoleculeSet::set_t,MoleculeDescriptor>   internal_MoleculeIterator;
     314
    232315
    233316  /**
     
    235318   * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
    236319   */
    237   MoleculeIterator getMoleculeIter(MoleculeDescriptor descr);
     320  internal_MoleculeIterator getMoleculeIter_internal(MoleculeDescriptor descr);
    238321
    239322  /**
     
    243326   * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
    244327   */
    245   MoleculeIterator moleculeEnd();
     328  internal_MoleculeIterator moleculeEnd_internal();
    246329
    247330
     
    254337  void releaseAtomId(atomId_t);
    255338  bool reserveAtomId(atomId_t);
     339  void defragAtomIdPool();
     340
     341  moleculeId_t getNextMoleculeId();
     342  void releaseMoleculeId(moleculeId_t);
     343  bool reserveMoleculeId(moleculeId_t);
     344  void defragMoleculeIdPool();
    256345
    257346  periodentafel *periode;
    258347  config *configuration;
    259   static double *cell_size;
     348  Box *cell_size;
    260349  std::string defaultName;
    261350  class ThermoStatContainer *Thermostats;
    262351  int ExitFlag;
    263 public:
     352private:
     353
    264354  AtomSet atoms;
    265 private:
    266   std::set<atomId_t> atomIdPool; //<!stores the pool for all available AtomIds below currAtomId
     355  AtomSet selectedAtoms;
     356  typedef std::set<std::pair<atomId_t, atomId_t> > atomIdPool_t;
     357  /**
     358   * stores the pool for all available AtomIds below currAtomId
     359   *
     360   * The pool contains ranges of free ids in the form [bottom,top).
     361   */
     362  atomIdPool_t atomIdPool;
    267363  atomId_t currAtomId; //!< stores the next available Id for atoms
     364  size_t lastAtomPoolSize; //!< size of the pool after last defrag, to skip some defrags
     365  unsigned int numAtomDefragSkips;
     366
    268367  MoleculeSet molecules;
     368  MoleculeSet selectedMolecules;
     369  typedef std::set<std::pair<moleculeId_t, moleculeId_t> > moleculeIdPool_t;
     370  /**
     371   * stores the pool for all available AtomIds below currAtomId
     372   *
     373   * The pool contains ranges of free ids in the form [bottom,top).
     374   */
     375  moleculeIdPool_t moleculeIdPool;
    269376  moleculeId_t currMoleculeId;
     377  size_t lastMoleculePoolSize; //!< size of the pool after last defrag, to skip some defrags
     378  unsigned int numMoleculeDefragSkips;
    270379private:
    271380  /**
Note: See TracChangeset for help on using the changeset viewer.