Changeset cb30d9 for src/Fragmentation/Summation
- Timestamp:
- Sep 14, 2016, 6:42:53 PM (8 years ago)
- 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)
- Location:
- src/Fragmentation/Summation/SetValues
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Fragmentation/Summation/SetValues/SamplingGrid.cpp
rca4b372 rcb30d9 158 158 { 159 159 // check that grids are compatible 160 if (is Compatible(other)) {160 if (isEquivalent(other)) { 161 161 /// get minimum of window 162 162 double min_begin_window[NDIM]; … … 199 199 { 200 200 /// check that grids are compatible 201 if (is Compatible(other)) {201 if (isEquivalent(other)) { 202 202 /// get maximum of window 203 203 double max_begin_window[NDIM]; … … 259 259 double SamplingGrid::integral(const SamplingGrid &weight) const 260 260 { 261 if (is Compatible(weight)) {261 if (isEquivalent(weight)) { 262 262 const double volume_element = getVolume()/(double)getTotalGridPoints(); 263 263 double int_value = 0.; -
src/Fragmentation/Summation/SetValues/SamplingGridProperties.cpp
rca4b372 rcb30d9 141 141 } 142 142 143 intSamplingGridProperties::getSurplusLevel(const SamplingGridProperties &_props) const143 double SamplingGridProperties::getSurplusLevel(const SamplingGridProperties &_props) const 144 144 { 145 145 static const double log_two = log(2.); … … 154 154 //!> states how many more levels we have because of smaller grid (assuming equal levels) 155 155 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 159 bool 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; 160 177 } 161 178 -
src/Fragmentation/Summation/SetValues/SamplingGridProperties.hpp
rca4b372 rcb30d9 56 56 * \return true - are compatible, false - else 57 57 */ 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 59 67 { 60 return level == _props.level;68 return (*this) == _props; 61 69 } 62 70 … … 140 148 * 141 149 * \param _props other grid to compare extension to 142 * \return surplus levels 150 * \return surplus levels, may be fractional 143 151 */ 144 intgetSurplusLevel(const SamplingGridProperties &_props) const;152 double getSurplusLevel(const SamplingGridProperties &_props) const; 145 153 146 154 public: -
src/Fragmentation/Summation/SetValues/unittests/SamplingGridPropertiesUnitTest.cpp
rca4b372 rcb30d9 75 75 } 76 76 77 /** UnitTest for is Compatible()77 /** UnitTest for isEquivalent() 78 78 */ 79 void SamplingGridPropertiesTest::is Compatible_Test()79 void SamplingGridPropertiesTest::isEquivalent_Test() 80 80 { 81 81 const double begin[3] = { 0., 0., 0. }; … … 91 91 92 92 // 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 */ 106 void 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 93 120 CPPUNIT_ASSERT( props->isCompatible(*props) ); 94 121 CPPUNIT_ASSERT( props->isCompatible(sameprops) ); 95 122 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) ); 102 129 } 103 130 -
src/Fragmentation/Summation/SetValues/unittests/SamplingGridPropertiesUnitTest.hpp
rca4b372 rcb30d9 24 24 { 25 25 CPPUNIT_TEST_SUITE( SamplingGridPropertiesTest) ; 26 CPPUNIT_TEST ( isEquivalent_Test ); 26 27 CPPUNIT_TEST ( isCompatible_Test ); 27 28 CPPUNIT_TEST ( equality_Test ); … … 32 33 void setUp(); 33 34 void tearDown(); 35 void isEquivalent_Test(); 34 36 void isCompatible_Test(); 35 37 void equality_Test(); -
src/Fragmentation/Summation/SetValues/unittests/SamplingGridUnitTest.cpp
rca4b372 rcb30d9 89 89 } 90 90 91 /** UnitTest on compatiblecombination of props and values92 */ 93 void SamplingGridTest:: compatibleGrids_Test()91 /** UnitTest on equivalent combination of props and values 92 */ 93 void SamplingGridTest::equivalentGrids_Test() 94 94 { 95 95 // check illegal grid 96 96 const double begin[NDIM] = { 0., 0., 0. }; 97 const double end[NDIM] = { 2., 2., 2. };97 const double end[NDIM] = { 1., 1., 1. }; 98 98 SamplingGridProperties illegal_props(begin, end, 5); 99 99 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 */ 125 void 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); 100 133 CPPUNIT_ASSERT( !grid->isCompatible(illegal_props) ); 101 134 CPPUNIT_ASSERT( grid->isCompatible(legal_props) ); … … 143 176 SamplingGrid default_grid(legal_props); 144 177 // note that we always construct a temporary SamplingGrid from given props 145 CPPUNIT_ASSERT( default_grid.is Compatible(illegal_begin_props) == default_grid.isCongruent(illegal_begin_props));146 CPPUNIT_ASSERT( default_grid.is Compatible(illegal_end_props) == default_grid.isCongruent(illegal_end_props));147 CPPUNIT_ASSERT( default_grid.is Compatible(illegal_level_props) == default_grid.isCongruent(illegal_level_props));148 CPPUNIT_ASSERT( default_grid.is Compatible(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) ); 149 182 150 183 default_grid.setWindowSize(begin, end); -
src/Fragmentation/Summation/SetValues/unittests/SamplingGridUnitTest.hpp
rca4b372 rcb30d9 24 24 { 25 25 CPPUNIT_TEST_SUITE( SamplingGridTest) ; 26 CPPUNIT_TEST ( equivalentGrids_Test ); 26 27 CPPUNIT_TEST ( compatibleGrids_Test ); 27 28 CPPUNIT_TEST ( operatorPlusEqual_Test ); … … 42 43 void setUp(); 43 44 void tearDown(); 45 void equivalentGrids_Test(); 44 46 void compatibleGrids_Test(); 45 47 void isCongruent_Test();
Note:
See TracChangeset
for help on using the changeset viewer.