source: src/Fragmentation/Summation/OrthogonalSummator.hpp@ a96b02

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 a96b02 was a96b02, checked in by Frederik Heber <heber@…>, 12 years ago

(Orthogonal)Summator now have internal instance Summation.

  • added createValues() and getSubsets() that are called in cstor to create the necessary variables for (Orthogonal)Summator's cstor.
  • Property mode set to 100644
File size: 6.0 KB
Line 
1/*
2 * OrthogonalSummator.hpp
3 *
4 * Created on: 28.07.2012
5 * Author: heber
6 */
7
8#ifndef ORTHOGONALSUMMATOR_HPP_
9#define ORTHOGONALSUMMATOR_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/** OrthogonalSummator 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 OrthogonalSummator {
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 OrthogonalSummator.
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 OrthogonalSummator(
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 indices(getSubsets(_container)),
76 values(createValues(_data, _jobids, _container, _MatrixNrLookup)),
77 OS(indices, values, _subsetmap)
78 {
79 ASSERT( _data.size() == _jobids.size(),
80 "OrthogonalSummator() - data and ids don't have same size.");
81 ASSERT( _jobids.size() == _MatrixNrLookup.size(),
82 "OrthogonalSummator() - ids and MatrixNrLookup don't have same size.");
83 }
84
85 /** Summation operator.
86 *
87 * Initialises instantiated OrthogonalSummation of the respective type via
88 * \a OrthogonalSummator::data, uses OrthogonalSummation::operator() to sum and returns
89 * the result.
90 *
91 * \param level up to which level to sum up
92 * \return result of OrthogonalSummation for given type from MPQCDataMap_t.
93 */
94 MapValue operator()(/* const size_t level */)
95 {
96 // evaluate
97 const MapValue result = OS();
98 return result;
99 }
100
101private:
102 /** Tiny helper to create the indices from a given IndexSetContainer.
103 *
104 * Basically, we just have to make sure we miss the last one but only
105 * if the \a container has more than one set.
106 *
107 * @param container container with IndexSet
108 * @return all subsets contained in \a container
109 */
110 typename OrthogonalSummation<MapValue>::InputSets_t getSubsets(
111 const IndexSetContainer::Container_t &container)
112 {
113 // if we just have one indexset, we don't need to get rid of the "union index set"
114 typename OrthogonalSummation<MapValue>::InputSets_t indices(
115 container.begin(),
116 container.end()-1 == container.begin() ? container.end() : container.end()-1);
117 return indices;
118 }
119
120 /** Tiny helper to create the values for the summation in the correct order.
121 *
122 * @param data
123 * @param jobids
124 * @param container
125 * @param MatrixNrLookup
126 * @return
127 */
128 typename OrthogonalSummation<MapValue>::InputValues_t createValues(
129 const std::vector<MapType> &data,
130 const std::vector<JobId_t> &jobids,
131 const IndexSetContainer::Container_t &container,
132 std::map< JobId_t, size_t > &MatrixNrLookup)
133 {
134 // if we just have one indexset, we don't need to get rid of the "union index set"
135 typename OrthogonalSummation<MapValue>::InputValues_t values(
136 container.size() == 1 ? (size_t)1 : container.size()-1);
137 typename std::vector<MapType>::const_iterator dataiter = data.begin();
138 std::vector<size_t>::const_iterator iditer = jobids.begin();
139 for (; dataiter != data.end(); ++dataiter, ++iditer) {
140 const MapType &Data = *dataiter;
141 const MapValue &value = boost::fusion::at_key<MapKey>(Data);
142 values[ MatrixNrLookup[*iditer] ] = value;
143 }
144 return values;
145 }
146private:
147 //!> created indices for OS such that we may hand over refs
148 typename OrthogonalSummation<MapValue>::InputSets_t indices;
149 //!> created values for OS such that we may hand over refs
150 typename OrthogonalSummation<MapValue>::InputValues_t values;
151 //!> Summation instance to use in operator()(level)
152 OrthogonalSummation<MapValue> OS;
153};
154
155
156#endif /* ORTHOGONALSUMMATOR_HPP_ */
Note: See TracBrowser for help on using the repository browser.