Ignore:
Timestamp:
Sep 14, 2016, 6:42:53 PM (8 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_StructOpt_integration_tests, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, 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_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, GeometryObjects, Gui_displays_atomic_force_velocity, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, RotateToPrincipalAxisSystem_UndoRedo, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, Ubuntu_1604_changes, stable
Children:
06653a
Parents:
ca4b372
git-author:
Frederik Heber <heber@…> (06/06/16 14:28:05)
git-committer:
Frederik Heber <heber@…> (09/14/16 18:42:53)
Message:

Extended SamplingGridProperties::isCompatible() to allow more finely resolved grids, added ::isEquivalent().

  • isEquivalent contains the old check and we replaced isCompatible() by it.
Location:
src/Fragmentation/Summation/SetValues
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Summation/SetValues/SamplingGrid.cpp

    rca4b372 rcb30d9  
    158158{
    159159  // check that grids are compatible
    160   if (isCompatible(other)) {
     160  if (isEquivalent(other)) {
    161161    /// get minimum of window
    162162    double min_begin_window[NDIM];
     
    199199{
    200200  /// check that grids are compatible
    201   if (isCompatible(other)) {
     201  if (isEquivalent(other)) {
    202202    /// get maximum of window
    203203    double max_begin_window[NDIM];
     
    259259double SamplingGrid::integral(const SamplingGrid &weight) const
    260260{
    261   if (isCompatible(weight)) {
     261  if (isEquivalent(weight)) {
    262262    const double volume_element = getVolume()/(double)getTotalGridPoints();
    263263    double int_value = 0.;
  • src/Fragmentation/Summation/SetValues/SamplingGridProperties.cpp

    rca4b372 rcb30d9  
    141141}
    142142
    143 int SamplingGridProperties::getSurplusLevel(const SamplingGridProperties &_props) const
     143double SamplingGridProperties::getSurplusLevel(const SamplingGridProperties &_props) const
    144144{
    145145  static const double log_two = log(2.);
     
    154154  //!> states how many more levels we have because of smaller grid (assuming equal levels)
    155155  const double surplus_level = log(domain_extent/props_extent)/log_two;
    156   ASSERT( fabs(surplus_level - round(surplus_level)) < std::numeric_limits<double>::epsilon()*1e4,
    157       "SamplingGridProperties::getSurplusLevel() - surplus level is not integer: "
    158       +toString(surplus_level));
    159   return round(surplus_level);
     156  return surplus_level;
     157}
     158
     159bool SamplingGridProperties::isCompatible(const SamplingGridProperties &_props) const
     160{
     161  // only equally sized or finer grids are compatible: we only downsample
     162  const double surplus_level = getSurplusLevel(_props);
     163  if (fabs(surplus_level - round(surplus_level)) > std::numeric_limits<double>::epsilon()*1e4)
     164    return false;
     165  if (level > (_props.level+surplus_level))
     166    return false;
     167  // check whether grid point corners coincide
     168  for (size_t i=0;i<NDIM;++i) {
     169    const double lowercorner = getNearestLowerGridPoint(_props.begin[i], i);
     170    if (fabs(lowercorner - _props.begin[i]) > std::numeric_limits<double>::epsilon()*1e4)
     171      return false;
     172    const double uppercorner = getNearestHigherGridPoint(_props.end[i], i);
     173    if (fabs(uppercorner - _props.end[i]) > std::numeric_limits<double>::epsilon()*1e4)
     174      return false;
     175  }
     176  return true;
    160177}
    161178
  • src/Fragmentation/Summation/SetValues/SamplingGridProperties.hpp

    rca4b372 rcb30d9  
    5656   * \return true - are compatible, false - else
    5757   */
    58   bool isCompatible(const SamplingGridProperties &_props) const
     58  bool isCompatible(const SamplingGridProperties &_props) const;
     59
     60  /** Checks whether another instance is equivalent with this one, i.e. they have
     61   * the same grid.
     62   *
     63   * \param _props other properties to check against
     64   * \return true - are compatible, false - else
     65   */
     66  bool isEquivalent(const SamplingGridProperties &_props) const
    5967  {
    60     return level == _props.level;
     68    return (*this) == _props;
    6169  }
    6270
     
    140148   *
    141149   * \param _props other grid to compare extension to
    142    * \return surplus levels
     150   * \return surplus levels, may be fractional
    143151   */
    144   int getSurplusLevel(const SamplingGridProperties &_props) const;
     152  double getSurplusLevel(const SamplingGridProperties &_props) const;
    145153
    146154public:
  • src/Fragmentation/Summation/SetValues/unittests/SamplingGridPropertiesUnitTest.cpp

    rca4b372 rcb30d9  
    7575}
    7676
    77 /** UnitTest for isCompatible()
     77/** UnitTest for isEquivalent()
    7878 */
    79 void SamplingGridPropertiesTest::isCompatible_Test()
     79void SamplingGridPropertiesTest::isEquivalent_Test()
    8080{
    8181  const double begin[3] = { 0., 0., 0. };
     
    9191
    9292  // only checks for same level
     93  CPPUNIT_ASSERT( props->isEquivalent(*props) );
     94  CPPUNIT_ASSERT( props->isEquivalent(sameprops) );
     95  CPPUNIT_ASSERT( sameprops.isEquivalent(*props) );
     96  CPPUNIT_ASSERT( !props->isEquivalent(otherprops) );
     97  CPPUNIT_ASSERT( !otherprops.isEquivalent(*props) );
     98  CPPUNIT_ASSERT( !props->isEquivalent(anotherprops) );
     99  CPPUNIT_ASSERT( !anotherprops.isEquivalent(*props) );
     100  CPPUNIT_ASSERT( !props->isEquivalent(moreotherprops) );
     101  CPPUNIT_ASSERT( !moreotherprops.isEquivalent(*props) );
     102}
     103
     104/** UnitTest for isCompatible()
     105 */
     106void SamplingGridPropertiesTest::isCompatible_Test()
     107{
     108  const double begin[3] = { 0., 0., 0. };
     109  const double otherbegin[3] = { .5, .5, .5 };
     110  const double end[3] = { 1., 1., 1. };
     111  const double otherend[3] = { 2., 2., 2. };
     112
     113  // create other props
     114  SamplingGridProperties sameprops(begin, end, 2); // same
     115  SamplingGridProperties secondhalf(otherbegin, end, 2); // second half
     116  SamplingGridProperties goingbeyond(begin, otherend, 2); // going beyond
     117  SamplingGridProperties finerlevel(begin, end, 4); // same but different level
     118
     119  // only checks for same level
    93120  CPPUNIT_ASSERT( props->isCompatible(*props) );
    94121  CPPUNIT_ASSERT( props->isCompatible(sameprops) );
    95122  CPPUNIT_ASSERT( sameprops.isCompatible(*props) );
    96   CPPUNIT_ASSERT( props->isCompatible(otherprops) );
    97   CPPUNIT_ASSERT( otherprops.isCompatible(*props) );
    98   CPPUNIT_ASSERT( props->isCompatible(anotherprops) );
    99   CPPUNIT_ASSERT( anotherprops.isCompatible(*props) );
    100   CPPUNIT_ASSERT( !props->isCompatible(moreotherprops) );
    101   CPPUNIT_ASSERT( !moreotherprops.isCompatible(*props) );
     123  CPPUNIT_ASSERT( props->isCompatible(secondhalf) );
     124  CPPUNIT_ASSERT( !secondhalf.isCompatible(*props) );
     125  CPPUNIT_ASSERT( !props->isCompatible(goingbeyond) );
     126  CPPUNIT_ASSERT( goingbeyond.isCompatible(*props) );
     127  CPPUNIT_ASSERT( props->isCompatible(finerlevel) );
     128  CPPUNIT_ASSERT( !finerlevel.isCompatible(*props) );
    102129}
    103130
  • src/Fragmentation/Summation/SetValues/unittests/SamplingGridPropertiesUnitTest.hpp

    rca4b372 rcb30d9  
    2424{
    2525    CPPUNIT_TEST_SUITE( SamplingGridPropertiesTest) ;
     26    CPPUNIT_TEST ( isEquivalent_Test );
    2627    CPPUNIT_TEST ( isCompatible_Test );
    2728    CPPUNIT_TEST ( equality_Test );
     
    3233      void setUp();
    3334      void tearDown();
     35      void isEquivalent_Test();
    3436      void isCompatible_Test();
    3537      void equality_Test();
  • src/Fragmentation/Summation/SetValues/unittests/SamplingGridUnitTest.cpp

    rca4b372 rcb30d9  
    8989}
    9090
    91 /** UnitTest on compatible combination of props and values
    92  */
    93 void SamplingGridTest::compatibleGrids_Test()
     91/** UnitTest on equivalent combination of props and values
     92 */
     93void SamplingGridTest::equivalentGrids_Test()
    9494{
    9595  // check illegal grid
    9696  const double begin[NDIM] = { 0., 0., 0. };
    97   const double end[NDIM] = { 2., 2., 2. };
     97  const double end[NDIM] = { 1., 1., 1. };
    9898  SamplingGridProperties illegal_props(begin, end, 5);
    9999  SamplingGridProperties legal_props(begin, end, 2);
     100  CPPUNIT_ASSERT( !grid->isEquivalent(illegal_props) );
     101  CPPUNIT_ASSERT( grid->isEquivalent(legal_props) );
     102  SamplingGrid::sampledvalues_t illegal_values;
     103  for (size_t i=0; i< NUMBEROFSAMPLES(1); ++i)
     104    illegal_values += 1.5;
     105  SamplingGrid::sampledvalues_t legal_values;
     106  for (size_t i=0; i< NUMBEROFSAMPLES(2); ++i)
     107    legal_values += 1.5;
     108#ifndef NDEBUG
     109  // throws because props and size of illegal_values don't match
     110  std::cout << "The following assertion is intended and does not indicate a failure of the test." << std::endl;
     111  CPPUNIT_ASSERT_THROW( SamplingGrid illegal_grid(illegal_props, illegal_values), Assert::AssertionFailure );
     112  std::cout << "The following assertion is intended and does not indicate a failure of the test." << std::endl;
     113  CPPUNIT_ASSERT_THROW( SamplingGrid illegal_grid(legal_props, illegal_values), Assert::AssertionFailure );
     114  std::cout << "The following assertion is intended and does not indicate a failure of the test." << std::endl;
     115  CPPUNIT_ASSERT_THROW( SamplingGrid illegal_grid(illegal_props, legal_values), Assert::AssertionFailure );
     116#endif
     117  // check that grid is still the same
     118  for (SamplingGrid::sampledvalues_t::const_iterator iter = grid->sampled_grid.begin();
     119      iter != grid->sampled_grid.end(); ++iter)
     120    CPPUNIT_ASSERT_EQUAL( grid_value, *iter );
     121}
     122
     123/** UnitTest on compatible combination of props and values
     124 */
     125void SamplingGridTest::compatibleGrids_Test()
     126{
     127  // check illegal grid
     128  const double begin[NDIM] = { 0., 0., 0. };
     129  const double end[NDIM] = { 1., 1., 1. };
     130  const double otherend[NDIM] = { 2.5, 2.5, 2.5 };
     131  SamplingGridProperties illegal_props(begin, otherend, 5);
     132  SamplingGridProperties legal_props(begin, end, 3);
    100133  CPPUNIT_ASSERT( !grid->isCompatible(illegal_props) );
    101134  CPPUNIT_ASSERT( grid->isCompatible(legal_props) );
     
    143176  SamplingGrid default_grid(legal_props);
    144177  // note that we always construct a temporary SamplingGrid from given props
    145   CPPUNIT_ASSERT( default_grid.isCompatible(illegal_begin_props) == default_grid.isCongruent(illegal_begin_props));
    146   CPPUNIT_ASSERT( default_grid.isCompatible(illegal_end_props) == default_grid.isCongruent(illegal_end_props));
    147   CPPUNIT_ASSERT( default_grid.isCompatible(illegal_level_props) == default_grid.isCongruent(illegal_level_props));
    148   CPPUNIT_ASSERT( default_grid.isCompatible(legal_props) == default_grid.isCongruent(legal_props) );
     178  CPPUNIT_ASSERT( default_grid.isEquivalent(illegal_begin_props) == default_grid.isCongruent(illegal_begin_props));
     179  CPPUNIT_ASSERT( default_grid.isEquivalent(illegal_end_props) == default_grid.isCongruent(illegal_end_props));
     180  CPPUNIT_ASSERT( default_grid.isEquivalent(illegal_level_props) == default_grid.isCongruent(illegal_level_props));
     181  CPPUNIT_ASSERT( default_grid.isEquivalent(legal_props) == default_grid.isCongruent(legal_props) );
    149182
    150183  default_grid.setWindowSize(begin, end);
  • src/Fragmentation/Summation/SetValues/unittests/SamplingGridUnitTest.hpp

    rca4b372 rcb30d9  
    2424{
    2525    CPPUNIT_TEST_SUITE( SamplingGridTest) ;
     26    CPPUNIT_TEST ( equivalentGrids_Test );
    2627    CPPUNIT_TEST ( compatibleGrids_Test );
    2728    CPPUNIT_TEST ( operatorPlusEqual_Test );
     
    4243      void setUp();
    4344      void tearDown();
     45      void equivalentGrids_Test();
    4446      void compatibleGrids_Test();
    4547      void isCongruent_Test();
Note: See TracChangeset for help on using the changeset viewer.