Ignore:
Timestamp:
Aug 20, 2014, 12:58:29 PM (11 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, 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_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
d5f7b8
Parents:
7e51e1
git-author:
Frederik Heber <heber@…> (08/02/14 09:43:22)
git-committer:
Frederik Heber <heber@…> (08/20/14 12:58:29)
Message:

Extended VerletIntegrationAction wirth Undo/Redo.

  • using new UndoRedoHelpers for this.
  • VerletForceIntegration::operator() does not return bool anymore, check for empty atom set is done in Action.
  • TESTFIX: Removed XFAIl from regression tests verlet-integration.
Location:
src/Actions/MoleculeAction
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/MoleculeAction/VerletIntegrationAction.cpp

    r7e51e1 r1e45f1f  
    33 * Description: creates and alters molecular systems
    44 * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
     5 * Copyright (C)  2013-2014 Frederik Heber. All rights reserved.
    56 *
    67 *
     
    3536#include "CodePatterns/MemDebug.hpp"
    3637
     38#include "Actions/UndoRedoHelpers.hpp"
    3739#include "Atom/atom.hpp"
     40#include "Atom/AtomicInfo.hpp"
    3841#include "Atom/AtomSet.hpp"
    3942#include "CodePatterns/Log.hpp"
     
    5356using namespace MoleCuilder;
    5457
     58enum {
     59  PositionIndex=0,
     60  VelocityIndex=1,
     61  ForceIndex=2,
     62  MAXINDEX
     63} VectorIndexType;
     64
    5565// and construct the stuff
    5666#include "VerletIntegrationAction.def"
     
    6474  }
    6575  // we always operate relative to current time step
    66   size_t CurrentStep = WorldTime::getInstance().getTime();
     76  const size_t CurrentStep = WorldTime::getInstance().getTime();
    6777  VerletForceIntegration<std::vector<atom *> > Verlet(set, params.Deltat.get(), true);
    6878  // parse forces into next step
     
    7484      LOG(2, "File " << params.forcesfile.get() << " found and parsed.");
    7585  }
     86
     87  // create undo state for all selected atoms (undo info)
     88  std::vector<AtomicInfo> UndoInfo;
     89  UndoInfo.reserve(set.size());
     90  {
     91    for (World::AtomSelectionConstIterator iter = World::getInstance().beginAtomSelection();
     92        iter != World::getInstance().endAtomSelection();
     93        ++iter)
     94      UndoInfo.push_back(AtomicInfo(*(iter->second)));
     95  }
     96
    7697  // perform velocity verlet update
    77   bool status = Verlet(CurrentStep+1, 1, 0, params.FixedCenterOfMass.get());
    78   if (!status) {
    79     ELOG(1, "Velocity verlet failed.");
    80     return Action::failure;
    81   } else {
    82     LOG(2, "DEBUG: Successfully performed updates on velocity and position.");
    83     // increment to next time step
    84     World::getInstance().setTime(CurrentStep+1);
     98  Verlet(CurrentStep+1, 1, 0, params.FixedCenterOfMass.get());
     99  LOG(0, "STATUS: Successfully performed updates on velocity and position.");
     100  // increment to next time step
     101  World::getInstance().setTime(CurrentStep+1);
     102
     103  // create undo state for all selected atoms (redo info):
     104  // we need:
     105  // -# forces from last step (possible parsing forces file, already in UndoInfo)
     106  // -# velocities from last step (..UpdateU(), already in UndoInfo)
     107  // -# current position (..UpdateX())
     108  std::vector<Vectors_t> UpdatedStep(MAXINDEX);
     109  UpdatedStep[PositionIndex].reserve(set.size());
     110  UpdatedStep[VelocityIndex].reserve(set.size());
     111  UpdatedStep[ForceIndex].reserve(set.size());
     112  {
     113    for (World::AtomSelectionConstIterator iter = World::getInstance().beginAtomSelection();
     114        iter != World::getInstance().endAtomSelection();
     115        ++iter) {
     116      UpdatedStep[PositionIndex].push_back(iter->second->getPositionAtStep(CurrentStep+1));
     117      UpdatedStep[VelocityIndex].push_back(iter->second->getAtomicVelocityAtStep(CurrentStep));
     118      UpdatedStep[ForceIndex].push_back(iter->second->getAtomicForceAtStep(CurrentStep));
     119    }
    85120  }
    86   return Action::success;
     121  MoleculeVerletIntegrationState *UndoState =
     122      new MoleculeVerletIntegrationState(UndoInfo, UpdatedStep, params);
     123
     124  return ActionState::ptr(UndoState);
    87125}
    88126
    89127ActionState::ptr MoleculeVerletIntegrationAction::performUndo(ActionState::ptr _state) {
    90 //  MoleculeVerletIntegrationState *state = assert_cast<MoleculeVerletIntegrationState*>(_state.get());
     128  MoleculeVerletIntegrationState *state =
     129      assert_cast<MoleculeVerletIntegrationState*>(_state.get());
    91130
    92 //  string newName = state->mol->getName();
    93 //  state->mol->setName(state->lastName);
     131  // go back one step
     132  const size_t CurrentStep = WorldTime::getInstance().getTime();
     133  World::getInstance().setTime(CurrentStep-1);
    94134
    95   STATUS("Undo of MoleculeVerletIntegrationAction not implemented.");
    96   return Action::failure;
     135  // remove current step for all modified atoms
     136  removeLastStep(getIdsFromAtomicInfo(state->UndoInfo));
     137
     138  // and set back the old step (forces have been changed)
     139  SetAtomsFromAtomicInfo(state->UndoInfo);
     140
     141  return ActionState::ptr(_state);
    97142}
    98143
    99144ActionState::ptr MoleculeVerletIntegrationAction::performRedo(ActionState::ptr _state){
    100   STATUS("Rddo of MoleculeVerletIntegrationAction not implemented.");
    101   return Action::failure;
     145  MoleculeVerletIntegrationState *state =
     146      assert_cast<MoleculeVerletIntegrationState*>(_state.get());
     147
     148  // set forces and velocities
     149  ResetAtomVelocity(state->UndoInfo, state->UpdatedStep[VelocityIndex]);
     150  ResetAtomForce(state->UndoInfo, state->UpdatedStep[ForceIndex]);
     151
     152  // set stored new state
     153  addNewStep(state->UndoInfo);
     154
     155  // add a new time step
     156  size_t CurrentStep = WorldTime::getInstance().getTime();
     157  World::getInstance().setTime(CurrentStep+1);
     158
     159  // and set positions of the new step
     160  ResetAtomPosition(state->UndoInfo, state->UpdatedStep[PositionIndex]);
     161
     162  return ActionState::ptr(_state);
    102163}
    103164
  • src/Actions/MoleculeAction/VerletIntegrationAction.def

    r7e51e1 r1e45f1f  
    77
    88// all includes and forward declarations necessary for non-integral types below
    9 class MoleculeListClass;
     9#include "LinearAlgebra/Vector.hpp"
     10#include <vector>
     11typedef std::vector<Vector> Vectors_t;
    1012
    1113#include "Parameters/Validators/DummyValidator.hpp"
     
    2729(DummyValidator< bool >())
    2830
    29 #undef statetypes
    30 #undef statereferences
     31#define statetypes (std::vector<AtomicInfo>)(std::vector<Vectors_t>)
     32#define statereferences (UndoInfo)(UpdatedStep)
    3133
    3234// some defines for all the names, you may use ACTION, STATE and PARAMS
Note: See TracChangeset for help on using the changeset viewer.