source: src/Fragmentation/Summation/Summator.hpp@ 56df37

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
Last change on this file since 56df37 was 56df37, checked in by Frederik Heber <heber@…>, 12 years ago

Added general-purpose Summator that is basis for OrthogonalSummation on an arbitrary struct of types.

  • Eventually, we need to sum up each variable in struct MPQCData. For this we need to place the initialisation and executing of OrthogonalSummation into a list and we need to enumerate the types in MPQCData in a unique fashion, i.e. to associate the name of the member variable and its type with a specific unique key. This is achieved via boost::fusion.
  • this is exemplarily used for energy.total.
  • later we add boost::fusion for_each to let the summation automatically go through each type by its own.
  • note that summing up a single IndexSet's must be specially treated as the single set corresponds to the full set also.
  • Property mode set to 100644
File size: 5.0 KB
Line 
1/*
2 * Summator.hpp
3 *
4 * Created on: 28.07.2012
5 * Author: heber
6 */
7
8#ifndef SUMMATOR_HPP_
9#define SUMMATOR_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16#include <boost/fusion/sequence.hpp>
17
18#include "Fragmentation/Summation/OrthogonalSummation.hpp"
19#include "Fragmentation/Summation/SetValue.hpp"
20#include "Jobs/MPQCDataMap.hpp"
21
22/** Summator is a general class for making us of OrthogonalSummation.
23 *
24 * The idea is that we want to sum up not only one value but a whole bunch of.
25 * However, in general the types of the values will all differ. We would like
26 * to call the summation in a as simple a fashion as possible and at best in
27 * a kind of for_each on each type/value.
28 * For this purpose we require a list of all the types, represented by the
29 * MPQCDataMap_t map that uses the types enumerated in namespace MPQCDataFused,
30 * see the simple example for the associative sequence in boost::fusion.
31 * The MPQCDataMap_t then gives the essential mapping from the type to a specific
32 * key. Via this key, which is a type and hence can be used for template
33 * specification, we may gather all information for launching the
34 * OrthogonalSummation. We only need to convert MPQCData into the above
35 * MPQCDataMap_t instance and may then access the member variables via the above
36 * key and also obtain the type at \b run-time through the key.
37 *
38 * Note that we then need a conversion from the type stored in the MPQCData,
39 * e.g. a vector<double>, to the type in MPQCDataMap_t, e.g. Histogram.
40 *
41 * Boost::fusion is very cool! If we have a namespace with just structs as keys
42 * and the fusion::map from these keys to the true types, then we may do ...
43 * \code
44 * MPQCDataMap_t MPQCDataMap;
45 * using namespace MPQCDataFused;
46 * double MPQCData_energy_total = boost::fusion::at_key<MPQCDataFused::energy_total>(MPQCDataMap);
47 * \endcode
48 * i.e. at_key knows the correct type!
49 *
50 */
51template <typename MapType, typename MapKey>
52struct Summator {
53 /** We retrieve the type of the MPQCData member variable from the
54 * boost::fusion::map and stored it in this typedef. Note that for
55 * internal types (e.g. MapValue::const_iterator we need to place
56 * \b typename before).
57 */
58 typedef typename boost::fusion::result_of::value_at_key<MapType, MapKey>::type MapValue;
59
60 /** Constructor for class Summator.
61 *
62 * \param _subsetmap map with hierarchy of IndexSet's
63 * \param _data MPQCData converted to MPQCDataMap_t type
64 * \param _jobids job ids to sum data in correct order
65 * \param _container container of IndexSet's such that each set has correct order
66 * to job id and hence to _data.
67 * \param _MatrixNrLookup lookup from job id to ordering in above vectors
68 */
69 Summator(
70 SubsetMap::ptr &_subsetmap,
71 const std::vector<MapType> &_data,
72 const std::vector<JobId_t> &_jobids,
73 const IndexSetContainer::Container_t &_container,
74 std::map< JobId_t, size_t > &_MatrixNrLookup) : /* cannot make this const due to operator[] */
75 subsetmap(_subsetmap),
76 data(_data),
77 jobids(_jobids),
78 container(_container),
79 MatrixNrLookup(_MatrixNrLookup)
80 {
81 ASSERT( data.size() == jobids.size(),
82 "Summator() - data and ids don't have same size.");
83 ASSERT( jobids.size() == MatrixNrLookup.size(),
84 "Summator() - ids and MatrixNrLookup don't have same size.");
85 }
86
87 /** Summation operator.
88 *
89 * Initialises instantiated OrthogonalSummation of the respective type via
90 * \a Summator::data, uses OrthogonalSummation::operator() to sum and returns
91 * the result.
92 *
93 * \return result of OrthogonalSummation for given type from MPQCDataMap_t.
94 */
95 MapValue operator()()
96 {
97 // if we just have one indexset, we don't need to get rid of the "union index set"
98 typename OrthogonalSummation<MapValue>::InputSets_t indices(
99 container.begin(),
100 container.end()-1 == container.begin() ? container.end() : container.end()-1);
101 typename OrthogonalSummation<MapValue>::InputValues_t values(
102 container.size() == 1 ? (size_t)1 : container.size()-1);
103 typename std::vector<MapType>::const_iterator dataiter = data.begin();
104 std::vector<size_t>::const_iterator iditer = jobids.begin();
105 for (; dataiter != data.end(); ++dataiter, ++iditer) {
106 const MapType &Data = *dataiter;
107 const MapValue &value = boost::fusion::at_key<MapKey>(Data);
108 values[ MatrixNrLookup[*iditer] ] = value;
109 }
110
111 // create the summation functor and evaluate
112 OrthogonalSummation<MapValue> OS(indices, values, subsetmap);
113 const MapValue result = OS();
114 return result;
115 }
116
117private:
118 //!> Hierarchy of IndexSet's
119 SubsetMap::ptr &subsetmap;
120 //!> vector of data converted from MPQCData
121 const std::vector<MapType> &data;
122 //!> vector of jobids
123 const std::vector<JobId_t> &jobids;
124 //!> container with all IndexSet's
125 const IndexSetContainer::Container_t &container;
126 //!> lookup map from job ids to ordering in above vectors
127 std::map< JobId_t, size_t > MatrixNrLookup;
128};
129
130
131#endif /* SUMMATOR_HPP_ */
Note: See TracBrowser for help on using the repository browser.