Changeset 46d958


Ignore:
Timestamp:
Feb 24, 2010, 4:21:12 PM (15 years ago)
Author:
Tillmann Crueger <crueger@…>
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:
02ee15
Parents:
b54ac8
git-author:
Tillmann Crueger <crueger@…> (02/24/10 15:29:12)
git-committer:
Tillmann Crueger <crueger@…> (02/24/10 16:21:12)
Message:

Made the world solely responsible for creating and destroying atoms.

Location:
src
Files:
1 added
26 edited

Legend:

Unmodified
Added
Removed
  • src/Legacy/oldmenu.cpp

    rb54ac8 r46d958  
    99#include "Legacy/oldmenu.hpp"
    1010#include "analysis_correlation.hpp"
     11#include "World.hpp"
    1112#include "atom.hpp"
    1213#include "bond.hpp"
     
    7778      case 'a': // absolute coordinates of atom
    7879        Log() << Verbose(0) << "Enter absolute coordinates." << endl;
    79         first = new atom;
     80        first = World::get()->createAtom();
    8081        first->x.AskPosition(mol->cell_size, false);
    8182        first->type = periode->AskElement();  // give type
     
    8485
    8586      case 'b': // relative coordinates of atom wrt to reference point
    86         first = new atom;
     87        first = World::get()->createAtom();
    8788        valid = true;
    8889        do {
     
    100101
    101102      case 'c': // relative coordinates of atom wrt to already placed atom
    102         first = new atom;
     103        first = World::get()->createAtom();
    103104        valid = true;
    104105        do {
     
    116117
    117118    case 'd': // two atoms, two angles and a distance
    118         first = new atom;
     119        first = World::get()->createAtom();
    119120        valid = true;
    120121        do {
     
    216217
    217218      case 'e': // least square distance position to a set of atoms
    218         first = new atom;
     219        first = World::get()->createAtom();
    219220        atoms = new (Vector*[128]);
    220221        valid = true;
     
    238239          mol->AddAtom(first);  // add to molecule
    239240        } else {
    240           delete first;
     241          World::get()->destroyAtom(first);
    241242          Log() << Verbose(0) << "Please enter at least two vectors!\n";
    242243        }
     
    781782        x.AddVector(&y); // per factor one cell width further
    782783        for (int k=count;k--;) { // go through every atom of the original cell
    783           first = new atom(); // create a new body
     784          first = World::get()->createAtom(); // create a new body
    784785          first->x.CopyVector(vectors[k]);  // use coordinate of original atom
    785786          first->x.AddVector(&x);     // translate the coordinates
  • src/Makefile.am

    rb54ac8 r46d958  
    3232DESCRIPTORHEADER = Descriptors/AtomDescriptor.hpp Descriptors/AtomIdDescriptor.hpp
    3333
    34 SOURCE = ${ANALYSISSOURCE} ${ATOMSOURCE} ${PATTERNSOURCE} ${UISOURCE} ${DESCRIPTORSOURCE} ${LEGACYSOURCE} bond.cpp bondgraph.cpp boundary.cpp config.cpp element.cpp ellipsoid.cpp errorlogger.cpp graph.cpp helpers.cpp info.cpp leastsquaremin.cpp linkedcell.cpp log.cpp logger.cpp memoryusageobserver.cpp moleculelist.cpp molecule.cpp molecule_dynamics.cpp molecule_fragmentation.cpp molecule_geometry.cpp molecule_graph.cpp molecule_pointcloud.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp vector.cpp verbose.cpp World.cpp
     34SOURCE = ${ANALYSISSOURCE} ${ATOMSOURCE} ${PATTERNSOURCE} ${UISOURCE} ${DESCRIPTORSOURCE} ${LEGACYSOURCE} bond.cpp bondgraph.cpp boundary.cpp config.cpp element.cpp ellipsoid.cpp errorlogger.cpp graph.cpp helpers.cpp info.cpp leastsquaremin.cpp linkedcell.cpp lists.cpp log.cpp logger.cpp memoryusageobserver.cpp moleculelist.cpp molecule.cpp molecule_dynamics.cpp molecule_fragmentation.cpp molecule_geometry.cpp molecule_graph.cpp molecule_pointcloud.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp vector.cpp verbose.cpp World.cpp
    3535HEADER = ${ANALYSISHEADER} ${ATOMHEADER} ${PATTERNHEADER} ${UIHEADER} ${DESCRIPTORHEADER} ${LEGACYHEADER} bond.hpp bondgraph.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp errorlogger.hpp graph.hpp helpers.hpp info.hpp leastsquaremin.hpp linkedcell.hpp lists.hpp log.hpp logger.hpp memoryallocator.hpp memoryusageobserver.hpp molecule.hpp molecule_template.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp World.hpp
    3636
  • src/World.cpp

    rb54ac8 r46d958  
    5151
    5252
     53atom *World::createAtom(){
     54  OBSERVE;
     55  atom *res = NewAtom();
     56  res->setId(currAtomId++);
     57  res->setWorld(this);
     58  atoms[res->getId()] = res;
     59  return res;
     60}
     61
     62int World::registerAtom(atom *atom){
     63  OBSERVE;
     64  atom->setId(currAtomId++);
     65  atom->setWorld(this);
     66  atoms[atom->getId()] = atom;
     67  return atom->getId();
     68}
     69
     70void World::destroyAtom(atom* atom){
     71  OBSERVE;
     72  int id = atom->getId();
     73  destroyAtom(id);
     74}
     75
     76void World::destroyAtom(int id) {
     77  OBSERVE;
     78  atom *atom = atoms[id];
     79  assert(atom);
     80  DeleteAtom(atom);
     81  atoms.erase(id);
     82}
     83
    5384ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){
    5485  return new ManipulateAtomsProcess(op, descr,name,true);
     
    160191
    161192World::World() :
    162     dummyId(0),
     193    currAtomId(0),
    163194    periode(new periodentafel),
    164195    molecules_deprecated(new MoleculeListClass),
     
    170201World::~World()
    171202{
     203  delete molecules_deprecated;
    172204  delete periode;
     205  AtomList::iterator iter;
     206  for(iter=atoms.begin();iter!=atoms.end();++iter){
     207    DeleteAtom((*iter).second);
     208  }
     209  atoms.clear();
    173210}
    174211
     
    183220
    184221void World::destroy(){
    185   // For legacy reasons all atoms have to be destroyed first, since unregistering would cause deadlocks otherwise
    186   theWorld->destroyLegacy();
    187   //WARNING: at this point we have a small race condition, when sombody now tries to access the world.
    188 
    189222  // boost supports RAII-Style locking, so we don't need to unlock
    190223  boost::mutex::scoped_lock guard(worldLock);
     
    194227
    195228World* World::reset(){
    196   // For legacy reasons all atoms have to be destroyed first, since unregistering would cause deadlocks otherwise
    197   theWorld->destroyLegacy();
    198   //WARNING: at this point we have a small race condition, when sombody now tries to access the world.
    199 
    200229  World* oldWorld = 0;
    201230  {
     
    224253  return molecules_deprecated;
    225254}
    226 
    227 // some legacy stuff to let the World know about items created outside
    228 void World::registerAtom(atom *theAtom){
    229   OBSERVE;
    230   atoms[dummyId++] = theAtom;
    231 }
    232 
    233 void World::destroyLegacy(){
    234   //delete molecules_deprecated;
    235 }
    236 
    237 void World::unregisterAtom(atom *theAtom){
    238   OBSERVE;
    239   atoms.erase(theAtom->getId());
    240 }
  • src/World.hpp

    rb54ac8 r46d958  
    5858  /***** Methods to work with the World *****/
    5959  molecule *createMolecule();
     60  atom *createAtom();
     61  int registerAtom(atom*);
     62  void destroyAtom(atom*);
     63  void destroyAtom(int);
    6064
    6165  ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string,AtomDescriptor);
     
    9599  periodentafel *periode;
    96100  AtomList atoms;
     101  int currAtomId; //!< stores the next available Id for atoms
    97102  std::set<molecule*> molecules;
    98103
     
    120125  MoleculeListClass *&getMolecules();
    121126
    122   // functions used for the WorldContent template mechanism
    123   void registerAtom(atom *theAtom);
    124   void unregisterAtom(atom *theAtom);
    125127private:
    126   // this function cleans up anything that cannot be cleaned while the lock is active
    127   // at a later point all these cleanups have to be moved to the World Class so the deadlock and
    128   // race condition can both be avoided.
    129   void destroyLegacy();
    130 
    131128  MoleculeListClass *molecules_deprecated;
    132 
    133   // this is needed to assign unique IDs to atoms... so far
    134   // IDs are not assigned upon Atom creation, so we cannot query the ID
    135   // during construction. By using the dummy ID we can make sure all atoms
    136   // are actually stored in the map and don't overwrite each other.
    137   int dummyId;
    138129};
    139130
  • src/atom.cpp

    rb54ac8 r46d958  
    2020/** Constructor of class atom.
    2121 */
    22 atom::atom() : previous(NULL), next(NULL), father(this), sort(&nr)
    23 {
    24   World::get()->registerAtom(this);
     22atom::atom() :
     23  previous(NULL), next(NULL), father(this), sort(&nr)
     24{
    2525  node = &x;  // TesselPoint::x can only be referenced from here
    2626};
     
    2828/** Constructor of class atom.
    2929 */
    30 atom::atom(atom *pointer) : previous(NULL), next(NULL), father(pointer), sort(&nr)
    31 {
    32   World::get()->registerAtom(this);
     30atom::atom(atom *pointer) :
     31    ParticleInfo(pointer),
     32    previous(NULL), next(NULL), father(pointer), sort(&nr)
     33{
    3334  type = pointer->type;  // copy element of atom
    3435  x.CopyVector(&pointer->x); // copy coordination
     
    3839};
    3940
     41atom *atom::clone(){
     42  atom *res = new atom();
     43  res->previous=0;
     44  res->next=0;
     45  res->father = this;
     46  res->sort = &nr;
     47  res->type = type;
     48  res->x.CopyVector(&this->x);
     49  res->v.CopyVector(&this->v);
     50  res->FixedIon = FixedIon;
     51  res->node = &x;
     52  World::get()->registerAtom(res);
     53  return res;
     54}
     55
    4056
    4157/** Destructor of class atom.
     
    4359atom::~atom()
    4460{
    45   World::get()->unregisterAtom(this);
    4661  unlink(this);
    4762};
     
    267282};
    268283
     284World *atom::getWorld(){
     285  return world;
     286}
     287
     288void atom::setWorld(World* _world){
     289  world = _world;
     290}
     291
     292void atom::setId(int _id) {
     293  id=_id;
     294}
     295
     296int atom::getId() {
     297  return id;
     298}
     299
     300atom* NewAtom(){
     301  return new atom();
     302}
     303
     304void  DeleteAtom(atom* atom){
     305  delete atom;
     306}
  • src/atom.hpp

    rb54ac8 r46d958  
    3232
    3333class Vector;
     34class World;
    3435
    3536/********************************************** declarations *******************************/
     
    3940 */
    4041class atom : public TesselPoint, public TrajectoryParticle, public GraphNode, public BondedParticle, public virtual ParticleInfo, public virtual AtomInfo {
     42  friend atom* NewAtom();
     43  friend void  DeleteAtom(atom*);
    4144  public:
    4245    atom *previous; //!< previous atom in molecule list
     
    4548    int *sort;      //!< sort criteria
    4649
    47   atom();
    48   atom(class atom *pointer);
    49   virtual ~atom();
     50  virtual atom *clone();
    5051
    5152  bool OutputIndexed(ofstream * const out, const int ElementNo, const int AtomNo, const char *comment = NULL) const;
     
    6768  bool IsInParallelepiped(const Vector offset, const double *parallelepiped) const;
    6869
     70  // getter and setter
     71
     72  /**
     73   * returns the World that contains this atom.
     74   * Use this if you need to get the world without locking
     75   * the singleton for example.
     76   *
     77   */
     78  World *getWorld();
     79  void setWorld(World*);
     80
     81  virtual int getId();
     82  virtual void setId(int);
     83  protected:
     84    /**
     85     * Protected constructor to ensure construction of atoms through the world.
     86     * see World::createAtom()
     87     */
     88    atom();
     89
     90    /**
     91     * Protected copy-constructor to ensure construction of atoms by cloning.
     92     * see atom::clone()
     93     */
     94    atom(class atom *pointer);
     95
     96    /**
     97     * Protected destructor to ensure destruction of atoms through the world.
     98     * see World::destroyAtom()
     99     */
     100    virtual ~atom();
    69101  private:
     102    World* world;
     103    int id;
    70104};
    71105
     106/**
     107 * internal method used by the world. Do not use if you don't know what you are doing.
     108 * You might get burned...
     109 * Use World::createAtom() instead.
     110 */
     111atom* NewAtom();
     112
     113/**
     114* internal method used by the world. Do not use if you don't know what you are doing.
     115 * You might get burned...
     116 * Use World::destroyAtom() instead.
     117 */
     118void  DeleteAtom(atom*);
     119
     120
    72121#endif /* ATOM_HPP_ */
  • src/atom_particleinfo.cpp

    rb54ac8 r46d958  
    1313ParticleInfo::ParticleInfo() : nr(-1), Name(NULL) {};
    1414
     15ParticleInfo::ParticleInfo(ParticleInfo *pointer) :
     16    Name(pointer->Name),
     17    nr(pointer->nr)
     18    {}
     19
     20
    1521/** Destructor of ParticleInfo.
    1622 */
     
    1925  Free(&Name);
    2026};
    21 
    22 int ParticleInfo::getId() {
    23   return nr;
    24 }
    2527
    2628ostream & operator << (ostream &ost, const ParticleInfo &a)
  • src/atom_particleinfo.hpp

    rb54ac8 r46d958  
    3131
    3232  ParticleInfo();
     33  ParticleInfo(ParticleInfo*);
    3334  ~ParticleInfo();
    3435
    3536  ostream & operator << (ostream &ost) const;
    36 
    37   virtual int getId();
    3837
    3938private:
  • src/boundary.cpp

    rb54ac8 r46d958  
    887887            Walker = Walker->next;
    888888            // copy atom ...
    889             CopyAtoms[Walker->nr] = new atom(Walker);
     889            CopyAtoms[Walker->nr] = Walker->clone();
    890890
    891891            // create atomic random translation vector ...
  • src/builder.cpp

    rb54ac8 r46d958  
    14811481                SaveFlag = true;
    14821482                Log() << Verbose(1) << "Adding new atom with element " << argv[argptr] << " at (" << argv[argptr+1] << "," << argv[argptr+2] << "," << argv[argptr+3] << "), ";
    1483                 first = new atom;
     1483                first = World::get()->createAtom();
    14841484                first->type = periode->FindElement(atoi(argv[argptr]));
    14851485                if (first->type != NULL)
     
    16411641//                first->x.Zero();
    16421642//                filler->AddAtom(first);
    1643                 first = new atom();
     1643                first = World::get()->createAtom();
    16441644                first->type = periode->FindElement(1);
    16451645                first->x.Init(0.441, -0.143, 0.);
    16461646                filler->AddAtom(first);
    1647                 second = new atom();
     1647                second = World::get()->createAtom();
    16481648                second->type = periode->FindElement(1);
    16491649                second->x.Init(-0.464, 1.137, 0.0);
    16501650                filler->AddAtom(second);
    1651                 third = new atom();
     1651                third = World::get()->createAtom();
    16521652                third->type = periode->FindElement(8);
    16531653                third->x.Init(-0.464, 0.177, 0.);
     
    20972097                      x.AddVector(&y); // per factor one cell width further
    20982098                      for (int k=count;k--;) { // go through every atom of the original cell
    2099                         first = new atom(); // create a new body
     2099                        first = World::get()->createAtom(); // create a new body
    21002100                        first->x.CopyVector(vectors[k]);  // use coordinate of original atom
    21012101                        first->x.AddVector(&x);      // translate the coordinates
  • src/config.cpp

    rb54ac8 r46d958  
    88#include <cstring>
    99
     10#include "World.hpp"
    1011#include "atom.hpp"
    1112#include "bond.hpp"
     
    732733            sprintf(keyword,"%s_%i",name, j+1);
    733734            if (repetition == 0) {
    734               neues = new atom();
     735              neues = World::get()->createAtom();
    735736              AtomList[i][j] = neues;
    736737              LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues;
     
    811812          sprintf(keyword,"%s_%i",name, j+1);
    812813          if (repetition == 0) {
    813             neues = new atom();
     814            neues = World::get()->createAtom();
    814815            AtomList[i][j] = neues;
    815816            LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues;
     
    12871288        }
    12881289        istringstream input2(zeile);
    1289         atom *neues = new atom();
     1290        atom *neues = World::get()->createAtom();
    12901291        input2 >> neues->x.x[0]; // x
    12911292        input2 >> neues->x.x[1]; // y
  • src/lists.hpp

    rb54ac8 r46d958  
    99#define LISTS_HPP_
    1010
     11class atom;
     12
    1113/******************************** Some templates for list management ***********************************/
    1214
     
    1820{
    1921  X *vorher = end->previous;
    20   if (vorher != NULL)
     22  if (vorher != 0)
    2123    vorher->next = walker;
    2224  end->previous = walker;
     
    3133template <typename X> void unlink(X *walker)
    3234{
    33   if (walker->next != NULL)
     35  if (walker->next != 0)
    3436    walker->next->previous = walker->previous;
    35   if (walker->previous != NULL)
     37  if (walker->previous != 0)
    3638    walker->previous->next = walker->next;
    37   walker->next = NULL;
    38   walker->previous= NULL;
     39  walker->next = 0;
     40  walker->previous= 0;
    3941};
    4042
     
    4648template <typename X>  bool add(X *pointer, X *end)
    4749{
    48   if (end != NULL) {
     50  if (end != 0) {
    4951    link(pointer, end);
    5052  } else {
    51     pointer->previous = NULL;
    52     pointer->next = NULL;
     53    pointer->previous = 0;
     54    pointer->next = 0;
    5355  }
    5456  return true;
     
    5961 * \param *start  begin of list
    6062 * \param *end  end of list
    61  * \return X - if found, NULL - if not found
     63 * \return X - if found, 0 - if not found
    6264 */
    6365template <typename X, typename Y> X * find(Y *suche, X *start, X *end)
     
    6870    if (*walker->sort == *suche) return (walker);
    6971  }
    70   return NULL;
     72  return 0;
    7173};
    7274
     
    7779template <typename X> void removewithoutcheck(X *walker)
    7880{
    79   if (walker != NULL) {
     81  if (walker != 0) {
    8082    unlink(walker);
    8183    delete(walker);
    82     walker = NULL;
     84    walker = 0;
    8385  }
    8486};
     87
     88/** Removes an item from the list without check.
     89 *  specialized for atoms, because these have to be removed from the world as well
     90 *  the implementation for this declaration is in lists.cpp
     91 * \param *walker item to be removed
     92 * \return true - removing succeeded, false - given item not found in list
     93 */
     94template <> void removewithoutcheck<atom>(atom *walker);
    8595
    8696/** Removes an item from the list, checks if exists.
     
    99109  }*/
    100110  // atom found, now unlink
    101   if (walker != NULL)
     111  if (walker != 0)
    102112    removewithoutcheck(walker);
    103113  else
     
    114124{
    115125  X *pointer = start->next;
    116   X *walker = NULL;
     126  X *walker = 0;
    117127  while (pointer != end) { // go through list
    118128    walker = pointer; // mark current
     
    131141{
    132142  X *Binder = me;
    133   while(Binder->previous != NULL)
     143  while(Binder->previous != 0)
    134144    Binder = Binder->previous;
    135145  return Binder;
     
    143153{
    144154  X *Binder = me;
    145   while(Binder->next != NULL)
     155  while(Binder->next != 0)
    146156    Binder = Binder->next;
    147157  return Binder;
  • src/molecule.cpp

    rb54ac8 r46d958  
    88#include <boost/bind.hpp>
    99
     10#include "World.hpp"
    1011#include "atom.hpp"
    1112#include "bond.hpp"
     
    3031 * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero.
    3132 */
    32 molecule::molecule(const periodentafel * const teil) : elemente(teil), start(new atom), end(new atom),
     33molecule::molecule(const periodentafel * const teil) : elemente(teil), start(World::get()->createAtom()), end(World::get()->createAtom()),
    3334  first(new bond(start, end, 1, -1)), last(new bond(start, end, 1, -1)), MDSteps(0), AtomCount(0),
    3435  BondCount(0), ElementCount(0), NoNonHydrogen(0), NoNonBonds(0), NoCyclicBonds(0), BondDistance(0.),
     
    6061  delete(first);
    6162  delete(last);
    62   delete(end);
    63   delete(start);
     63  end->getWorld()->destroyAtom(end);
     64  start->getWorld()->destroyAtom(start);
    6465};
    6566
     
    135136  OBSERVE;
    136137  if (pointer != NULL) {
    137     atom *walker = new atom(pointer);
     138    atom *walker = pointer->clone();
    138139    walker->Name = Malloc<char>(strlen(pointer->Name) + 1, "atom::atom: *Name");
    139140    strcpy (walker->Name, pointer->Name);
     
    242243  switch(TopBond->BondDegree) {
    243244    case 1:
    244       FirstOtherAtom = new atom();    // new atom
     245      FirstOtherAtom = World::get()->createAtom();    // new atom
    245246      FirstOtherAtom->type = elemente->FindElement(1);  // element is Hydrogen
    246247      FirstOtherAtom->v.CopyVector(&TopReplacement->v); // copy velocity
     
    299300
    300301      // create the two Hydrogens ...
    301       FirstOtherAtom = new atom();
    302       SecondOtherAtom = new atom();
     302      FirstOtherAtom = World::get()->createAtom();
     303      SecondOtherAtom = World::get()->createAtom();
    303304      FirstOtherAtom->type = elemente->FindElement(1);
    304305      SecondOtherAtom->type = elemente->FindElement(1);
     
    354355    case 3:
    355356      // take the "usual" tetraoidal angle and add the three Hydrogen in direction of the bond (height of the tetraoid)
    356       FirstOtherAtom = new atom();
    357       SecondOtherAtom = new atom();
    358       ThirdOtherAtom = new atom();
     357      FirstOtherAtom = World::get()->createAtom();
     358      SecondOtherAtom = World::get()->createAtom();
     359      ThirdOtherAtom = World::get()->createAtom();
    359360      FirstOtherAtom->type = elemente->FindElement(1);
    360361      SecondOtherAtom->type = elemente->FindElement(1);
     
    475476    MDSteps++;
    476477  for(i=0;i<NumberOfAtoms;i++){
    477     Walker = new atom;
     478    Walker = World::get()->createAtom();
    478479    getline(xyzfile,line,'\n');
    479480    istringstream *item = new istringstream(line);
  • src/moleculelist.cpp

    rb54ac8 r46d958  
    342342    Log() << Verbose(2) << "INFO: Current Walker is " << *Walker << "." << endl;
    343343    if (!TesselStruct->IsInnerPoint(Walker->x, LCList)) {
    344       CopyAtoms[Walker->nr] = new atom(Walker);
     344      CopyAtoms[Walker->nr] = Walker->clone();
    345345      mol->AddAtom(CopyAtoms[Walker->nr]);
    346346      nr++;
  • src/unittests/AnalysisCorrelationToPointUnitTest.cpp

    rb54ac8 r46d958  
    1717#include "AnalysisCorrelationToPointUnitTest.hpp"
    1818
     19#include "World.hpp"
    1920#include "atom.hpp"
    2021#include "boundary.hpp"
     
    5657  // construct molecule (tetraeder of hydrogens)
    5758  TestMolecule = new molecule(tafel);
    58   Walker = new atom();
     59  Walker = World::get()->createAtom();
    5960  Walker->type = hydrogen;
    6061  Walker->node->Init(1., 0., 1. );
    6162  TestMolecule->AddAtom(Walker);
    62   Walker = new atom();
     63  Walker = World::get()->createAtom();
    6364  Walker->type = hydrogen;
    6465  Walker->node->Init(0., 1., 1. );
    6566  TestMolecule->AddAtom(Walker);
    66   Walker = new atom();
     67  Walker = World::get()->createAtom();
    6768  Walker->type = hydrogen;
    6869  Walker->node->Init(1., 1., 0. );
    6970  TestMolecule->AddAtom(Walker);
    70   Walker = new atom();
     71  Walker = World::get()->createAtom();
    7172  Walker->type = hydrogen;
    7273  Walker->node->Init(0., 0., 0. );
  • src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp

    rb54ac8 r46d958  
    1717#include "AnalysisCorrelationToSurfaceUnitTest.hpp"
    1818
     19#include "World.hpp"
    1920#include "atom.hpp"
    2021#include "boundary.hpp"
     
    6162  // construct molecule (tetraeder of hydrogens) base
    6263  TestMolecule = new molecule(tafel);
    63   Walker = new atom();
     64  Walker = World::get()->createAtom();
    6465  Walker->type = hydrogen;
    6566  Walker->node->Init(1., 0., 1. );
    6667  TestMolecule->AddAtom(Walker);
    67   Walker = new atom();
     68  Walker = World::get()->createAtom();
    6869  Walker->type = hydrogen;
    6970  Walker->node->Init(0., 1., 1. );
    7071  TestMolecule->AddAtom(Walker);
    71   Walker = new atom();
     72  Walker = World::get()->createAtom();
    7273  Walker->type = hydrogen;
    7374  Walker->node->Init(1., 1., 0. );
    7475  TestMolecule->AddAtom(Walker);
    75   Walker = new atom();
     76  Walker = World::get()->createAtom();
    7677  Walker->type = hydrogen;
    7778  Walker->node->Init(0., 0., 0. );
     
    9495
    9596  // add outer atoms
    96   Walker = new atom();
     97  Walker = World::get()->createAtom();
    9798  Walker->type = carbon;
    9899  Walker->node->Init(4., 0., 4. );
    99100  TestMolecule->AddAtom(Walker);
    100   Walker = new atom();
     101  Walker = World::get()->createAtom();
    101102  Walker->type = carbon;
    102103  Walker->node->Init(0., 4., 4. );
    103104  TestMolecule->AddAtom(Walker);
    104   Walker = new atom();
     105  Walker = World::get()->createAtom();
    105106  Walker->type = carbon;
    106107  Walker->node->Init(4., 4., 0. );
    107108  TestMolecule->AddAtom(Walker);
    108109  // add inner atoms
    109   Walker = new atom();
     110  Walker = World::get()->createAtom();
    110111  Walker->type = carbon;
    111112  Walker->node->Init(0.5, 0.5, 0.5 );
  • src/unittests/AnalysisPairCorrelationUnitTest.cpp

    rb54ac8 r46d958  
    1717#include "AnalysisPairCorrelationUnitTest.hpp"
    1818
     19#include "World.hpp"
    1920#include "atom.hpp"
    2021#include "boundary.hpp"
     
    5556  // construct molecule (tetraeder of hydrogens)
    5657  TestMolecule = new molecule(tafel);
    57   Walker = new atom();
     58  Walker = World::get()->createAtom();
    5859  Walker->type = hydrogen;
    5960  Walker->node->Init(1., 0., 1. );
    6061  TestMolecule->AddAtom(Walker);
    61   Walker = new atom();
     62  Walker = World::get()->createAtom();
    6263  Walker->type = hydrogen;
    6364  Walker->node->Init(0., 1., 1. );
    6465  TestMolecule->AddAtom(Walker);
    65   Walker = new atom();
     66  Walker = World::get()->createAtom();
    6667  Walker->type = hydrogen;
    6768  Walker->node->Init(1., 1., 0. );
    6869  TestMolecule->AddAtom(Walker);
    69   Walker = new atom();
     70  Walker = World::get()->createAtom();
    7071  Walker->type = hydrogen;
    7172  Walker->node->Init(0., 0., 0. );
  • src/unittests/DescriptorUnittest.cpp

    rb54ac8 r46d958  
    2222CPPUNIT_TEST_SUITE_REGISTRATION( DescriptorUnittest );
    2323
    24 // some stubs
    25 class AtomStub : public atom {
    26 public:
    27   AtomStub(int _id) :
    28   atom(),
    29   id(_id)
    30   {}
    31 
    32   virtual int getId(){
    33     return id;
    34   }
    35 
    36 private:
    37   int id;
    38 };
    39 
    40 
    4124// set up and tear down
    4225void DescriptorUnittest::setUp(){
    4326  World::get();
    4427  for(int i=0;i<ATOM_COUNT;++i){
    45     atoms[i]= new AtomStub(i);
     28    atoms[i]= World::get()->createAtom();
     29    atomIds[i] = atoms[i]->getId();
    4630  }
    4731}
    4832void DescriptorUnittest::tearDown(){
    4933  World::destroy();
    50   for(int i=0;i<ATOM_COUNT;++i){
    51     delete atoms[i];
    52   }
    5334}
    5435
    5536// some helper functions
    56 bool hasAll(std::vector<atom*> atoms,int min, int max, std::set<int> excluded = std::set<int>()){
    57   for(int i=min;i<max;++i){
    58     if(!excluded.count(i)){
     37bool hasAll(std::vector<atom*> atoms,int ids[ATOM_COUNT], std::set<int> excluded = std::set<int>()){
     38  for(int i=0;i<ATOM_COUNT;++i){
     39    int id = ids[i];
     40    if(!excluded.count(id)){
    5941      std::vector<atom*>::iterator iter;
    6042      bool res=false;
    6143      for(iter=atoms.begin();iter!=atoms.end();++iter){
    62         res |= (*iter)->getId() == i;
     44        res |= (*iter)->getId() == id;
    6345      }
    6446      if(!res) {
    65         cout << "Atom " << i << " missing in returned list" << endl;
     47        cout << "Atom " << id << " missing in returned list" << endl;
    6648        return false;
    6749      }
     
    8668void DescriptorUnittest::AtomBaseSetsTest(){
    8769  std::vector<atom*> allAtoms = World::get()->getAllAtoms(AllAtoms());
    88   CPPUNIT_ASSERT_EQUAL( true , hasAll(allAtoms,0,ATOM_COUNT));
     70  CPPUNIT_ASSERT_EQUAL( true , hasAll(allAtoms,atomIds));
    8971  CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(allAtoms));
    9072
     
    9577  // test Atoms from boundaries and middle of the set
    9678  atom* testAtom;
    97   testAtom = World::get()->getAtom(AtomById(0));
    98   CPPUNIT_ASSERT_EQUAL( 0, testAtom->getId());
    99   testAtom = World::get()->getAtom(AtomById(ATOM_COUNT/2));
    100   CPPUNIT_ASSERT_EQUAL( ATOM_COUNT/2, testAtom->getId());
    101   testAtom = World::get()->getAtom(AtomById(ATOM_COUNT-1));
    102   CPPUNIT_ASSERT_EQUAL( ATOM_COUNT-1, testAtom->getId());
     79  testAtom = World::get()->getAtom(AtomById(atomIds[0]));
     80  CPPUNIT_ASSERT(testAtom);
     81  CPPUNIT_ASSERT_EQUAL( atomIds[0], testAtom->getId());
     82  testAtom = World::get()->getAtom(AtomById(atomIds[ATOM_COUNT/2]));
     83  CPPUNIT_ASSERT(testAtom);
     84  CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtom->getId());
     85  testAtom = World::get()->getAtom(AtomById(atomIds[ATOM_COUNT-1]));
     86  CPPUNIT_ASSERT(testAtom);
     87  CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT-1], testAtom->getId());
    10388
     89  // find some ID that has not been created
     90  int outsideId =-1;
     91  bool res = false;
     92  while(!res) {
     93    ++outsideId;
     94    res = true;
     95    for(int i = 0; i < ATOM_COUNT; ++i){
     96      res &= atomIds[i]!=outsideId;
     97    }
     98  }
    10499  // test from outside of set
    105   testAtom = World::get()->getAtom(AtomById(ATOM_COUNT));
     100  testAtom = World::get()->getAtom(AtomById(outsideId));
    106101  CPPUNIT_ASSERT(!testAtom);
    107102}
     
    110105  {
    111106    std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()||NoAtoms());
    112     CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,0,ATOM_COUNT));
     107    CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds));
    113108    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
    114109  }
     
    116111  {
    117112    std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||AllAtoms());
    118     CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,0,ATOM_COUNT));
     113    CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds));
    119114    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
    120115  }
     
    137132  {
    138133    std::vector<atom*> testAtoms = World::get()->getAllAtoms(!NoAtoms());
    139     CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,0,ATOM_COUNT));
     134    CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds));
    140135    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
    141136  }
     
    143138  // exclude and include some atoms
    144139  {
    145     std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()&&(!AtomById(ATOM_COUNT/2)));
     140    std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()&&(!AtomById(atomIds[ATOM_COUNT/2])));
    146141    std::set<int> excluded;
    147     excluded.insert(ATOM_COUNT/2);
    148     CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,0,ATOM_COUNT,excluded));
     142    excluded.insert(atomIds[ATOM_COUNT/2]);
     143    CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds,excluded));
    149144    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
    150145    CPPUNIT_ASSERT_EQUAL( (size_t)(ATOM_COUNT-1), testAtoms.size());
     
    152147
    153148  {
    154     std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||(AtomById(ATOM_COUNT/2)));
     149    std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||(AtomById(atomIds[ATOM_COUNT/2])));
    155150    CPPUNIT_ASSERT_EQUAL( (size_t)1, testAtoms.size());
    156     CPPUNIT_ASSERT_EQUAL( ATOM_COUNT/2, testAtoms[0]->getId());
     151    CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtoms[0]->getId());
    157152  }
    158153}
  • src/unittests/DescriptorUnittest.hpp

    rb54ac8 r46d958  
    3333private:
    3434  atom *atoms [ATOM_COUNT];
     35  int atomIds [ATOM_COUNT];
    3536};
    3637
  • src/unittests/Makefile.am

    rb54ac8 r46d958  
    3030  CacheableTest \
    3131  DescriptorUnittest \
    32   manipulateAtomsTest \
     32  manipulateAtomsTest \ 
    3333  atomsCalculationTest \
    34   ${MENUTESTS} 
    35    
     34  ${MENUTESTS}
     35 
     36
     37     
    3638 
    3739check_PROGRAMS = $(TESTS)
  • src/unittests/analysisbondsunittest.cpp

    rb54ac8 r46d958  
    1616#include <cstring>
    1717
     18#include "World.hpp"
    1819#include "analysis_bonds.hpp"
    1920#include "analysisbondsunittest.hpp"
     
    6263  // construct molecule (tetraeder of hydrogens)
    6364  TestMolecule = new molecule(tafel);
    64   Walker = new atom();
     65  Walker = World::get()->createAtom();
    6566  Walker->type = hydrogen;
    6667  Walker->node->Init(1.5, 0., 1.5 );
    6768  TestMolecule->AddAtom(Walker);
    68   Walker = new atom();
     69  Walker = World::get()->createAtom();
    6970  Walker->type = hydrogen;
    7071  Walker->node->Init(0., 1.5, 1.5 );
    7172  TestMolecule->AddAtom(Walker);
    72   Walker = new atom();
     73  Walker = World::get()->createAtom();
    7374  Walker->type = hydrogen;
    7475  Walker->node->Init(1.5, 1.5, 0. );
    7576  TestMolecule->AddAtom(Walker);
    76   Walker = new atom();
     77  Walker = World::get()->createAtom();
    7778  Walker->type = hydrogen;
    7879  Walker->node->Init(0., 0., 0. );
    7980  TestMolecule->AddAtom(Walker);
    80   Walker = new atom();
     81  Walker = World::get()->createAtom();
    8182  Walker->type = carbon;
    8283  Walker->node->Init(0.5, 0.5, 0.5 );
  • src/unittests/atomsCalculationTest.cpp

    rb54ac8 r46d958  
    5454  for(int i=0;i<ATOM_COUNT;++i){
    5555    atoms[i]= new AtomStub(i);
     56    World::get()->registerAtom(atoms[i]);
    5657  }
    5758}
    5859void atomsCalculationTest::tearDown(){
    5960  World::destroy();
    60   for(int i=0;i<ATOM_COUNT;++i){
    61     delete atoms[i];
    62   }
    6361  ActionRegistry::purgeRegistry();
    6462}
  • src/unittests/atomsCalculationTest.hpp

    rb54ac8 r46d958  
    3131private:
    3232  atom *atoms [ATOM_COUNT];
     33  int atomIds [ATOM_COUNT];
    3334};
    3435
  • src/unittests/bondgraphunittest.cpp

    rb54ac8 r46d958  
    1616#include <cstring>
    1717
     18#include "World.hpp"
    1819#include "atom.hpp"
    1920#include "bond.hpp"
     
    5758  // construct molecule (tetraeder of hydrogens)
    5859  TestMolecule = new molecule(tafel);
    59   Walker = new atom();
     60  Walker = World::get()->createAtom();
    6061  Walker->type = hydrogen;
    6162  Walker->node->Init(1., 0., 1. );
    6263  TestMolecule->AddAtom(Walker);
    63   Walker = new atom();
     64  Walker = World::get()->createAtom();
    6465  Walker->type = hydrogen;
    6566  Walker->node->Init(0., 1., 1. );
    6667  TestMolecule->AddAtom(Walker);
    67   Walker = new atom();
     68  Walker = World::get()->createAtom();
    6869  Walker->type = hydrogen;
    6970  Walker->node->Init(1., 1., 0. );
    7071  TestMolecule->AddAtom(Walker);
    71   Walker = new atom();
     72  Walker = World::get()->createAtom();
    7273  Walker->type = hydrogen;
    7374  Walker->node->Init(0., 0., 0. );
  • src/unittests/listofbondsunittest.cpp

    rb54ac8 r46d958  
    1616#include "listofbondsunittest.hpp"
    1717
     18#include "World.hpp"
    1819#include "atom.hpp"
    1920#include "bond.hpp"
     
    5051  // construct molecule (tetraeder of hydrogens)
    5152  TestMolecule = new molecule(tafel);
    52   Walker = new atom();
     53  Walker = World::get()->createAtom();
    5354  Walker->type = hydrogen;
    5455  Walker->node->Init(1., 0., 1. );
    5556  TestMolecule->AddAtom(Walker);
    56   Walker = new atom();
     57  Walker = World::get()->createAtom();
    5758  Walker->type = hydrogen;
    5859  Walker->node->Init(0., 1., 1. );
    5960  TestMolecule->AddAtom(Walker);
    60   Walker = new atom();
     61  Walker = World::get()->createAtom();
    6162  Walker->type = hydrogen;
    6263  Walker->node->Init(1., 1., 0. );
    6364  TestMolecule->AddAtom(Walker);
    64   Walker = new atom();
     65  Walker = World::get()->createAtom();
    6566  Walker->type = hydrogen;
    6667  Walker->node->Init(0., 0., 0. );
     
    242243
    243244  // remove atom2
    244   delete(atom2);
     245  World::get()->destroyAtom(atom2);
    245246
    246247  // check bond if removed from other atom
  • src/unittests/manipulateAtomsTest.cpp

    rb54ac8 r46d958  
    6969  for(int i=0;i<ATOM_COUNT;++i){
    7070    atoms[i]= new AtomStub(i);
     71    World::get()->registerAtom(atoms[i]);
    7172  }
    7273}
    7374void manipulateAtomsTest::tearDown(){
    7475  World::destroy();
    75   for(int i=0;i<ATOM_COUNT;++i){
    76     delete atoms[i];
    77   }
    7876  ActionRegistry::purgeRegistry();
    7977}
Note: See TracChangeset for help on using the changeset viewer.