source: src/Fragmentation/Summation/Summator.hpp@ 0398bd

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 0398bd was 302345, checked in by Frederik Heber <heber@…>, 13 years ago

FIX: (Orthogonal)Summator would not create correct indices for present super set.

  • when the super set is contained as a normal set, i.e. we obtain a value from the calculations for it, then we only treated this correctly for a single index sets.
  • Property mode set to 100644
File size: 5.8 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 <iterator>
19
20#include "Fragmentation/Summation/Summation.hpp"
21#include "Fragmentation/Summation/SetValue.hpp"
22#include "Jobs/MPQCDataMap.hpp"
23
24/** Summator is a general class for making us of Summation.
25 *
26 * The idea is that we want to sum up not only one value but a whole bunch of.
27 * However, in general the types of the values will all differ. We would like
28 * to call the summation in a as simple a fashion as possible and at best in
29 * a kind of for_each on each type/value.
30 * For this purpose we require a list of all the types, represented by the
31 * MPQCDataMap_t map that uses the types enumerated in namespace MPQCDataFused,
32 * see the simple example for the associative sequence in boost::fusion.
33 * The MPQCDataMap_t then gives the essential mapping from the type to a specific
34 * key. Via this key, which is a type and hence can be used for template
35 * specification, we may gather all information for launching the
36 * Summation. We only need to convert MPQCData into the above
37 * MPQCDataMap_t instance and may then access the member variables via the above
38 * key and also obtain the type at \b run-time through the key.
39 *
40 * Note that we then need a conversion from the type stored in the MPQCData,
41 * e.g. a vector<double>, to the type in MPQCDataMap_t, e.g. Histogram.
42 *
43 * Boost::fusion is very cool! If we have a namespace with just structs as keys
44 * and the fusion::map from these keys to the true types, then we may do ...
45 * \code
46 * MPQCDataMap_t MPQCDataMap;
47 * using namespace MPQCDataFused;
48 * double MPQCData_energy_total = boost::fusion::at_key<MPQCDataFused::energy_total>(MPQCDataMap);
49 * \endcode
50 * i.e. at_key knows the correct type!
51 *
52 */
53template <typename MapType, typename MapKey>
54struct Summator {
55 /** We retrieve the type of the MPQCData member variable from the
56 * boost::fusion::map and stored it in this typedef. Note that for
57 * internal types (e.g. MapValue::const_iterator we need to place
58 * \b typename before).
59 */
60 typedef typename boost::fusion::result_of::value_at_key<MapType, MapKey>::type MapValue;
61
62 /** Constructor for class Summator.
63 *
64 * \param _subsetmap map with hierarchy of IndexSet's
65 * \param _data MPQCData converted to MPQCDataMap_t type
66 * \param _jobids job ids to sum data in correct order
67 * \param _container container of IndexSet's such that each set has correct order
68 * to job id and hence to _data.
69 * \param _MatrixNrLookup lookup from job id to ordering in above vectors
70 */
71 Summator(
72 SubsetMap::ptr &_subsetmap,
73 const std::vector<MapType> &_data,
74 const std::vector<JobId_t> &_jobids,
75 const IndexSetContainer::Container_t &_container,
76 std::map< JobId_t, size_t > &_MatrixNrLookup) : /* cannot make this const due to operator[] */
77 indices(getSubsets(_data.size(),_container)),
78 values(createValues(_data, _jobids, _container, _MatrixNrLookup)),
79 OS(indices, values, _subsetmap)
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 Summation of the respective type via
90 * \a Summator::data, uses Summation::operator() to sum and returns
91 * the result.
92 *
93 * \param level up to which level to sum up
94 * \return result of Summation for given type from MPQCDataMap_t.
95 */
96 MapValue operator()(const size_t level)
97 {
98 // evaluate
99 const MapValue result = OS(level);
100 return result;
101 }
102
103private:
104 /** Tiny helper to create the indices from a given IndexSetContainer.
105 *
106 * Basically, we just have to make sure we miss the last one but only
107 * if the \a container has more than one set.
108 *
109 * @param count how many indices of container to use
110 * @param container container with IndexSet
111 * @return all subsets contained in \a container
112 */
113 typename Summation<MapValue>::InputSets_t getSubsets(
114 const size_t count,
115 const IndexSetContainer::Container_t &container)
116 {
117 IndexSetContainer::Container_t::const_iterator iter = container.begin();
118 std::advance(iter, count); // step till after desired element
119 typename Summation<MapValue>::InputSets_t indices(container.begin(), iter);
120 return indices;
121 }
122
123 /** Tiny helper to create the values for the summation in the correct order.
124 *
125 * @param data
126 * @param jobids
127 * @param container
128 * @param MatrixNrLookup
129 * @return
130 */
131 typename Summation<MapValue>::InputValues_t createValues(
132 const std::vector<MapType> &data,
133 const std::vector<JobId_t> &jobids,
134 const IndexSetContainer::Container_t &container,
135 std::map< JobId_t, size_t > &MatrixNrLookup)
136 {
137 // if we just have one indexset, we don't need to get rid of the "union index set"
138 typename Summation<MapValue>::InputValues_t values(data.size());
139 typename std::vector<MapType>::const_iterator dataiter = data.begin();
140 std::vector<size_t>::const_iterator iditer = jobids.begin();
141 for (; dataiter != data.end(); ++dataiter, ++iditer) {
142 const MapType &Data = *dataiter;
143 const MapValue &value = boost::fusion::at_key<MapKey>(Data);
144 values[ MatrixNrLookup[*iditer] ] = value;
145 }
146 return values;
147 }
148private:
149 //!> created indices for OS such that we may hand over refs
150 typename Summation<MapValue>::InputSets_t indices;
151 //!> created values for OS such that we may hand over refs
152 typename Summation<MapValue>::InputValues_t values;
153 //!> Summation instance to use in operator()(level)
154 Summation<MapValue> OS;
155};
156
157
158#endif /* SUMMATOR_HPP_ */
Note: See TracBrowser for help on using the repository browser.