source: src/Fragmentation/Summation/OrthogonalSummation_impl.hpp@ 8a91f5

Fix_IndependentFragmentGrids
Last change on this file since 8a91f5 was 8a91f5, checked in by Frederik Heber <heber@…>, 9 years ago

FIX: (Orthogonal)Summation::Sum() summed small fragments then large ones.

  • added rbegin() and rend() to SetValueMap's interface.
  • this fails for the new individual fragment SamplingGrids because there we assume that we always sum a grid of smaller extension onto a larger one. now, we go in reverse order through the list of setvalues and sum from largest down to smallest.
  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*
2 * OrthogonalSummation_impl.hpp
3 *
4 * Created on: Jun 25, 2012
5 * Author: heber
6 */
7
8#ifndef ORTHOGONALSUMMATION_IMPL_HPP_
9#define ORTHOGONALSUMMATION_IMPL_HPP_
10
11
12// include config.h
13#ifdef HAVE_CONFIG_H
14#include <config.h>
15#endif
16
17#include "CodePatterns/IteratorAdaptors.hpp"
18#include "CodePatterns/Log.hpp"
19
20#include "Fragmentation/Summation/OrthogonalSummation.hpp"
21
22#include "Fragmentation/Summation/ZeroInstance.hpp"
23#include "Fragmentation/Summation/printKeyNames.hpp"
24
25/** Constructor of class OrthogonalSummation.
26 *
27 */
28template <class T>
29OrthogonalSummation<T>::OrthogonalSummation(
30 InputSets_t &indices,
31 InputValues_t& values,
32 SubsetMap::ptr _subsetmap) :
33 subsetmap(_subsetmap),
34 zeroinstance(ZeroInstance<T>())
35{
36 ASSERT( indices.size() == values.size(),
37 "OrthogonalSummation<T>::OrthogonalSummation() - indices and values mismatch in size: "
38 +toString(indices.size())+" != "+toString(values.size())+".");
39 /// place each index
40 /// create own map if none is given
41 if (!subsetmap) {
42 typename InputSets_t::iterator iter = indices.begin();
43 IndexSetContainer container(*iter);
44 for (; iter != indices.end(); ++iter)
45 container.insert(*iter);
46 subsetmap.reset(new SubsetMap(container));
47 } else {
48 LOG(2, "DEBUG: Using given SubsetMap.");
49 }
50 /// instantiate all SubSetValue's by requesting the IndexSet from the Subsetmap
51 typename InputSets_t::iterator indexiter = indices.begin();
52 typename InputValues_t::iterator valueiter = values.begin();
53 for (;valueiter != values.end(); ++indexiter, ++valueiter) {
54 LOG(2, "DEBUG: Adding set " << **indexiter << " with value " << *valueiter << ".");
55 setvalues.addValue( *indexiter, *valueiter );
56 }
57 /// bind static lookup functions for SetValue<T>
58 SetValue<T>::lookupSubset =
59 boost::bind(&SubsetMap::getSubsets, boost::ref(*subsetmap), _1);
60 SetValue<T>::lookupValue =
61 boost::bind(&SetValueMap<T>::getValue, boost::ref(setvalues), _1);
62}
63
64template <class T>
65T OrthogonalSummation<T>::operator()(const size_t level) const
66{
67 return Sum(level);
68}
69
70template <class T>
71T OrthogonalSummation<T>::Sum(const size_t level) const
72{
73 T sum(zeroinstance);
74 // go from largest fragments to smallest
75 for(typename SetValueMap<T>::const_reverse_iterator iter = setvalues.rbegin();
76 iter != setvalues.rend(); ++iter) {
77 if (iter->first->size() > level)
78 continue;
79 const T tempvalue = (iter->second)->getContribution();
80 sum += tempvalue;
81 LOG(3, "DEBUG: Contribution from subset "+toString(*(iter->second->getIndexSet()))
82 +" is "+toString(tempvalue)+".");
83 }
84 return sum;
85}
86
87
88#endif /* ORTHOGONALSUMMATION_IMPL_HPP_ */
Note: See TracBrowser for help on using the repository browser.