Changeset 851be8


Ignore:
Timestamp:
Oct 25, 2011, 12:08:03 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:
3a9091
Parents:
730d7a
git-author:
Frederik Heber <heber@…> (10/20/11 11:05:14)
git-committer:
Frederik Heber <heber@…> (10/25/11 12:08:03)
Message:

Moved functions that deal with adaptivity from fragmentation_helpers into AdaptivityMap.

Location:
src/Fragmentation
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/AdaptivityMap.cpp

    r730d7a r851be8  
    2323#include <fstream>
    2424
     25#include "CodePatterns/Assert.hpp"
    2526#include "CodePatterns/Log.hpp"
    2627
     
    5152 * \param value energy value
    5253 */
    53 void AdaptivityMap::InsertIntoAdaptiveCriteriaList(std::map<int, std::pair<double,int> > *AdaptiveCriteriaList, int FragOrder, int No, double Value) const
    54 {
     54void AdaptivityMap::InsertIntoAdaptiveCriteriaList(int FragOrder, int No, double Value)
     55{
     56  ASSERT( AdaptiveCriteriaList != NULL,
     57      "AdaptivityMap::InsertIntoAdaptiveCriteriaList() - AdaptiveCriteriaList is not allocated yet.");
    5558  const_iterator marker = find(No);    // find keyset to Frag No.
    5659  if (marker != end()) {  // if found
     
    8083/** Scans the adaptive order file and insert (index, value) into map.
    8184 * \param &path path to ENERGYPERFRAGMENT file (may be NULL if Order is non-negative)
    82  * \return adaptive criteria list from file
    83  */
    84 std::map<int, std::pair<double,int> > * AdaptivityMap::ScanAdaptiveFileIntoMap(std::string &path)
    85 {
    86   std::map<int, pair<double,int> > *AdaptiveCriteriaList = new std::map<int, pair<double,int> >;
     85 */
     86void AdaptivityMap::ScanAdaptiveFileIntoMap(std::string &path)
     87{
    8788  int No = 0, FragOrder = 0;
    8889  double Value = 0.;
     
    9394  if (InputFile.fail()) {
    9495    DoeLog(1) && (eLog() << Verbose(1) << "Cannot find file " << filename << "." << endl);
    95     return AdaptiveCriteriaList;
     96    return;
    9697  }
    9798
     
    113114
    114115        // clean the list of those entries that have been superceded by higher order terms already
    115         InsertIntoAdaptiveCriteriaList(AdaptiveCriteriaList, FragOrder, No, Value);
     116        InsertIntoAdaptiveCriteriaList(FragOrder, No, Value);
    116117      }
    117118    }
     
    120121    InputFile.clear();
    121122  }
    122 
    123   return AdaptiveCriteriaList;
    124123};
    125124
    126125/** Maps adaptive criteria list back onto (Value, (Root Nr., Order))
    127126 * (i.e. sorted by value to pick the highest ones)
    128  * \param *out output stream for debugging
    129  * \param &AdaptiveCriteriaList list to insert into
    130127 * \param *mol molecule with atoms
    131128 * \return remapped list
    132129 */
    133 std::map<double, std::pair<int,int> >  * AdaptivityMap::ReMapAdaptiveCriteriaListToValue(std::map<int, std::pair<double,int> > *AdaptiveCriteriaList, molecule *mol)
     130void AdaptivityMap::ReMapAdaptiveCriteriaListToValue(molecule *mol)
    134131{
    135132  atom *Walker = NULL;
    136   std::map<double, std::pair<int,int> > *FinalRootCandidates = new std::map<double, std::pair<int,int> > ;
     133  ASSERT( AdaptiveCriteriaList != NULL,
     134      "AdaptivityMap::ReMapAdaptiveCriteriaListToValue() - AdaptiveCriteriaList is not allocated yet.");
     135  FinalRootCandidates = new AdaptiveCriteriaValueMap;
    137136  DoLog(1) && (Log() << Verbose(1) << "Root candidate list is: " << endl);
    138   for(std::map<int, std::pair<double,int> >::iterator runner = AdaptiveCriteriaList->begin(); runner != AdaptiveCriteriaList->end(); runner++) {
     137  for(AdaptiveCriteriaIndexMap::const_iterator runner = AdaptiveCriteriaList->begin(); runner != AdaptiveCriteriaList->end(); runner++) {
    139138    Walker = mol->FindAtom((*runner).first);
    140139    if (Walker != NULL) {
     
    151150    }
    152151  }
    153   return FinalRootCandidates;
    154152};
    155153
     
    175173  return lines;
    176174};
     175
     176/** Marks all candidate sites for update if below adaptive threshold.
     177 * Picks a given number of highest values and set *AtomMask to true.
     178 * \param *AtomMask defines true/false per global Atom::Nr to mask in/out each nuclear site, used to activate given number of site to increment order adaptively
     179 * \param Order desired order
     180 * \param *mol molecule with atoms
     181 * \return true - if update is necessary, false - not
     182 */
     183bool AdaptivityMap::MarkUpdateCandidates(bool *AtomMask, int Order, molecule *mol) const
     184{
     185  atom *Walker = NULL;
     186  int No = -1;
     187  bool status = false;
     188  ASSERT( FinalRootCandidates != NULL,
     189      "AdaptivityMap::MarkUpdateCandidates() - FinalRootCandidates is not allocated yet.");
     190  for(AdaptiveCriteriaValueMap::const_iterator runner = FinalRootCandidates->upper_bound(pow(10.,Order)); runner != FinalRootCandidates->end(); runner++) {
     191    No = (*runner).second.first;
     192    Walker = mol->FindAtom(No);
     193    //if (Walker->AdaptiveOrder < MinimumRingSize[Walker->getNr()]) {
     194      DoLog(2) && (Log() << Verbose(2) << "Root " << No << " is still above threshold (10^{" << Order <<"}: " << runner->first << ", setting entry " << No << " of Atom mask to true." << endl);
     195      AtomMask[No] = true;
     196      status = true;
     197    //} else
     198      //Log() << Verbose(2) << "Root " << No << " is still above threshold (10^{" << Order <<"}: " << runner->first << ", however MinimumRingSize of " << MinimumRingSize[Walker->getNr()] << " does not allow further adaptive increase." << endl;
     199  }
     200  return status;
     201};
     202
     203/** Checks whether there are any adaptive items currently.
     204 *
     205 * @return true - there are items for adaptive refinement, false - there are none
     206 */
     207bool AdaptivityMap::IsAdaptiveCriteriaListEmpty() const
     208{
     209  ASSERT( AdaptiveCriteriaList != NULL,
     210      "AdaptivityMap::ReMapAdaptiveCriteriaListToValue() - AdaptiveCriteriaList is not allocated yet.");
     211  return AdaptiveCriteriaList->empty();
     212}
  • src/Fragmentation/AdaptivityMap.hpp

    r730d7a r851be8  
    2929  ~AdaptivityMap();
    3030
    31   void InsertIntoAdaptiveCriteriaList(std::map<int, std::pair<double,int> > *AdaptiveCriteriaList, int FragOrder, int No, double Value) const;
    32   std::map<int, std::pair<double,int> > * ScanAdaptiveFileIntoMap(std::string &path);
    33   std::map<double, std::pair<int,int> >  * ReMapAdaptiveCriteriaListToValue(std::map<int, std::pair<double,int> > *AdaptiveCriteriaList, molecule *mol);
     31  void InsertIntoAdaptiveCriteriaList(int FragOrder, int No, double Value);
     32  void ScanAdaptiveFileIntoMap(std::string &path);
     33  void ReMapAdaptiveCriteriaListToValue(molecule *mol);
    3434  int CountLinesinFile(std::ifstream &InputFile) const;
     35  bool MarkUpdateCandidates(bool *AtomMask, int Order, molecule *mol) const ;
     36
     37  bool IsAdaptiveCriteriaListEmpty() const;
     38
     39private:
     40  typedef std::map<double, std::pair<int,int> > AdaptiveCriteriaValueMap;
     41  typedef std::map<int, std::pair<double,int> > AdaptiveCriteriaIndexMap;
     42
     43  AdaptiveCriteriaIndexMap *AdaptiveCriteriaList;
     44  AdaptiveCriteriaValueMap *FinalRootCandidates;
    3545};
    3646
  • src/Fragmentation/Fragmentation.cpp

    r730d7a r851be8  
    468468
    469469    // parse the EnergyPerFragment file
    470     std::map<int, std::pair<double,int> > *AdaptiveCriteriaList = IndexKeySetList->ScanAdaptiveFileIntoMap(path); // (Root No., (Value, Order)) !
    471     if (AdaptiveCriteriaList->empty()) {
     470    IndexKeySetList->ScanAdaptiveFileIntoMap(path); // (Root No., (Value, Order)) !
     471    // then map back onto (Value, (Root Nr., Order)) (i.e. sorted by value to pick the highest ones)
     472    IndexKeySetList->ReMapAdaptiveCriteriaListToValue(mol);
     473
     474    // pick the ones still below threshold and mark as to be adaptively updated
     475    if (IndexKeySetList->IsAdaptiveCriteriaListEmpty()) {
    472476      DoeLog(2) && (eLog()<< Verbose(2) << "Unable to parse file, incrementing all." << endl);
    473477      for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     
    480484        }
    481485      }
    482     }
    483     // then map back onto (Value, (Root Nr., Order)) (i.e. sorted by value to pick the highest ones)
    484     std::map<double, std::pair<int,int> > *FinalRootCandidates = IndexKeySetList->ReMapAdaptiveCriteriaListToValue(AdaptiveCriteriaList, mol);
    485 
    486     // pick the ones still below threshold and mark as to be adaptively updated
    487     MarkUpdateCandidates(AtomMask, *FinalRootCandidates, Order, mol);
     486    } else {
     487      IndexKeySetList->MarkUpdateCandidates(AtomMask, Order, mol);
     488    }
    488489
    489490    delete[](IndexKeySetList);
    490     delete[](AdaptiveCriteriaList);
    491     delete[](FinalRootCandidates);
    492491  } else { // global increase of Bond Order
    493492    for(molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
  • src/Fragmentation/fragmentation_helpers.cpp

    r730d7a r851be8  
    3737
    3838using namespace std;
    39 
    40 
    41 
    42 
    43 /** Marks all candidate sites for update if below adaptive threshold.
    44  * Picks a given number of highest values and set *AtomMask to true.
    45  * \param *out output stream for debugging
    46  * \param *AtomMask defines true/false per global Atom::Nr to mask in/out each nuclear site, used to activate given number of site to increment order adaptively
    47  * \param FinalRootCandidates list candidates to check
    48  * \param Order desired order
    49  * \param *mol molecule with atoms
    50  * \return true - if update is necessary, false - not
    51  */
    52 bool MarkUpdateCandidates(bool *AtomMask, std::map<double, std::pair<int,int> > &FinalRootCandidates, int Order, molecule *mol)
    53 {
    54   atom *Walker = NULL;
    55   int No = -1;
    56   bool status = false;
    57   for(map<double, pair<int,int> >::iterator runner = FinalRootCandidates.upper_bound(pow(10.,Order)); runner != FinalRootCandidates.end(); runner++) {
    58     No = (*runner).second.first;
    59     Walker = mol->FindAtom(No);
    60     //if (Walker->AdaptiveOrder < MinimumRingSize[Walker->getNr()]) {
    61       DoLog(2) && (Log() << Verbose(2) << "Root " << No << " is still above threshold (10^{" << Order <<"}: " << runner->first << ", setting entry " << No << " of Atom mask to true." << endl);
    62       AtomMask[No] = true;
    63       status = true;
    64     //} else
    65       //Log() << Verbose(2) << "Root " << No << " is still above threshold (10^{" << Order <<"}: " << runner->first << ", however MinimumRingSize of " << MinimumRingSize[Walker->getNr()] << " does not allow further adaptive increase." << endl;
    66   }
    67   return status;
    68 };
    6939
    7040/** print atom mask for debugging.
  • src/Fragmentation/fragmentation_helpers.hpp

    r730d7a r851be8  
    2222typedef std::deque<int> KeyStack;
    2323
    24 class AdaptivityMap;
    25 class bond;
    2624class Graph;
    2725class KeySet;
    2826class molecule;
    2927
    30 bool MarkUpdateCandidates(bool *AtomMask, std::map<double, std::pair<int,int> > &FinalRootCandidates, int Order, molecule *mol);
    3128void PrintAtomMask(bool *AtomMask, int AtomCount);
    3229
Note: See TracChangeset for help on using the changeset viewer.