Changeset 698308


Ignore:
Timestamp:
Jul 20, 2017, 9:38:38 AM (8 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
ForceAnnealing_with_BondGraph_continued
Children:
12d20c
Parents:
b7fe6e
git-author:
Frederik Heber <frederik.heber@…> (06/27/17 21:17:18)
git-committer:
Frederik Heber <frederik.heber@…> (07/20/17 09:38:38)
Message:

Fixing annealWithBondgraph().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Dynamics/ForceAnnealing.hpp

    rb7fe6e r698308  
    441441        const double &bondforce = projected_forces[0][side][index];
    442442        const double &oldbondforce = projected_forces[1][side][index];
    443         const double bondforcedifference = (bondforce - oldbondforce);
     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);
    444448        // if difference or bondforce itself is zero, do nothing
    445449        if ((fabs(bondforce) < MYEPSILON) || (fabs(bondforcedifference) < MYEPSILON))
    446450          continue;
     451
     452        // get BondVector to bond
    447453        const BondVectors::mapped_t::const_iterator bviter =
    448454            bondvectors.find(current_bond);
    449455        ASSERT( bviter != bondvectors.end(),
    450456            "ForceAnnealing() - cannot find current_bond ?");
     457        ASSERT( fabs(bviter->second.Norm() -1.) < MYEPSILON,
     458            "ForceAnnealing() - norm of BondVector is not one");
    451459        const Vector &BondVector = bviter->second;
    452         const Vector &oldPosition = bondatom[side]->getPositionAtStep(CurrentTimeStep-1 >= 0 ? CurrentTimeStep - 1 : 0);
    453         const Vector &currentPosition = bondatom[side]->getPosition();
    454         const double stepwidth =
    455             fabs((currentPosition - oldPosition).ScalarProduct(BondVector))/bondforcedifference;
    456         Vector PositionUpdate = stepwidth * BondVector;
     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;
    457477        if (fabs(stepwidth) < 1e-10) {
    458478          // dont' warn in first step, deltat usage normal
    459479          if (currentStep != 1)
    460480            ELOG(1, "INFO: Barzilai-Borwein stepwidth is zero, using deltat " << currentDeltat << " instead.");
    461           PositionUpdate = currentDeltat * BondVector;
     481          stepwidth = currentDeltat;
    462482        }
    463         LOG(3, "DEBUG: Update would be " << PositionUpdate);
     483        Vector PositionUpdate = stepwidth * currentGradient;
     484        LOG(3, "DEBUG: Update would be " << stepwidth << "*" << currentGradient << " = " << PositionUpdate);
    464485
    465486        // add PositionUpdate for all nodes in the bondside_set
     
    470491          ASSERT( diter != distance_map[side].end(),
    471492              "ForceAnnealing() - could not find distance to an atom.");
    472           const double factor = pow(damping_factor, diter->second);
     493          const double factor = pow(damping_factor, diter->second+1);
    473494          LOG(3, "DEBUG: Update for atom #" << *setiter << " will be "
    474495              << factor << "*" << PositionUpdate);
Note: See TracChangeset for help on using the changeset viewer.