Changeset 025048


Ignore:
Timestamp:
Oct 20, 2011, 12:39:01 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:
9317be
Parents:
93d78e8
Message:

Enhanced Box::periodicDistanceSquared() by an internal_explode().

  • internal_explode() works on an static internal VECTORSET(list) such that there is no need for repeated memory allocation/deallocation for said list.
Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Box.cpp

    r93d78e8 r025048  
    3838
    3939using namespace std;
     40
     41VECTORSET(std::list) Box::internal_list;
    4042
    4143Box::Box() :
     
    135137VECTORSET(std::list) Box::explode(const Vector &point,int n) const{
    136138  ASSERT(isInside(point),"Exploded point not inside Box");
    137   VECTORSET(std::list) res;
     139  internal_explode(point, n);
     140  VECTORSET(std::list) res(internal_list);
     141  return res;
     142}
     143
     144void Box::internal_explode(const Vector &point,int n) const{
     145  internal_list.clear();
    138146
    139147  Vector translater = translateOut(point);
     
    156164  if(!dims){
    157165    // all boundaries are ignored
    158     res.push_back(point);
    159     return res;
     166    internal_list.push_back(point);
     167    return;
    160168  }
    161169
     
    189197        case Ignore:
    190198          ASSERT(0,"Ignored coordinate handled in generation loop");
     199          break;
    191200        default:
    192201          ASSERT(0,"No default case for this switch-case");
     202          break;
    193203      }
    194204
     
    196206    // add back all ignored coordinates (not handled in above loop)
    197207    helper+=mask;
    198     res.push_back(translateIn(helper));
     208    internal_list.push_back(translateIn(helper));
    199209    // set the new indexes
    200210    int pos=0;
     
    209219    }
    210220  }
    211   return res;
    212221}
    213222
     
    218227
    219228double Box::periodicDistanceSquared(const Vector &point1,const Vector &point2) const{
    220   Vector helper1 = WrapPeriodically(point1);
    221   Vector helper2 = WrapPeriodically(point2);
    222   VECTORSET(std::list) expansion = explode(helper1);
    223   double res = expansion.minDistSquared(helper2);
     229  Vector helper1(!isInside(point1) ? WrapPeriodically(point1) : point1);
     230  Vector helper2(!isInside(point2) ? WrapPeriodically(point2) : point2);
     231  internal_explode(helper1,1);
     232  double res = internal_list.minDistSquared(helper2);
    224233  return res;
    225234}
  • src/Box.hpp

    r93d78e8 r025048  
    122122
    123123private:
     124  /** Internal explode function that works on the staticly present internal_list
     125   *
     126   * \todo Note that is not thread-safe!
     127   *
     128   * Most of the time of explode is consumed by memory allocation if it is called
     129   * repeatedly.
     130   *
     131   * @param point point to explode
     132   * @param n neighbour shells to explode
     133   */
     134  void internal_explode(const Vector &point,int n) const;
     135
     136  //!> Internal vector list for exploding vectors and checking.
     137  static VECTORSET(std::list) internal_list;
     138
    124139  Conditions_t conditions;
    125140  RealSpaceMatrix *M;    //!< Defines the layout of the box
Note: See TracChangeset for help on using the changeset viewer.