| [358ddb] | 1 | /*
 | 
|---|
 | 2 |  * OrthogonalFullSummator.hpp
 | 
|---|
 | 3 |  *
 | 
|---|
 | 4 |  *  Created on: 08.09.2012
 | 
|---|
 | 5 |  *      Author: heber
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | #ifndef ORTHOGONALFULLSUMMATOR_HPP_
 | 
|---|
 | 9 | #define ORTHOGONALFULLSUMMATOR_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 | 
 | 
|---|
| [3dd32f] | 18 | #include "CodePatterns/Assert.hpp"
 | 
|---|
 | 19 | 
 | 
|---|
| [358ddb] | 20 | #include "Fragmentation/Summation/OrthogonalSummation.hpp"
 | 
|---|
 | 21 | #include "Fragmentation/Summation/SetValue.hpp"
 | 
|---|
 | 22 | #include "Jobs/MPQCDataMap.hpp"
 | 
|---|
 | 23 | 
 | 
|---|
 | 24 | /** OrthogonalFullSummator is a general class for making us of OrthogonalSummation.
 | 
|---|
 | 25 |  *
 | 
|---|
 | 26 |  *
 | 
|---|
 | 27 |  * This class is very similar to OrthogonalSummation only that we specifically include
 | 
|---|
 | 28 |  * the full set (with a value!) as well. Also there is a function to obtain the
 | 
|---|
 | 29 |  * contribution. This is intended to check a full calculation against the truncated
 | 
|---|
 | 30 |  * sum.
 | 
|---|
 | 31 |  */
 | 
|---|
 | 32 | template <typename MapType, typename MapKey>
 | 
|---|
 | 33 | struct OrthogonalFullSummator {
 | 
|---|
 | 34 |   /** We retrieve the type of the MPQCData member variable from the
 | 
|---|
 | 35 |    * boost::fusion::map and stored it in this typedef. Note that for
 | 
|---|
 | 36 |    * internal types (e.g. MapValue::const_iterator we need to place
 | 
|---|
 | 37 |    * \b typename before).
 | 
|---|
 | 38 |    */
 | 
|---|
 | 39 |   typedef typename boost::fusion::result_of::value_at_key<MapType, MapKey>::type MapValue;
 | 
|---|
 | 40 | 
 | 
|---|
 | 41 |   /** Constructor for class OrthogonalFullSummator.
 | 
|---|
 | 42 |    *
 | 
|---|
 | 43 |    * \param _subsetmap map with hierarchy of IndexSet's
 | 
|---|
| [c9f9bb] | 44 |    * \param _data MPQCData converted to MPQCDataMap_t type, associated to job id
 | 
|---|
| [358ddb] | 45 |    * \param _container container of IndexSet's such that each set has correct order
 | 
|---|
 | 46 |    *        to job id and hence to _data.
 | 
|---|
 | 47 |    * \param _MatrixNrLookup lookup from job id to ordering in above vectors
 | 
|---|
 | 48 |    */
 | 
|---|
 | 49 |   OrthogonalFullSummator(
 | 
|---|
 | 50 |       SubsetMap::ptr &_subsetmap,
 | 
|---|
| [c9f9bb] | 51 |       const std::map<JobId_t, MapType> &_data,
 | 
|---|
| [358ddb] | 52 |       const IndexSetContainer::Container_t &_container,
 | 
|---|
| [3dd32f] | 53 |       const std::map< JobId_t, size_t > &_MatrixNrLookup) :
 | 
|---|
| [358ddb] | 54 |     indices(getSubsets(_container)),
 | 
|---|
| [c9f9bb] | 55 |     values(createValues(_data, _container, _MatrixNrLookup)),
 | 
|---|
| [358ddb] | 56 |     OS(indices, values, _subsetmap)
 | 
|---|
 | 57 |   {
 | 
|---|
 | 58 |     ASSERT( _data.size() == _container.size(),
 | 
|---|
 | 59 |         "OrthogonalFullSummator() - data and indices don't have same size.");
 | 
|---|
| [c9f9bb] | 60 |     ASSERT( _data.size() == _MatrixNrLookup.size(),
 | 
|---|
| [358ddb] | 61 |         "OrthogonalFullSummator() - ids and MatrixNrLookup don't have same size.");
 | 
|---|
 | 62 |   }
 | 
|---|
 | 63 | 
 | 
|---|
 | 64 |   /** Summation operator.
 | 
|---|
 | 65 |    *
 | 
|---|
 | 66 |    * Initialises instantiated OrthogonalSummation of the respective type via
 | 
|---|
 | 67 |    * \a OrthogonalFullSummator::data, uses OrthogonalSummation::operator() to sum and returns
 | 
|---|
 | 68 |    * the result.
 | 
|---|
 | 69 |    *
 | 
|---|
 | 70 |    * \param level up to which level to sum up
 | 
|---|
 | 71 |    * \return result of OrthogonalSummation for given type from MPQCDataMap_t.
 | 
|---|
 | 72 |    */
 | 
|---|
 | 73 |   MapValue operator()(const size_t level)
 | 
|---|
 | 74 |   {
 | 
|---|
 | 75 |     // evaluate
 | 
|---|
 | 76 |     const MapValue result = OS(level);
 | 
|---|
 | 77 |     return result;
 | 
|---|
 | 78 |   }
 | 
|---|
 | 79 | 
 | 
|---|
 | 80 |   /** Getter for the remaining contribution of the full set.
 | 
|---|
 | 81 |    *
 | 
|---|
 | 82 |    * @return contribution of allindices
 | 
|---|
 | 83 |    */
 | 
|---|
 | 84 |   MapValue getFullContribution() const {
 | 
|---|
 | 85 |     typename SetValueMap<MapValue>::const_iterator iter = --OS.getSetValues().end();
 | 
|---|
| [a2295a] | 86 |     LOG(2, "DEBUG: Returning Full contribution of level " << iter->first->size() << ".");
 | 
|---|
| [358ddb] | 87 |     return iter->second->getContribution();
 | 
|---|
 | 88 |   }
 | 
|---|
 | 89 | 
 | 
|---|
 | 90 | private:
 | 
|---|
 | 91 |   /** Tiny helper to create the indices from a given IndexSetContainer.
 | 
|---|
 | 92 |    *
 | 
|---|
 | 93 |    * @param container container with IndexSet
 | 
|---|
 | 94 |    * @return all subsets contained in \a container
 | 
|---|
 | 95 |    */
 | 
|---|
 | 96 |   typename OrthogonalSummation<MapValue>::InputSets_t getSubsets(
 | 
|---|
 | 97 |       const IndexSetContainer::Container_t &container)
 | 
|---|
 | 98 |   {
 | 
|---|
 | 99 |     typename OrthogonalSummation<MapValue>::InputSets_t indices(
 | 
|---|
 | 100 |         container.begin(),
 | 
|---|
 | 101 |         container.end());
 | 
|---|
 | 102 |     return indices;
 | 
|---|
 | 103 |   }
 | 
|---|
 | 104 | 
 | 
|---|
 | 105 |   /** Tiny helper to create the values for the summation in the correct order.
 | 
|---|
 | 106 |    *
 | 
|---|
 | 107 |    * @param data
 | 
|---|
 | 108 |    * @param container
 | 
|---|
 | 109 |    * @param MatrixNrLookup
 | 
|---|
 | 110 |    * @return
 | 
|---|
 | 111 |    */
 | 
|---|
 | 112 |   typename OrthogonalSummation<MapValue>::InputValues_t createValues(
 | 
|---|
| [c9f9bb] | 113 |       const std::map<JobId_t, MapType> &data,
 | 
|---|
| [358ddb] | 114 |       const IndexSetContainer::Container_t &container,
 | 
|---|
| [3dd32f] | 115 |       const std::map< JobId_t, size_t > &MatrixNrLookup)
 | 
|---|
| [358ddb] | 116 |   {
 | 
|---|
 | 117 |     typename OrthogonalSummation<MapValue>::InputValues_t values(container.size());
 | 
|---|
| [c9f9bb] | 118 |     for (typename std::map<JobId_t, MapType>::const_iterator dataiter = data.begin();
 | 
|---|
 | 119 |         dataiter != data.end(); ++dataiter) {
 | 
|---|
 | 120 |       const MapType &Data = dataiter->second;
 | 
|---|
 | 121 |       const JobId_t &jobid = dataiter->first;
 | 
|---|
| [358ddb] | 122 |       const MapValue &value = boost::fusion::at_key<MapKey>(Data);
 | 
|---|
| [3dd32f] | 123 |       const std::map< JobId_t, size_t >::const_iterator nriter = MatrixNrLookup.find(jobid);
 | 
|---|
 | 124 |       ASSERT( nriter != MatrixNrLookup.end(),
 | 
|---|
 | 125 |           "OrthogonalFullSummation<>::createValues() - MatrixNrLookup does not contain id "
 | 
|---|
 | 126 |           +toString(jobid)+".");
 | 
|---|
 | 127 |       values[ nriter->second ] = value;
 | 
|---|
| [358ddb] | 128 |     }
 | 
|---|
 | 129 |     return values;
 | 
|---|
 | 130 |   }
 | 
|---|
 | 131 | private:
 | 
|---|
 | 132 |   //!> created indices for OS such that we may hand over refs
 | 
|---|
 | 133 |   typename OrthogonalSummation<MapValue>::InputSets_t indices;
 | 
|---|
 | 134 |   //!> created values for OS such that we may hand over refs
 | 
|---|
 | 135 |   typename OrthogonalSummation<MapValue>::InputValues_t values;
 | 
|---|
 | 136 |   //!> Summation instance to use in operator()(level)
 | 
|---|
 | 137 |   OrthogonalSummation<MapValue> OS;
 | 
|---|
 | 138 | };
 | 
|---|
 | 139 | 
 | 
|---|
 | 140 | 
 | 
|---|
 | 141 | #endif /* ORTHOGONALFULLSUMMATOR_HPP_ */
 | 
|---|