Changeset c889b7 for src/Jobs/Grid


Ignore:
Timestamp:
Nov 14, 2012, 3:41:02 PM (12 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:
cb3363
Parents:
4adfba
git-author:
Frederik Heber <heber@…> (07/30/12 08:12:02)
git-committer:
Frederik Heber <heber@…> (11/14/12 15:41:02)
Message:

Extended SamplingGrid to be usable as SetValue.

Location:
src/Jobs/Grid
Files:
5 added
4 edited

Legend:

Unmodified
Added
Removed
  • src/Jobs/Grid/SamplingGrid.cpp

    r4adfba rc889b7  
    4242#include "Jobs/Grid/SamplingGrid.hpp"
    4343
     44#include "CodePatterns/Assert.hpp"
    4445
    4546SamplingGrid::SamplingGrid(const double _begin[3],
    4647    const double _size,
    4748    const int _level,
    48     const std::vector<double> &_sampled_grid) :
     49    const sampledvalues_t &_sampled_grid) :
    4950  SamplingGridProperties(_begin, _size, _level),
    5051  sampled_grid(_sampled_grid)
     
    6061{}
    6162
     63SamplingGrid::SamplingGrid(
     64    const SamplingGridProperties &_props,
     65    const sampledvalues_t &_sampled_grid) :
     66  SamplingGridProperties(_props),
     67  sampled_grid(_sampled_grid)
     68{}
     69
    6270SamplingGrid::~SamplingGrid()
    6371{}
     72
     73SamplingGrid& SamplingGrid::operator=(const SamplingGrid& other)
     74{
     75  // check for self-assignment
     76  if (this != &other) {
     77    static_cast<SamplingGridProperties &>(*this) = other;
     78    sampled_grid = other.sampled_grid;
     79  }
     80  return *this;
     81}
     82
     83void SamplingGrid::superposeOtherGrids(const SamplingGrid &other, const double prefactor)
     84{
     85  // check that grids are compatible
     86  if (isCompatible(other)) {
     87    // then add other's grid onto this one
     88    sampledvalues_t::iterator iter = sampled_grid.begin();
     89    sampledvalues_t::const_iterator otheriter = other.sampled_grid.begin();
     90    for(; iter != sampled_grid.end(); ++iter, ++otheriter )
     91      *iter += prefactor * (*otheriter);
     92  } else {
     93    ASSERT(0, "SamplingGrid::superposeOtherGrids() - superposing incompatible grids is so far not in the cards.");
     94  }
     95}
     96
     97std::ostream & operator<<(std::ostream &ost, const SamplingGrid& other)
     98{
     99  return ost;
     100}
    64101
    65102// we need to explicitly instantiate the serialization functions as
  • src/Jobs/Grid/SamplingGrid.hpp

    r4adfba rc889b7  
    1414#endif
    1515
     16#include <iosfwd>
    1617#include <vector>
    1718
     
    2223
    2324class MPQCData;
     25class SamplingGridTest;
    2426
    2527/** This class stores a sample function on a three-dimensional grid.
    2628 *
    2729 */
    28 class SamplingGrid : public SamplingGridProperties {
     30class SamplingGrid : public SamplingGridProperties
     31{
     32  //!> grant unit test access to private parts
     33  friend class SamplingGridTest;
     34  //!> grant output operator access
     35  friend std::ostream & operator<<(std::ostream &ost, const SamplingGrid& other);
    2936public:
     37  //!> typedef for sampled values
     38  typedef std::vector< double > sampledvalues_t;
     39
    3040  /** Constructor for class SamplingGrid.
    3141   *
     
    3848      const double _size,
    3949      const int _level,
    40       const std::vector<double> &_sampled_grid);
     50      const sampledvalues_t &_sampled_grid);
    4151
    4252  /** Copy constructor for class SamplingGrid.
     
    5262  SamplingGrid(const SamplingGridProperties &_props);
    5363
     64  /** Copy constructor for class SamplingGrid from SamplingGridProperties.
     65   *
     66   * \param _props properties to copy
     67   * \param _sampled_grid sample points
     68   */
     69  SamplingGrid(
     70      const SamplingGridProperties &_props,
     71      const sampledvalues_t &_sampled_grid);
     72
    5473  /** default cstor.
    5574   */
     
    5978  virtual ~SamplingGrid();
    6079
     80  /** Assignment operator.
     81   *
     82   * \param other other instance to assign ourselves to
     83   */
     84  SamplingGrid& operator=(const SamplingGrid& other);
     85
     86  /** Addition operator with another SamplingGrid instance \a other.
     87   *
     88   * \param other other instance to sum onto this one.
     89   * \return ref to this instance
     90   */
     91  SamplingGrid& operator+=(const SamplingGrid& other)
     92  {
     93    superposeOtherGrids(other, +1.);
     94    return *this;
     95  }
     96
     97  /** Subtraction operator with another SamplingGrid instance \a other.
     98   *
     99   * \param other other instance to subtract from this one.
     100   * \return ref to this instance
     101   */
     102  SamplingGrid& operator-=(const SamplingGrid& other)
     103  {
     104    superposeOtherGrids(other, -1.);
     105    return *this;
     106  }
     107
     108private:
     109  /** Helper function that contains all the logic of how to superpose two
     110   * grids.
     111   *
     112   * Is called by SamplingGrid::operator+=() and SamplingGrid::operator-=()
     113   *
     114   * @param other other histogram
     115   * @param prefactor +1. is then addition, -1. is subtraction.
     116   */
     117  void superposeOtherGrids(const SamplingGrid &other, const double prefactor);
     118
    61119public:
    62120  //!> sample points
    63   std::vector< double > sampled_grid;
     121  sampledvalues_t sampled_grid;
    64122
    65123private:
     
    72130  {
    73131    ar & boost::serialization::base_object<SamplingGridProperties>(*this);
    74     ar & const_cast< std::vector<double> &>(sampled_grid);
     132    ar & const_cast< sampledvalues_t &>(sampled_grid);
    75133  }
     134};
    76135
    77 };
     136/** Output operator for class SamplingGrid.
     137 *
     138 * \param ost output stream to print to
     139 * \param other instance to print
     140 * \return ref to stream for concatenation
     141 */
     142std::ostream & operator<<(std::ostream &ost, const SamplingGrid& other);
    78143
    79144// we need to give this class a unique key for serialization
  • src/Jobs/Grid/SamplingGridProperties.cpp

    r4adfba rc889b7  
    7272{}
    7373
     74bool SamplingGridProperties::operator==(const SamplingGridProperties &_props) const
     75{
     76  bool status = true;
     77  for (size_t i=0; i<3; ++i)
     78    status &= begin[i] == _props.begin[i];
     79  status &= size == _props.size;
     80  status &= level == _props.level;
     81  return status;
     82}
     83
    7484// we need to explicitly instantiate the serialization functions as
    7585// its is only serialized through its base class FragmentJob
  • src/Jobs/Grid/SamplingGridProperties.hpp

    r4adfba rc889b7  
    4545  virtual ~SamplingGridProperties();
    4646
     47  /** Checks whether another instance is compatible with this one.
     48   *
     49   * \param _props other properties to check against
     50   * \return true - are compatible, false - else
     51   */
     52  bool isCompatible(const SamplingGridProperties &_props) const
     53  {
     54    return *this == _props;
     55  }
     56
     57  /** Equality operator for class SamplingGridProperties.
     58   *
     59   * \param _props other object to compare to
     60   */
     61  bool operator==(const SamplingGridProperties &_props) const;
     62
     63  /** Inequality operator for class SamplingGridProperties.
     64   *
     65   * \param _props other object to compare to
     66   */
     67  bool operator!=(const SamplingGridProperties &_props) const
     68  {
     69    return (!(*this == _props));
     70  }
     71
    4772public:
    4873  //!> offset of grid
Note: See TracChangeset for help on using the changeset viewer.