Changeset 8c31865 for src/LinkedCell


Ignore:
Timestamp:
Jan 2, 2012, 1:34:42 PM (13 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:
54f3d1
Parents:
e776dc
git-author:
Frederik Heber <heber@…> (12/20/11 14:28:33)
git-committer:
Frederik Heber <heber@…> (01/02/12 13:34:42)
Message:

Added new class LinkedCellArrayCache that performs the lazy updates on a LinkedCellArray.

  • basically, we cache all write operations and perform them first when there is a read operation that requires an up-to-date structure.
  • we cannot do this via the Cacheable pattern was there we always have a return value of the update structure. It is currently unknown how to initialize a cached pointer (apart from always checking for this in the update function).
Location:
src/LinkedCell
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • src/LinkedCell/LinkedCell_Model.cpp

    re776dc r8c31865  
    4141#include "LinkedCell/LinkedCell.hpp"
    4242#include "LinkedCell/LinkedCell_Model_changeModel.hpp"
     43#include "LinkedCell/LinkedCell_Model_LinkedCellArrayCache.hpp"
    4344#include "World.hpp"
    44 
    45 #include "LinkedCell_Model_inline.hpp"
    4645
    4746// initialize static entities
     
    5857    Changes( new changeModel(radius) ),
    5958    internal_Sizes(NULL),
     59    N(new LinkedCellArrayCache(Changes, boost::bind(&changeModel::performUpdates, Changes), std::string("N_cached"))),
    6060    domain(_domain)
    6161{
     
    8383    Changes( new changeModel(radius) ),
    8484    internal_Sizes(NULL),
     85    N(new LinkedCellArrayCache(Changes, boost::bind(&changeModel::performUpdates, Changes), std::string("N_cached"))),
    8586    domain(_domain)
    8687{
     
    146147  for (int i=0;i<NDIM;i++)
    147148    index[i] = static_cast<LinkedCellArray::index>(Dimensions.at(i,i));
    148   N.resize(index);
     149  N->setN().resize(index);
    149150  ASSERT(getSize(0)*getSize(1)*getSize(2) < MAX_LINKEDCELLNODES,
    150151      "LinkedCell_Model::AllocateCells() - Number linked of linked cell nodes exceeded hard-coded limit, use greater edge length!");
     
    155156      for(index[2] = 0; index[2] != static_cast<LinkedCellArray::index>(Dimensions.at(2,2)); ++index[2]) {
    156157        LOG(5, "INFO: Creating cell at " << index[0] << " " << index[1] << " " << index[2] << ".");
    157         N(index) = new LinkedCell(index);
     158        N->setN()(index) = new LinkedCell(index);
    158159      }
    159160    }
     
    167168{
    168169  // free all LinkedCell instances
    169   for(iterator3 iter3 = N.begin(); iter3 != N.end(); ++iter3) {
     170  for(iterator3 iter3 = N->setN().begin(); iter3 != N->setN().end(); ++iter3) {
    170171    for(iterator2 iter2 = (*iter3).begin(); iter2 != (*iter3).end(); ++iter2) {
    171172      for(iterator1 iter1 = (*iter2).begin(); iter1 != (*iter2).end(); ++iter1) {
     
    175176  }
    176177  // set dimensions to zero
    177   N.resize(boost::extents[0][0][0]);
     178  N->setN().resize(boost::extents[0][0][0]);
    178179}
    179180
     
    314315  LOG(2, "INFO: " << *Walker << " goes into cell " << index[0] << ", " << index[1] << ", " << index[2] << ".");
    315316  LOG(2, "INFO: Cell's indices are "
    316       << N(index)->getIndex(0) << " "
    317       << N(index)->getIndex(1) << " "
    318       << N(index)->getIndex(2) << ".");
     317      << (N->getN())(index)->getIndex(0) << " "
     318      << (N->getN())(index)->getIndex(1) << " "
     319      << (N->getN())(index)->getIndex(2) << ".");
    319320  // add to cell
    320   N(index)->addPoint(Walker);
     321  (N->setN())(index)->addPoint(Walker);
    321322  // add to index with check for presence
    322   std::pair<MapPointToCell::iterator, bool> inserter = CellLookup.insert( std::make_pair(Walker, N(index)) );
     323  std::pair<MapPointToCell::iterator, bool> inserter = CellLookup.insert( std::make_pair(Walker, (N->setN())(index)) );
    323324  ASSERT( inserter.second,
    324325      "LinkedCell_Model::addNode() - Walker "
     
    341342      "LinkedCell_Model::deleteNode() - Walker not present in cell stored under CellLookup.");
    342343  if (iter != CellLookup.end()) {
     344    // remove from lookup
    343345    CellLookup.erase(iter);
     346    // remove from cell
    344347    iter->second->deletePoint(Walker);
    345348  }
     
    361364      iter->second->deletePoint(Walker);
    362365      // add to new cell
    363       N(index)->addPoint(Walker);
     366      N->setN()(index)->addPoint(Walker);
    364367      // update lookup
    365       iter->second = N(index);
     368      iter->second = N->setN()(index);
    366369    }
    367370  }
     
    482485}
    483486
     487/** Returns a reference to the cell indicated by LinkedCell_Model::internal_index.
     488 *
     489 * \return LinkedCell ref to current cell
     490 */
     491const LinkedCell::LinkedCell& LinkedCell::LinkedCell_Model::getCell(const tripleIndex &index) const
     492{
     493  return *(N->getN()(index));
     494}
     495
     496
     497/** Returns size of array for given \a dim.
     498 *
     499 * @param dim desired dimension
     500 * @return size of array along dimension
     501 */
     502LinkedCell::LinkedCellArray::index LinkedCell::LinkedCell_Model::getSize(const size_t dim) const
     503{
     504  ASSERT((dim >= 0) && (dim < NDIM),
     505      "LinkedCell_Model::getSize() - dimension "
     506      +toString(dim)+" is out of bounds.");
     507  return N->getN().shape()[dim];
     508}
     509
    484510/** Callback function for Observer mechanism.
    485511 *
  • src/LinkedCell/LinkedCell_Model.hpp

    re776dc r8c31865  
    118118    boost::array<double, 3> EdgeLength;
    119119
    120     //!> Linked cell array
    121     LinkedCellArray N;
     120    // forward declaration for LinkedCellArrayContainer, containing cached LinkedCellArray
     121    class LinkedCellArrayCache;
     122    //!> Linked cell array cache
     123    LinkedCellArrayCache *N;
    122124
    123125    //!> matrix to divide Box with
     
    133135}
    134136
    135 // inlined functions
    136 #include "LinkedCell_Model_inline.hpp"
    137 
    138137#endif /* LINKEDCELL_MODEL_HPP_ */
  • src/LinkedCell/LinkedCell_Model_changeModel.cpp

    re776dc r8c31865  
    2121
    2222#include "LinkedCell_Model_changeModel.hpp"
     23
     24#include "CodePatterns/toString.hpp"
    2325
    2426/** Constructor of LinkedCell_Model::changeModel.
  • src/LinkedCell/LinkedCell_Model_changeModel.hpp

    re776dc r8c31865  
    4141        boost::function<void (const TesselPoint *)> _updateMethod
    4242        );
    43   protected:
     43  private:
     44    //!> grant LinkedCell_Model access to bind LinkedCellArrayCache to update funcation
     45    friend class LinkedCell_Model;
    4446    void performUpdates();
    4547  private:
  • src/LinkedCell/LinkedCell_Model_inline.hpp

    re776dc r8c31865  
    1414#endif
    1515
     16#include "LinkedCell_Model_LinkedCellArrayCache.hpp"
     17
    1618// have all includes only needed here extra
    1719#ifdef HAVE_INLINE
     
    2830const LinkedCell::LinkedCell& LinkedCell::LinkedCell_Model::getCell(const tripleIndex &index) const
    2931{
    30   return *N(index);
     32  return *(N->getN()(index));
    3133}
    3234
     
    4547      "LinkedCell_Model::getSize() - dimension "
    4648      +toString(dim)+" is out of bounds.");
    47   return N.shape()[dim];
     49  return N->getN().shape()[dim];
    4850}
    4951
  • src/LinkedCell/Makefile.am

    re776dc r8c31865  
    88  LinkedCell/LinkedCell_Model.cpp \
    99  LinkedCell/LinkedCell_Model_changeModel.cpp \
     10  LinkedCell/LinkedCell_Model_LinkedCellArrayCache.cpp \
    1011  LinkedCell/LinkedCell_Model_Update.cpp \
    1112  LinkedCell/LinkedCell_View.cpp \
     
    1920  LinkedCell/LinkedCell_Model.hpp \
    2021  LinkedCell/LinkedCell_Model_changeModel.hpp \
    21   LinkedCell/LinkedCell_Model_inline.hpp \
     22  LinkedCell/LinkedCell_Model_LinkedCellArrayCache.hpp \
    2223  LinkedCell/LinkedCell_Model_Update.hpp \
    2324  LinkedCell/LinkedCell_View.hpp \
  • src/LinkedCell/unittests/LinkedCell_ModelUnitTest.cpp

    re776dc r8c31865  
    3232#include "LinkedCell/LinkedCell.hpp"
    3333#include "LinkedCell/LinkedCell_Model.hpp"
     34#include "LinkedCell/LinkedCell_Model_LinkedCellArrayCache.hpp"
    3435#include "LinkedCell/PointCloudAdaptor.hpp"
    3536#include "LinkedCell/unittests/defs.hpp"
     
    99100  LinkedCell::tripleIndex index;
    100101  index[0] = index[1] = index[2] = 0;
    101   CPPUNIT_ASSERT(LC->N(index) != NULL);
     102  CPPUNIT_ASSERT(LC->N->getN()(index) != NULL);
    102103
    103104  // check that very last cell is allocated
    104105  index[0] = index[1] = index[2] = (size_t)floor(NUMBERCELLS)-1;
    105   CPPUNIT_ASSERT(LC->N(index) != NULL);
     106  CPPUNIT_ASSERT(LC->N->getN()(index) != NULL);
    106107
    107108}
     
    146147    index[0] = index[1] = index[2] = i;
    147148    // assert that in the destined cell we have one Walker
    148     CPPUNIT_ASSERT_EQUAL((size_t)1, LC->N(index)->size());
     149    CPPUNIT_ASSERT_EQUAL((size_t)1, LC->N->getN()(index)->size());
    149150  }
    150151  index[0] = 9;
    151152  index[1] = index[2] = 0;
    152153  // assert that in the destined cell we have one Walker
    153   CPPUNIT_ASSERT_EQUAL((size_t)0, LC->N(index)->size());
    154 
    155 }
    156 
    157 /** UnitTest for insertPointCloud()
     154  CPPUNIT_ASSERT_EQUAL((size_t)0, LC->N->getN()(index)->size());
     155
     156}
     157
     158/** UnitTest for setPartition()
    158159 */
    159160void LinkedCell_ModelTest::setPartitionTest()
     
    173174}
    174175
    175 /** UnitTest for insertPointCloud()
     176/** UnitTest for getStep()
    176177 */
    177178void LinkedCell_ModelTest::getStepTest()
     
    197198}
    198199
    199 /** UnitTest for insertPointCloud()
     200/** UnitTest for getIndexToVector()
    200201 */
    201202void LinkedCell_ModelTest::getIndexToVectorTest()
     
    221222}
    222223
    223 /** UnitTest for insertPointCloud()
     224/** UnitTest for updating nodes
    224225 */
    225226void LinkedCell_ModelTest::nodeTest()
Note: See TracChangeset for help on using the changeset viewer.