Changeset de6dfb for src/Jobs/Grid


Ignore:
Timestamp:
Feb 15, 2013, 9:51:49 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:
c6355f
Parents:
e2404f
git-author:
Frederik Heber <heber@…> (02/11/13 09:24:45)
git-committer:
Frederik Heber <heber@…> (02/15/13 09:51:49)
Message:

Extending AddOntoWindow() by prefactor, can deal with differently sized windows.

  • also extended unit tests to check on working asymmetry.
Location:
src/Jobs/Grid
Files:
4 edited

Legend:

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

    re2404f rde6dfb  
    144144      }
    145145    }
     146    LOG(2, "DEBUG: max begin is " << max_begin_window[0] << "," << max_begin_window[1] << "," << max_begin_window[2] << ".");
     147    LOG(2, "DEBUG: max end is " << max_end_window[0] << "," << max_end_window[1] << "," << max_end_window[2] << ".");
    146148    if (doExtend)
    147149      extendWindow(max_begin_window, max_end_window);
    148150    /// and copy other into larger window, too
    149     addOntoWindow(other.begin_window, other.end_window, other.sampled_grid);
    150     // then add other's grid onto this one
    151     sampledvalues_t::iterator iter = sampled_grid.begin();
    152     sampledvalues_t::const_iterator otheriter = other.sampled_grid.begin();
    153     for(; iter != sampled_grid.end(); ++iter, ++otheriter )
    154       *iter += prefactor * (*otheriter);
     151    addOntoWindow(other.begin_window, other.end_window, other.sampled_grid, prefactor);
    155152  } else {
    156153    ASSERT(0, "SamplingGrid::superposeOtherGrids() - superposing incompatible grids is so far not in the cards.");
     
    290287  }
    291288  sampledvalues_t old_values(sampled_grid);
     289  // set new window
     290  setWindow(_begin_window,_end_window);
    292291  // now extend it ...
    293   addOntoWindow(old_begin_window, old_end_window, old_values);
     292  addOntoWindow(old_begin_window, old_end_window, old_values, +1.);
     293  LOG(2, "DEBUG: Grid after extension is " << sampled_grid << ".");
    294294}
    295295
     
    297297    const double _begin_window[3],
    298298    const double _end_window[3],
    299     const sampledvalues_t &_sampled_grid)
     299    const sampledvalues_t &_sampled_grid,
     300    const double prefactor)
    300301{
    301302#ifndef NDEBUG
     
    311312  // the only issue are indices
    312313  const size_t gridpoints_axis = pow(2, level);
    313   size_t offset[3];
     314  size_t pre_offset[3];
     315  size_t post_offset[3];
    314316  size_t length[3];
     317  size_t total[3];
    315318  for(size_t index=0;index<3;++index) {
    316     offset[index] = gridpoints_axis*(_begin_window[index] - begin_window[index]);
    317     length[index] =  gridpoints_axis*(_end_window[index] - _begin_window[index]);
     319    pre_offset[index] = (_begin_window[index] - begin_window[index])*gridpoints_axis;
     320    post_offset[index] = (end_window[index] - _end_window[index])*gridpoints_axis;
     321    length[index] = (_end_window[index] - _begin_window[index])*gridpoints_axis;
     322    total[index] = (end_window[index] - begin_window[index])*gridpoints_axis;
     323    ASSERT( pre_offset[index]+post_offset[index]+length[index] == total[index],
     324        "SamplingGrid::addOntoWindow() - pre, past, and length don't sum up to total for "
     325        +toString(index)+"th component.");
    318326  }
    319327  ASSERT( length[0]*length[1]*length[2] ==  _sampled_grid.size(),
    320328      "SamplingGrid::addOntoWindow() - not enough sampled values given.");
     329  ASSERT( length[0]*length[1]*length[2] <=  sampled_grid.size(),
     330      "SamplingGrid::addOntoWindow() - not enough sampled values available.");
    321331  size_t N[3];
    322 //  sampledvalues_t::iterator griditer = sampled_grid.begin();
     332  sampledvalues_t::iterator griditer = sampled_grid.begin();
     333  std::advance(griditer, pre_offset[0]*total[1]*total[2]);
    323334  sampledvalues_t::const_iterator copyiter = _sampled_grid.begin();
    324   for(N[0]=offset[0]; N[0] < length[0]; ++N[0]) {
    325     for(N[1]=offset[1]; N[1] < length[1]; ++N[1]) {
    326       for(N[2]=offset[2]; N[2] < length[2]; ++N[2]) {
    327         const size_t index =
    328             (N[0]*gridpoints_axis+N[1])*gridpoints_axis+N[2];
    329         sampled_grid[index] += *copyiter;
     335  for(N[0]=0; N[0] < length[0]; ++N[0]) {
     336    std::advance(griditer, pre_offset[1]*total[2]);
     337    for(N[1]=0; N[1] < length[1]; ++N[1]) {
     338      std::advance(griditer, pre_offset[2]);
     339      for(N[2]=0; N[2] < length[2]; ++N[2]) {
     340        *griditer++ += prefactor*(*copyiter++);
    330341      }
     342      std::advance(griditer, post_offset[2]);
    331343    }
    332   }
     344    std::advance(griditer, post_offset[1]*total[2]);
     345  }
     346  //std::advance(griditer, post_offset[0]*total[1]*total[2]);
     347  LOG(2, "DEBUG: Grid after adding other is " << sampled_grid << ".");
    333348}
    334349
  • src/Jobs/Grid/SamplingGrid.hpp

    re2404f rde6dfb  
    199199   * \param _end_window end of other window
    200200   * \param _sampled_grid other set of sampled values
     201   * @param prefactor +1. is then addition, -1. is subtraction.
    201202   */
    202203  void addOntoWindow(
    203204      const double _begin_window[3],
    204205      const double _end_window[3],
    205       const sampledvalues_t &_sampled_grid);
     206      const sampledvalues_t &_sampled_grid,
     207      const double prefactor);
    206208
    207209  /** Helper function that contains all the logic of how to superpose two
  • src/Jobs/Grid/unittests/SamplingGridUnitTest.cpp

    re2404f rde6dfb  
    149149  // we have a grid with size of two, extend to twice the size and check
    150150  const double begin[3] = { 0., 0., 0. };
     151  const double size = 2.;
     152  const double end[3] = { size, size, size };
     153  grid->extendWindow(begin, end);
     154
     155  // check integral
     156  CPPUNIT_ASSERT_EQUAL( grid_value/(NUMBEROFSAMPLES(grid->level)/NUMBEROFSAMPLES(grid->level)), grid->integral() );
     157
     158  // check number of points
     159  CPPUNIT_ASSERT_EQUAL( (size_t)NUMBEROFSAMPLES(grid->level), grid->getWindowGridPoints() );
     160}
     161
     162/** UnitTest for extendWindow() with asymmetric values
     163 */
     164void SamplingGridTest::extendWindow_asymmetric_Test()
     165{
     166  const double begin[3] = { 0., 0., 0. };
    151167  const double end[3] = { 2., 2., 2. };
     168  grid->sampled_grid.clear();
     169  SamplingGrid::sampledvalues_t::iterator griditer = grid->sampled_grid.begin();
     170  for (size_t i=0; i< NUMBEROFSAMPLES(grid->level); ++i)
     171     *griditer++ += grid_value*i;
    152172  grid->extendWindow(begin, end);
    153173
    154   // check integral
    155   CPPUNIT_ASSERT_EQUAL( NUMBEROFSAMPLES(2)*grid_value, grid->integral() );
    156 
    157   // check number of points
    158   CPPUNIT_ASSERT_EQUAL( (size_t)NUMBEROFSAMPLES(3), grid->getWindowGridPoints() );
     174  CPPUNIT_ASSERT_EQUAL( grid_value, grid->integral() );
    159175}
    160176
     
    176192  const double wrongend[3] = { 1.5, 1.5, 1.5 };
    177193  std::cout << "The following assertion is intended and does not indicate a failure of the test." << std::endl;
    178   CPPUNIT_ASSERT_THROW( grid->addOntoWindow(begin, wrongend, values), Assert::AssertionFailure );
     194  CPPUNIT_ASSERT_THROW( grid->addOntoWindow(begin, wrongend, values, +1.), Assert::AssertionFailure );
    179195#endif
    180196  // now perform working operation
    181   grid->addOntoWindow(begin, end, values);
     197  grid->addOntoWindow(begin, end, values, +1.);
    182198
    183199  // check integral to be one and half times the old value
    184200  CPPUNIT_ASSERT_EQUAL( (1.+pow(.5,3))*grid_value, grid->integral() );
     201}
     202
     203/** UnitTest for addOntoWindow() with asymmetric values
     204 */
     205void SamplingGridTest::addOntoWindow_asymmetric_Test()
     206{
     207  // check with asymmetric values
     208  grid->sampled_grid.clear();
     209  grid->sampled_grid.resize(NUMBEROFSAMPLES(2), 0.);
     210
     211  for (size_t i=0;i<grid->level*(grid->end[0]-grid->begin[0]);++i)
     212    grid->sampled_grid[(i*2+0)*2+0] += .5*grid_value;
     213  for (size_t i=0;i<grid->level*(grid->end[1]-grid->begin[1]);++i)
     214    grid->sampled_grid[(0*2+i)*2+0] += 1.*grid_value;
     215  for (size_t i=0;i<grid->level*(grid->end[2]-grid->begin[2]);++i)
     216    grid->sampled_grid[(0*2+0)*2+i] += 1.5*grid_value;
     217
     218  const double integral = grid->integral();
     219  const double begin[3] = { 0., 0., 0. };
     220  for(double size=2.; size<=5.; size += 1.) {
     221    const double newend[3] = {size, size, size};
     222    grid->extendWindow(begin, newend);
     223    CPPUNIT_ASSERT_EQUAL( pow(size,3)*integral, grid->integral() );
     224  }
    185225}
    186226
  • src/Jobs/Grid/unittests/SamplingGridUnitTest.hpp

    re2404f rde6dfb  
    3030    CPPUNIT_TEST ( getWindowSize_Test );
    3131    CPPUNIT_TEST ( extendWindow_Test );
     32    CPPUNIT_TEST ( extendWindow_asymmetric_Test );
    3233    CPPUNIT_TEST ( addOntoWindow_Test );
     34    CPPUNIT_TEST ( addOntoWindow_asymmetric_Test );
    3335    CPPUNIT_TEST_SUITE_END();
    3436
     
    4042      void getWindowSize_Test();
    4143      void extendWindow_Test();
     44      void extendWindow_asymmetric_Test();
    4245      void addOntoWindow_Test();
     46      void addOntoWindow_asymmetric_Test();
    4347      void operatorPlusEqual_Test();
    4448      void operatorMinusEqual_Test();
Note: See TracChangeset for help on using the changeset viewer.