Changeset 92e5cb for src


Ignore:
Timestamp:
Feb 3, 2011, 9:51:19 AM (14 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:
b25fa3
Parents:
cd7a87
git-author:
Frederik Heber <heber@…> (12/30/10 11:10:50)
git-committer:
Frederik Heber <heber@…> (02/03/11 09:51:19)
Message:

Refactored Output..Correlation...() code into a single templated one.

  • template function OutputCorrelationMap() that accepts two function pointers for header and value to print the map's specifics.
  • all other function have been refactored into these two output functions per CorrelationMap type.

TESTFIXES:

Location:
src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/AnalysisAction/DipoleAngularCorrelationAction.cpp

    rcd7a87 r92e5cb  
    6161  ASSERT(!params.periodic, "AnalysisDipoleAngularCorrelationAction() - periodic case not implemented.");
    6262  correlationmap = DipoleAngularCorrelation(molecules);
    63   OutputDipoleAngularCorrelation(&output, correlationmap);
     63  OutputCorrelationMap<DipoleAngularCorrelationMap>(&output, correlationmap, OutputDipoleAngularCorrelation_Header, OutputDipoleAngularCorrelation_Value);
    6464  binmap = BinData( correlationmap, params.BinWidth, params.BinStart, params.BinEnd );
    65   OutputCorrelation ( &binoutput, binmap );
     65  OutputCorrelationMap<BinPairMap> ( &binoutput, binmap, OutputCorrelation_Header, OutputCorrelation_Value );
    6666  delete(binmap);
    6767  delete(correlationmap);
  • src/Actions/AnalysisAction/PairCorrelationAction.cpp

    rcd7a87 r92e5cb  
    6262  else
    6363    correlationmap = PairCorrelation(molecules, params.elements);
    64   OutputPairCorrelation(&output, correlationmap);
     64  OutputCorrelationMap<PairCorrelationMap>(&output, correlationmap, OutputPairCorrelation_Header, OutputPairCorrelation_Value);
    6565  binmap = BinData( correlationmap, params.BinWidth, params.BinStart, params.BinEnd );
    66   OutputCorrelation ( &binoutput, binmap );
     66  OutputCorrelationMap<BinPairMap> ( &binoutput, binmap, OutputCorrelation_Header, OutputCorrelation_Value );
    6767  delete(binmap);
    6868  delete(correlationmap);
  • src/Actions/AnalysisAction/PointCorrelationAction.cpp

    rcd7a87 r92e5cb  
    6767  else
    6868    correlationmap = CorrelationToPoint(molecules, params.elements, &params.Point);
    69   OutputCorrelationToPoint(&output, correlationmap);
     69  OutputCorrelationMap<CorrelationToPointMap>(&output, correlationmap, OutputCorrelationToPoint_Header, OutputCorrelationToPoint_Value);
    7070  binmap = BinData( correlationmap, params.BinWidth, params.BinStart, params.BinEnd );
    71   OutputCorrelation ( &binoutput, binmap );
     71  OutputCorrelationMap<BinPairMap> ( &binoutput, binmap, OutputCorrelation_Header, OutputCorrelation_Value );
    7272  delete(binmap);
    7373  delete(correlationmap);
  • src/Actions/AnalysisAction/SurfaceCorrelationAction.cpp

    rcd7a87 r92e5cb  
    8181    surfacemap = CorrelationToSurface( molecules, params.elements, TesselStruct, LCList);
    8282  delete LCList;
    83   OutputCorrelationToSurface(&output, surfacemap);
     83  OutputCorrelationMap<CorrelationToSurfaceMap>(&output, surfacemap, OutputCorrelationToSurface_Header, OutputCorrelationToSurface_Value);
    8484  // check whether radius was appropriate
    8585  {
     
    9090  }
    9191  binmap = BinData( surfacemap, params.BinWidth, params.BinStart, params.BinEnd );
    92   OutputCorrelation ( &binoutput, binmap );
     92  OutputCorrelationMap<BinPairMap> ( &binoutput, binmap, OutputCorrelation_Header, OutputCorrelation_Value );
    9393  delete TesselStruct;  // surfacemap contains refs to triangles! delete here, not earlier!
    9494  delete(binmap);
  • src/analysis_correlation.cpp

    rcd7a87 r92e5cb  
    108108  outmap = new DipoleAngularCorrelationMap;
    109109  for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin();
    110       MolWalker != molecules.end();) {
     110      MolWalker != molecules.end(); ++MolWalker) {
    111111    DoLog(2) && (Log()<< Verbose(2) << "Current molecule is "
    112112        << (*MolWalker)->getId() << "." << endl);
    113113    const Vector Dipole = getDipole((*MolWalker)->begin(), (*MolWalker)->end());
    114     for (std::vector<molecule *>::const_iterator MolOtherWalker = ++MolWalker;
     114    std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker;
     115    for (++MolOtherWalker;
    115116        MolOtherWalker != molecules.end();
    116         MolOtherWalker++) {
     117        ++MolOtherWalker) {
    117118      DoLog(2) && (Log() << Verbose(2) << "Current other molecule is "
    118119          << (*MolOtherWalker)->getId() << "." << endl);
     
    469470int GetBin ( const double value, const double BinWidth, const double BinStart )
    470471{
    471   Info FunctionInfo(__func__);
     472  //Info FunctionInfo(__func__);
    472473  int bin =(int) (floor((value - BinStart)/BinWidth));
    473474  return (bin);
     
    475476
    476477
    477 /** Prints correlation (double, int) pairs to file.
    478  * \param *file file to write to
    479  * \param *map map to write
    480  */
    481 void OutputCorrelation( ofstream * const file, const BinPairMap * const map )
    482 {
    483   Info FunctionInfo(__func__);
    484   *file << "BinStart\tCount" << endl;
    485   for (BinPairMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
    486     *file << setprecision(8) << runner->first << "\t" << runner->second << endl;
    487   }
    488 };
    489 
    490 /** Prints correlation (double, (atom*,atom*) ) pairs to file.
    491  * \param *file file to write to
    492  * \param *map map to write
    493  */
    494 void OutputDipoleAngularCorrelation( ofstream * const file, const DipoleAngularCorrelationMap * const map )
    495 {
    496   Info FunctionInfo(__func__);
    497   *file << "BinStart\tMolecule1\tMolecule2" << endl;
    498   for (DipoleAngularCorrelationMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
    499     *file << setprecision(8) << runner->first << "\t" << runner->second.first->getId() << "\t" << runner->second.second->getId() << endl;
    500   }
    501 };
    502 
    503 /** Prints correlation (double, (atom*,atom*) ) pairs to file.
    504  * \param *file file to write to
    505  * \param *map map to write
    506  */
    507 void OutputPairCorrelation( ofstream * const file, const PairCorrelationMap * const map )
    508 {
    509   Info FunctionInfo(__func__);
    510   *file << "BinStart\tAtom1\tAtom2" << endl;
    511   for (PairCorrelationMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
    512     *file << setprecision(8) << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl;
    513   }
    514 };
    515 
    516 /** Prints correlation (double, int) pairs to file.
    517  * \param *file file to write to
    518  * \param *map map to write
    519  */
    520 void OutputCorrelationToPoint( ofstream * const file, const CorrelationToPointMap * const map )
    521 {
    522   Info FunctionInfo(__func__);
    523   *file << "BinStart\tAtom::x[i]-point.x[i]" << endl;
    524   for (CorrelationToPointMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
    525     *file << runner->first;
    526     for (int i=0;i<NDIM;i++)
    527       *file << "\t" << setprecision(8) << (runner->second.first->at(i) - runner->second.second->at(i));
    528     *file << endl;
    529   }
    530 };
    531 
    532 /** Prints correlation (double, int) pairs to file.
    533  * \param *file file to write to
    534  * \param *map map to write
    535  */
    536 void OutputCorrelationToSurface( ofstream * const file, const CorrelationToSurfaceMap * const map )
    537 {
    538   Info FunctionInfo(__func__);
    539   *file << "BinStart\tTriangle" << endl;
    540   if (!map->empty())
    541     for (CorrelationToSurfaceMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
    542       *file << setprecision(8) << runner->first << "\t";
    543       *file << *(runner->second.first) << "\t";
    544       *file << *(runner->second.second) << endl;
    545     }
    546 };
    547 
     478/** Adds header part that is unique to BinPairMap.
     479 *
     480 * @param file stream to print to
     481 */
     482void OutputCorrelation_Header( ofstream * const file )
     483{
     484  *file << "\tCount";
     485};
     486
     487/** Prints values stored in BinPairMap iterator.
     488 *
     489 * @param file stream to print to
     490 * @param runner iterator pointing at values to print
     491 */
     492void OutputCorrelation_Value( ofstream * const file, BinPairMap::const_iterator &runner )
     493{
     494  *file << runner->second;
     495};
     496
     497
     498/** Adds header part that is unique to DipoleAngularCorrelationMap.
     499 *
     500 * @param file stream to print to
     501 */
     502void OutputDipoleAngularCorrelation_Header( ofstream * const file )
     503{
     504  *file << "\tAtom1\tAtom2";
     505};
     506
     507/** Prints values stored in DipoleAngularCorrelationMap iterator.
     508 *
     509 * @param file stream to print to
     510 * @param runner iterator pointing at values to print
     511 */
     512void OutputDipoleAngularCorrelation_Value( ofstream * const file, DipoleAngularCorrelationMap::const_iterator &runner )
     513{
     514  *file << runner->second.first->getId() << "\t" << runner->second.second->getId();
     515};
     516
     517
     518/** Adds header part that is unique to PairCorrelationMap.
     519 *
     520 * @param file stream to print to
     521 */
     522void OutputPairCorrelation_Header( ofstream * const file )
     523{
     524  *file << "\tAtom1\tAtom2";
     525};
     526
     527/** Prints values stored in PairCorrelationMap iterator.
     528 *
     529 * @param file stream to print to
     530 * @param runner iterator pointing at values to print
     531 */
     532void OutputPairCorrelation_Value( ofstream * const file, PairCorrelationMap::const_iterator &runner )
     533{
     534  *file << *(runner->second.first) << "\t" << *(runner->second.second);
     535};
     536
     537
     538/** Adds header part that is unique to CorrelationToPointMap.
     539 *
     540 * @param file stream to print to
     541 */
     542void OutputCorrelationToPoint_Header( ofstream * const file )
     543{
     544  *file << "\tAtom::x[i]-point.x[i]";
     545};
     546
     547/** Prints values stored in CorrelationToPointMap iterator.
     548 *
     549 * @param file stream to print to
     550 * @param runner iterator pointing at values to print
     551 */
     552void OutputCorrelationToPoint_Value( ofstream * const file, CorrelationToPointMap::const_iterator &runner )
     553{
     554  for (int i=0;i<NDIM;i++)
     555    *file << "\t" << setprecision(8) << (runner->second.first->at(i) - runner->second.second->at(i));
     556};
     557
     558
     559/** Adds header part that is unique to CorrelationToSurfaceMap.
     560 *
     561 * @param file stream to print to
     562 */
     563void OutputCorrelationToSurface_Header( ofstream * const file )
     564{
     565  *file << "\tTriangle";
     566};
     567
     568/** Prints values stored in CorrelationToSurfaceMap iterator.
     569 *
     570 * @param file stream to print to
     571 * @param runner iterator pointing at values to print
     572 */
     573void OutputCorrelationToSurface_Value( ofstream * const file, CorrelationToSurfaceMap::const_iterator &runner )
     574{
     575  *file << *(runner->second.first) << "\t" << *(runner->second.second);
     576};
  • src/analysis_correlation.hpp

    rcd7a87 r92e5cb  
    1919
    2020#include <cmath>
     21#include <iomanip>
    2122#include <fstream>
    2223
     
    2829
    2930#include "atom.hpp"
     31#include "CodePatterns/Info.hpp"
     32#include "CodePatterns/Log.hpp"
    3033#include "CodePatterns/Verbose.hpp"
    3134
     
    5760CorrelationToSurfaceMap *PeriodicCorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] );
    5861int GetBin ( const double value, const double BinWidth, const double BinStart );
    59 void OutputCorrelation( ofstream * const file, const BinPairMap * const map );
    60 void OutputDipoleAngularCorrelation( ofstream * const file, const DipoleAngularCorrelationMap * const map );
    61 void OutputPairCorrelation( ofstream * const file, const PairCorrelationMap * const map );
    62 void OutputCorrelationToPoint( ofstream * const file, const CorrelationToPointMap * const map );
    63 void OutputCorrelationToSurface( ofstream * const file, const CorrelationToSurfaceMap * const map );
    64 
     62void OutputCorrelation_Header( ofstream * const file );
     63void OutputCorrelation_Value( ofstream * const file, BinPairMap::const_iterator &runner );
     64void OutputDipoleAngularCorrelation_Header( ofstream * const file );
     65void OutputDipoleAngularCorrelation_Value( ofstream * const file, DipoleAngularCorrelationMap::const_iterator &runner );
     66void OutputPairCorrelation_Header( ofstream * const file );
     67void OutputPairCorrelation_Value( ofstream * const file, PairCorrelationMap::const_iterator &runner );
     68void OutputCorrelationToPoint_Header( ofstream * const file );
     69void OutputCorrelationToPoint_Value( ofstream * const file, CorrelationToPointMap::const_iterator &runner );
     70void OutputCorrelationToSurface_Header( ofstream * const file );
     71void OutputCorrelationToSurface_Value( ofstream * const file, CorrelationToSurfaceMap::const_iterator &runner );
    6572
    6673/** Searches for lowest and highest value in a given map of doubles.
     
    143150};
    144151
     152/** Prints correlation map of template type to file.
     153 * \param *file file to write to
     154 * \param *map map to write
     155 * \param (*header) pointer to function that adds specific part to header
     156 * \param (*value) pointer to function that prints value from given iterator
     157 */
     158template <typename T>
     159void OutputCorrelationMap(
     160    ofstream * const file,
     161    const T * const map,
     162    void (*header)( ofstream * const file),
     163    void (*value)( ofstream * const file, typename T::const_iterator &runner)
     164    )
     165{
     166  Info FunctionInfo(__func__);
     167  *file << "BinStart\tBinCenter\tBinEnd";
     168  header(file);
     169  *file << endl;
     170  typename T::const_iterator advancer = map->begin();
     171  typename T::const_iterator runner = map->begin();
     172  if (advancer != map->end())
     173    advancer++;
     174  for ( ;(advancer != map->end()) && (runner != map->end()); ++advancer, ++runner) {
     175    *file << setprecision(8)
     176        << runner->first << "\t"
     177        << (advancer->first + runner->first)/2. << "\t"
     178        << advancer->first << "\t";
     179    value(file, runner);
     180    *file << endl;
     181  }
     182  if(runner != map->end()) {
     183    *file << setprecision(8) << runner->first << "\t0\t0\t";
     184    value(file, runner);
     185    *file << endl;
     186  }
     187};
     188
     189
    145190#endif /* ANALYSIS_HPP_ */
  • src/unittests/AnalysisCorrelationToPointUnitTest.cpp

    rcd7a87 r92e5cb  
    125125  // put pair correlation into bins and check with no range
    126126  binmap = BinData( pointmap, 0.5, 0., 0. );
    127   OutputCorrelation ( (ofstream *)&cout, binmap );
     127  OutputCorrelationMap<BinPairMap> ( (ofstream *)&cout, binmap, OutputCorrelation_Header, OutputCorrelation_Value );
    128128  CPPUNIT_ASSERT_EQUAL( (size_t)3, binmap->size() );
    129129  tester = binmap->begin();
     
    138138  // ... and check with [0., 2.] range
    139139  binmap = BinData( pointmap, 0.5, 0., 2. );
    140   OutputCorrelation ( (ofstream *)&cout, binmap );
     140  OutputCorrelationMap<BinPairMap> ( (ofstream *)&cout, binmap, OutputCorrelation_Header, OutputCorrelation_Value );
    141141  CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
    142142  tester = binmap->begin();
  • src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp

    rcd7a87 r92e5cb  
    183183  binmap = BinData( surfacemap, 0.5, 0., 0. );
    184184  CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() );
    185   OutputCorrelation ( (ofstream *)&cout, binmap );
     185  OutputCorrelationMap<BinPairMap> ( (ofstream *)&cout, binmap, OutputCorrelation_Header, OutputCorrelation_Value );
    186186  tester = binmap->begin();
    187187  CPPUNIT_ASSERT_EQUAL( 0., tester->first );
Note: See TracChangeset for help on using the changeset viewer.