source: src/Jobs/Grid/SamplingGrid.cpp@ 98f8fe

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing 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_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 98f8fe was 98f8fe, checked in by Frederik Heber <heber@…>, 12 years ago

SamplingGrid must have power of 2 grid size.

  • all number gridpoints returning functions were wrong as they related to unit length whereas they should have been relative to domain size.
  • Property mode set to 100644
File size: 5.3 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * SamplingGrid.cpp
25 *
26 * Created on: 25.07.2012
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35// include headers that implement a archive in simple text format
36// otherwise BOOST_CLASS_EXPORT_IMPLEMENT has no effect
37#include <boost/archive/text_oarchive.hpp>
38#include <boost/archive/text_iarchive.hpp>
39
40#include "CodePatterns/MemDebug.hpp"
41
42#include "Jobs/Grid/SamplingGrid.hpp"
43
44#include <limits>
45
46#include "CodePatterns/Assert.hpp"
47#include "CodePatterns/Log.hpp"
48
49SamplingGrid::SamplingGrid(const double _begin[3],
50 const double _end[3],
51 const int _level,
52 const sampledvalues_t &_sampled_grid) :
53 SamplingGridProperties(_begin, _end, _level),
54 sampled_grid(_sampled_grid)
55{}
56
57SamplingGrid::SamplingGrid(const SamplingGrid &_grid) :
58 SamplingGridProperties(_grid),
59 sampled_grid(_grid.sampled_grid)
60{}
61
62SamplingGrid::SamplingGrid(const SamplingGridProperties &_props) :
63 SamplingGridProperties(_props)
64{}
65
66SamplingGrid::SamplingGrid(
67 const SamplingGridProperties &_props,
68 const sampledvalues_t &_sampled_grid) :
69 SamplingGridProperties(_props),
70 sampled_grid(_sampled_grid)
71{}
72
73SamplingGrid::~SamplingGrid()
74{}
75
76SamplingGrid& SamplingGrid::operator=(const SamplingGrid& other)
77{
78 // check for self-assignment
79 if (this != &other) {
80 static_cast<SamplingGridProperties &>(*this) = other;
81 sampled_grid = other.sampled_grid;
82 }
83 return *this;
84}
85
86SamplingGrid& SamplingGrid::operator*=(const SamplingGrid& other)
87{
88 // check that grids are compatible
89 if (isCompatible(other)) {
90 sampledvalues_t::iterator iter = sampled_grid.begin();
91 sampledvalues_t::const_iterator otheriter = other.sampled_grid.begin();
92 for(; iter != sampled_grid.end(); ++iter, ++otheriter )
93 *iter *= (*otheriter);
94 } else {
95 ASSERT(0, "SamplingGrid::operator*=() - superposing incompatible grids is so far not in the cards.");
96 }
97 return *this;
98}
99
100void SamplingGrid::superposeOtherGrids(const SamplingGrid &other, const double prefactor)
101{
102 // check that grids are compatible
103 if (isCompatible(other)) {
104 // then add other's grid onto this one
105 sampledvalues_t::iterator iter = sampled_grid.begin();
106 sampledvalues_t::const_iterator otheriter = other.sampled_grid.begin();
107 for(; iter != sampled_grid.end(); ++iter, ++otheriter )
108 *iter += prefactor * (*otheriter);
109 } else {
110 ASSERT(0, "SamplingGrid::superposeOtherGrids() - superposing incompatible grids is so far not in the cards.");
111 }
112}
113
114double SamplingGrid::getVolume() const
115{
116 double volume = 1.;
117 for (size_t i=0;i<3;++i)
118 volume *= end[i]-begin[i];
119 return volume;
120}
121
122const size_t SamplingGrid::getTotalGridPoints() const
123{
124 return pow(getGridPointsPerAxis(),3);
125}
126
127const size_t SamplingGrid::getGridPointsPerAxis() const
128{
129 return pow(2, level);
130}
131
132double SamplingGrid::integral() const
133{
134 const double volume_element = getVolume()/(double)getTotalGridPoints();
135 double int_value = 0.;
136 for (sampledvalues_t::const_iterator iter = sampled_grid.begin();
137 iter != sampled_grid.end();
138 ++iter)
139 int_value += *iter;
140 int_value *= volume_element;
141 LOG(2, "DEBUG: SamplingGrid::integral() is " << scientific << setprecision(13) << int_value << ".");
142 return int_value;
143}
144
145double SamplingGrid::integral(const SamplingGrid &weight) const
146{
147 if (isCompatible(weight)) {
148 const size_t gridpoints = pow(2, level);
149 const double volume_element = getVolume()/(double)getTotalGridPoints();
150 double int_value = 0.;
151 sampledvalues_t::const_iterator iter = sampled_grid.begin();
152 sampledvalues_t::const_iterator weightiter = weight.sampled_grid.begin();
153 for (;iter != sampled_grid.end();++iter,++weightiter)
154 int_value += (*weightiter) * (*iter);
155 int_value *= volume_element;
156 //LOG(2, "DEBUG: SamplingGrid::integral() is " << scientific << setprecision(13) << int_value << ".");
157 return int_value;
158 } else
159 return 0.;
160}
161
162std::ostream & operator<<(std::ostream &ost, const SamplingGrid& other)
163{
164 ost << "SamplingGrid starting at " << other.begin[0] << "," << other.begin[1] << "," << other.begin[2];
165 ost << ", ending at " << other.end[0] << "," << other.end[1] << "," << other.end[2];
166 ost << ", level of " << other.level;
167 ost << " and integrated value of " << other.integral();
168 return ost;
169}
170
171template<> SamplingGrid ZeroInstance<SamplingGrid>()
172{
173 SamplingGrid returnvalue;
174 return returnvalue;
175}
176
177// we need to explicitly instantiate the serialization functions as
178// its is only serialized through its base class FragmentJob
179BOOST_CLASS_EXPORT_IMPLEMENT(SamplingGrid)
Note: See TracBrowser for help on using the repository browser.