source: src/Fragmentation/Exporters/HydrogenPool.cpp@ fba720

Candidate_v1.6.1 ChemicalSpaceEvaluator TremoloParser_IncreasedPrecision
Last change on this file since fba720 was 7294dc, checked in by Frederik Heber <frederik.heber@…>, 8 years ago

FIX: Fixing the use of the trajectories that were changed to maps.

  • as the atom's trajectories are now stored inside a map, i.e. not every step necessarily needs to be present, there will still some places in the code that were meant for the old vector storing.
  • Atom::UpdateStep() updates the current step, not the future step.
  • AtomInfo::append/removeTrajectoryStep() now no longer ASSERT that the step is not the current one. Due to the trajectory in map concept (with current it simply sought by lower_bound()) this is no longer necessary.
  • HydrogenPool no longer adds all trajectory steps till current time.
  • World has commented out code for also copying the current atom positions in case a new time step is added, but this is not used as so far we do not recognize whether it is a new time step ... and also it is not really necessary.
  • TESTS: Removed XFAILs from tests of previous commit. They are all working again.
  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2013 University of Bonn. All rights reserved.
5 * Copyright (C) 2013 Frederik Heber. All rights reserved.
6 *
7 *
8 * This file is part of MoleCuilder.
9 *
10 * MoleCuilder is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * MoleCuilder is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24/*
25 * HydrogenPool.cpp
26 *
27 * Created on: Mar 3, 2013
28 * Author: heber
29 */
30
31// include config.h
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35
36//#include "CodePatterns/MemDebug.hpp"
37
38#include "HydrogenPool.hpp"
39
40#include "CodePatterns/Assert.hpp"
41#include "CodePatterns/Log.hpp"
42
43#include "Atom/atom.hpp"
44#include "Atom/AtomObserver.hpp"
45#include "Descriptors/AtomIdDescriptor.hpp"
46#include "Element/periodentafel.hpp"
47#include "World.hpp"
48#include "WorldTime.hpp"
49
50HydrogenPool::HydrogenPool() :
51 HydrogenCount(0)
52{}
53
54HydrogenPool::~HydrogenPool()
55{
56 cleanup();
57}
58
59void HydrogenPool::requestHydrogenIntoPool()
60{
61 // get new hydrogen from world, but remove its observers
62 atom * const Walker = World::getInstance().createAtom();
63 Walker->setType(HYDROGEN); // set element
64 Walker->setName(std::string("H_")+toString(HydrogenCount));
65 Walker->signOff(AtomObserver::getPointer(), AtomObservable::PositionChanged);
66 Walker->signOff(AtomObserver::getPointer(), AtomObservable::ElementChanged);
67 HydrogenQueue.push_back(Walker);
68 ++HydrogenCount;
69
70 // give warning if pool has more than threshold
71 if (HydrogenCount >= WARNINGTHRESHOLD) {
72 ELOG(2, "HydrogenPool contains more hydrogen atoms than limit.");
73 ELOG(2, "Either someone requesting too eagerly, or another not returning them.");
74 }
75
76 // final check
77 ASSERT(!HydrogenQueue.empty(),
78 "HydrogenPool::requestHydrogenIntoPool() - failed to request more hydrogens.");
79}
80
81atom * HydrogenPool::leaseHydrogen()
82{
83 // check the queue, if empty, add more hydrogens
84 if (HydrogenQueue.empty())
85 requestHydrogenIntoPool();
86
87 // pop hydrogen, mark down, and deliver
88 atom * const Walker = HydrogenQueue.front();
89 ASSERT( HydrogenInUse.count(Walker->getId()) == 0,
90 "HydrogenPool::leaseHydrogen() - hydrogen "+toString(*Walker)
91 +" from pool is already in use.");
92 LOG(3, "DEBUG: Leasing " << *Walker << ".");
93 HydrogenInUse.insert( std::make_pair( Walker->getId(), Walker) );
94 HydrogenQueue.pop_front();
95
96 return Walker;
97}
98
99void HydrogenPool::releaseHydrogen(atom * _atom)
100{
101 if (_atom == NULL) {
102 ASSERT( 0,
103 "HydrogenPool::releaseHydrogen() - got NULL atom.");
104 return;
105 }
106
107 // check that it is marked down
108 {
109 HydrogenInUse_t::iterator iter = HydrogenInUse.find(_atom->getId());
110 if (iter == HydrogenInUse.end()) {
111 ASSERT( 0,
112 "HydrogenPool::releaseHydrogen() - got unknown atom "+toString(_atom)+".");
113 return;
114 }
115 LOG(3, "DEBUG: Releasing " << *_atom << ".");
116 HydrogenInUse.erase(iter);
117 }
118 // check into queue
119 HydrogenQueue.push_back(_atom);
120}
121
122void HydrogenPool::releaseHydrogen(atomId_t _atom)
123{
124 atom * const Walker = World::getInstance().getAtom(AtomById(_atom));
125 ASSERT( Walker != NULL,
126 "HydrogenPool::releaseHydrogen() - id "
127 +toString(_atom)+" unknown to World.");
128 releaseHydrogen(Walker);
129}
130
131void HydrogenPool::cleanup()
132{
133 ASSERT(HydrogenInUse.empty(),
134 "HydrogenPool::cleanup() - cleanup called, but still hydrogens in use.");
135 for (HydrogenQueue_t::iterator iter = HydrogenQueue.begin();
136 !HydrogenQueue.empty(); iter = HydrogenQueue.begin()) {
137 atom * const Walker = *iter;
138 HydrogenQueue.erase(iter);
139 World::getInstance().destroyAtom(Walker);
140 }
141}
Note: See TracBrowser for help on using the repository browser.