Changeset 90e540 for src/Dynamics/ForceAnnealing.hpp
- Timestamp:
- Jul 20, 2017, 9:38:39 AM (8 years ago)
- Branches:
- ForceAnnealing_with_BondGraph_continued
- Children:
- ccbdf4
- Parents:
- 6d7c73
- git-author:
- Frederik Heber <frederik.heber@…> (07/18/17 22:24:12)
- git-committer:
- Frederik Heber <frederik.heber@…> (07/20/17 09:38:39)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Dynamics/ForceAnnealing.hpp
r6d7c73 r90e540 117 117 LOG(2, "DEBUG: current step is #" << currentStep); 118 118 119 // bond graph annealing is always followed by a normal annealing 119 120 if (_UseBondgraph) 120 121 annealWithBondGraph(_CurrentTimeStep, _offset, maxComponents); 121 else 122 anneal(_CurrentTimeStep, _offset, maxComponents); 122 anneal(_CurrentTimeStep, _offset, maxComponents); 123 123 } 124 124 … … 203 203 } 204 204 205 // knowing the number of bonds in total, we can setup the storage for the 206 // projected forces 207 enum whichatom_t { 208 leftside=0, 209 rightside=1, 210 MAX_sides 211 }; 212 213 /** Helper function to put bond force into a container. 214 * 215 * \param _walker atom 216 * \param _current_bond current bond of \a _walker 217 * \param _timestep time step 218 * \param _force calculated bond force 219 * \param _bv bondvectors for obtaining the correct index 220 * \param _projected_forces container 221 */ 222 static void ForceStore( 223 const atom &_walker, 224 const bond::ptr &_current_bond, 225 const size_t &_timestep, 226 const double _force, 227 const BondVectors &_bv, 228 std::vector< // time step 229 std::vector< // which bond side 230 std::vector<double> > // over all bonds 231 > &_projected_forces) 232 { 233 std::vector<double> &forcelist = (&_walker == _current_bond->leftatom) ? 234 _projected_forces[_timestep][leftside] : _projected_forces[_timestep][rightside]; 235 const size_t index = _bv.getIndexForBond(_current_bond); 236 ASSERT( index != (size_t)-1, 237 "ForceAnnealing() - could not find bond "+toString(*_current_bond) 238 +" in bondvectors"); 239 forcelist[index] = _force; 240 } 241 205 242 /** Performs Gradient optimization on the bonds. 206 243 * … … 260 297 const BondVectors::container_t &sorted_bonds = bv.getSorted(); 261 298 262 // knowing the number of bonds in total, we can setup the storage for the263 // projected forces264 enum whichatom_t {265 leftside=0,266 rightside=1,267 MAX_sides268 };269 299 std::vector< // time step 270 300 std::vector< // which bond side … … 280 310 typedef std::map<atomId_t, BondVectors::weights_t > weights_per_atom_t; 281 311 std::vector<weights_per_atom_t> weights_per_atom(2); 312 typedef std::map<atomId_t, Vector> RemnantGradient_per_atom_t; 313 RemnantGradient_per_atom_t RemnantGradient_per_atom; 282 314 for (size_t timestep = 0; timestep <= 1; ++timestep) { 283 315 // TODO: We have this extra step in between because of DoOutput copying … … 304 336 weights_per_atom[timestep].insert( 305 337 std::make_pair(walker.getId(), 306 bv.getWeightsForAtomAtStep(walker, CurrentStep)) );338 bv.getWeightsForAtomAtStep(walker, BondVectors, CurrentStep)) ); 307 339 ASSERT( inserter.second, 308 340 "ForceAnnealing::operator() - weight map for atom "+toString(walker) … … 316 348 // projected gradient over all bonds and place in one of projected_forces 317 349 // using the obtained weights 318 { 319 BondVectors::weights_t::const_iterator weightiter = weights.begin(); 320 std::vector<Vector>::const_iterator vectoriter = BondVectors.begin(); 321 Vector forcesum_check; 322 for(BondList::const_iterator bonditer = ListOfBonds.begin(); 323 bonditer != ListOfBonds.end(); ++bonditer, ++weightiter, ++vectoriter) { 324 const bond::ptr ¤t_bond = *bonditer; 325 const Vector &BondVector = *vectoriter; 326 327 std::vector<double> &forcelist = (&walker == current_bond->leftatom) ? 328 projected_forces[timestep][leftside] : projected_forces[timestep][rightside]; 329 const size_t index = bv.getIndexForBond(current_bond); 330 ASSERT( index != (size_t)-1, 331 "ForceAnnealing() - could not find bond "+toString(*current_bond) 332 +" in bondvectors"); 333 forcelist[index] = (*weightiter)*walkerGradient.ScalarProduct(BondVector); 334 LOG(4, "DEBUG: BondVector " << BondVector << " receives projected force of " 335 << forcelist[index]); 336 forcesum_check += forcelist[index] * BondVector; 337 } 338 ASSERT( weightiter == weights.end(), 339 "ForceAnnealing - weightiter is not at end when it should be."); 340 ASSERT( vectoriter == BondVectors.end(), 341 "ForceAnnealing - vectoriter is not at end when it should be."); 342 LOG(3, "DEBUG: sum of projected forces is " << forcesum_check); 343 } 344 350 BondVectors::forcestore_t forcestoring = 351 boost::bind(&ForceAnnealing::ForceStore, _1, _2, _3, _4, 352 boost::cref(bv), boost::ref(projected_forces)); 353 const Vector RemnantGradient = bv.getRemnantGradientForAtomAtStep( 354 walker, BondVectors, weights, timestep, forcestoring 355 ); 356 RemnantGradient_per_atom.insert( std::make_pair(walker.getId(), RemnantGradient) ); 345 357 } else { 346 358 LOG(2, "DEBUG: Gradient is " << walkerGradient << " less than " … … 465 477 } 466 478 467 // apply the gathered updates 479 // apply the gathered updates and set remnant gradients for atomic annealing 468 480 for (std::map<atomId_t, Vector>::const_iterator iter = GatheredUpdates.begin(); 469 481 iter != GatheredUpdates.end(); ++iter) { … … 476 488 << ", namely " << *walker); 477 489 walker->setPosition( walker->getPosition() + update ); 490 walker->setAtomicForce( RemnantGradient_per_atom[walker->getId()] ); 478 491 } 479 492 }
Note:
See TracChangeset
for help on using the changeset viewer.