source: src/Fragmentation/Summation/Summation_impl.hpp@ ff7ac6

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator 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_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since ff7ac6 was ff7ac6, checked in by Frederik Heber <heber@…>, 9 years ago

BREAKS: Summation and OrthogonalSummation both now allow to set a specific "ZeroInstance".

  • this replaces then the default ZeroInstance<T> used and may be used to enforce specific parameters in the summation, e.g. a smaller grid when summing SamplingGrid.
  • Note that this breaks all long-range results for the moment. The reason is that so far the ZeroInstance was effectively the first result/contribution upon which all others were summed. This worked because each fragment used the same grid size, namely the one of the global grid. With the independent fragment grids this will no longer be possible, which is why we introduce the possibility to set a specific ZeroInstance, i.e. providing the global grid to sum onto externally.
  • to be absolutely precise: The reasons why the tests break is that the little change in ::Sum(): sum =.. -> sum +=..
  • TESTS: Setting regression tests AnalyseFragmentResults to failed.
  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*
2 * Summation_impl.hpp
3 *
4 * Created on: Jun 30, 2012
5 * Author: heber
6 */
7
8#ifndef SUMMATION_IMPL_HPP_
9#define SUMMATION_IMPL_HPP_
10
11
12// include config.h
13#ifdef HAVE_CONFIG_H
14#include <config.h>
15#endif
16
17#include "CodePatterns/Assert.hpp"
18#include "CodePatterns/IteratorAdaptors.hpp"
19#include "CodePatterns/Log.hpp"
20
21#include "Fragmentation/Summation/Summation.hpp"
22
23#include "Fragmentation/Summation/printKeyNames.hpp"
24#include "Fragmentation/Summation/ZeroInstance.hpp"
25
26/** Constructor of class Summation.
27 *
28 */
29template <class T>
30Summation<T>::Summation(
31 InputSets_t &indices,
32 InputValues_t& values,
33 SubsetMap::ptr _subsetmap) :
34 subsetmap(_subsetmap),
35 zeroinstance(ZeroInstance<T>())
36{
37 ASSERT( indices.size() == values.size(),
38 "Summation<T>::Summation() - indices and values mismatch in size: "
39 +toString(indices.size())+" != "+toString(values.size())+".");
40 /// place each index
41 /// create own map if none is given
42 if (!subsetmap) {
43 typename InputSets_t::iterator iter = indices.begin();
44 IndexSetContainer container(*iter);
45 for (; iter != indices.end(); ++iter)
46 container.insert(*iter);
47 subsetmap.reset(new SubsetMap(container));
48 } else {
49 LOG(2, "DEBUG: Using given SubsetMap.");
50 }
51 /// instantiate all SubSetValue's by requesting the IndexSet from the Subsetmap
52 typename InputSets_t::iterator indexiter = indices.begin();
53 typename InputValues_t::iterator valueiter = values.begin();
54 for (;valueiter != values.end(); ++indexiter, ++valueiter) {
55 LOG(2, "DEBUG: Adding set " << **indexiter << " with value " << *valueiter << ".");
56 setvalues.addValue( *indexiter, *valueiter );
57 }
58 /// bind static lookup functions for SetValue<T>
59 SetValue<T>::lookupSubset =
60 boost::bind(&SubsetMap::getSubsets, boost::ref(*subsetmap), _1);
61 SetValue<T>::lookupValue =
62 boost::bind(&SetValueMap<T>::getValue, boost::ref(setvalues), _1);
63}
64
65template <class T>
66T Summation<T>::operator()(const size_t level) const
67{
68 return Sum(level);
69}
70
71template <class T>
72T Summation<T>::Sum(const size_t level) const
73{
74 typename SetValueMap<T>::const_iterator iter = setvalues.begin();
75 T sum(zeroinstance);
76 if (iter->first->size() <= level)
77 sum += (iter->second)->getValue();
78 LOG(3, "DEBUG: Value from subset "+toString(*(iter->second->getIndexSet()))
79 +" is "+toString(sum)+".");
80 for(++iter;(iter != setvalues.end()) && (iter->first->size() <= level); ++iter) {
81 const T tempvalue = (iter->second)->getValue();
82 sum += tempvalue;
83 LOG(3, "DEBUG: Value from subset "+toString(*(iter->second->getIndexSet()))
84 +" is "+toString(tempvalue)+".");
85 }
86 return sum;
87}
88
89
90#endif /* SUMMATION_IMPL_HPP_ */
Note: See TracBrowser for help on using the repository browser.