source: src/Fragmentation/Summation/OrthogonalSummator.hpp@ 8eafd6

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests 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_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 FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix 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 8eafd6 was 675cd6, checked in by Frederik Heber <heber@…>, 11 years ago

(Orthogonal)Summator are notified via out-of-range matrixnr to omit contribution.

  • (Orthogonal)Summator uses ZeroInstance as default value and sets the value only when given matrixnr from lookup is within range.
  • this is preparatory for masking certain fragment results in the summation process.
  • Property mode set to 100644
File size: 7.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 <iterator>
19
20#include "CodePatterns/Assert.hpp"
21
22#include "Fragmentation/Summation/OrthogonalSummation.hpp"
23#include "Fragmentation/Summation/SetValue.hpp"
24#include "Fragmentation/Summation/ZeroInstance.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 * Note that you may skip values in the summation by setting their index in
55 * _MatrixNrLookup to something outside the range of [0,_data.size()], e.g.
56 * -1.
57 *
58 */
59template <typename MapType, typename MapKey>
60struct OrthogonalSummator {
61 /** We retrieve the type of the MPQCData member variable from the
62 * boost::fusion::map and stored it in this typedef. Note that for
63 * internal types (e.g. MapValue::const_iterator we need to place
64 * \b typename before).
65 */
66 typedef typename boost::fusion::result_of::value_at_key<MapType, MapKey>::type MapValue;
67
68 /** Constructor for class OrthogonalSummator.
69 *
70 * \param _subsetmap map with hierarchy of IndexSet's
71 * \param _data MPQCData converted to MPQCDataMap_t type, associated to job id
72 * \param _container container of IndexSet's such that each set has correct order
73 * to job id and hence to _data.
74 * \param _MatrixNrLookup lookup from job id to ordering in above vectors
75 */
76 OrthogonalSummator(
77 SubsetMap::ptr &_subsetmap,
78 const std::map<JobId_t, MapType> &_data,
79 const IndexSetContainer::Container_t &_container,
80 const std::map< JobId_t, size_t > &_MatrixNrLookup) :
81 indices(getSubsets(_data.size(),_container)),
82 values(createValues(_data, _container, _MatrixNrLookup)),
83 OS(indices, values, _subsetmap)
84 {
85 ASSERT( _data.size() == _MatrixNrLookup.size(),
86 "OrthogonalSummator() - ids and MatrixNrLookup don't have same size.");
87 }
88
89 /** Summation operator.
90 *
91 * Initialises instantiated OrthogonalSummation of the respective type via
92 * \a OrthogonalSummator::data, uses OrthogonalSummation::operator() to sum and returns
93 * the result.
94 *
95 * \param level up to which level to sum up
96 * \return result of OrthogonalSummation for given type from MPQCDataMap_t.
97 */
98 MapValue operator()(const size_t level)
99 {
100 // evaluate
101 const MapValue result = OS(level);
102 return result;
103 }
104
105 /** Getter for the contribution of the SetValue<> to a specific \a index.
106 *
107 * @param index SetValue to this index
108 * @return contribution
109 */
110 MapValue getContributionForIndexSet(const IndexSet::ptr &ptr) const
111 {
112 typedef SetValueMap<MapValue> setvalues_t;
113 const setvalues_t &values = OS.getSetValues();
114 return values.getConstValue(ptr)->getContribution();
115 }
116
117 /** Getter for the value of the SetValue<> to a specific \a index.
118 *
119 * @param index SetValue to this index
120 * @return value
121 */
122 MapValue getValueForIndexSet(const IndexSet::ptr &ptr) const
123 {
124 typedef SetValueMap<MapValue> setvalues_t;
125 const setvalues_t &values = OS.getSetValues();
126 return values.getConstValue(ptr)->getValue();
127 }
128
129private:
130 /** Tiny helper to create the indices from a given IndexSetContainer.
131 *
132 * Basically, we just have to make sure we miss the last one but only
133 * if the \a container has more than one set.
134 *
135 * @param count how many indices of container to use
136 * @param container container with IndexSet
137 * @return all subsets contained in \a container
138 */
139 typename OrthogonalSummation<MapValue>::InputSets_t getSubsets(
140 const size_t count,
141 const IndexSetContainer::Container_t &container)
142 {
143 IndexSetContainer::Container_t::const_iterator iter = container.begin();
144 std::advance(iter, count); // step till after desired element
145 typename OrthogonalSummation<MapValue>::InputSets_t indices(container.begin(), iter);
146 return indices;
147 }
148
149 /** Tiny helper to create the values for the summation in the correct order.
150 *
151 * @param data
152 * @param container
153 * @param MatrixNrLookup
154 * @return
155 */
156 typename OrthogonalSummation<MapValue>::InputValues_t createValues(
157 const std::map<JobId_t, MapType> &data,
158 const IndexSetContainer::Container_t &container,
159 const std::map< JobId_t, size_t > &MatrixNrLookup)
160 {
161 // if the power set of , we don't need to get rid of the "union index set"
162 typename OrthogonalSummation<MapValue>::InputValues_t values(data.size(), ZeroInstance<MapValue>());
163 for (typename std::map<JobId_t, MapType>::const_iterator dataiter = data.begin();
164 dataiter != data.end(); ++dataiter) {
165 const MapType &Data = dataiter->second;
166 const JobId_t &jobid = dataiter->first;
167 const MapValue &value = boost::fusion::at_key<MapKey>(Data);
168 const std::map< JobId_t, size_t >::const_iterator nriter = MatrixNrLookup.find(jobid);
169 ASSERT( nriter != MatrixNrLookup.end(),
170 "OrthogonalSummation<>::createValues() - MatrixNrLookup does not contain id "
171 +toString(jobid)+".");
172 if ((nriter->second >= 0 ) && (nriter->second < data.size()))
173 values[ nriter->second ] = value;
174 }
175 return values;
176 }
177private:
178 //!> created indices for OS such that we may hand over refs
179 typename OrthogonalSummation<MapValue>::InputSets_t indices;
180 //!> created values for OS such that we may hand over refs
181 typename OrthogonalSummation<MapValue>::InputValues_t values;
182 //!> Summation instance to use in operator()(level)
183 OrthogonalSummation<MapValue> OS;
184};
185
186
187#endif /* ORTHOGONALSUMMATOR_HPP_ */
Note: See TracBrowser for help on using the repository browser.