source: src/Fragmentation/Summation/AllLevelOrthogonalSummator.hpp@ bb8b0a

FitPartialCharges_GlobalError PartialCharges_OrthogonalSummation
Last change on this file since bb8b0a 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.9 KB
RevLine 
[286e36]1/*
[ff9963]2 * AllLevelOrthogonalSummator.hpp
[286e36]3 *
4 * Created on: 29.07.2012
5 * Author: heber
6 */
7
[ff9963]8#ifndef ALLLEVELORTHOGONALSUMMATOR_HPP_
9#define ALLLEVELORTHOGONALSUMMATOR_HPP_
[286e36]10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16#include <vector>
17
[dbd841]18#include <boost/fusion/sequence.hpp>
19
[ff9963]20#include "CodePatterns/Assert.hpp"
21
[286e36]22#include "Fragmentation/Summation/IndexSetContainer.hpp"
23#include "Fragmentation/Summation/SubsetMap.hpp"
[c6ca23]24#include "Fragmentation/Summation/OrthogonalSummator.hpp"
[da098d2]25#include "Fragmentation/Summation/ZeroInstance.hpp"
[286e36]26
[1f66c7]27#include "Fragmentation/Summation/printKeyNames.hpp"
[286e36]28
[ff9963]29/** Tiny template functor to use OrthogonalSummation, sum up each level, and store the
30 * result in a given vector.
[286e36]31 *
32 */
33template <typename MapType>
[ff9963]34struct AllLevelOrthogonalSummator {
[c6ca23]35 /** Constructor takes the arguments that \a OrthogonalSummator also needs and stores
[286e36]36 * them internally.
37 *
38 * \param _subsetmap map with hierarchy of IndexSet's
[c9f9bb]39 * \param _data MPQCData converted to MPQCDataMap_t type, associated to the jobid
[286e36]40 * \param _container container of IndexSet's such that each set has correct order
41 * to job id and hence to _data.
[675cd6]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.
[da098d2]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
[286e36]47 */
[ff9963]48 AllLevelOrthogonalSummator(
[286e36]49 SubsetMap::ptr &_subsetmap,
[c9f9bb]50 const std::map<JobId_t, MapType> &_data,
[286e36]51 const IndexSetContainer::Container_t &_container,
[3dd32f]52 const std::map< JobId_t, size_t > &_MatrixNrLookup,
[b8f0b25]53 std::vector<MapType> &_levelresults,
[da098d2]54 std::map<IndexSet::ptr, std::pair<MapType, MapType> > &_keysetresults,
55 MapType &_ZeroInstances) :
[286e36]56 subsetmap(_subsetmap),
57 data(_data),
58 container(_container),
[ff9963]59 MatrixNrLookup(_MatrixNrLookup),
[b8f0b25]60 levelresults(_levelresults),
[da098d2]61 keysetresults(_keysetresults),
62 ZeroInstances(_ZeroInstances)
[ff9963]63 {
[b8f0b25]64 ASSERT( levelresults.size() >= subsetmap->getMaximumSetLevel(),
[ff9963]65 "AllLevelOrthogonalSummator() - result vector is not large enough.");
66 }
[286e36]67
[c6ca23]68 /** Operator that calls on OrthogonalSummator and prints the value.
[286e36]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;
[b8f0b25]77
[c6ca23]78 // create OrthogonalSummator instance
79 OrthogonalSummator<MapType, MapKey> sum_value(
[c9f9bb]80 subsetmap, data, container, MatrixNrLookup
[286e36]81 );
[b8f0b25]82
[da098d2]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
[b8f0b25]88 // fill levelresults
[19c50e]89 const size_t MaxLevel = subsetmap->getMaximumSetLevel();
[ff9963]90 for (size_t level=1; level <= MaxLevel; ++level) {
[b8f0b25]91 MapType &LevelResults = levelresults[level-1];
92 // sum up and store in levelresults
[ff9963]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 }
[b8f0b25]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
[79398d]104 boost::fusion::at_key<MapKey>(keysetresults[index].first) =
105 sum_value.getValueForIndexSet(index);
106 boost::fusion::at_key<MapKey>(keysetresults[index].second) =
[b8f0b25]107 sum_value.getContributionForIndexSet(index);
108 }
[286e36]109 }
110
111private:
112 //!> Hierarchy of IndexSet's
113 SubsetMap::ptr &subsetmap;
[c9f9bb]114 //!> map from jobids to data converted from MPQCData
115 const std::map<JobId_t, MapType> &data;
[286e36]116 //!> container with all IndexSet's
117 const IndexSetContainer::Container_t &container;
118 //!> lookup map from job ids to ordering in above vectors
[3dd32f]119 const std::map< JobId_t, size_t > &MatrixNrLookup;
[b8f0b25]120 //!> vector of levelresults
121 std::vector<MapType> &levelresults;
[79398d]122 typedef std::pair< IndexSet::ptr, std::pair<MapType, MapType> > keysetresults_pair_t;
[b8f0b25]123 //!> typedef for map for keyset and each resulting value
[79398d]124 typedef std::map<IndexSet::ptr, std::pair<MapType, MapType> > keysetresults_t;
[b8f0b25]125 //!> map for IndexSet and its associated contribution
126 keysetresults_t &keysetresults;
[da098d2]127 //!> map per type to sum of base/zero instances to enforce specific parameters in summation
128 MapType &ZeroInstances;
[286e36]129};
130
[ff9963]131#endif /* ALLLEVELORTHOGONALSUMMATOR_HPP_ */
Note: See TracBrowser for help on using the repository browser.