Ignore:
Timestamp:
Sep 14, 2016, 6:42:52 PM (9 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:
e51f2c
Parents:
028790
git-author:
Frederik Heber <heber@…> (05/26/16 09:51:07)
git-committer:
Frederik Heber <heber@…> (09/14/16 18:42:52)
Message:

FIX: Replaced 3 by NDIM in SamplingGrid which avoids some confusion with numeric grid levels.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Summation/SetValues/unittests/SamplingGridUnitTest.cpp

    r028790 r5b1e5e  
    6262const double grid_value=1.;
    6363
    64 #define NUMBEROFSAMPLES(n) (size_t)(pow(pow(2,n),3))
    65 #define DOMAINVOLUME(l) (size_t)pow(l,3)
     64#define NUMBEROFSAMPLES(n) (size_t)(pow(pow(2,n),(int)NDIM))
     65#define DOMAINVOLUME(l) (size_t)pow(l,(int)NDIM)
    6666
    6767// Registers the fixture into the 'registry'
     
    7575
    7676  // create the grid
    77   const double begin[3] = { 0., 0., 0. };
    78   const double end[3] = { 1., 1., 1. };
     77  const double begin[NDIM] = { 0., 0., 0. };
     78  const double end[NDIM] = { 1., 1., 1. };
    7979  for (size_t i=0; i< DOMAINVOLUME(1)*NUMBEROFSAMPLES(2); ++i)
    8080    values += grid_value;
     
    9494{
    9595  // check illegal grid
    96   const double begin[3] = { 0., 0., 0. };
    97   const double end[3] = { 2., 2., 2. };
     96  const double begin[NDIM] = { 0., 0., 0. };
     97  const double end[NDIM] = { 2., 2., 2. };
    9898  SamplingGridProperties illegal_props(begin, end, 5);
    9999  SamplingGridProperties legal_props(begin, end, 2);
     
    125125void SamplingGridTest::isCongruent_Test()
    126126{
    127   const double begin[3] = { 0., 0., 0. };
    128   const double end[3] = { 2., 2., 2. };
    129   const double otherbegin[3] = { 0.1, 0.1, 0.1 };
    130   const double otherend[3] = { 1., 1., 1. };
     127  const double begin[NDIM] = { 0., 0., 0. };
     128  const double end[NDIM] = { 2., 2., 2. };
     129  const double otherbegin[NDIM] = { 0.1, 0.1, 0.1 };
     130  const double otherend[NDIM] = { 1., 1., 1. };
    131131  SamplingGridProperties illegal_begin_props(otherbegin, end, 5);
    132132  SamplingGridProperties illegal_end_props(begin, otherend, 5);
     
    135135
    136136  // differing windows
    137 //  const double begin_window[3] = { 0.5, 0.5, 0.5 };
    138 //  const double end_window[3] = { 1., 1., 1. };
    139   const double otherbegin_window[3] = { 0.45, 0.45, 0.45 };
    140   const double otherend_window[3] = { 1.05, 1.05, 1.05 };
     137//  const double begin_window[NDIM] = { 0.5, 0.5, 0.5 };
     138//  const double end_window[NDIM] = { 1., 1., 1. };
     139  const double otherbegin_window[NDIM] = { 0.45, 0.45, 0.45 };
     140  const double otherend_window[NDIM] = { 1.05, 1.05, 1.05 };
    141141
    142142  // check that incompatible grid are also incongruent
     
    238238
    239239  // create another one and check its size, too
    240   const double begin[3] = { 0., 0., 0. };
    241   const double end[3] = { 1., 1., 1. };
     240  const double begin[NDIM] = { 0., 0., 0. };
     241  const double end[NDIM] = { 1., 1., 1. };
    242242  for (size_t level = 3; level<=6; ++level) {
    243243    values.clear();
     
    257257{
    258258  // we have a grid with size of one, extend to twice the size and check
    259   const double begin[3] = { 0., 0., 0. };
     259  const double begin[NDIM] = { 0., 0., 0. };
    260260  const double size = 2.;
    261   const double end[3] = { size, size, size };
    262   double offset[3];
     261  const double end[NDIM] = { size, size, size };
     262  double offset[NDIM];
    263263  for (offset[0] = 0.; offset[0] <= 1.; offset[0] += .5)
    264264    for (offset[1] = 0.; offset[1] <= 1.; offset[1] += .5)
    265265      for (offset[2] = 0.; offset[2] <= 1.; offset[2] += .5) {
    266         const double window_begin[3] = { 0.+offset[0], 0.+offset[1], 0.+offset[2]};
    267         const double window_end[3] = { 1.+offset[0], 1.+offset[1], 1.+offset[2]};
     266        const double window_begin[NDIM] = { 0.+offset[0], 0.+offset[1], 0.+offset[2]};
     267        const double window_end[NDIM] = { 1.+offset[0], 1.+offset[1], 1.+offset[2]};
    268268        SamplingGrid newgrid(begin, end, 2);
    269269        newgrid.setWindowSize(window_begin, window_end);
     
    292292{
    293293  std::cout << "SamplingGridTest::extendWindow_asymmetric_Test()" << std::endl;
    294   const double begin[3] = { 0., 0., 0. };
    295   const double end[3] = { 2., 2., 2. };
    296   double offset[3];
     294  const double begin[NDIM] = { 0., 0., 0. };
     295  const double end[NDIM] = { 2., 2., 2. };
     296  double offset[NDIM];
    297297  for (offset[0] = 0.; offset[0] <= 1.; offset[0] += .5)
    298298    for (offset[1] = 0.; offset[1] <= 1.; offset[1] += .5)
    299299      for (offset[2] = 0.; offset[2] <= 1.; offset[2] += .5) {
    300         const double window_begin[3] = { 0.+offset[0], 0.+offset[1], 0.+offset[2]};
    301         const double window_end[3] = { 1.+offset[0], 1.+offset[1], 1.+offset[2]};
     300        const double window_begin[NDIM] = { 0.+offset[0], 0.+offset[1], 0.+offset[2]};
     301        const double window_end[NDIM] = { 1.+offset[0], 1.+offset[1], 1.+offset[2]};
    302302        SamplingGrid newgrid(begin, end, 2);
    303303        CPPUNIT_ASSERT_EQUAL( (size_t)0, newgrid.getWindowGridPoints() );
    304304        newgrid.setWindowSize(window_begin, window_end);
    305305        // window size is only half of domain size
    306         const size_t max_samples = NUMBEROFSAMPLES(newgrid.level)*pow(0.5,3);
     306        const size_t max_samples = NUMBEROFSAMPLES(newgrid.level)*pow(0.5,(int)NDIM);
    307307        for (size_t i=0; i< max_samples; ++i)
    308308          newgrid.sampled_grid += grid_value*i;
     
    326326  // create values for half-sized window
    327327  values.clear();
    328   for (size_t i=0; i< (size_t)pow(.5*pow(2,2),3); ++i)
     328  for (size_t i=0; i< (size_t)pow(.5*pow(2,2),(int)NDIM); ++i)
    329329    values += grid_value;
    330330
    331331  // check that too large a window throws
    332332#ifndef NDEBUG
    333   const double begin[3] = { .5, .5, .5 };
    334   const double wrongend[3] = { 1.5, 1.5, 1.5 };
     333  const double begin[NDIM] = { .5, .5, .5 };
     334  const double wrongend[NDIM] = { 1.5, 1.5, 1.5 };
    335335  std::cout << "The following assertion is intended and does not indicate a failure of the test." << std::endl;
    336336  CPPUNIT_ASSERT_THROW( grid->addOntoWindow(begin, wrongend, values, +1.), Assert::AssertionFailure );
     
    338338
    339339  // create another window from (.5,.5,.5) to (1., 1., 1.)
    340   double offset[3];
     340  double offset[NDIM];
    341341  for (offset[0] = 0.; offset[0] <= .5; offset[0] += .5)
    342342    for (offset[1] = 0.; offset[1] <= .5; offset[1] += .5)
    343343      for (offset[2] = 0.; offset[2] <= .5; offset[2] += .5) {
    344         const double window_begin[3] = { 0.+offset[0], 0.+offset[1], 0.+offset[2]};
    345         const double window_end[3] = { .5+offset[0], .5+offset[1], .5+offset[2]};
     344        const double window_begin[NDIM] = { 0.+offset[0], 0.+offset[1], 0.+offset[2]};
     345        const double window_end[NDIM] = { .5+offset[0], .5+offset[1], .5+offset[2]};
    346346
    347347        SamplingGrid newgrid(*grid);
     
    350350
    351351        // check integral to be one and one eighth times the old value
    352         CPPUNIT_ASSERT_EQUAL( (1.+pow(.5,3))*grid_value, newgrid.integral() );
     352        CPPUNIT_ASSERT_EQUAL( (1.+pow(.5,(int)NDIM))*grid_value, newgrid.integral() );
    353353      }
    354354}
     
    383383{
    384384  // create other grid
    385   const double begin[3] = { 0., 0., 0. };
    386   const double end[3] = { 1., 1., 1. };
     385  const double begin[NDIM] = { 0., 0., 0. };
     386  const double end[NDIM] = { 1., 1., 1. };
    387387  SamplingGrid::sampledvalues_t othervalues;
    388388  const double othergrid_value = 1.5;
     
    407407{
    408408  // create other grid
    409   const double begin[3] = { 0., 0., 0. };
    410   const double end[3] = { 1., 1., 1. };
     409  const double begin[NDIM] = { 0., 0., 0. };
     410  const double end[NDIM] = { 1., 1., 1. };
    411411  SamplingGrid::sampledvalues_t othervalues;
    412412  const double othergrid_value = 1.5;
     
    431431void SamplingGridTest::equality_Test()
    432432{
    433   const double begin[3] = { 0., 0., 0. };
    434   const double otherbegin[3] = { .5, 0.1, -0.5 };
    435   const double end[3] = { 1., 1., 1. };
    436   const double otherend[3] = { 2., 2., 2. };
    437   const double begin_window[3] = { 0., 0., 0. };
    438   const double otherbegin_window[3] = { .75, 0.1, 0. };
    439   const double end_window[3] = { 1., 1., 1. };
    440   const double otherend_window[3] = { .9, .9, .9 };
     433  const double begin[NDIM] = { 0., 0., 0. };
     434  const double otherbegin[NDIM] = { .5, 0.1, -0.5 };
     435  const double end[NDIM] = { 1., 1., 1. };
     436  const double otherend[NDIM] = { 2., 2., 2. };
     437  const double begin_window[NDIM] = { 0., 0., 0. };
     438  const double otherbegin_window[NDIM] = { .75, 0.1, 0. };
     439  const double end_window[NDIM] = { 1., 1., 1. };
     440  const double otherend_window[NDIM] = { .9, .9, .9 };
    441441
    442442  // create other grid
     
    515515  delete samegrid;
    516516}
     517
Note: See TracChangeset for help on using the changeset viewer.