Ignore:
Timestamp:
Feb 15, 2013, 5:09:58 PM (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:
313f83
Parents:
c0e8fb
git-author:
Frederik Heber <heber@…> (01/31/13 13:25:31)
git-committer:
Frederik Heber <heber@…> (02/15/13 17:09:58)
Message:

Refactored copy routine out of AddOntoWindow().

  • this is preparatory for preparing a shrinking and copying into a smaller window functionalities.
File:
1 edited

Legend:

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

    rc0e8fb rfb3485  
    4242#include "Jobs/Grid/SamplingGrid.hpp"
    4343
     44#include <boost/bind.hpp>
    4445#include <limits>
    4546
     
    333334}
    334335
     336static void addElements(
     337    double &dest,
     338    const double &source,
     339    const double prefactor)
     340{
     341  dest += prefactor*(source);
     342}
     343
    335344void SamplingGrid::addOntoWindow(
    336345    const double _begin_window[3],
     
    339348    const double prefactor)
    340349{
     350  addWindowOntoWindow(
     351      begin_window,
     352      end_window,
     353      _begin_window,
     354      _end_window,
     355      sampled_grid,
     356      _sampled_grid,
     357      boost::bind(addElements, _1, _2, boost::cref(prefactor)),
     358      thiswindow);
     359}
     360
     361void SamplingGrid::addWindowOntoWindow(
     362    const double wbegin[3],
     363    const double wend[3],
     364    const double other_wbegin[3],
     365    const double other_wend[3],
     366    sampledvalues_t &sampled_grid,
     367    const sampledvalues_t &other_sampled_grid,
     368    boost::function<void (double &, const double &)> op,
     369    enum LargerWindow choice)
     370{
    341371#ifndef NDEBUG
    342372  for(size_t index=0;index<3;++index) {
    343     ASSERT( _begin_window[index] >= begin_window[index],
    344         "SamplingGrid::addOntoWindow() - given window starts earlier in component "
     373    ASSERT( other_wbegin[index] >= wbegin[index],
     374        "SamplingGrid::addWindowOntoWindow() - given smaller window starts earlier than larger window in component "
    345375        +toString(index)+".");
    346     ASSERT( _end_window[index] <= end_window[index],
    347         "SamplingGrid::addOntoWindow() - given window ends later in component "
     376    ASSERT( other_wend[index] <= wend[index],
     377        "SamplingGrid::addWindowOntoWindow() - given smaller window ends later than larger window in component "
    348378        +toString(index)+".");
    349379  }
     
    364394    const double delta = (double)gridpoints_axis/(end[index] - begin[index]);
    365395    // delta is conversion factor from box length to discrete length, i.e. number of points
    366     pre_offset[index] = delta*(_begin_window[index] - begin_window[index])+round_offset;
    367     length[index] = delta*(_end_window[index] - _begin_window[index])+round_offset;
    368     post_offset[index] = delta*(end_window[index] - _end_window[index])+round_offset;
    369     total[index] = delta*(end_window[index] - begin_window[index])+round_offset;
     396    pre_offset[index] = delta*(other_wbegin[index] - wbegin[index])+round_offset;
     397    length[index] = delta*(other_wend[index] - other_wbegin[index])+round_offset;
     398    post_offset[index] = delta*(wend[index] - other_wend[index])+round_offset;
     399    total[index] = delta*(wend[index] - wbegin[index])+round_offset;
    370400    // total is used as safe-guard against loss due to discrete conversion
    371401    ASSERT( pre_offset[index]+post_offset[index]+length[index] == total[index],
    372         "SamplingGrid::addOntoWindow() - pre, post, and length don't sum up to total for "
     402        "SamplingGrid::addWindowOntoWindow() - pre, post, and length don't sum up to total for "
    373403        +toString(index)+"th component.");
    374404  }
     
    376406#ifndef NDEBUG
    377407  const size_t calculated_size = length[0]*length[1]*length[2];
    378   ASSERT( calculated_size == _sampled_grid.size(),
    379       "SamplingGrid::addOntoWindow() - not enough sampled values given: "
    380       +toString(calculated_size)+" != "+toString(_sampled_grid.size())+".");
     408  ASSERT( calculated_size == other_sampled_grid.size(),
     409      "SamplingGrid::addWindowOntoWindow() - not enough sampled values given: "
     410      +toString(calculated_size)+" != "+toString(other_sampled_grid.size())+".");
    381411  ASSERT( calculated_size <=  sampled_grid.size(),
    382       "SamplingGrid::addOntoWindow() - not enough sampled values available: "
     412      "SamplingGrid::addWindowOntoWindow() - not enough sampled values available: "
    383413      +toString(calculated_size)+" <= "+toString(sampled_grid.size())+".");
    384414  const size_t total_size = total[0]*total[1]*total[2];
    385415  ASSERT( total_size == sampled_grid.size(),
    386       "SamplingGrid::addOntoWindow() - total size is not equal to number of present points: "
     416      "SamplingGrid::addWindowOntoWindow() - total size is not equal to number of present points: "
    387417      +toString(total_size)+" != "+toString(sampled_grid.size())+".");
    388418#endif
     
    390420//  size_t counter = 0;
    391421  sampledvalues_t::iterator griditer = sampled_grid.begin();
    392   std::advance(griditer, pre_offset[0]*total[1]*total[2]);
    393   sampledvalues_t::const_iterator copyiter = _sampled_grid.begin();
     422  sampledvalues_t::const_iterator copyiter = other_sampled_grid.begin();
     423  if (choice == thiswindow)
     424    std::advance(griditer, pre_offset[0]*total[1]*total[2]);
     425  else
     426    std::advance(copyiter, pre_offset[0]*total[1]*total[2]);
    394427  for(N[0]=0; N[0] < length[0]; ++N[0]) {
    395     std::advance(griditer, pre_offset[1]*total[2]);
     428    if (choice == thiswindow)
     429      std::advance(griditer, pre_offset[1]*total[2]);
     430    else
     431      std::advance(copyiter, pre_offset[1]*total[2]);
    396432    for(N[1]=0; N[1] < length[1]; ++N[1]) {
    397       std::advance(griditer, pre_offset[2]);
     433      if (choice == thiswindow)
     434        std::advance(griditer, pre_offset[2]);
     435      else
     436        std::advance(copyiter, pre_offset[2]);
    398437      for(N[2]=0; N[2] < length[2]; ++N[2]) {
    399438        ASSERT( griditer != sampled_grid.end(),
    400             "SamplingGrid::addOntoWindow() - griditer is already at end of window.");
    401         ASSERT( copyiter != _sampled_grid.end(),
    402             "SamplingGrid::addOntoWindow() - griditer is already at end of window.");
    403         *griditer++ += prefactor*(*copyiter++);
     439            "SamplingGrid::addWindowOntoWindow() - griditer is already at end of window.");
     440        ASSERT( copyiter != other_sampled_grid.end(),
     441            "SamplingGrid::addWindowOntoWindow() - griditer is already at end of window.");
     442        op(*griditer, *copyiter);
     443        ++griditer;
     444        ++copyiter;
    404445      }
    405       std::advance(griditer, post_offset[2]);
     446      if (choice == thiswindow)
     447        std::advance(griditer, post_offset[2]);
     448      else
     449        std::advance(copyiter, post_offset[2]);
    406450    }
    407     std::advance(griditer, post_offset[1]*total[2]);
     451    if (choice == thiswindow)
     452      std::advance(griditer, post_offset[1]*total[2]);
     453    else
     454      std::advance(copyiter, post_offset[1]*total[2]);
    408455  }
    409456#ifndef NDEBUG
    410   std::advance(griditer, post_offset[0]*total[1]*total[2]);
     457  if (choice == thiswindow)
     458    std::advance(griditer, post_offset[0]*total[1]*total[2]);
     459  else
     460    std::advance(copyiter, post_offset[0]*total[1]*total[2]);
    411461  ASSERT( griditer == sampled_grid.end(),
    412       "SamplingGrid::addOntoWindow() - griditer is not at end of window.");
    413   ASSERT( copyiter == _sampled_grid.end(),
    414       "SamplingGrid::addOntoWindow() - copyiter is not at end of window.");
     462      "SamplingGrid::addWindowOntoWindow() - griditer is not at end of window.");
     463  ASSERT( copyiter == other_sampled_grid.end(),
     464      "SamplingGrid::addWindowOntoWindow() - copyiter is not at end of window.");
    415465#endif
    416466  LOG(2, "DEBUG: Grid after adding other is " << sampled_grid << ".");
Note: See TracChangeset for help on using the changeset viewer.