Ignore:
Timestamp:
Feb 15, 2013, 9:51:48 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:
e2404f
Parents:
98f8fe
git-author:
Frederik Heber <heber@…> (12/03/12 09:02:23)
git-committer:
Frederik Heber <heber@…> (02/15/13 09:51:48)
Message:

Rewrote parts of SampingGrid such that a window of non-zero entries is used.

  • this makes the last part final O(N) as so far for the sampled_grid the whole domain has to be used instead of a tiny region around the specific fragment.
  • for this we added extendWindow() and addOntoWindow() including some new member variables that hold the window size.
  • added default cstor that correctly used SampingGridProperties default cstor. Otherwise we got the funny behavior that on some systems the very first job of q MPQCCommandJob (tests/JobMarket/2) is not re-instantiated.
  • unit test extended to cover the new functionality but marked as expected to fail because it is not yet working correctly.
File:
1 edited

Legend:

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

    r98f8fe r1a00bb  
    4646#include "CodePatterns/Assert.hpp"
    4747#include "CodePatterns/Log.hpp"
     48
     49// static instances
     50const double SamplingGrid::zeroOffset[3] = { 0., 0., 0. };
     51
     52SamplingGrid::SamplingGrid() :
     53    SamplingGridProperties()
     54{
     55  setWindowSize(zeroOffset, zeroOffset);
     56  ASSERT( getWindowGridPoints() == (size_t)0,
     57      "SamplingGrid::SamplingGrid() - incorrect number of samples given for the window.");
     58}
    4859
    4960SamplingGrid::SamplingGrid(const double _begin[3],
     
    5364  SamplingGridProperties(_begin, _end, _level),
    5465  sampled_grid(_sampled_grid)
    55 {}
     66{
     67  setWindowSize(_begin, _end);
     68  ASSERT( getWindowGridPoints() == (size_t)_sampled_grid.size(),
     69      "SamplingGrid::SamplingGrid() - incorrect number of samples given for the window.");
     70}
    5671
    5772SamplingGrid::SamplingGrid(const SamplingGrid &_grid) :
    5873  SamplingGridProperties(_grid),
    5974  sampled_grid(_grid.sampled_grid)
    60 {}
     75{
     76  setWindowSize(_grid.begin, _grid.end);
     77}
    6178
    6279SamplingGrid::SamplingGrid(const SamplingGridProperties &_props) :
    6380  SamplingGridProperties(_props)
    64 {}
     81{
     82  setWindowSize(_props.begin, _props.end);
     83}
    6584
    6685SamplingGrid::SamplingGrid(
     
    6988  SamplingGridProperties(_props),
    7089  sampled_grid(_sampled_grid)
    71 {}
     90{
     91  setWindowSize(_props.begin, _props.end);
     92  ASSERT( getWindowGridPoints() == (size_t)_sampled_grid.size(),
     93      "SamplingGrid::SamplingGrid() - incorrect number of samples given for the window.");
     94}
    7295
    7396SamplingGrid::~SamplingGrid()
     
    79102  if (this != &other) {
    80103    static_cast<SamplingGridProperties &>(*this) = other;
     104    setWindow(other.begin_window, other.end_window);
    81105    sampled_grid = other.sampled_grid;
    82106  }
     
    100124void SamplingGrid::superposeOtherGrids(const SamplingGrid &other, const double prefactor)
    101125{
    102   // check that grids are compatible
     126  /// check that grids are compatible
    103127  if (isCompatible(other)) {
     128    /// get maximum of window
     129    double max_begin_window[3];
     130    double max_end_window[3];
     131    bool doExtend = false;
     132    for (size_t index=0; index<3;++index) {
     133      if (begin_window[index] >= other.begin_window[index]) {
     134        max_begin_window[index] = other.begin_window[index];
     135        doExtend = true;
     136      } else {
     137        max_begin_window[index] = begin_window[index];
     138      }
     139      if (end_window[index] >= other.end_window[index]) {
     140        max_end_window[index] = end_window[index];
     141      } else {
     142        max_end_window[index] = other.end_window[index];
     143        doExtend = true;
     144      }
     145    }
     146    if (doExtend)
     147      extendWindow(max_begin_window, max_end_window);
     148    /// and copy other into larger window, too
     149    addOntoWindow(other.begin_window, other.end_window, other.sampled_grid);
    104150    // then add other's grid onto this one
    105151    sampledvalues_t::iterator iter = sampled_grid.begin();
     
    112158}
    113159
    114 double SamplingGrid::getVolume() const
     160const double SamplingGrid::getVolume() const
    115161{
    116162  double volume = 1.;
     
    120166}
    121167
     168const double SamplingGrid::getWindowVolume() const
     169{
     170  double volume = 1.;
     171  for (size_t i=0;i<3;++i)
     172    volume *= end_window[i]-begin_window[i];
     173  return volume;
     174}
     175
    122176const size_t SamplingGrid::getTotalGridPoints() const
    123177{
     
    128182{
    129183  return pow(2, level);
     184}
     185
     186const size_t SamplingGrid::getWindowGridPoints() const
     187{
     188  const double volume = getVolume();
     189  if (fabs(volume) < std::numeric_limits<double>::epsilon())
     190    return 0;
     191  else
     192    return (getWindowVolume()*getTotalGridPoints())/volume;
    130193}
    131194
     
    146209{
    147210  if (isCompatible(weight)) {
    148     const size_t gridpoints = pow(2, level);
    149211    const double volume_element = getVolume()/(double)getTotalGridPoints();
    150212    double int_value = 0.;
     
    160222}
    161223
     224void SamplingGrid::setWindowSize(
     225    const double _begin_window[3],
     226    const double _end_window[3])
     227{
     228  for (size_t index=0;index<3;++index) {
     229    begin_window[index] = _begin_window[index];
     230    end_window[index] = _end_window[index];
     231  }
     232}
     233
     234void SamplingGrid::setWindow(
     235    const double _begin_window[3],
     236    const double _end_window[3])
     237{
     238  setWindowSize(_begin_window, _end_window);
     239  const size_t gridpoints_window = getWindowGridPoints();
     240  sampled_grid.resize(gridpoints_window, 0.);
     241}
     242
     243void SamplingGrid::setWindowSize(
     244    const double _begin_window[3],
     245    const double _size)
     246{
     247  for (size_t index=0;index<3;++index) {
     248    begin_window[index] = _begin_window[index];
     249    end_window[index] = _begin_window[index]+_size;
     250  }
     251}
     252
     253void SamplingGrid::extendWindow(
     254    const double _begin_window[3],
     255    const double _end_window[3])
     256{
     257  // check that we truly have to extend the window
     258#ifndef NDEBUG
     259  for(size_t index=0;index < 3; ++index) {
     260    ASSERT ( begin_window[index] >= _begin_window[index],
     261        "SamplingGrid::extendWindow() - component "+toString(index)+
     262        " of window start is greater than old value.");
     263    ASSERT ( end_window[index] <= _end_window[index],
     264        "SamplingGrid::extendWindow() - component "+toString(index)+
     265        " of window end is less than old value.");
     266  }
     267#endif
     268  // copy old window size and values
     269  double old_begin_window[3];
     270  double old_end_window[3];
     271  for(size_t index=0;index<3;++index) {
     272    old_begin_window[index] = begin_window[index];
     273    old_end_window[index] = end_window[index];
     274  }
     275  sampledvalues_t old_values(sampled_grid);
     276  // now extend it ...
     277  addOntoWindow(old_begin_window, old_end_window, old_values);
     278}
     279
     280void SamplingGrid::addOntoWindow(
     281    const double _begin_window[3],
     282    const double _end_window[3],
     283    const sampledvalues_t &_sampled_grid)
     284{
     285#ifndef NDEBUG
     286  for(size_t index=0;index<3;++index) {
     287    ASSERT( _begin_window[index] >= begin_window[index],
     288        "SamplingGrid::addOntoWindow() - given window starts earlier in component "
     289        +toString(index)+".");
     290    ASSERT( _end_window[index] <= end_window[index],
     291        "SamplingGrid::addOntoWindow() - given window ends later in component "
     292        +toString(index)+".");
     293  }
     294#endif
     295  // the only issue are indices
     296  const size_t gridpoints_axis = pow(2, level);
     297  size_t offset[3];
     298  size_t length[3];
     299  for(size_t index=0;index<3;++index) {
     300    offset[index] = gridpoints_axis*(_begin_window[index] - begin_window[index]);
     301    length[index] =  gridpoints_axis*(_end_window[index] - _begin_window[index]);
     302  }
     303  ASSERT( length[0]*length[1]*length[2] ==  _sampled_grid.size(),
     304      "SamplingGrid::addOntoWindow() - not enough sampled values given.");
     305  size_t N[3];
     306//  sampledvalues_t::iterator griditer = sampled_grid.begin();
     307  sampledvalues_t::const_iterator copyiter = _sampled_grid.begin();
     308  for(N[0]=offset[0]; N[0] < length[0]; ++N[0]) {
     309    for(N[1]=offset[1]; N[1] < length[1]; ++N[1]) {
     310      for(N[2]=offset[2]; N[2] < length[2]; ++N[2]) {
     311        const size_t index =
     312            (N[0]*gridpoints_axis+N[1])*gridpoints_axis+N[2];
     313        sampled_grid[index] += *copyiter;
     314      }
     315    }
     316  }
     317}
     318
    162319std::ostream & operator<<(std::ostream &ost, const SamplingGrid& other)
    163320{
    164   ost << "SamplingGrid starting at " << other.begin[0] << "," << other.begin[1] << "," << other.begin[2];
    165   ost << ", ending at " << other.end[0] << "," << other.end[1] << "," << other.end[2];
     321  ost << "SamplingGrid";
     322  ost << " starting at " << other.begin[0] << "," << other.begin[1] << "," << other.begin[2];
     323  ost << " ending at " << other.end[0] << "," << other.end[1] << "," << other.end[2];
     324  ost << ", window starting at " << other.begin_window[0] << "," << other.begin_window[1] << "," << other.begin_window[2];
     325  ost << ", window ending at " << other.end_window[0] << "," << other.end_window[1] << "," << other.end_window[2];
    166326  ost << ", level of " << other.level;
    167327  ost << " and integrated value of " << other.integral();
Note: See TracChangeset for help on using the changeset viewer.