Changeset 040a5c


Ignore:
Timestamp:
Feb 22, 2012, 11:28:52 AM (13 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:
429069
Parents:
38c5d1
git-author:
Frederik Heber <heber@…> (01/05/12 18:26:00)
git-committer:
Frederik Heber <heber@…> (02/22/12 11:28:52)
Message:

WorldTime is now Observable.

  • this is required for the LinkedCell_Controller. It has to know when its models have to be re-initialized because all atoms changed positions.
  • WorldTime::setTime() is no more static and his caused changes in all classes that are friend and may use this private function.
Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/WorldAction/SetWorldTimeAction.cpp

    r38c5d1 r040a5c  
    4444  getParametersfromValueStorage();
    4545
    46   WorldTime::setTime(params.newtime);
     46  WorldTime::getInstance().setTime(params.newtime);
    4747  LOG(0, "Current time step is now: " << WorldTime::getTime() << ".");
    4848  return Action::state_ptr(UndoState);
     
    5252  WorldSetWorldTimeState *state = assert_cast<WorldSetWorldTimeState*>(_state.get());
    5353
    54   WorldTime::setTime(state->oldtime);
     54  WorldTime::getInstance().setTime(state->oldtime);
    5555  LOG(0, "Current time step is now again: " << WorldTime::getTime() << ".");
    5656
     
    6161  WorldSetWorldTimeState *state = assert_cast<WorldSetWorldTimeState*>(_state.get());
    6262
    63   WorldTime::setTime(state->params.newtime);
     63  WorldTime::getInstance().setTime(state->params.newtime);
    6464  LOG(0, "Current time step is now: " << WorldTime::getTime() << ".");
    6565
  • src/World.cpp

    r38c5d1 r040a5c  
    151151  if (_step != WorldTime::getTime()) {
    152152    // set new time
    153     WorldTime::setTime(_step);
     153    WorldTime::getInstance().setTime(_step);
    154154    // TODO: removed when BondGraph creates the adjacency
    155155    // 1. remove all of World's molecules
  • src/WorldTime.cpp

    r38c5d1 r040a5c  
    2323
    2424#include "CodePatterns/Log.hpp"
     25#include "CodePatterns/Observer/Channels.hpp"
     26#include "CodePatterns/Observer/Notification.hpp"
    2527#include "CodePatterns/Singleton_impl.hpp"
    2628
     
    2830
    2931WorldTime::WorldTime() :
     32  Observable("WorldTime"),
    3033  StepWidth(0.)
    31 {}
     34{
     35  // observable stuff
     36  Channels *OurChannel = new Channels;
     37  NotificationChannels.insert( std::make_pair(this, OurChannel) );
     38  // add instance for each notification type
     39  for (size_t type = 0; type < NotificationType_MAX; ++type)
     40    OurChannel->addChannel(type);
     41}
    3242
    3343WorldTime::~WorldTime()
    34 {}
     44{
     45  // observable stuff
     46  std::map<Observable *, Channels*>::iterator iter = NotificationChannels.find(this);
     47  delete iter->second;
     48  NotificationChannels.erase(iter);
     49}
    3550
    3651void WorldTime::setStepWidth(const double _width)
     
    4560}
    4661
     62void WorldTime::setTime(const unsigned int _time)
     63{
     64  OBSERVE;
     65  NOTIFY(TimeChanged);
     66  WorldTime::CurrentTime = _time;
     67}
     68
    4769CONSTRUCT_SINGLETON(WorldTime)
  • src/WorldTime.hpp

    r38c5d1 r040a5c  
    1414#endif
    1515
     16#include "CodePatterns/Observer/Observable.hpp"
    1617#include "CodePatterns/Singleton.hpp"
    1718
     
    2223}
    2324
    24 class WorldTime : public Singleton<WorldTime>
     25class WorldTime : public Singleton<WorldTime>, public Observable
    2526{
    2627  //!> own unit test should be friend to access private variables.
     
    3839  friend class MoleCuilder::WorldSetWorldTimeAction;
    3940public:
     41  enum NotificationType {
     42    TimeChanged,
     43    NotificationType_MAX  // denotes the maximum of available notification types
     44  };
    4045
    4146  /** Getter for CurrentTime.
     
    6570   * @param _time value to set CurrentTime to
    6671   */
    67   static void setTime(const unsigned int _time)
    68     { WorldTime::CurrentTime = _time; }
     72  void setTime(const unsigned int _time);
    6973
    7074  static unsigned int CurrentTime;  //!< contains current time step
  • src/unittests/ListOfBondsUnitTest.cpp

    r38c5d1 r040a5c  
    5252  atom *Walker = NULL;
    5353
    54   WorldTime::setTime(0);
     54  WorldTime::getInstance().setTime(0);
    5555
    5656  // construct element
     
    362362
    363363  // add bond
    364   WorldTime::setTime(0);
    365   Binder = TestMolecule->AddBond(atom1, atom2, 1);
    366   CPPUNIT_ASSERT( Binder != NULL );
    367   WorldTime::setTime(1);
     364  WorldTime::getInstance().setTime(0);
     365  Binder = TestMolecule->AddBond(atom1, atom2, 1);
     366  CPPUNIT_ASSERT( Binder != NULL );
     367  WorldTime::getInstance().setTime(1);
    368368  Binder = TestMolecule->AddBond(atom1, atom2, 1);
    369369  CPPUNIT_ASSERT( Binder != NULL );
     
    371371  // access test via CurrentTime
    372372  { // time step 0
    373     WorldTime::setTime(0);
     373    WorldTime::getInstance().setTime(0);
    374374    {
    375375      const BondList& ListOfBonds = atom1->getListOfBonds();
     
    383383  }
    384384  { // time step 1
    385     WorldTime::setTime(1);
     385    WorldTime::getInstance().setTime(1);
    386386    {
    387387      const BondList& ListOfBonds = atom1->getListOfBonds();
     
    393393    }
    394394    CPPUNIT_ASSERT_EQUAL( true, TestMolecule->hasBondStructure() );
    395     WorldTime::setTime(0);
     395    WorldTime::getInstance().setTime(0);
    396396  }
    397397
     
    423423  // check bond if removed from other atom for all time steps
    424424  {
    425     WorldTime::setTime(0);
     425    WorldTime::getInstance().setTime(0);
    426426    const BondList& ListOfBonds = atom1->getListOfBonds();
    427427    CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
     
    429429  }
    430430  {
    431     WorldTime::setTime(1);
     431    WorldTime::getInstance().setTime(1);
    432432    const BondList& ListOfBonds = atom1->getListOfBonds();
    433433    CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
    434434    CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
    435     WorldTime::setTime(0);
     435    WorldTime::getInstance().setTime(0);
    436436  }
    437437
Note: See TracChangeset for help on using the changeset viewer.