Changeset 99f4ee for src/Box.cpp


Ignore:
Timestamp:
Jan 2, 2012, 1:34:58 PM (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:
4a8169
Parents:
9ed706
git-author:
Frederik Heber <heber@…> (12/21/11 18:02:07)
git-committer:
Frederik Heber <heber@…> (01/02/12 13:34:58)
Message:

Class Box is now also an Observable.

  • it has two channels to notify about changes in its Matrix and boundary conditions.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Box.cpp

    r9ed706 r99f4ee  
    2828#include "CodePatterns/Assert.hpp"
    2929#include "CodePatterns/Log.hpp"
     30#include "CodePatterns/Observer/Channels.hpp"
     31#include "CodePatterns/Observer/Notification.hpp"
    3032#include "CodePatterns/Verbose.hpp"
    3133#include "Helpers/defs.hpp"
     
    3840
    3941Box::Box() :
     42    Observable("Box"),
    4043    M(new RealSpaceMatrix()),
    4144    Minv(new RealSpaceMatrix())
     
    4447  coords.reserve(NDIM);
    4548  index.reserve(NDIM);
     49
     50  // observable stuff
     51  Channels *OurChannel = new Channels;
     52  NotificationChannels.insert( std::make_pair(this, OurChannel) );
     53  // add instance for each notification type
     54  for (size_t type = 0; type < NotificationType_MAX; ++type)
     55    OurChannel->addChannel(type);
     56
    4657  M->setIdentity();
    4758  Minv->setIdentity();
     
    5162
    5263Box::Box(const Box& src) :
    53   conditions(src.conditions),
    54   M(new RealSpaceMatrix(*src.M)),
    55   Minv(new RealSpaceMatrix(*src.Minv))
     64    Observable("Box"),
     65    conditions(src.conditions),
     66    M(new RealSpaceMatrix(*src.M)),
     67    Minv(new RealSpaceMatrix(*src.Minv))
    5668{
    5769  internal_list.reserve(pow(3,3));
    5870  coords.reserve(NDIM);
    5971  index.reserve(NDIM);
     72
     73  // observable stuff
     74  Channels *OurChannel = new Channels;
     75  NotificationChannels.insert( std::make_pair(this, OurChannel) );
     76  // add instance for each notification type
     77  for (size_t type = 0; type < NotificationType_MAX; ++type)
     78    OurChannel->addChannel(type);
    6079}
    6180
    6281Box::Box(RealSpaceMatrix _M) :
     82    Observable("Box"),
    6383    M(new RealSpaceMatrix(_M)),
    6484    Minv(new RealSpaceMatrix())
     
    6787  coords.reserve(NDIM);
    6888  index.reserve(NDIM);
     89
     90  // observable stuff
     91  Channels *OurChannel = new Channels;
     92  NotificationChannels.insert( std::make_pair(this, OurChannel) );
     93  // add instance for each notification type
     94  for (size_t type = 0; type < NotificationType_MAX; ++type)
     95    OurChannel->addChannel(type);
     96
    6997  ASSERT(M->determinant()!=0,"Matrix in Box construction was not invertible");
    7098  *Minv = M->invert();
     
    75103Box::~Box()
    76104{
     105  // observable stuff
     106  std::map<Observable *, Channels*>::iterator iter = NotificationChannels.find(this);
     107  delete iter->second;
     108  NotificationChannels.erase(iter);
     109
    77110  delete M;
    78111  delete Minv;
     
    88121void Box::setM(RealSpaceMatrix _M){
    89122  ASSERT(_M.determinant()!=0,"Matrix in Box construction was not invertible");
     123  OBSERVE;
     124  NOTIFY(MatrixChanged);
    90125  *M    =_M;
    91126  *Minv = M->invert();
     
    278313}
    279314
    280 void Box::setCondition(int i,Box::BoundaryCondition_t condition){
     315void Box::setCondition(int i,Box::BoundaryCondition_t condition)
     316{
     317  OBSERVE;
     318  NOTIFY(BoundaryConditionsChanged);
    281319  conditions[i]=condition;
    282320}
     
    303341}
    304342
    305 void Box::setCuboid(const Vector &endpoint){
     343void Box::setCuboid(const Vector &endpoint)
     344{
     345  OBSERVE;
     346  NOTIFY(MatrixChanged);
    306347  ASSERT(endpoint[0]>0 && endpoint[1]>0 && endpoint[2]>0,"Vector does not define a full cuboid");
    307348  M->setIdentity();
     
    312353}
    313354
    314 Box &Box::operator=(const Box &src){
     355Box &Box::operator=(const Box &src)
     356{
    315357  if(&src!=this){
     358    OBSERVE;
     359    // new matrix
     360    NOTIFY(MatrixChanged);
    316361    delete M;
    317362    delete Minv;
    318363    M    = new RealSpaceMatrix(*src.M);
    319364    Minv = new RealSpaceMatrix(*src.Minv);
     365    // new boundary conditions
     366    NOTIFY(BoundaryConditionsChanged);
    320367    conditions = src.conditions;
    321368  }
     
    323370}
    324371
    325 Box &Box::operator=(const RealSpaceMatrix &mat){
     372Box &Box::operator=(const RealSpaceMatrix &mat)
     373{
     374  OBSERVE;
     375  NOTIFY(MatrixChanged);
    326376  setM(mat);
    327377  return *this;
Note: See TracChangeset for help on using the changeset viewer.