source: src/Fragmentation/Summation/AllLevelSummator.hpp@ dbd841

FitPartialCharges_GlobalError PartialCharges_OrthogonalSummation
Last change on this file since dbd841 was dbd841, checked in by Frederik Heber <heber@…>, 8 years ago

FIX: Fixed some missing includes in ..(Orthogonal)Summator.

  • Property mode set to 100644
File size: 4.8 KB
Line 
1/*
2 * AllLevelSummator.hpp
3 *
4 * Created on: 29.07.2012
5 * Author: heber
6 */
7
8#ifndef ALLLEVELSUMMATOR_HPP_
9#define ALLLEVELSUMMATOR_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16#include <vector>
17
18#include <boost/fusion/sequence.hpp>
19
20#include "CodePatterns/Assert.hpp"
21
22#include "Fragmentation/Summation/IndexSetContainer.hpp"
23#include "Fragmentation/Summation/SubsetMap.hpp"
24#include "Fragmentation/Summation/Summator.hpp"
25#include "Fragmentation/Summation/ZeroInstance.hpp"
26
27#include "Fragmentation/Summation/printKeyNames.hpp"
28
29/** Tiny template functor to use Summation, sum up each level, and store the
30 * result in a given vector.
31 *
32 */
33template <typename MapType>
34struct AllLevelSummator {
35 /** Constructor takes the arguments that \a Summator also needs and stores
36 * them internally.
37 *
38 * \param _subsetmap map with hierarchy of IndexSet's
39 * \param _data MPQCData converted to MPQCDataMap_t type, associated to job id
40 * \param _container container of IndexSet's such that each set has correct order
41 * to job id and hence to _data.
42 * \param _MatrixNrLookup lookup from job id to ordering in above vectors, if
43 * out of range this value is set to zero, hence ignored.
44 * \param _levelresults vector place levelresults into
45 * \param _keysetresults results per index set, set by operator()
46 * \param _ZeroInstances zero instance to use in summation for each type
47 */
48 AllLevelSummator(
49 SubsetMap::ptr &_subsetmap,
50 const std::map<JobId_t, MapType> &_data,
51 const IndexSetContainer::Container_t &_container,
52 const std::map< JobId_t, size_t > &_MatrixNrLookup,
53 std::vector<MapType> &_levelresults,
54 std::map<IndexSet::ptr, std::pair<MapType, MapType> > &_keysetresults,
55 MapType &_ZeroInstances) :
56 subsetmap(_subsetmap),
57 data(_data),
58 container(_container),
59 MatrixNrLookup(_MatrixNrLookup),
60 levelresults(_levelresults),
61 keysetresults(_keysetresults),
62 ZeroInstances(_ZeroInstances)
63 {
64 ASSERT( levelresults.size() >= subsetmap->getMaximumSetLevel(),
65 "AllLevelSummator() - result vector is not large enough.");
66 }
67
68 /** Operator that calls on Summator and prints the value.
69 *
70 * \note the parameter is needed for boost::mpl::for_each but is not
71 * used here.
72 */
73 template <typename MapKey>
74 void operator()(MapKey &) {
75 // We retrieve the type of the MPQCData member variable from the boost::fusion::map.
76 typedef typename boost::fusion::result_of::value_at_key<MapType, MapKey>::type MapValue;
77
78 // create Summator instance
79 Summator<MapType, MapKey> sum_value(
80 subsetmap, data, container, MatrixNrLookup
81 );
82
83 // set zero instance
84 const MapValue &DesiredZeroInstance = boost::fusion::at_key<MapKey>(ZeroInstances);
85 if (DesiredZeroInstance != ZeroInstance<MapValue>())
86 sum_value.setZeroInstance(DesiredZeroInstance);
87
88 // fill levelresults
89 const size_t MaxLevel = subsetmap->getMaximumSetLevel();
90 for (size_t level=1; level <= MaxLevel; ++level) {
91 MapType &LevelResults = levelresults[level-1];
92 // sum up and store in levelresults
93 const MapValue value = sum_value(level);
94 boost::fusion::at_key<MapKey>(LevelResults) = value;
95 // print value
96 //LOG(0, "STATUS: Level " << level << " resulting " << printKeyNames::printName<MapKey>() << " is " << value << ".");
97 }
98
99 // fill keysetresults
100 for (IndexSetContainer::Container_t::const_iterator indexsetiter = container.begin();
101 indexsetiter != container.end(); ++indexsetiter) {
102 const IndexSet::ptr &index = *indexsetiter;
103 // this either generates a new entry or updates the present one, as we obtain ref to value
104 boost::fusion::at_key<MapKey>(keysetresults[index].first) =
105 sum_value.getValueForIndexSet(index);
106 boost::fusion::at_key<MapKey>(keysetresults[index].second) =
107 sum_value.getContributionForIndexSet(index);
108 }
109 }
110
111private:
112 //!> Hierarchy of IndexSet's
113 SubsetMap::ptr &subsetmap;
114 //!> vector of data converted from MPQCData
115 const std::map<JobId_t, MapType> &data;
116 //!> container with all IndexSet's
117 const IndexSetContainer::Container_t &container;
118 //!> lookup map from job ids to ordering in above vectors
119 const std::map< JobId_t, size_t > &MatrixNrLookup;
120 //!> vector of levelresults
121 std::vector<MapType> &levelresults;
122 typedef std::pair< IndexSet::ptr, std::pair<MapType, MapType> > keysetresults_pair_t;
123 //!> typedef for map for keyset and each resulting value
124 typedef std::map<IndexSet::ptr, std::pair<MapType, MapType> > keysetresults_t;
125 //!> map for IndexSet and its associated contribution
126 keysetresults_t &keysetresults;
127 //!> map per type to sum of base/zero instances to enforce specific parameters in summation
128 MapType &ZeroInstances;
129};
130
131#endif /* ALLLEVELSUMMATOR_HPP_ */
Note: See TracBrowser for help on using the repository browser.