Changeset 3d9a8d for src/Jobs/Grid


Ignore:
Timestamp:
Feb 14, 2013, 1:29:24 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:
98f8fe
Parents:
e089fb
git-author:
Frederik Heber <heber@…> (12/04/12 09:32:04)
git-committer:
Frederik Heber <heber@…> (02/14/13 13:29:24)
Message:

SamplingGrid has no more size parameter but an end array.

  • this rather fits into scheme with the later to come window.
  • also several changes in interface due to SamplingGrid::size -> ::end[3] replacement.
Location:
src/Jobs/Grid
Files:
8 edited

Legend:

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

    re089fb r3d9a8d  
    4646
    4747SamplingGrid::SamplingGrid(const double _begin[3],
    48     const double _size,
     48    const double _end[3],
    4949    const int _level,
    5050    const sampledvalues_t &_sampled_grid) :
    51   SamplingGridProperties(_begin, _size, _level),
     51  SamplingGridProperties(_begin, _end, _level),
    5252  sampled_grid(_sampled_grid)
    5353{}
     
    110110}
    111111
     112double SamplingGrid::getVolume() const
     113{
     114  double volume = 1.;
     115  for (size_t i=0;i<3;++i)
     116    volume *= end[i]-begin[i];
     117  return volume;
     118}
     119
    112120double SamplingGrid::integral() const
    113121{
    114122  const size_t gridpoints = pow(2, level);
    115   const double volume_element = pow(size/(double)gridpoints, 3);
     123  const double volume_element = getVolume()/pow((double)gridpoints, 3);
    116124  double int_value = 0.;
    117125  for (sampledvalues_t::const_iterator iter = sampled_grid.begin();
     
    128136  if (isCompatible(weight)) {
    129137    const size_t gridpoints = pow(2, level);
    130     const double volume_element = pow(size/(double)gridpoints, 3);
     138    const double volume_element = getVolume()/pow((double)gridpoints, 3);
    131139    double int_value = 0.;
    132140    sampledvalues_t::const_iterator iter = sampled_grid.begin();
     
    144152{
    145153  ost << "SamplingGrid starting at " << other.begin[0] << "," << other.begin[1] << "," << other.begin[2];
    146   ost << ", size of " << other.size;
     154  ost << ", ending at " << other.end[0] << "," << other.end[1] << "," << other.end[2];
    147155  ost << ", level of " << other.level;
    148156  ost << " and integrated value of " << other.integral();
  • src/Jobs/Grid/SamplingGrid.hpp

    re089fb r3d9a8d  
    2727/** This class stores a sample function on a three-dimensional grid.
    2828 *
     29 *  \note We do not use boost::multi_array because it is not trivial to serialize.
     30 *
    2931 */
    3032class SamplingGrid : public SamplingGridProperties
     
    4042  /** Constructor for class SamplingGrid.
    4143   *
    42    * \param _begin offset for grid
    43    * \param _size edge length of grid
    44    * \param _level number of grid points in \f$2^{\text{level}}\f$
     44   * \param _begin offset for grid per axis
     45   * \param _end edge length of grid per axis
     46   * \param _level number of grid points in \f$2^{\mathrm{level}}\f$
    4547   * \param _sampled_grid sample points
    4648   */
    4749  SamplingGrid(const double _begin[3],
    48       const double _size,
     50      const double _end[3],
    4951      const int _level,
    5052      const sampledvalues_t &_sampled_grid);
     
    127129
    128130private:
     131  /** Returns the volume of the domain for this sampled function.
     132   *
     133   * @return volume
     134   */
     135  double getVolume() const;
     136
    129137  /** Helper function that contains all the logic of how to superpose two
    130138   * grids.
  • src/Jobs/Grid/SamplingGridProperties.cpp

    re089fb r3d9a8d  
    4444SamplingGridProperties::SamplingGridProperties(
    4545    const double _begin[3],
    46     const double _size,
     46    const double _end[3],
    4747    const int _level) :
    48   size(_size),
    4948  level(_level)
    5049{
    51   for(size_t i=0; i<3; ++i)
     50  for(size_t i=0; i<3; ++i) {
    5251    begin[i] = _begin[i];
     52    end[i] = _end[i];
     53  }
    5354}
    5455
    5556SamplingGridProperties::SamplingGridProperties(const SamplingGridProperties &_props) :
    56   size(_props.size),
    5757  level(_props.level)
    5858{
    59   for(size_t i=0; i<3; ++i)
     59  for(size_t i=0; i<3; ++i) {
    6060    begin[i] = _props.begin[i];
     61    end[i] = _props.end[i];
     62  }
    6163}
    6264
    6365SamplingGridProperties::SamplingGridProperties() :
    64   size(0.),
    6566  level(0)
    6667{
    67   for(size_t i=0; i<3; ++i)
     68  for(size_t i=0; i<3; ++i) {
    6869    begin[i] = 0.;
     70    end[i] = 0.;
     71  }
    6972}
    7073
     
    7275{}
    7376
     77SamplingGridProperties& SamplingGridProperties::operator=(const SamplingGridProperties& other)
     78{
     79  // check for self-assignment
     80  if (this != &other) {
     81    for(size_t index=0; index<3; ++index) {
     82      begin[index] = other.begin[index];
     83      end[index] = other.end[index];
     84    }
     85    level = other.level;
     86  }
     87  return *this;
     88}
     89
    7490bool SamplingGridProperties::operator==(const SamplingGridProperties &_props) const
    7591{
    7692  bool status = true;
    77   for (size_t i=0; i<3; ++i)
     93  for (size_t i=0; i<3; ++i) {
    7894    status &= begin[i] == _props.begin[i];
    79   status &= size == _props.size;
     95    status &= end[i] == _props.end[i];
     96  }
    8097  status &= level == _props.level;
    8198  return status;
  • src/Jobs/Grid/SamplingGridProperties.hpp

    re089fb r3d9a8d  
    2525   *
    2626   * \param _begin offset of grid
    27    * \param _size edge length of cubic(!) domain
    28    * \param _level number of gridpoints as \f$2^{\text{level}}\f$
     27   * \param _end edge length per axis
     28   * \param _level number of gridpoints as \f$2^{\mathrm{level}}\f$ per unit(!) length
    2929   */
    3030  SamplingGridProperties(
    3131      const double _begin[3],
    32       const double _size,
     32      const double _end[3],
    3333      const int _level);
    3434
     
    5555  }
    5656
     57  /** Assignment operator.
     58   *
     59   * \param other other instance to assign ourselves to
     60   */
     61  SamplingGridProperties& operator=(const SamplingGridProperties& other);
     62
    5763  /** Equality operator for class SamplingGridProperties.
    5864   *
     
    7379  //!> offset of grid
    7480  double begin[3];
    75   //!> size of grid, i.e. edge length of cubic(!) domain
    76   double size;
    77   //!> level, i.e. \f$2^{\text{level}}\f$ grid points per axis
     81  //!> size of grid, i.e. edge length per axis of domain
     82  double end[3];
     83  //!> level, i.e. \f$2^{\mathrm{level}}\f$ grid points per axis per unit(!) length
    7884  int level;
    7985
     
    8894    for (i=0; i<3; ++i)
    8995      ar & begin[i];
    90     ar & size;
     96    for (i=0; i<3; ++i)
     97      ar & end[i];
    9198    ar & level;
    9299  }
  • src/Jobs/Grid/unittests/Makefile.am

    re089fb r3d9a8d  
    2525SamplingGridPropertiesUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \
    2626        ../Jobs/Grid/unittests/SamplingGridPropertiesUnitTest.cpp \
    27         ../Jobs/Grid/unittests/SamplingGridPropertiesUnitTest.hpp
     27        ../Jobs/Grid/unittests/SamplingGridPropertiesUnitTest.hpp \
     28        ../Jobs/Grid/SamplingGridProperties.cpp \
     29        ../Jobs/Grid/SamplingGriPropertiesd.hpp
    2830SamplingGridPropertiesUnitTest_LDADD = ${JOBSGRIDLIBS}
    2931
    3032SamplingGridUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \
    3133        ../Jobs/Grid/unittests/SamplingGridUnitTest.cpp \
    32         ../Jobs/Grid/unittests/SamplingGridUnitTest.hpp
     34        ../Jobs/Grid/unittests/SamplingGridUnitTest.hpp \
     35        ../Jobs/Grid/SamplingGridProperties.cpp \
     36        ../Jobs/Grid/SamplingGriPropertiesd.hpp \
     37        ../Jobs/Grid/SamplingGrid.cpp \
     38        ../Jobs/Grid/SamplingGrid.hpp
     39SamplingGridUnitTest_LDADD = \
     40        ${CodePatterns_LIBS} \
     41        $(BOOST_LIB)
    3342
    34 SamplingGridUnitTest_LDADD = ${JOBSGRIDLIBS}
    3543
    3644#AUTOMAKE_OPTIONS = parallel-tests
  • src/Jobs/Grid/unittests/SamplingGridPropertiesUnitTest.cpp

    re089fb r3d9a8d  
    6060  // create the grid
    6161  const double begin[3] = { 0., 0., 0. };
    62   props = new SamplingGridProperties(begin, 1., 2);
     62  const double end[3] = { 1., 1., 1. };
     63  props = new SamplingGridProperties(begin, end, 2);
    6364}
    6465
     
    7576  const double begin[3] = { 0., 0., 0. };
    7677  const double otherbegin[3] = { 1., 0.1, -0.5 };
     78  const double end[3] = { 1., 1., 1. };
     79  const double otherend[3] = { 2., 2., 2. };
    7780
    7881  // create other props
    79   SamplingGridProperties sameprops(begin, 1., 2);
    80   SamplingGridProperties otherprops(otherbegin, 1., 2);
    81   SamplingGridProperties anotherprops(begin, 2., 2);
    82   SamplingGridProperties moreotherprops(begin, 1., 4);
     82  SamplingGridProperties sameprops(begin, end, 2);
     83  SamplingGridProperties otherprops(otherbegin, end, 2);
     84  SamplingGridProperties anotherprops(begin, otherend, 2);
     85  SamplingGridProperties moreotherprops(begin, end, 4);
    8386
    8487  CPPUNIT_ASSERT( props->isCompatible(*props) );
     
    99102  const double begin[3] = { 0., 0., 0. };
    100103  const double otherbegin[3] = { 1., 0.1, -0.5 };
     104  const double end[3] = { 1., 1., 1. };
     105  const double otherend[3] = { 2., 2., 2. };
    101106
    102107  // create other props
    103   SamplingGridProperties sameprops(begin, 1., 2);
    104   SamplingGridProperties otherprops(otherbegin, 1., 2);
    105   SamplingGridProperties anotherprops(begin, 2., 2);
    106   SamplingGridProperties moreotherprops(begin, 1., 4);
     108  SamplingGridProperties sameprops(begin, end, 2);
     109  SamplingGridProperties otherprops(otherbegin, end, 2);
     110  SamplingGridProperties anotherprops(begin, otherend, 2);
     111  SamplingGridProperties moreotherprops(begin, end, 4);
    107112
    108113  CPPUNIT_ASSERT( *props == *props );
  • src/Jobs/Grid/unittests/SamplingGridUnitTest.cpp

    re089fb r3d9a8d  
    5656const double grid_value=1.;
    5757
     58#define NUMBEROFSAMPLES(n) (size_t)(pow(pow(2,n),3))
     59
    5860// Registers the fixture into the 'registry'
    5961CPPUNIT_TEST_SUITE_REGISTRATION( SamplingGridTest );
     
    6769  // create the grid
    6870  const double begin[3] = { 0., 0., 0. };
    69   for (size_t i=0; i< pow(pow(2,2),3); ++i)
     71  const double end[3] = { 1., 1., 1. };
     72  for (size_t i=0; i< pow(1,3)*NUMBEROFSAMPLES(2); ++i)
    7073    values += grid_value;
    71   grid = new SamplingGrid(begin, 1., 2, values);
     74  grid = new SamplingGrid(begin, end, 2, values);
    7275  CPPUNIT_ASSERT_EQUAL( grid_value, *(grid->sampled_grid.begin()) );
    7376}
     
    8790  // check illegal grid
    8891  const double begin[3] = { 0., 0., 0. };
    89   SamplingGridProperties illegal_props(begin, 2., 1);
     92  const double end[3] = { 2., 2., 2. };
     93  SamplingGridProperties illegal_props(begin, end, 1);
    9094  CPPUNIT_ASSERT( !grid->isCompatible(illegal_props) );
    9195  SamplingGrid::sampledvalues_t illegal_values;
     
    9498  SamplingGrid illegal_grid(illegal_props, illegal_values);
    9599#ifndef NDEBUG
     100  std::cout << "The following assertion is intended and does not indicate a failure of the test." << std::endl;
    96101  CPPUNIT_ASSERT_THROW( *grid += illegal_grid, Assert::AssertionFailure );
    97102#else
     
    105110}
    106111
     112/** UnitTest for getVolume_Test
     113 */
     114void SamplingGridTest::getVolume_Test()
     115{
     116  CPPUNIT_ASSERT_EQUAL( 1., grid->getVolume() );
     117}
     118
    107119/** UnitTest for operator+=()
    108120 */
     
    111123  // create other grid
    112124  const double begin[3] = { 0., 0., 0. };
     125  const double end[3] = { 1., 1., 1. };
    113126  SamplingGrid::sampledvalues_t othervalues;
    114127  const double othergrid_value = 1.5;
    115128  for (size_t i=0; i< NUMBEROFSAMPLES(2); ++i)
    116129    othervalues += othergrid_value;
    117   SamplingGrid othergrid(begin, 1., 2, othervalues);
     130  SamplingGrid othergrid(begin, end, 2, othervalues);
    118131  CPPUNIT_ASSERT_EQUAL( othergrid_value, *(othergrid.sampled_grid.begin()) );
    119132
     
    134147  // create other grid
    135148  const double begin[3] = { 0., 0., 0. };
     149  const double end[3] = { 1., 1., 1. };
    136150  SamplingGrid::sampledvalues_t othervalues;
    137151  const double othergrid_value = 1.5;
    138152  for (size_t i=0; i< NUMBEROFSAMPLES(2); ++i)
    139153    othervalues += othergrid_value;
    140   SamplingGrid othergrid(begin, 1., 2, othervalues);
     154  SamplingGrid othergrid(begin, end, 2, othervalues);
    141155  CPPUNIT_ASSERT_EQUAL( othergrid_value, *(othergrid.sampled_grid.begin()) );
    142156
  • src/Jobs/Grid/unittests/SamplingGridUnitTest.hpp

    re089fb r3d9a8d  
    2727    CPPUNIT_TEST ( operatorPlusEqual_Test );
    2828    CPPUNIT_TEST ( operatorMinusEqual_Test );
     29    CPPUNIT_TEST ( getVolume_Test );
    2930    CPPUNIT_TEST_SUITE_END();
    3031
     
    3334      void tearDown();
    3435      void superposeOtherGrid_Test();
     36      void getVolume_Test();
    3537      void operatorPlusEqual_Test();
    3638      void operatorMinusEqual_Test();
Note: See TracChangeset for help on using the changeset viewer.