Changeset 8cae4c


Ignore:
Timestamp:
Nov 12, 2012, 4:04:51 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:
adccae
Parents:
56df37
git-author:
Frederik Heber <heber@…> (07/31/12 14:30:24)
git-committer:
Frederik Heber <heber@…> (11/12/12 16:04:51)
Message:

FragmentationAutomationAction now may sum up almost everything.

  • split MPQCDataMap_t into Energy, Force, and TimeMap as boost::fusion::map may only consist of up to 9 template types.
  • added boost::mpl::list enumerations of the map keys.
  • using boost::mpl::for_each to go through each map key that is used a specialization type to a printSum() function that calls OrthogonalSummation, sums up, and prints the result.
  • TODO: Missing Histogram cstor for vector<double>, missing class for forces with the four required operators, times need just to be summed up, not orthogonalized.
Location:
src
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/FragmentationAction/FragmentationAutomationAction.cpp

    r56df37 r8cae4c  
    5959#include "Jobs/MPQCJob.hpp"
    6060#include "Jobs/MPQCData.hpp"
     61#include "Jobs/MPQCData_printName.hpp"
    6162#include "molecule.hpp"
    6263#include "World.hpp"
     
    6566#include <string>
    6667#include <vector>
     68
     69#include <boost/mpl/for_each.hpp>
    6770
    6871#include "Actions/FragmentationAction/FragmentationAutomationAction.hpp"
     
    138141}
    139142
     143
     144template <typename MapType>
     145struct printSum {
     146  printSum(
     147      SubsetMap::ptr &_subsetmap,
     148      const std::vector<MapType> &_data,
     149      const std::vector<JobId_t> &_jobids,
     150      const IndexSetContainer::Container_t &_container,
     151      std::map< JobId_t, size_t > &_MatrixNrLookup) : /* cannot make this const due to operator[] */
     152    subsetmap(_subsetmap),
     153    data(_data),
     154    jobids(_jobids),
     155    container(_container),
     156    MatrixNrLookup(_MatrixNrLookup)
     157  {}
     158  template <typename MapKey>
     159  void operator()(MapKey &) {
     160    Summator<MapType, MapKey> sum_value(
     161        subsetmap, data, jobids, container, MatrixNrLookup
     162        );
     163    double value = sum_value();
     164    LOG(0, "STATUS: Resulting " << MPQCDataNames::printName<MapKey>() << " is " << value << ".");
     165  }
     166
     167private:
     168  //!> Hierarchy of IndexSet's
     169  SubsetMap::ptr &subsetmap;
     170  //!> vector of data converted from MPQCData
     171  const std::vector<MapType> &data;
     172  //!> vector of jobids
     173  const std::vector<JobId_t> &jobids;
     174  //!> container with all IndexSet's
     175  const IndexSetContainer::Container_t &container;
     176  //!> lookup map from job ids to ordering in above vectors
     177  std::map< JobId_t, size_t > MatrixNrLookup;
     178};
    140179
    141180/** Print MPQCData from received results.
     
    276315  SubsetMap::ptr subsetmap(new SubsetMap(*container));
    277316
    278   // convert all MPQCData to MPQCDataMap_t
    279   std::vector<MPQCDataMap_t> MPQCData_fused;
    280   MPQCData_fused.reserve(fragmentData.size());
    281   for(std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
    282       dataiter != fragmentData.end(); ++dataiter) {
    283     MPQCDataMap_t instance;
    284     boost::fusion::at_key<MPQCDataFused::energy_total>(instance) = dataiter->energies.total;
    285 //    boost::fusion::at_key<MPQCDataFused::energy_eigenvalues>(instance) = dataiter->energies.eigenvalues;
    286 //    boost::fusion::at_key<MPQCDataFused::forces>(instance) = dataiter->forces;
    287 //    boost::fusion::at_key<MPQCDataFused::times_walltime>(instance) = dataiter->times.walltime;
    288   }
    289 
    290   // get a vector of a job ids
    291   std::vector<JobId_t> jobids(results.size(), JobId::IllegalJob);
    292 //  std::transform(results.begin(), results.end(), jobids.begin(),
    293 //      boost::bind(&FragmentResult::getId,
    294 //          boost::bind(&FragmentResult::ptr::, _1)));
    295   std::vector<JobId_t>::iterator iditer = jobids.begin();
    296   for (std::vector<FragmentResult::ptr>::const_iterator resultiter = results.begin();
    297       resultiter != results.end(); ++resultiter) {
    298     *iditer = (*resultiter)->getId();
    299     ++iditer;
    300   }
    301 
    302   // associate each index set with its value (do not use the full set, that is also contained!)
    303   const IndexSetContainer::Container_t &_container = container->getContainer();
    304   Summator<MPQCDataMap_t, MPQCDataFused::energy_total> sum_energy_total(
    305       subsetmap,
    306       MPQCData_fused,
    307       jobids,
    308       _container,
    309       MatrixNrLookup
    310       );
    311   double energy_total = sum_energy_total();
    312   LOG(0, "STATUS: Resulting total energy is " << energy_total << ".");
    313 
    314   //  Summator<MPQCDataMap_t, MPQCDataFused::energy_eigenvalues> sum_energy_eigenvalues(
    315 //      subsetmap,
    316 //      MPQCData_fused,
    317 //      jobids,
    318 //      _container,
    319 //      MatrixNrLookup
    320 //      );
    321 
    322   // associate each index set with its value (do not use the full set, that is also contained!)
    323 //  {
    324 //    OrthogonalSummation<double>::InputSets_t indices(_container.begin(), _container.end()-1);
    325 //    OrthogonalSummation<double>::InputValues_t values(_container.size()-1, 0.);
    326 //    std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
    327 //    std::vector<FragmentResult::ptr>::const_iterator resultiter = results.begin();
    328 //    for (; dataiter != fragmentData.end(); ++dataiter, ++resultiter) {
    329 //      const MPQCData &extractedData = *dataiter;
    330 //      values[ MatrixNrLookup[(*resultiter)->getId()] ] = extractedData.energies.total;
    331 //    }
    332 //
    333 //    // create the summation functor and evaluate
    334 //    OrthogonalSummation<double> OS(indices, values, subsetmap);
    335 //    const double energyresult = OS();
    336 //    LOG(0, "STATUS: Resulting energy is " << energyresult << ".");
    337 //  }
    338 //  {
    339 //    OrthogonalSummation<Histogram>::InputSets_t indices(_container.begin(), _container.end()-1);
    340 //    OrthogonalSummation<Histogram>::InputValues_t values(_container.size()-1);
    341 //    std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
    342 //    std::vector<FragmentResult::ptr>::const_iterator resultiter = results.begin();
    343 //    for (; dataiter != fragmentData.end(); ++dataiter, ++resultiter) {
    344 //      const MPQCData &extractedData = *dataiter;
    345 //      values[ MatrixNrLookup[(*resultiter)->getId()] ] = Histogram(extractedData.energies.eigenvalues, 0., 0.1);
    346 //    }
    347 //
    348 //    // create the summation functor and evaluate
    349 //    OrthogonalSummation<Histogram> OS(indices, values, subsetmap);
    350 //    const Histogram eigenvaluegram = OS();
    351 //    LOG(0, "STATUS: Resulting histogram is " << eigenvaluegram << ".");
    352 //  }
     317  {
     318    /// convert all MPQCData to MPQCDataMap_t
     319
     320    // energy_t
     321    std::vector<MPQCDataEnergyMap_t> MPQCData_Energy_fused;
     322    MPQCData_Energy_fused.reserve(fragmentData.size());
     323    for(std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
     324        dataiter != fragmentData.end(); ++dataiter) {
     325      const MPQCData &extractedData = *dataiter;
     326      LOG(2, "DEBUG: Current extracted Data is " << extractedData << ".");
     327      MPQCDataEnergyMap_t instance;
     328      boost::fusion::at_key<MPQCDataFused::energy_total>(instance) = extractedData.energies.total;
     329      boost::fusion::at_key<MPQCDataFused::energy_nuclear_repulsion>(instance) = extractedData.energies.nuclear_repulsion;
     330      boost::fusion::at_key<MPQCDataFused::energy_electron_repulsion>(instance) = extractedData.energies.electron_repulsion;
     331      boost::fusion::at_key<MPQCDataFused::energy_correlation>(instance) = extractedData.energies.correlation;
     332      boost::fusion::at_key<MPQCDataFused::energy_overlap>(instance) = extractedData.energies.overlap;
     333      boost::fusion::at_key<MPQCDataFused::energy_kinetic>(instance) = extractedData.energies.kinetic;
     334      boost::fusion::at_key<MPQCDataFused::energy_hcore>(instance) = extractedData.energies.hcore;
     335  //    boost::fusion::at_key<MPQCDataFused::energy_eigenvalues>(instance) = extractedData.energies.eigenvalues;
     336      MPQCData_Energy_fused.push_back(instance);
     337    }
     338
     339    // forces
     340    std::vector<MPQCDataForceMap_t> MPQCData_Force_fused;
     341    MPQCData_Force_fused.reserve(fragmentData.size());
     342    for(std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
     343        dataiter != fragmentData.end(); ++dataiter) {
     344      const MPQCData &extractedData = *dataiter;
     345      LOG(2, "DEBUG: Current extracted Data is " << extractedData << ".");
     346      MPQCDataForceMap_t instance;
     347      boost::fusion::at_key<MPQCDataFused::forces>(instance) = extractedData.forces;
     348      MPQCData_Force_fused.push_back(instance);
     349    }
     350
     351    // times
     352    std::vector<MPQCDataTimeMap_t> MPQCData_Time_fused;
     353    MPQCData_Time_fused.reserve(fragmentData.size());
     354    for(std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
     355        dataiter != fragmentData.end(); ++dataiter) {
     356      const MPQCData &extractedData = *dataiter;
     357      LOG(2, "DEBUG: Current extracted Data is " << extractedData << ".");
     358      MPQCDataTimeMap_t instance;
     359      boost::fusion::at_key<MPQCDataFused::times_walltime>(instance) = extractedData.times.walltime;
     360      boost::fusion::at_key<MPQCDataFused::times_cputime>(instance) = extractedData.times.cputime;
     361      boost::fusion::at_key<MPQCDataFused::times_flops>(instance) = extractedData.times.flops;
     362      MPQCData_Time_fused.push_back(instance);
     363    }
     364
     365    // create a vector of all job ids
     366    std::vector<JobId_t> jobids(results.size(), JobId::IllegalJob);
     367    std::transform(results.begin(), results.end(), jobids.begin(),
     368        boost::bind(&FragmentResult::getId,
     369            boost::bind(&FragmentResult::ptr::operator->, _1)));
     370
     371    // sum up and print energies
     372    boost::mpl::for_each<MPQCDataEnergyVector_t>(
     373        printSum<MPQCDataEnergyMap_t>(
     374            subsetmap,
     375            MPQCData_Energy_fused,
     376            jobids,
     377            container->getContainer(),
     378            MatrixNrLookup)
     379        );
     380    // TODO: Histogram still needs cstor taking just vector<double>
     381
     382
     383    // TODO: We need to put forces into specific class and implement operators
     384//    // sum up and print forces
     385//    boost::mpl::for_each<MPQCDataForceVector_t>(
     386//        printSum<MPQCDataForceMap_t>(
     387//            subsetmap,
     388//            MPQCData_Force_fused,
     389//            jobids,
     390//            container->getContainer(),
     391//            MatrixNrLookup)
     392//        );
     393
     394    // TODO: Times should just be summed not orthogonalized
     395//    // sum up and print times
     396//    boost::mpl::for_each<MPQCDataTimeVector_t>(
     397//        printSum<MPQCDataTimeMap_t>(
     398//            subsetmap,
     399//            MPQCData_Time_fused,
     400//            jobids,
     401//            container->getContainer(),
     402//            MatrixNrLookup)
     403//        );
     404  }
    353405
    354406  // combine all found data
  • src/Jobs/MPQCDataFused.hpp

    r56df37 r8cae4c  
    1919 * generic algorithms to work on it.
    2020 *
    21  *
     21 * \note forward declarations are not enough as we need the true (but empty)
     22 * instance when going throughb the list with boost::mpl::for_each.
    2223 */
    2324namespace MPQCDataFused {
    24   struct energy_total;
    25   struct energy_eigenvalues;
    26   struct forces;
    27   struct times_walltime;
     25  // keys for energy_t
     26  struct energy_total {};
     27  struct energy_nuclear_repulsion {};
     28  struct energy_electron_repulsion {};
     29  struct energy_correlation {};
     30  struct energy_overlap {};
     31  struct energy_kinetic {};
     32  struct energy_hcore {};
     33  struct energy_eigenvalues {};
     34
     35  // keys for forces
     36  struct forces {};
     37
     38  // keys for times_t
     39  struct times_walltime {};
     40  struct times_cputime {};
     41  struct times_flops {};
    2842}
    2943
     44
    3045#endif /* MPQCDATAFUSED_HPP_ */
  • src/Jobs/MPQCDataMap.hpp

    r56df37 r8cae4c  
    1515
    1616#include <boost/fusion/container/map.hpp>
     17#include <boost/mpl/list.hpp>
    1718
    1819#include "Jobs/MPQCDataFused.hpp"
    1920
     21class Histogram;
     22
     23/// \note: We had to split up the map because boost::fusion only allows for
     24/// up to 9 template types.
     25
    2026/** This boost::fusion map defines key-value or rather key-type pairs with
    21  * which we associate data members in MPQCData and their type.
     27 * which we associate all energy_t data members in MPQCData and their type.
    2228 *
    2329 * This lets us resolves any ambiguitites of types in MPQCData, e.g.
     
    2733typedef boost::fusion::map<
    2834    boost::fusion::pair<MPQCDataFused::energy_total, double>
     35  ,  boost::fusion::pair<MPQCDataFused::energy_nuclear_repulsion, double>
     36  ,  boost::fusion::pair<MPQCDataFused::energy_electron_repulsion, double>
     37  ,  boost::fusion::pair<MPQCDataFused::energy_correlation, double>
     38  ,  boost::fusion::pair<MPQCDataFused::energy_overlap, double>
     39  ,  boost::fusion::pair<MPQCDataFused::energy_kinetic, double>
     40  ,  boost::fusion::pair<MPQCDataFused::energy_hcore, double>
    2941  ,  boost::fusion::pair<MPQCDataFused::energy_eigenvalues, Histogram >
    30   ,  boost::fusion::pair<MPQCDataFused::forces, std::vector< std::vector<double> > >
    31   ,  boost::fusion::pair<MPQCDataFused::times_walltime, double> >
    32 MPQCDataMap_t;
     42> MPQCDataEnergyMap_t;
     43
     44typedef boost::mpl::list<
     45    MPQCDataFused::energy_total,
     46    MPQCDataFused::energy_nuclear_repulsion,
     47    MPQCDataFused::energy_electron_repulsion,
     48    MPQCDataFused::energy_correlation,
     49    MPQCDataFused::energy_overlap,
     50    MPQCDataFused::energy_kinetic,
     51    MPQCDataFused::energy_hcore /*,
     52    MPQCDataFused::energy_eigenvalues */
     53> MPQCDataEnergyVector_t;
     54
     55/** This boost::fusion map defines key-value or rather key-type pairs with
     56 * which we associate all forces data members in MPQCData and their type.
     57 *
     58 * This lets us resolves any ambiguitites of types in MPQCData, e.g.
     59 * to know vector<double> is forces or energy_eigenvalues.
     60 *
     61 */
     62typedef boost::fusion::map<
     63  boost::fusion::pair<MPQCDataFused::forces, std::vector< std::vector<double> > >
     64> MPQCDataForceMap_t;
     65
     66typedef boost::mpl::list<
     67    MPQCDataFused::forces
     68> MPQCDataForceVector_t;
     69
     70/** This boost::fusion map defines key-value or rather key-type pairs with
     71 * which we associate all times_t data members in MPQCData and their type.
     72 *
     73 * This lets us resolves any ambiguitites of types in MPQCData, e.g.
     74 * to know vector<double> is forces or energy_eigenvalues.
     75 *
     76 */
     77typedef boost::fusion::map<
     78  boost::fusion::pair<MPQCDataFused::times_walltime, double >
     79  , boost::fusion::pair<MPQCDataFused::times_cputime, double >
     80  , boost::fusion::pair<MPQCDataFused::times_flops, double >
     81> MPQCDataTimeMap_t;
     82
     83typedef boost::mpl::list<
     84    MPQCDataFused::times_walltime,
     85    MPQCDataFused::times_cputime,
     86    MPQCDataFused::times_flops
     87> MPQCDataTimeVector_t;
    3388
    3489#endif /* MPQCDATAMAP_HPP_ */
  • src/Jobs/Makefile.am

    r56df37 r8cae4c  
    1212        Jobs/MPQCDataFused.hpp \
    1313        Jobs/MPQCDataMap.hpp \
     14        Jobs/MPQCData_printName.hpp \
    1415        Jobs/MPQCJob.hpp
    1516
Note: See TracChangeset for help on using the changeset viewer.