Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/World.hpp

    r387b36 r4d72e4  
    2323#include "Patterns/Cacheable.hpp"
    2424#include "Patterns/Singleton.hpp"
     25#include "Patterns/ObservedContainer.hpp"
     26#include "Helpers/Range.hpp"
     27#include "AtomSet.hpp"
    2528
    2629// include config.h
     
    3033
    3134// forward declarations
    32 class config;
    33 class periodentafel;
    34 class MoleculeListClass;
    3535class atom;
    36 class molecule;
    3736class AtomDescriptor;
    3837class AtomDescriptor_impl;
     38template<typename T> class AtomsCalculation;
     39class Box;
     40class config;
     41class ManipulateAtomsProcess;
     42class Matrix;
     43class molecule;
    3944class MoleculeDescriptor;
    4045class MoleculeDescriptor_impl;
    41 class ManipulateAtomsProcess;
    42 template<typename T>
    43 class AtomsCalculation;
     46class MoleculeListClass;
     47class periodentafel;
     48class ThermoStatContainer;
     49
    4450
    4551/****************************************** forward declarations *****************************/
     
    5864friend class MoleculeDescriptor_impl;
    5965friend class MoleculeDescriptor;
     66// coupling with descriptors over selection
     67friend class AtomSelectionDescriptor_impl;
     68friend class MoleculeSelectionDescriptor_impl;
    6069
    6170// Actions, calculations etc associated with the World
     
    6574
    6675  // Types for Atom and Molecule structures
    67   typedef std::map<atomId_t,atom*> AtomSet;
    68   typedef std::map<moleculeId_t,molecule*> MoleculeSet;
     76  typedef ObservedContainer<std::map<atomId_t,atom*> > AtomSet;
     77  typedef ObservedContainer<std::map<moleculeId_t,molecule*> > MoleculeSet;
     78
     79  typedef ATOMSET(std::vector) AtomComposite;
    6980
    7081  /***** getter and setter *****/
     
    89100   * returns a vector containing all atoms that match a given descriptor
    90101   */
    91   std::vector<atom*> getAllAtoms(AtomDescriptor descriptor);
    92   std::vector<atom*> getAllAtoms();
     102  AtomComposite getAllAtoms(AtomDescriptor descriptor);
     103  AtomComposite getAllAtoms();
    93104
    94105  /**
     
    125136   * get the domain size as a symmetric matrix (6 components)
    126137   */
    127   double * getDomain();
     138  Box& getDomain();
     139
     140  /**
     141   * Set the domain size from a matrix object
     142   *
     143   * Matrix needs to be symmetric
     144   */
     145  void setDomain(const Matrix &mat);
    128146
    129147  /**
     
    141159   */
    142160  void setDefaultName(std::string name);
     161
     162  /**
     163   * get pointer to World's ThermoStatContainer
     164   */
     165  ThermoStatContainer * getThermostats();
    143166
    144167  /*
     
    202225  ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string);
    203226
     227  /****
     228   * Iterators to use internal data structures
     229   * All these iterators are observed to track changes.
     230   * There is a corresponding protected section with unobserved iterators,
     231   * which can be used internally when the extra speed is needed
     232   */
     233
     234  typedef SelectiveIterator<atom*,AtomSet,AtomDescriptor>       AtomIterator;
     235
     236  /**
     237   * returns an iterator over all Atoms matching a given descriptor.
     238   * This iterator is observed, so don't keep it around unnecessary to
     239   * avoid unintended blocking.
     240   */
     241  AtomIterator getAtomIter(AtomDescriptor descr);
     242  AtomIterator getAtomIter();
     243
     244  AtomIterator atomEnd();
     245
     246  typedef SelectiveIterator<molecule*,MoleculeSet,MoleculeDescriptor>   MoleculeIterator;
     247
     248  /**
     249   * returns an iterator over all Molecules matching a given descriptor.
     250   * This iterator is observed, so don't keep it around unnecessary to
     251   * avoid unintended blocking.
     252   */
     253  MoleculeIterator getMoleculeIter(MoleculeDescriptor descr);
     254  MoleculeIterator getMoleculeIter();
     255
     256  MoleculeIterator moleculeEnd();
     257
     258  /******** Selections of molecules and Atoms *************/
     259  void clearAtomSelection();
     260  void selectAtom(atom*);
     261  void selectAtom(atomId_t);
     262  void selectAllAtoms(AtomDescriptor);
     263  void selectAtomsOfMolecule(molecule*);
     264  void selectAtomsOfMolecule(moleculeId_t);
     265  void unselectAtom(atom*);
     266  void unselectAtom(atomId_t);
     267  void unselectAllAtoms(AtomDescriptor);
     268  void unselectAtomsOfMolecule(molecule*);
     269  void unselectAtomsOfMolecule(moleculeId_t);
     270  size_t countSelectedAtoms() const;
     271  bool isSelected(atom *_atom) const;
     272  const std::vector<atom *> getSelectedAtoms() const;
     273
     274  void clearMoleculeSelection();
     275  void selectMolecule(molecule*);
     276  void selectMolecule(moleculeId_t);
     277  void selectAllMolecules(MoleculeDescriptor);
     278  void selectMoleculeOfAtom(atom*);
     279  void selectMoleculeOfAtom(atomId_t);
     280  void unselectMolecule(molecule*);
     281  void unselectMolecule(moleculeId_t);
     282  void unselectAllMolecules(MoleculeDescriptor);
     283  void unselectMoleculeOfAtom(atom*);
     284  void unselectMoleculeOfAtom(atomId_t);
     285  size_t countSelectedMolecules() const;
     286  bool isSelected(molecule *_mol) const;
     287  const std::vector<molecule *> getSelectedMolecules() const;
     288
     289  /******************** Iterators to selections *****************/
     290  typedef AtomSet::iterator AtomSelectionIterator;
     291  AtomSelectionIterator beginAtomSelection();
     292  AtomSelectionIterator endAtomSelection();
     293
     294  typedef MoleculeSet::iterator MoleculeSelectionIterator;
     295  MoleculeSelectionIterator beginMoleculeSelection();
     296  MoleculeSelectionIterator endMoleculeSelection();
     297
    204298protected:
    205   /**** Iterators to use internal data structures */
     299  /****
     300   * Iterators to use internal data structures
     301   * All these iterators are unobserved for speed reasons.
     302   * There is a corresponding public section to these methods,
     303   * which produce observed iterators.*/
    206304
    207305  // Atoms
    208   typedef SelectiveIterator<atom*,AtomSet,AtomDescriptor> AtomIterator;
     306  typedef SelectiveIterator<atom*,AtomSet::set_t,AtomDescriptor>        internal_AtomIterator;
    209307
    210308  /**
     
    212310   * used for internal purposes, like AtomProcesses and AtomCalculations.
    213311   */
    214   AtomIterator getAtomIter(AtomDescriptor descr);
     312  internal_AtomIterator getAtomIter_internal(AtomDescriptor descr);
    215313
    216314  /**
     
    220318   * used for internal purposes, like AtomProcesses and AtomCalculations.
    221319   */
    222   AtomIterator atomEnd();
     320  internal_AtomIterator atomEnd_internal();
    223321
    224322  // Molecules
    225 
    226   typedef SelectiveIterator<molecule*,MoleculeSet,MoleculeDescriptor> MoleculeIterator;
     323  typedef SelectiveIterator<molecule*,MoleculeSet::set_t,MoleculeDescriptor>   internal_MoleculeIterator;
     324
    227325
    228326  /**
     
    230328   * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
    231329   */
    232   MoleculeIterator getMoleculeIter(MoleculeDescriptor descr);
     330  internal_MoleculeIterator getMoleculeIter_internal(MoleculeDescriptor descr);
    233331
    234332  /**
     
    238336   * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
    239337   */
    240   MoleculeIterator moleculeEnd();
     338  internal_MoleculeIterator moleculeEnd_internal();
    241339
    242340
     
    249347  void releaseAtomId(atomId_t);
    250348  bool reserveAtomId(atomId_t);
     349  void defragAtomIdPool();
     350
     351  moleculeId_t getNextMoleculeId();
     352  void releaseMoleculeId(moleculeId_t);
     353  bool reserveMoleculeId(moleculeId_t);
     354  void defragMoleculeIdPool();
    251355
    252356  periodentafel *periode;
    253357  config *configuration;
    254   static double *cell_size;
     358  Box *cell_size;
    255359  std::string defaultName;
     360  class ThermoStatContainer *Thermostats;
    256361  int ExitFlag;
    257 public:
     362private:
     363
    258364  AtomSet atoms;
    259 private:
    260   std::set<atomId_t> atomIdPool; //<!stores the pool for all available AtomIds below currAtomId
     365  AtomSet selectedAtoms;
     366  typedef std::set<range<atomId_t> > atomIdPool_t;
     367  /**
     368   * stores the pool for all available AtomIds below currAtomId
     369   *
     370   * The pool contains ranges of free ids in the form [bottom,top).
     371   */
     372  atomIdPool_t atomIdPool;
    261373  atomId_t currAtomId; //!< stores the next available Id for atoms
     374  size_t lastAtomPoolSize; //!< size of the pool after last defrag, to skip some defrags
     375  unsigned int numAtomDefragSkips;
     376
    262377  MoleculeSet molecules;
     378  MoleculeSet selectedMolecules;
     379  typedef std::set<range<atomId_t> > moleculeIdPool_t;
     380  /**
     381   * stores the pool for all available AtomIds below currAtomId
     382   *
     383   * The pool contains ranges of free ids in the form [bottom,top).
     384   */
     385  moleculeIdPool_t moleculeIdPool;
    263386  moleculeId_t currMoleculeId;
     387  size_t lastMoleculePoolSize; //!< size of the pool after last defrag, to skip some defrags
     388  unsigned int numMoleculeDefragSkips;
    264389private:
    265390  /**
Note: See TracChangeset for help on using the changeset viewer.