Ignore:
Timestamp:
Feb 15, 2013, 9:52:02 AM (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:
8f3cdd
Parents:
c6355f
git-author:
Frederik Heber <heber@…> (12/19/12 12:46:23)
git-committer:
Frederik Heber <heber@…> (02/15/13 09:52:02)
Message:

SamplingGrid's Window start and end are now always set on a grid point

  • also made addWindowOntoWindow() safe with respect to rounding.
  • TESTFIX: this fixes SamplingGridUnitTest, removed expected to fail.
File:
1 edited

Legend:

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

    rc6355f r64bafe0  
    233233}
    234234
     235double SamplingGrid::getNearestLowerGridPoint(
     236    const double value, const size_t axis) const
     237{
     238  const double length = end[axis] - begin[axis];
     239  if ((fabs(length) < std::numeric_limits<double>::epsilon()) || (getGridPointsPerAxis() == 0)) {
     240    return 0.;
     241  } else {
     242    const double offset = value - begin[axis];
     243    const double factor = floor((double)getGridPointsPerAxis()*(offset/length));
     244    return factor*(length/(double)getGridPointsPerAxis());
     245  }
     246}
     247
     248double SamplingGrid::getNearestHigherGridPoint(
     249    const double value, const size_t axis) const
     250{
     251  const double length = end[axis] - begin[axis];
     252  if ((fabs(length) < std::numeric_limits<double>::epsilon()) || (getGridPointsPerAxis() == 0)) {
     253    return 0.;
     254  } else {
     255    const double offset = value - begin[axis];
     256    const double factor = ceil((double)getGridPointsPerAxis()*(offset/length));
     257    return factor*(length/(double)getGridPointsPerAxis());
     258  }
     259}
     260
    235261void SamplingGrid::setWindowSize(
    236262    const double _begin_window[3],
     
    238264{
    239265  for (size_t index=0;index<3;++index) {
    240     ASSERT( _begin_window[index] >= begin[index],
     266    begin_window[index] = getNearestLowerGridPoint(_begin_window[index], index);
     267    ASSERT( begin_window[index] >= begin[index],
    241268        "SamplingGrid::setWindowSize() - window starts earlier than domain on "
    242269        +toString(index)+"th component.");
    243     begin_window[index] = _begin_window[index];
    244     ASSERT( _end_window[index] <= end[index],
     270    end_window[index] = getNearestHigherGridPoint(_end_window[index], index);
     271    ASSERT( end_window[index] <= end[index],
    245272        "SamplingGrid::setWindowSize() - window ends later than domain on "
    246273        +toString(index)+"th component.");
    247     end_window[index] = _end_window[index];
    248274  }
    249275}
     
    339365  size_t length[3];
    340366  size_t total[3];
     367  const double round_offset =
     368      (std::numeric_limits<size_t>::round_style == std::round_toward_zero) ?
     369          0.5 : 0.; // need offset to get to round_toward_nearest behavior
    341370  for(size_t index=0;index<3;++index) {
    342     pre_offset[index] = (_begin_window[index] - begin_window[index])*gridpoints_axis;
    343     length[index] = (_end_window[index] - _begin_window[index])*gridpoints_axis;
    344     post_offset[index] = (end_window[index] - _end_window[index])*gridpoints_axis;
    345     total[index] = (end_window[index] - begin_window[index])*gridpoints_axis;
     371    // we refrain from using floor/ceil as the window's starts and ends,
     372    // the grids have to be compatible (equal level), should always be on
     373    // discrete grid point locations.
     374    const double delta = (double)gridpoints_axis/(end[index] - begin[index]);
     375    // delta is conversion factor from box length to discrete length, i.e. number of points
     376    pre_offset[index] = delta*(_begin_window[index] - begin_window[index])+round_offset;
     377    length[index] = delta*(_end_window[index] - _begin_window[index])+round_offset;
     378    post_offset[index] = delta*(end_window[index] - _end_window[index])+round_offset;
     379    total[index] = delta*(end_window[index] - begin_window[index])+round_offset;
     380    // total is used as safe-guard against loss due to discrete conversion
    346381    ASSERT( pre_offset[index]+post_offset[index]+length[index] == total[index],
    347382        "SamplingGrid::addOntoWindow() - pre, post, and length don't sum up to total for "
    348383        +toString(index)+"th component.");
    349384  }
     385  // assert that calculated lengths match with given vector sizes
    350386#ifndef NDEBUG
    351387  const size_t calculated_size = length[0]*length[1]*length[2];
     
    362398#endif
    363399  size_t N[3];
    364   size_t counter = 0;
     400//  size_t counter = 0;
    365401  sampledvalues_t::iterator griditer = sampled_grid.begin();
    366402  std::advance(griditer, pre_offset[0]*total[1]*total[2]);
Note: See TracChangeset for help on using the changeset viewer.