source: src/Dynamics/ForceAnnealing.hpp@ 698308

ForceAnnealing_with_BondGraph_continued
Last change on this file since 698308 was 698308, checked in by Frederik Heber <frederik.heber@…>, 8 years ago

Fixing annealWithBondgraph().

  • Property mode set to 100644
File size: 24.5 KB
Line 
1/*
2 * ForceAnnealing.hpp
3 *
4 * Created on: Aug 02, 2014
5 * Author: heber
6 */
7
8#ifndef FORCEANNEALING_HPP_
9#define FORCEANNEALING_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16#include <algorithm>
17#include <functional>
18#include <iterator>
19
20#include <boost/bind.hpp>
21
22#include "Atom/atom.hpp"
23#include "Atom/AtomSet.hpp"
24#include "CodePatterns/Assert.hpp"
25#include "CodePatterns/Info.hpp"
26#include "CodePatterns/Log.hpp"
27#include "CodePatterns/Verbose.hpp"
28#include "Descriptors/AtomIdDescriptor.hpp"
29#include "Dynamics/AtomicForceManipulator.hpp"
30#include "Dynamics/BondVectors.hpp"
31#include "Fragmentation/ForceMatrix.hpp"
32#include "Graph/BoostGraphCreator.hpp"
33#include "Graph/BoostGraphHelpers.hpp"
34#include "Graph/BreadthFirstSearchGatherer.hpp"
35#include "Helpers/helpers.hpp"
36#include "Helpers/defs.hpp"
37#include "LinearAlgebra/LinearSystemOfEquations.hpp"
38#include "LinearAlgebra/MatrixContent.hpp"
39#include "LinearAlgebra/Vector.hpp"
40#include "LinearAlgebra/VectorContent.hpp"
41#include "Thermostats/ThermoStatContainer.hpp"
42#include "Thermostats/Thermostat.hpp"
43#include "World.hpp"
44
45/** This class is the essential build block for performing structural optimization.
46 *
47 * Sadly, we have to use some static instances as so far values cannot be passed
48 * between actions. Hence, we need to store the current step and the adaptive-
49 * step width (we cannot perform a line search, as we have no control over the
50 * calculation of the forces).
51 *
52 * However, we do use the bond graph, i.e. if a single atom needs to be shifted
53 * to the left, then the whole molecule left of it is shifted, too. This is
54 * controlled by the \a max_distance parameter.
55 */
56template <class T>
57class ForceAnnealing : public AtomicForceManipulator<T>
58{
59public:
60 /** Constructor of class ForceAnnealing.
61 *
62 * \note We use a fixed delta t of 1.
63 *
64 * \param _atoms set of atoms to integrate
65 * \param _Deltat time step width in atomic units
66 * \param _IsAngstroem whether length units are in angstroem or bohr radii
67 * \param _maxSteps number of optimization steps to perform
68 * \param _max_distance up to this bond order is bond graph taken into account.
69 */
70 ForceAnnealing(
71 AtomSetMixin<T> &_atoms,
72 const double _Deltat,
73 bool _IsAngstroem,
74 const size_t _maxSteps,
75 const int _max_distance,
76 const double _damping_factor) :
77 AtomicForceManipulator<T>(_atoms, _Deltat, _IsAngstroem),
78 maxSteps(_maxSteps),
79 max_distance(_max_distance),
80 damping_factor(_damping_factor)
81 {}
82
83 /** Destructor of class ForceAnnealing.
84 *
85 */
86 ~ForceAnnealing()
87 {}
88
89 /** Performs Gradient optimization.
90 *
91 * We assume that forces have just been calculated.
92 *
93 *
94 * \param CurrentTimeStep current time step (i.e. \f$ t + \Delta t \f$ in the sense of the velocity verlet)
95 * \param offset offset in matrix file to the first force component
96 * \todo This is not yet checked if it is correctly working with DoConstrainedMD set >0.
97 */
98 void operator()(
99 const int _CurrentTimeStep,
100 const size_t _offset,
101 const bool _UseBondgraph)
102 {
103 // make sum of forces equal zero
104 AtomicForceManipulator<T>::correctForceMatrixForFixedCenterOfMass(_offset, _CurrentTimeStep);
105
106 // are we in initial step? Then set static entities
107 Vector maxComponents(zeroVec);
108 if (currentStep == 0) {
109 currentDeltat = AtomicForceManipulator<T>::Deltat;
110 currentStep = 1;
111 LOG(2, "DEBUG: Initial step, setting values, current step is #" << currentStep);
112
113 // always use atomic annealing on first step
114 anneal(_CurrentTimeStep, _offset, maxComponents);
115 } else {
116 ++currentStep;
117 LOG(2, "DEBUG: current step is #" << currentStep);
118
119 if (_UseBondgraph)
120 annealWithBondGraph(_CurrentTimeStep, _offset, maxComponents);
121 else
122 anneal(_CurrentTimeStep, _offset, maxComponents);
123 }
124
125 LOG(1, "STATUS: Largest remaining force components at step #"
126 << currentStep << " are " << maxComponents);
127
128 // are we in final step? Remember to reset static entities
129 if (currentStep == maxSteps) {
130 LOG(2, "DEBUG: Final step, resetting values");
131 reset();
132 }
133 }
134
135 /** Performs Gradient optimization on the atoms.
136 *
137 * We assume that forces have just been calculated.
138 *
139 * \param CurrentTimeStep current time step (i.e. \f$ t + \Delta t \f$ in the sense of the velocity verlet)
140 * \param offset offset in matrix file to the first force component
141 * \param maxComponents to be filled with maximum force component over all atoms
142 */
143 void anneal(
144 const int CurrentTimeStep,
145 const size_t offset,
146 Vector &maxComponents)
147 {
148 bool deltat_decreased = false;
149 for(typename AtomSetMixin<T>::iterator iter = AtomicForceManipulator<T>::atoms.begin();
150 iter != AtomicForceManipulator<T>::atoms.end(); ++iter) {
151 // atom's force vector gives steepest descent direction
152 const Vector oldPosition = (*iter)->getPositionAtStep(CurrentTimeStep-2 >= 0 ? CurrentTimeStep - 2 : 0);
153 const Vector currentPosition = (*iter)->getPosition();
154 const Vector oldGradient = (*iter)->getAtomicForceAtStep(CurrentTimeStep-2 >= 0 ? CurrentTimeStep - 2 : 0);
155 const Vector currentGradient = (*iter)->getAtomicForce();
156 LOG(4, "DEBUG: oldPosition for atom " << **iter << " is " << oldPosition);
157 LOG(4, "DEBUG: currentPosition for atom " << **iter << " is " << currentPosition);
158 LOG(4, "DEBUG: oldGradient for atom " << **iter << " is " << oldGradient);
159 LOG(4, "DEBUG: currentGradient for atom " << **iter << " is " << currentGradient);
160// LOG(4, "DEBUG: Force for atom " << **iter << " is " << currentGradient);
161
162 // we use Barzilai-Borwein update with position reversed to get descent
163 const Vector PositionDifference = currentPosition - oldPosition;
164 const Vector GradientDifference = (currentGradient - oldGradient);
165 double stepwidth = 0.;
166 if (GradientDifference.Norm() > MYEPSILON)
167 stepwidth = fabs(PositionDifference.ScalarProduct(GradientDifference))/
168 GradientDifference.NormSquared();
169 if (fabs(stepwidth) < 1e-10) {
170 // dont' warn in first step, deltat usage normal
171 if (currentStep != 1)
172 ELOG(1, "INFO: Barzilai-Borwein stepwidth is zero, using deltat " << currentDeltat << " instead.");
173 stepwidth = currentDeltat;
174 }
175 Vector PositionUpdate = stepwidth * currentGradient;
176 LOG(3, "DEBUG: Update would be " << stepwidth << "*" << currentGradient << " = " << PositionUpdate);
177
178 // extract largest components for showing progress of annealing
179 for(size_t i=0;i<NDIM;++i)
180 if (currentGradient[i] > maxComponents[i])
181 maxComponents[i] = currentGradient[i];
182
183 // steps may go back and forth again (updates are of same magnitude but
184 // have different sign: Check whether this is the case and one step with
185 // deltat to interrupt this sequence
186 if ((currentStep > 1) && (!PositionDifference.IsZero()))
187 if ((PositionUpdate.ScalarProduct(PositionDifference) < 0)
188 && (fabs(PositionUpdate.NormSquared()-PositionDifference.NormSquared()) < 1e-3)) {
189 // for convergence we want a null sequence here, too
190 if (!deltat_decreased) {
191 deltat_decreased = true;
192 currentDeltat = .5*currentDeltat;
193 }
194 LOG(2, "DEBUG: Upgrade in other direction: " << PositionUpdate
195 << " > " << PositionDifference
196 << ", using deltat: " << currentDeltat);
197 PositionUpdate = currentDeltat * currentGradient;
198 }
199
200 // finally set new values
201 (*iter)->setPosition(currentPosition + PositionUpdate);
202 }
203 }
204
205 /** Performs Gradient optimization on the bonds.
206 *
207 * We assume that forces have just been calculated. These forces are projected
208 * onto the bonds and these are annealed subsequently by moving atoms in the
209 * bond neighborhood on either side conjunctively.
210 *
211 *
212 * \param CurrentTimeStep current time step (i.e. \f$ t + \Delta t \f$ in the sense of the velocity verlet)
213 * \param offset offset in matrix file to the first force component
214 * \param maxComponents to be filled with maximum force component over all atoms
215 */
216 void annealWithBondGraph(
217 const int CurrentTimeStep,
218 const size_t offset,
219 Vector &maxComponents)
220 {
221 // get nodes on either side of selected bond via BFS discovery
222 BoostGraphCreator BGcreator;
223 BGcreator.createFromRange(
224 AtomicForceManipulator<T>::atoms.begin(),
225 AtomicForceManipulator<T>::atoms.end(),
226 AtomicForceManipulator<T>::atoms.size(),
227 BreadthFirstSearchGatherer::AlwaysTruePredicate);
228 BreadthFirstSearchGatherer NodeGatherer(BGcreator);
229
230 /// We assume that a force is local, i.e. a bond is too short yet and hence
231 /// the atom needs to be moved. However, all the adjacent (bound) atoms might
232 /// already be at the perfect distance. If we just move the atom alone, we ruin
233 /// all the other bonds. Hence, it would be sensible to move every atom found
234 /// through the bond graph in the direction of the force as well by the same
235 /// PositionUpdate. This is almost what we are going to do.
236
237 /// One issue is: If we need to shorten bond, then we use the PositionUpdate
238 /// also on the the other bond partner already. This is because it is in the
239 /// direction of the bond. Therefore, the update is actually performed twice on
240 /// each bond partner, i.e. the step size is twice as large as it should be.
241 /// This problem only occurs when bonds need to be shortened, not when they
242 /// need to be made longer (then the force vector is facing the other
243 /// direction than the bond vector).
244 /// As a remedy we need to average the force on either end of the bond and
245 /// check whether each gradient points inwards out or outwards with respect
246 /// to the bond and then shift accordingly.
247
248 /// One more issue is that the projection onto the bond directions does not
249 /// recover the gradient but may be larger as the bond directions are a
250 /// generating system and not a basis (e.g. 3 bonds on a plane where 2 would
251 /// suffice to span the plane). To this end, we need to account for the
252 /// overestimation and obtain a weighting for each bond.
253
254 // initialize helper class for bond vectors using bonds from range of atoms
255 BondVectors bv;
256 bv.setFromAtomRange< T >(
257 AtomicForceManipulator<T>::atoms.begin(),
258 AtomicForceManipulator<T>::atoms.end(),
259 currentStep);
260 const BondVectors::container_t &sorted_bonds = bv.getSorted();
261
262 // knowing the number of bonds in total, we can setup the storage for the
263 // projected forces
264 enum whichatom_t {
265 leftside=0,
266 rightside=1,
267 MAX_sides
268 };
269 std::vector< // time step
270 std::vector< // which bond side
271 std::vector<double> > // over all bonds
272 > projected_forces(2); // one for leftatoms, one for rightatoms (and for both time steps)
273 for (size_t i=0;i<2;++i) {
274 projected_forces[i].resize(MAX_sides);
275 for (size_t j=0;j<MAX_sides;++j)
276 projected_forces[i][j].resize(sorted_bonds.size(), 0.);
277 }
278
279 // for each atom we need to gather weights and then project the gradient
280 typedef std::deque<double> weights_t;
281 typedef std::map<atomId_t, weights_t > weights_per_atom_t;
282 std::vector<weights_per_atom_t> weights_per_atom(2);
283 for (size_t timestep = 0; timestep <= 1; ++timestep) {
284 // TODO: We have this extra step in between because of DoOutput copying
285 // change this making the code easier to understand
286 const size_t CurrentStep = CurrentTimeStep-2*timestep >= 0 ? CurrentTimeStep - 2*timestep : 0;
287
288 // get all bond vectors for this time step (from the perspective of the
289 // bonds taken from the currentStep)
290 const BondVectors::mapped_t bondvectors = bv.getBondVectorsAtStep(CurrentStep);
291
292 for(typename AtomSetMixin<T>::const_iterator iter = AtomicForceManipulator<T>::atoms.begin();
293 iter != AtomicForceManipulator<T>::atoms.end(); ++iter) {
294 const atom &walker = *(*iter);
295 const Vector &walkerGradient = walker.getAtomicForceAtStep(CurrentStep);
296 LOG(3, "DEBUG: Gradient of atom #" << walker.getId() << ", namely "
297 << walker << " is " << walkerGradient);
298
299 const BondList& ListOfBonds = walker.getListOfBonds();
300 if (walkerGradient.Norm() > MYEPSILON) {
301
302 // gather subset of BondVectors for the current atom
303 std::vector<Vector> BondVectors;
304 for(BondList::const_iterator bonditer = ListOfBonds.begin();
305 bonditer != ListOfBonds.end(); ++bonditer) {
306 const bond::ptr &current_bond = *bonditer;
307 const BondVectors::mapped_t::const_iterator bviter =
308 bondvectors.find(current_bond);
309 ASSERT( bviter != bondvectors.end(),
310 "ForceAnnealing() - cannot find current_bond ?");
311 ASSERT( bviter != bondvectors.end(),
312 "ForceAnnealing - cannot find current bond "+toString(*current_bond)
313 +" in bonds.");
314 BondVectors.push_back(bviter->second);
315 }
316 LOG(4, "DEBUG: BondVectors for atom #" << walker.getId() << ": " << BondVectors);
317
318 // go through all its bonds and calculate what magnitude is represented
319 // by the others i.e. sum of scalar products against other bonds
320 std::pair<weights_per_atom_t::iterator, bool> inserter =
321 weights_per_atom[timestep].insert(
322 std::make_pair(walker.getId(), weights_t()) );
323 ASSERT( inserter.second,
324 "ForceAnnealing::operator() - weight map for atom "+toString(walker)
325 +" and time step "+toString(timestep)+" already filled?");
326 weights_t &weights = inserter.first->second;
327 for (std::vector<Vector>::const_iterator iter = BondVectors.begin();
328 iter != BondVectors.end(); ++iter) {
329 std::vector<double> scps;
330 scps.reserve(BondVectors.size());
331 std::transform(
332 BondVectors.begin(), BondVectors.end(),
333 std::back_inserter(scps),
334 boost::bind(static_cast< double (*)(double) >(&fabs),
335 boost::bind(&Vector::ScalarProduct, boost::cref(*iter), _1))
336 );
337 const double scp_sum = std::accumulate(scps.begin(), scps.end(), 0.);
338 ASSERT( (scp_sum-1.) > -MYEPSILON,
339 "ForceAnnealing() - sum of weights must be equal or larger one but is "
340 +toString(scp_sum));
341 weights.push_back( 1./scp_sum );
342 }
343 LOG(4, "DEBUG: Weights for atom #" << walker.getId() << ": " << weights);
344
345 // for testing we check whether all weighted scalar products now come out as 1.
346#ifndef NDEBUG
347 for (std::vector<Vector>::const_iterator iter = BondVectors.begin();
348 iter != BondVectors.end(); ++iter) {
349 std::vector<double> scps;
350 scps.reserve(BondVectors.size());
351 std::transform(
352 BondVectors.begin(), BondVectors.end(),
353 weights.begin(),
354 std::back_inserter(scps),
355 boost::bind(static_cast< double (*)(double) >(&fabs),
356 boost::bind(std::multiplies<double>(),
357 boost::bind(&Vector::ScalarProduct, boost::cref(*iter), _1),
358 _2))
359 );
360 const double scp_sum = std::accumulate(scps.begin(), scps.end(), 0.);
361 ASSERT( fabs(scp_sum - 1.) < MYEPSILON,
362 "ForceAnnealing::operator() - for BondVector "+toString(*iter)
363 +" we have weighted scalar product of "+toString(scp_sum)+" != 1.");
364 }
365#endif
366
367 // projected gradient over all bonds and place in one of projected_forces
368 // using the obtained weights
369 {
370 weights_t::const_iterator weightiter = weights.begin();
371 std::vector<Vector>::const_iterator vectoriter = BondVectors.begin();
372 Vector forcesum_check;
373 for(BondList::const_iterator bonditer = ListOfBonds.begin();
374 bonditer != ListOfBonds.end(); ++bonditer, ++weightiter, ++vectoriter) {
375 const bond::ptr &current_bond = *bonditer;
376 const Vector &BondVector = *vectoriter;
377
378 std::vector<double> &forcelist = (&walker == current_bond->leftatom) ?
379 projected_forces[timestep][leftside] : projected_forces[timestep][rightside];
380 const size_t index = bv.getIndexForBond(current_bond);
381 ASSERT( index != (size_t)-1,
382 "ForceAnnealing() - could not find bond "+toString(*current_bond)
383 +" in bondvectors");
384 forcelist[index] = (*weightiter)*walkerGradient.ScalarProduct(BondVector);
385 LOG(4, "DEBUG: BondVector " << BondVector << " receives projected force of "
386 << forcelist[index]);
387 forcesum_check += forcelist[index] * BondVector;
388 }
389 ASSERT( weightiter == weights.end(),
390 "ForceAnnealing - weightiter is not at end when it should be.");
391 ASSERT( vectoriter == BondVectors.end(),
392 "ForceAnnealing - vectoriter is not at end when it should be.");
393 LOG(3, "DEBUG: sum of projected forces is " << forcesum_check);
394 }
395
396 } else {
397 LOG(2, "DEBUG: Gradient is " << walkerGradient << " less than "
398 << MYEPSILON << " for atom " << walker);
399 // note that projected_forces is initialized to full length and filled
400 // with zeros. Hence, nothing to do here
401 }
402 }
403 }
404
405 // step through each bond and shift the atoms
406 std::map<atomId_t, Vector> GatheredUpdates; //!< gathers all updates which are applied at the end
407
408 LOG(3, "DEBUG: current step is " << currentStep << ", given time step is " << CurrentTimeStep);
409 const BondVectors::mapped_t bondvectors = bv.getBondVectorsAtStep(currentStep);
410
411 for (BondVectors::container_t::const_iterator bondsiter = sorted_bonds.begin();
412 bondsiter != sorted_bonds.end(); ++bondsiter) {
413 const bond::ptr &current_bond = *bondsiter;
414 const size_t index = bv.getIndexForBond(current_bond);
415 const atom* bondatom[MAX_sides] = {
416 current_bond->leftatom,
417 current_bond->rightatom
418 };
419
420 // remove the edge
421#ifndef NDEBUG
422 const bool status =
423#endif
424 BGcreator.removeEdge(bondatom[leftside]->getId(), bondatom[rightside]->getId());
425 ASSERT( status, "ForceAnnealing() - edge to found bond is not present?");
426
427 // gather nodes for either atom
428 BoostGraphHelpers::Nodeset_t bondside_set[MAX_sides];
429 BreadthFirstSearchGatherer::distance_map_t distance_map[MAX_sides];
430 for (size_t side=leftside;side<MAX_sides;++side) {
431 bondside_set[side] = NodeGatherer(bondatom[side]->getId(), max_distance);
432 distance_map[side] = NodeGatherer.getDistances();
433 std::sort(bondside_set[side].begin(), bondside_set[side].end());
434 }
435
436 // re-add edge
437 BGcreator.addEdge(bondatom[leftside]->getId(), bondatom[rightside]->getId());
438
439 // do for both leftatom and rightatom of bond
440 for (size_t side = leftside; side < MAX_sides; ++side) {
441 const double &bondforce = projected_forces[0][side][index];
442 const double &oldbondforce = projected_forces[1][side][index];
443 const double bondforcedifference = fabs(bondforce - oldbondforce);
444 LOG(4, "DEBUG: bondforce for " << (side == leftside ? "left" : "right")
445 << " side of bond is " << bondforce);
446 LOG(4, "DEBUG: oldbondforce for " << (side == leftside ? "left" : "right")
447 << " side of bond is " << oldbondforce);
448 // if difference or bondforce itself is zero, do nothing
449 if ((fabs(bondforce) < MYEPSILON) || (fabs(bondforcedifference) < MYEPSILON))
450 continue;
451
452 // get BondVector to bond
453 const BondVectors::mapped_t::const_iterator bviter =
454 bondvectors.find(current_bond);
455 ASSERT( bviter != bondvectors.end(),
456 "ForceAnnealing() - cannot find current_bond ?");
457 ASSERT( fabs(bviter->second.Norm() -1.) < MYEPSILON,
458 "ForceAnnealing() - norm of BondVector is not one");
459 const Vector &BondVector = bviter->second;
460
461 // calculate gradient and position differences for stepwidth
462 const Vector currentGradient = bondforce * BondVector;
463 LOG(4, "DEBUG: current projected gradient for "
464 << (side == leftside ? "left" : "right") << " side of bond is " << currentGradient);
465 const Vector &oldPosition = bondatom[side]->getPositionAtStep(CurrentTimeStep-2 >= 0 ? CurrentTimeStep - 2 : 0);
466 const Vector &currentPosition = bondatom[side]->getPositionAtStep(currentStep);
467 const Vector PositionDifference = currentPosition - oldPosition;
468 LOG(4, "DEBUG: old position is " << oldPosition);
469 LOG(4, "DEBUG: current position is " << currentPosition);
470 LOG(4, "DEBUG: difference in position is " << PositionDifference);
471 LOG(4, "DEBUG: abs. difference in forces is " << bondforcedifference);
472 LOG(4, "DEBUG: bondvector is " << BondVector);
473
474 // calculate step width
475 double stepwidth =
476 fabs(PositionDifference.ScalarProduct(BondVector))/bondforcedifference;
477 if (fabs(stepwidth) < 1e-10) {
478 // dont' warn in first step, deltat usage normal
479 if (currentStep != 1)
480 ELOG(1, "INFO: Barzilai-Borwein stepwidth is zero, using deltat " << currentDeltat << " instead.");
481 stepwidth = currentDeltat;
482 }
483 Vector PositionUpdate = stepwidth * currentGradient;
484 LOG(3, "DEBUG: Update would be " << stepwidth << "*" << currentGradient << " = " << PositionUpdate);
485
486 // add PositionUpdate for all nodes in the bondside_set
487 for (BoostGraphHelpers::Nodeset_t::const_iterator setiter = bondside_set[side].begin();
488 setiter != bondside_set[side].end(); ++setiter) {
489 const BreadthFirstSearchGatherer::distance_map_t::const_iterator diter
490 = distance_map[side].find(*setiter);
491 ASSERT( diter != distance_map[side].end(),
492 "ForceAnnealing() - could not find distance to an atom.");
493 const double factor = pow(damping_factor, diter->second+1);
494 LOG(3, "DEBUG: Update for atom #" << *setiter << " will be "
495 << factor << "*" << PositionUpdate);
496 if (GatheredUpdates.count((*setiter))) {
497 GatheredUpdates[(*setiter)] += factor*PositionUpdate;
498 } else {
499 GatheredUpdates.insert(
500 std::make_pair(
501 (*setiter),
502 factor*PositionUpdate) );
503 }
504 }
505 }
506 }
507
508 for(typename AtomSetMixin<T>::iterator iter = AtomicForceManipulator<T>::atoms.begin();
509 iter != AtomicForceManipulator<T>::atoms.end(); ++iter) {
510 atom &walker = *(*iter);
511 // extract largest components for showing progress of annealing
512 const Vector currentGradient = walker.getAtomicForce();
513 for(size_t i=0;i<NDIM;++i)
514 if (currentGradient[i] > maxComponents[i])
515 maxComponents[i] = currentGradient[i];
516 }
517
518 // apply the gathered updates
519 for (std::map<atomId_t, Vector>::const_iterator iter = GatheredUpdates.begin();
520 iter != GatheredUpdates.end(); ++iter) {
521 const atomId_t &atomid = iter->first;
522 const Vector &update = iter->second;
523 atom* const walker = World::getInstance().getAtom(AtomById(atomid));
524 ASSERT( walker != NULL,
525 "ForceAnnealing() - walker with id "+toString(atomid)+" has suddenly disappeared.");
526 LOG(3, "DEBUG: Applying update " << update << " to atom #" << atomid
527 << ", namely " << *walker);
528 walker->setPosition( walker->getPosition() + update );
529 }
530 }
531
532 /** Reset function to unset static entities and artificial velocities.
533 *
534 */
535 void reset()
536 {
537 currentDeltat = 0.;
538 currentStep = 0;
539 }
540
541private:
542 //!> contains the current step in relation to maxsteps
543 static size_t currentStep;
544 //!> contains the maximum number of steps, determines initial and final step with currentStep
545 size_t maxSteps;
546 static double currentDeltat;
547 //!> minimum deltat for internal while loop (adaptive step width)
548 static double MinimumDeltat;
549 //!> contains the maximum bond graph distance up to which shifts of a single atom are spread
550 const int max_distance;
551 //!> the shifted is dampened by this factor with the power of the bond graph distance to the shift causing atom
552 const double damping_factor;
553};
554
555template <class T>
556double ForceAnnealing<T>::currentDeltat = 0.;
557template <class T>
558size_t ForceAnnealing<T>::currentStep = 0;
559template <class T>
560double ForceAnnealing<T>::MinimumDeltat = 1e-8;
561
562#endif /* FORCEANNEALING_HPP_ */
Note: See TracBrowser for help on using the repository browser.