source: src/Fragmentation/Exporters/HydrogenPool.cpp@ 0983e6

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator 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_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 0983e6 was 910a5d, checked in by Frederik Heber <heber@…>, 10 years ago

atom::father is now accessible through getter and setter only.

  • this allows to manage signing on and off to and from father to be notified when it's destroyed.
  • Property mode set to 100644
File size: 4.4 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 UpdateSteps(Walker);
94 HydrogenInUse.insert( std::make_pair( Walker->getId(), Walker) );
95 HydrogenQueue.pop_front();
96
97 return Walker;
98}
99
100void HydrogenPool::UpdateSteps(atom * _atom) const
101{
102 // make sure we are up to current time step
103 const size_t CurrentTime = WorldTime::getTime();
104 for (size_t step = _atom->getTrajectorySize(); step <= CurrentTime; ++step)
105 _atom->UpdateStep(step);
106}
107
108void HydrogenPool::releaseHydrogen(atom * _atom)
109{
110 if (_atom == NULL) {
111 ASSERT( 0,
112 "HydrogenPool::releaseHydrogen() - got NULL atom.");
113 return;
114 }
115
116 // check that it is marked down
117 {
118 HydrogenInUse_t::iterator iter = HydrogenInUse.find(_atom->getId());
119 if (iter == HydrogenInUse.end()) {
120 ASSERT( 0,
121 "HydrogenPool::releaseHydrogen() - got unknown atom "+toString(_atom)+".");
122 return;
123 }
124 LOG(3, "DEBUG: Releasing " << *_atom << ".");
125 HydrogenInUse.erase(iter);
126 }
127 // check into queue
128 HydrogenQueue.push_back(_atom);
129}
130
131void HydrogenPool::releaseHydrogen(atomId_t _atom)
132{
133 atom * const Walker = World::getInstance().getAtom(AtomById(_atom));
134 ASSERT( Walker != NULL,
135 "HydrogenPool::releaseHydrogen() - id "
136 +toString(_atom)+" unknown to World.");
137 releaseHydrogen(Walker);
138}
139
140void HydrogenPool::cleanup()
141{
142 ASSERT(HydrogenInUse.empty(),
143 "HydrogenPool::cleanup() - cleanup called, but still hydrogens in use.");
144 for (HydrogenQueue_t::iterator iter = HydrogenQueue.begin();
145 !HydrogenQueue.empty(); iter = HydrogenQueue.begin()) {
146 atom * const Walker = *iter;
147 HydrogenQueue.erase(iter);
148 World::getInstance().destroyAtom(Walker);
149 }
150}
Note: See TracBrowser for help on using the repository browser.