source: src/Jobs/Grid/SamplingGrid.hpp@ 1a00bb

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 1a00bb was 1a00bb, checked in by Frederik Heber <heber@…>, 12 years ago

Rewrote parts of SampingGrid such that a window of non-zero entries is used.

  • this makes the last part final O(N) as so far for the sampled_grid the whole domain has to be used instead of a tiny region around the specific fragment.
  • for this we added extendWindow() and addOntoWindow() including some new member variables that hold the window size.
  • added default cstor that correctly used SampingGridProperties default cstor. Otherwise we got the funny behavior that on some systems the very first job of q MPQCCommandJob (tests/JobMarket/2) is not re-instantiated.
  • unit test extended to cover the new functionality but marked as expected to fail because it is not yet working correctly.
  • Property mode set to 100644
File size: 7.4 KB
Line 
1/*
2 * SamplingGrid.hpp
3 *
4 * Created on: 25.07.2012
5 * Author: heber
6 */
7
8#ifndef SAMPLINGGRID_HPP_
9#define SAMPLINGGRID_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16#include <iosfwd>
17#include <vector>
18
19#include "boost/serialization/export.hpp"
20#include "boost/serialization/vector.hpp"
21
22#include "Jobs/Grid/SamplingGridProperties.hpp"
23
24class MPQCData;
25class SamplingGridTest;
26
27/** This class stores a sample function on a three-dimensional grid.
28 *
29 * \note We do not use boost::multi_array because it is not trivial to serialize.
30 *
31 */
32class SamplingGrid : public SamplingGridProperties
33{
34 //!> grant unit test access to private parts
35 friend class SamplingGridTest;
36 //!> grant output operator access
37 friend std::ostream & operator<<(std::ostream &ost, const SamplingGrid& other);
38public:
39 //!> typedef for sampled values
40 typedef std::vector< double > sampledvalues_t;
41
42 /** Constructor for class SamplingGrid.
43 *
44 * \param _begin offset for grid per axis
45 * \param _end edge length of grid per axis
46 * \param _level number of grid points in \f$2^{\mathrm{level}}\f$
47 * \param _sampled_grid sample points
48 */
49 SamplingGrid(const double _begin[3],
50 const double _end[3],
51 const int _level,
52 const sampledvalues_t &_sampled_grid);
53
54 /** Copy constructor for class SamplingGrid.
55 *
56 * \param _grid grid to copy
57 */
58 SamplingGrid(const SamplingGrid &_grid);
59
60 /** Copy constructor for class SamplingGrid from SamplingGridProperties.
61 *
62 * \param _props properties to copy
63 */
64 SamplingGrid(const SamplingGridProperties &_props);
65
66 /** Copy constructor for class SamplingGrid from SamplingGridProperties.
67 *
68 * \param _props properties to copy
69 * \param _sampled_grid sample points
70 */
71 SamplingGrid(
72 const SamplingGridProperties &_props,
73 const sampledvalues_t &_sampled_grid);
74
75 /** default cstor.
76 */
77 SamplingGrid();
78
79 virtual ~SamplingGrid();
80
81 /** Assignment operator.
82 *
83 * \param other other instance to assign ourselves to
84 */
85 SamplingGrid& operator=(const SamplingGrid& other);
86
87 /** Addition operator with another SamplingGrid instance \a other.
88 *
89 * \param other other instance to sum onto this one.
90 * \return ref to this instance
91 */
92 SamplingGrid& operator+=(const SamplingGrid& other)
93 {
94 superposeOtherGrids(other, +1.);
95 return *this;
96 }
97
98 /** Element-wise multiplication operator with another SamplingGrid instance \a other.
99 *
100 * \param other other instance to sum onto this one.
101 * \return ref to this instance
102 */
103 SamplingGrid& operator*=(const SamplingGrid& other);
104
105 /** Subtraction operator with another SamplingGrid instance \a other.
106 *
107 * \param other other instance to subtract from this one.
108 * \return ref to this instance
109 */
110 SamplingGrid& operator-=(const SamplingGrid& other)
111 {
112 superposeOtherGrids(other, -1.);
113 return *this;
114 }
115
116 /** Returns the numeric integral over the grid.
117 *
118 * @return sum of grid values times volume element
119 */
120 double integral() const;
121
122 /** Returns the numeric integral over the grid where the grid is element-wise multiplied with \a weight.
123 *
124 * @param weight grid of weights
125 * @return sum of grid values weighted by respective element in weight times volume element
126 */
127 double integral(const SamplingGrid &weight) const;
128
129 /** Returns the volume of the domain for this sampled function.
130 *
131 * @return volume
132 */
133 const double getVolume() const;
134
135 /** Returns the total number of gridpoints of the discrete mesh covering the (window) volume.
136 *
137 * @return number of gridpoints sampled_values should have
138 */
139 const size_t getWindowGridPoints() const;
140
141 /** Returns the total number of gridpoints of the discrete mesh covering the volume.
142 *
143 * @return number of gridpoints sampled_values should have
144 */
145 const size_t getTotalGridPoints() const;
146
147 /** Returns the number of grid points per axis.
148 *
149 * @return number of grid points per unit length
150 */
151 const size_t getGridPointsPerAxis() const;
152
153 /** Returns the volume of the domain covered by the current window.
154 *
155 * @return volume of window
156 */
157 const double getWindowVolume() const;
158
159 /** Sets the size of the window.
160 *
161 * \note also resets the sampled points so far.
162 *
163 * \param _begin_window start of new window
164 * \param _end_window end of window
165 */
166 void setWindow(const double _begin_window[3], const double _end_window[3]);
167
168private:
169 /** Extends the window while keeping the values.
170 *
171 * \param _begin_window new start of window
172 * \param _end_window new end of window
173 */
174 void extendWindow(const double _begin_window[3], const double _end_window[3]);
175
176 /** Adds another window onto the one in this instance.
177 *
178 * \note We assume here that the given window fits on the this one.
179 *
180 * \param _begin_window start of other window
181 * \param _end_window end of other window
182 * \param _sampled_grid other set of sampled values
183 */
184 void addOntoWindow(
185 const double _begin_window[3],
186 const double _end_window[3],
187 const sampledvalues_t &_sampled_grid);
188
189 /** Helper function that contains all the logic of how to superpose two
190 * grids.
191 *
192 * Is called by SamplingGrid::operator+=() and SamplingGrid::operator-=()
193 *
194 * @param other other histogram
195 * @param prefactor +1. is then addition, -1. is subtraction.
196 */
197 void superposeOtherGrids(const SamplingGrid &other, const double prefactor);
198
199 /** Sets the size of the window.
200 *
201 * \note also resets the sampled points so far.
202 *
203 * \param _begin_window start of new window
204 * \param _size size of the window
205 */
206 void setWindowSize(const double _begin_window[3], const double _size);
207
208 /** Sets the size of the window.
209 *
210 * \note also resets the sampled points so far.
211 *
212 * \param _begin_window start of new window
213 * \param _end_window end of window
214 */
215 void setWindowSize(const double _begin_window[3], const double _end_window[3]);
216
217public:
218 /// We do not store the whole grid if many entries are actually zero
219 /// but only a window wherein the sampled function is non-zero.
220
221 //!> sample points of the window
222 sampledvalues_t sampled_grid;
223
224 //!> start of the window relative to SamplingGridProperties::begin and SamplingGridProperties::size
225 double begin_window[3];
226 //!> end of the window relative to SamplingGridProperties::begin and SamplingGridProperties::size
227 double end_window[3];
228
229private:
230 friend class MPQCData;
231
232 friend class boost::serialization::access;
233 // serialization
234 template <typename Archive>
235 void serialize(Archive& ar, const unsigned int version)
236 {
237 ar & boost::serialization::base_object<SamplingGridProperties>(*this);
238 ar & const_cast< sampledvalues_t &>(sampled_grid);
239 for(size_t i=0;i<3;++i) {
240 ar & begin_window[i];
241 ar & end_window[i];
242 }
243 }
244
245 //!> static typedef to use in cstor when no initial values are given
246 static const double zeroOffset[3];
247};
248
249/** Output operator for class SamplingGrid.
250 *
251 * \param ost output stream to print to
252 * \param other instance to print
253 * \return ref to stream for concatenation
254 */
255std::ostream & operator<<(std::ostream &ost, const SamplingGrid& other);
256
257template<typename T> T ZeroInstance();
258template<> SamplingGrid ZeroInstance<SamplingGrid>();
259
260// we need to give this class a unique key for serialization
261// its is only serialized through its base class FragmentJob
262BOOST_CLASS_EXPORT_KEY(SamplingGrid)
263
264#endif /* SAMPLINGGRID_HPP_ */
Note: See TracBrowser for help on using the repository browser.