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

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

Placed Containers, Converter, and SetValues as subfolders into Summation.

  • also libMolecuilderFragmentationSummation is now a shared library, easing linkage to libMolecuilderJobs, and contains all of the three convenience libraries.
  • libMolecuilderFragmentationSetValues is now again convenience, as contained in ..Summation which in turn is shared.
  • KeySetsContainer right now is the link between lib..Summation and lib.. Fragmentation. Hence, we had to extract the module and change it into a shared library, as it is required by libMolecuilderJobs through ..Summation but also by ..Fragmentation that heavily relies on this container.
  • moved parseKeySetFile down into Fragmentation folder to KeySetsContainer, it is also contained in new shared library libMolecuilderFragmentation_ KeySetsContainer.
  • Property mode set to 100644
File size: 6.8 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 <iterator>
19
20#include "CodePatterns/Assert.hpp"
21
22#include "Fragmentation/Summation/OrthogonalSummation.hpp"
23#include "Fragmentation/Summation/SetValue.hpp"
24#include "Fragmentation/Summation/Containers/MPQCDataMap.hpp"
25
26/** OrthogonalSummator is a general class for making us of OrthogonalSummation.
27 *
28 * The idea is that we want to sum up not only one value but a whole bunch of.
29 * However, in general the types of the values will all differ. We would like
30 * to call the summation in a as simple a fashion as possible and at best in
31 * a kind of for_each on each type/value.
32 * For this purpose we require a list of all the types, represented by the
33 * MPQCDataMap_t map that uses the types enumerated in namespace MPQCDataFused,
34 * see the simple example for the associative sequence in boost::fusion.
35 * The MPQCDataMap_t then gives the essential mapping from the type to a specific
36 * key. Via this key, which is a type and hence can be used for template
37 * specification, we may gather all information for launching the
38 * OrthogonalSummation. We only need to convert MPQCData into the above
39 * MPQCDataMap_t instance and may then access the member variables via the above
40 * key and also obtain the type at \b run-time through the key.
41 *
42 * Note that we then need a conversion from the type stored in the MPQCData,
43 * e.g. a vector<double>, to the type in MPQCDataMap_t, e.g. Histogram.
44 *
45 * Boost::fusion is very cool! If we have a namespace with just structs as keys
46 * and the fusion::map from these keys to the true types, then we may do ...
47 * \code
48 * MPQCDataMap_t MPQCDataMap;
49 * using namespace MPQCDataFused;
50 * double MPQCData_energy_total = boost::fusion::at_key<MPQCDataFused::energy_total>(MPQCDataMap);
51 * \endcode
52 * i.e. at_key knows the correct type!
53 *
54 */
55template <typename MapType, typename MapKey>
56struct OrthogonalSummator {
57 /** We retrieve the type of the MPQCData member variable from the
58 * boost::fusion::map and stored it in this typedef. Note that for
59 * internal types (e.g. MapValue::const_iterator we need to place
60 * \b typename before).
61 */
62 typedef typename boost::fusion::result_of::value_at_key<MapType, MapKey>::type MapValue;
63
64 /** Constructor for class OrthogonalSummator.
65 *
66 * \param _subsetmap map with hierarchy of IndexSet's
67 * \param _data MPQCData converted to MPQCDataMap_t type, associated to job id
68 * \param _container container of IndexSet's such that each set has correct order
69 * to job id and hence to _data.
70 * \param _MatrixNrLookup lookup from job id to ordering in above vectors
71 */
72 OrthogonalSummator(
73 SubsetMap::ptr &_subsetmap,
74 const std::map<JobId_t, MapType> &_data,
75 const IndexSetContainer::Container_t &_container,
76 const std::map< JobId_t, size_t > &_MatrixNrLookup) :
77 indices(getSubsets(_data.size(),_container)),
78 values(createValues(_data, _container, _MatrixNrLookup)),
79 OS(indices, values, _subsetmap)
80 {
81 ASSERT( _data.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(level);
98 return result;
99 }
100
101 /** Getter for the contribution of the SetValue<> to a specific \a index.
102 *
103 * @param index SetValue to this index
104 * @return contribution
105 */
106 MapValue getContributionForIndexSet(const IndexSet::ptr &ptr) const
107 {
108 typedef SetValueMap<MapValue> setvalues_t;
109 const setvalues_t &values = OS.getSetValues();
110 return values.getConstValue(ptr)->getContribution();
111 }
112
113 /** Getter for the value of the SetValue<> to a specific \a index.
114 *
115 * @param index SetValue to this index
116 * @return value
117 */
118 MapValue getValueForIndexSet(const IndexSet::ptr &ptr) const
119 {
120 typedef SetValueMap<MapValue> setvalues_t;
121 const setvalues_t &values = OS.getSetValues();
122 return values.getConstValue(ptr)->getValue();
123 }
124
125private:
126 /** Tiny helper to create the indices from a given IndexSetContainer.
127 *
128 * Basically, we just have to make sure we miss the last one but only
129 * if the \a container has more than one set.
130 *
131 * @param count how many indices of container to use
132 * @param container container with IndexSet
133 * @return all subsets contained in \a container
134 */
135 typename OrthogonalSummation<MapValue>::InputSets_t getSubsets(
136 const size_t count,
137 const IndexSetContainer::Container_t &container)
138 {
139 IndexSetContainer::Container_t::const_iterator iter = container.begin();
140 std::advance(iter, count); // step till after desired element
141 typename OrthogonalSummation<MapValue>::InputSets_t indices(container.begin(), iter);
142 return indices;
143 }
144
145 /** Tiny helper to create the values for the summation in the correct order.
146 *
147 * @param data
148 * @param container
149 * @param MatrixNrLookup
150 * @return
151 */
152 typename OrthogonalSummation<MapValue>::InputValues_t createValues(
153 const std::map<JobId_t, MapType> &data,
154 const IndexSetContainer::Container_t &container,
155 const std::map< JobId_t, size_t > &MatrixNrLookup)
156 {
157 // if the power set of , we don't need to get rid of the "union index set"
158 typename OrthogonalSummation<MapValue>::InputValues_t values(data.size());
159 for (typename std::map<JobId_t, MapType>::const_iterator dataiter = data.begin();
160 dataiter != data.end(); ++dataiter) {
161 const MapType &Data = dataiter->second;
162 const JobId_t &jobid = dataiter->first;
163 const MapValue &value = boost::fusion::at_key<MapKey>(Data);
164 const std::map< JobId_t, size_t >::const_iterator nriter = MatrixNrLookup.find(jobid);
165 ASSERT( nriter != MatrixNrLookup.end(),
166 "OrthogonalSummation<>::createValues() - MatrixNrLookup does not contain id "
167 +toString(jobid)+".");
168 values[ nriter->second ] = value;
169 }
170 return values;
171 }
172private:
173 //!> created indices for OS such that we may hand over refs
174 typename OrthogonalSummation<MapValue>::InputSets_t indices;
175 //!> created values for OS such that we may hand over refs
176 typename OrthogonalSummation<MapValue>::InputValues_t values;
177 //!> Summation instance to use in operator()(level)
178 OrthogonalSummation<MapValue> OS;
179};
180
181
182#endif /* ORTHOGONALSUMMATOR_HPP_ */
Note: See TracBrowser for help on using the repository browser.