Changeset 06653a for src/Fragmentation/Summation/SetValues/unittests
- Timestamp:
- Sep 14, 2016, 6:42:53 PM (9 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:
- 91e7658
- Parents:
- cb30d9
- git-author:
- Frederik Heber <heber@…> (06/08/16 13:22:11)
- git-committer:
- Frederik Heber <heber@…> (09/14/16 18:42:53)
- Location:
- src/Fragmentation/Summation/SetValues/unittests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Fragmentation/Summation/SetValues/unittests/SamplingGridUnitTest.cpp
rcb30d9 r06653a 49 49 50 50 #include <boost/assign.hpp> 51 51 52 #include <cmath> 52 53 #include <numeric> … … 549 550 } 550 551 552 #ifdef HAVE_INLINE 553 inline 554 #endif 555 static int calculateIndex(const int N[NDIM], const int &_length) 556 { 557 return N[2] + N[1]*_length + N[0]*_length*_length; 558 } 559 560 #ifdef HAVE_INLINE 561 inline 562 #endif 563 static double calculateDistanceSquared(const int N[NDIM], const int &_length) 564 { 565 return 566 ::pow(N[0]/(double)_length-.5,2) 567 + ::pow(N[1]/(double)_length-.5,2) 568 + ::pow(N[2]/(double)_length-.5,2); 569 } 570 /** UnitTest for downsample() 571 */ 572 void SamplingGridTest::downsampleTest() 573 { 574 const double begin[NDIM] = { 0., 0., 0. }; 575 const double end[NDIM] = { 1., 1., 1. }; 576 577 // simple test, one level difference, same value everywhere 578 { 579 SamplingGrid::sampledvalues_t checkvalues; 580 SamplingGrid::sampledvalues_t othervalues; 581 const double othergrid_value = 1.5; 582 for (size_t i=0; i< NUMBEROFSAMPLES(2); ++i) 583 checkvalues += othergrid_value; 584 for (size_t i=0; i< NUMBEROFSAMPLES(3); ++i) 585 othervalues += othergrid_value; 586 587 SamplingGrid largegrid(begin, end, 3, othervalues); 588 // std::cout << " largegrid value " << largegrid.sampled_grid << std::endl; 589 SamplingGrid smallgrid(begin, end, 2); 590 SamplingGrid::downsample(smallgrid, largegrid, 2); 591 SamplingGrid checkgrid(begin, end, 2, checkvalues); 592 // std::cout << " smallgrid value " << smallgrid.sampled_grid << std::endl; 593 // std::cout << " checkgrid value " << checkgrid.sampled_grid << std::endl; 594 CPPUNIT_ASSERT_EQUAL( smallgrid, checkgrid ); 595 } 596 597 // simple test, two level difference, same value everywhere 598 { 599 SamplingGrid::sampledvalues_t checkvalues; 600 SamplingGrid::sampledvalues_t othervalues; 601 const double othergrid_value = 1.5; 602 for (size_t i=0; i< NUMBEROFSAMPLES(2); ++i) 603 checkvalues += othergrid_value; 604 for (size_t i=0; i< NUMBEROFSAMPLES(4); ++i) 605 othervalues += othergrid_value; 606 607 SamplingGrid largegrid(begin, end, 4, othervalues); 608 // std::cout << " largegrid value " << largegrid.sampled_grid << std::endl; 609 SamplingGrid smallgrid(begin, end, 2); 610 SamplingGrid::downsample(smallgrid, largegrid, 2); 611 SamplingGrid checkgrid(begin, end, 2, checkvalues); 612 // std::cout << " smallgrid value " << smallgrid.sampled_grid << std::endl; 613 // std::cout << " checkgrid value " << checkgrid.sampled_grid << std::endl; 614 CPPUNIT_ASSERT_EQUAL( smallgrid, checkgrid ); 615 } 616 617 // same grid, window equals grids, different values 618 { 619 const int length_c = ::pow(2,2); 620 const int length_f = ::pow(2,3); 621 SamplingGrid::sampledvalues_t checkvalues((int)::pow(length_c, NDIM), 0.); 622 SamplingGrid::sampledvalues_t othervalues((int)::pow(length_f, NDIM), 0.); 623 int N[NDIM]; 624 for (N[0]=0; N[0]< length_f; ++N[0]) { 625 for (N[1]=0; N[1]< length_f; ++N[1]) { 626 for (N[2]=0; N[2]< length_f; ++N[2]) { 627 const int index = calculateIndex(N, length_f); 628 const double dist = calculateDistanceSquared(N, length_f); 629 othervalues[index] = cos(M_PI*dist/1.5); 630 } 631 } 632 } 633 for (N[0]=0; N[0]< length_c; ++N[0]) { 634 for (N[1]=0; N[1]< length_c; ++N[1]) { 635 for (N[2]=0; N[2]< length_c; ++N[2]) { 636 const int index = calculateIndex(N, length_c); 637 const double dist = calculateDistanceSquared(N, length_c); 638 checkvalues[index] = cos(M_PI*dist/1.5); 639 } 640 } 641 } 642 643 SamplingGrid largegrid(begin, end, 3, othervalues); 644 // std::cout << " largegrid value " << largegrid.sampled_grid << std::endl; 645 SamplingGrid smallgrid(begin, end, 2); 646 SamplingGrid::downsample(smallgrid, largegrid, 2); 647 SamplingGrid checkgrid(begin, end, 2, checkvalues); 648 // std::cout << " smallgrid value " << smallgrid.sampled_grid << std::endl; 649 // std::cout << " checkgrid value " << checkgrid.sampled_grid << std::endl; 650 static const double threshold = 1.2e-1; 651 for (N[0]=0; N[0]< length_c; ++N[0]) 652 for (N[1]=0; N[1]< length_c; ++N[1]) 653 for (N[2]=0; N[2]< length_c; ++N[2]) { 654 const double check_threshold = 655 (((N[0] == 0) || (N[0] == length_c-1)) 656 && ((N[1] == 0) || (N[1] == length_c-1)) 657 && ((N[2] == 0) || (N[2] == length_c-1))) 658 ? 2.*threshold : threshold; 659 const int index = calculateIndex(N, length_c); 660 // std::cout << "Comparing " 661 // << fabs((smallgrid.sampled_grid[index] - checkgrid.sampled_grid[index])) 662 // << " < " << threshold << std::endl; 663 CPPUNIT_ASSERT( 664 fabs((smallgrid.sampled_grid[index] - checkgrid.sampled_grid[index])) < check_threshold); 665 } 666 } 667 } -
src/Fragmentation/Summation/SetValues/unittests/SamplingGridUnitTest.hpp
rcb30d9 r06653a 38 38 CPPUNIT_TEST ( equality_Test ); 39 39 CPPUNIT_TEST ( serializeTest ); 40 CPPUNIT_TEST ( downsampleTest ); 40 41 CPPUNIT_TEST_SUITE_END(); 41 42 … … 57 58 void equality_Test(); 58 59 void serializeTest(); 60 void downsampleTest(); 59 61 60 62 private:
Note:
See TracChangeset
for help on using the changeset viewer.