source: src/Jobs/Grid/SamplingGrid.hpp@ 64bafe0

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

SamplingGrid's Window start and end are now always set on a grid point

  • also made addWindowOntoWindow() safe with respect to rounding.
  • TESTFIX: this fixes SamplingGridUnitTest, removed expected to fail.
  • Property mode set to 100644
File size: 9.0 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 for full window.
43 *
44 * Here, the window of sampled values spans the given domain.
45 *
46 * \param _begin offset for grid per axis
47 * \param _end edge length of grid per axis
48 * \param _level number of grid points in \f$2^{\mathrm{level}}\f$
49 * \param _sampled_grid sample points
50 */
51 SamplingGrid(const double _begin[3],
52 const double _end[3],
53 const int _level,
54 const sampledvalues_t &_sampled_grid);
55
56 /** Constructor for class SamplingGrid for empty window.
57 *
58 * Here, the window is initially of size zero.
59 *
60 * \param _begin offset for grid per axis
61 * \param _end edge length of grid per axis
62 * \param _level number of grid points in \f$2^{\text{level}}\f$
63 */
64 SamplingGrid(const double _begin[3],
65 const double _end[3],
66 const int _level);
67
68 /** Copy constructor for class SamplingGrid with full window from SamplingGridProperties.
69 *
70 * Here, the window is initially empty.
71 *
72 * \param _props properties to copy
73 */
74 SamplingGrid(const SamplingGridProperties &_props);
75
76 /** Copy constructor for class SamplingGrid with empty window from SamplingGridProperties.
77 *
78 * Here, the window must span the whole domain
79 *
80 * \param _props properties to copy
81 * \param _sampled_grid sample points
82 */
83 SamplingGrid(
84 const SamplingGridProperties &_props,
85 const sampledvalues_t &_sampled_grid);
86
87 /** Copy constructor for class SamplingGrid.
88 *
89 * The window of sampled values corresponds to the one on \a _grid.
90 *
91 * \param _grid grid to copy
92 */
93 SamplingGrid(const SamplingGrid &_grid);
94
95 /** default cstor.
96 */
97 SamplingGrid();
98
99 virtual ~SamplingGrid();
100
101 /** Assignment operator.
102 *
103 * \param other other instance to assign ourselves to
104 */
105 SamplingGrid& operator=(const SamplingGrid& other);
106
107 /** Addition operator with another SamplingGrid instance \a other.
108 *
109 * \param other other instance to sum onto this one.
110 * \return ref to this instance
111 */
112 SamplingGrid& operator+=(const SamplingGrid& other)
113 {
114 superposeOtherGrids(other, +1.);
115 return *this;
116 }
117
118 /** Element-wise multiplication operator with another SamplingGrid instance \a other.
119 *
120 * \param other other instance to sum onto this one.
121 * \return ref to this instance
122 */
123 SamplingGrid& operator*=(const SamplingGrid& other);
124
125 /** Subtraction operator with another SamplingGrid instance \a other.
126 *
127 * \param other other instance to subtract from this one.
128 * \return ref to this instance
129 */
130 SamplingGrid& operator-=(const SamplingGrid& other)
131 {
132 superposeOtherGrids(other, -1.);
133 return *this;
134 }
135
136 /** Returns the numeric integral over the grid.
137 *
138 * @return sum of grid values times volume element
139 */
140 double integral() const;
141
142 /** Returns the numeric integral over the grid where the grid is element-wise multiplied with \a weight.
143 *
144 * @param weight grid of weights
145 * @return sum of grid values weighted by respective element in weight times volume element
146 */
147 double integral(const SamplingGrid &weight) const;
148
149 /** Returns the volume of the domain for this sampled function.
150 *
151 * @return volume
152 */
153 const double getVolume() const;
154
155 /** Returns the total number of gridpoints of the discrete mesh covering the (window) volume.
156 *
157 * @return number of gridpoints sampled_values should have
158 */
159 const size_t getWindowGridPoints() const;
160
161 /** Returns the total number of gridpoints of the discrete mesh covering the volume.
162 *
163 * @return number of gridpoints sampled_values should have
164 */
165 const size_t getTotalGridPoints() const;
166
167 /** Returns the number of grid points per axis.
168 *
169 * @return number of grid points per unit length
170 */
171 const size_t getGridPointsPerAxis() const;
172
173 /** Returns the volume of the domain covered by the current window.
174 *
175 * @return volume of window
176 */
177 const double getWindowVolume() const;
178
179private:
180 /** Sets the size of the window.
181 *
182 * \note also resets the sampled points so far.
183 *
184 * \param _begin_window start of new window
185 * \param _end_window end of window
186 */
187 void setWindow(const double _begin_window[3], const double _end_window[3]);
188
189 /** Sets the size of the domain.
190 *
191 * \note also resets the sampled points so far and the window.
192 *
193 * \param _begin start of new window
194 * \param _end end of window
195 */
196 void setDomain(const double _begin[3], const double _end[3]);
197
198 /** Sets the size of the domain.
199 *
200 * \note this is just internally used for easing the array setting.
201 *
202 * \param _begin start of domain
203 * \param _end end of domain
204 */
205 void setDomainSize(const double _begin[3], const double _end[3]);
206
207 /** Extends the window while keeping the values.
208 *
209 * \param _begin_window new start of window
210 * \param _end_window new end of window
211 */
212 void extendWindow(const double _begin_window[3], const double _end_window[3]);
213
214 /** Adds another window onto the one in this instance.
215 *
216 * \note We assume here that the given window fits on the this one.
217 *
218 * \param _begin_window start of other window
219 * \param _end_window end of other window
220 * \param _sampled_grid other set of sampled values
221 * @param prefactor +1. is then addition, -1. is subtraction.
222 */
223 void addOntoWindow(
224 const double _begin_window[3],
225 const double _end_window[3],
226 const sampledvalues_t &_sampled_grid,
227 const double prefactor);
228
229 /** Helper function that contains all the logic of how to superpose two
230 * grids.
231 *
232 * Is called by SamplingGrid::operator+=() and SamplingGrid::operator-=()
233 *
234 * @param other other histogram
235 * @param prefactor +1. is then addition, -1. is subtraction.
236 */
237 void superposeOtherGrids(const SamplingGrid &other, const double prefactor);
238
239 /** Sets the size of the window.
240 *
241 * \note also resets the sampled points so far.
242 *
243 * \param _begin_window start of new window
244 * \param _end_window end of window
245 */
246 void setWindowSize(const double _begin_window[3], const double _end_window[3]);
247
248 /** Helper function to get point at grid point for given \a axis and less than value.
249 *
250 * @param value value to find nearest grid point to
251 * @param axis axis of the value
252 * @return nearest lower grid point
253 */
254 double getNearestLowerGridPoint(
255 const double value, const size_t axis) const;
256
257 /** Helper function to get point at grid point for given \a axis and greater than value.
258 *
259 * @param value value to find nearest grid point to
260 * @param axis axis of the value
261 * @return nearest lower grid point
262 */
263 double getNearestHigherGridPoint(
264 const double value, const size_t axis) const;
265
266public:
267 /// We do not store the whole grid if many entries are actually zero
268 /// but only a window wherein the sampled function is non-zero.
269
270 //!> sample points of the window
271 sampledvalues_t sampled_grid;
272
273 //!> start of the window relative to SamplingGridProperties::begin and SamplingGridProperties::size
274 double begin_window[3];
275 //!> end of the window relative to SamplingGridProperties::begin and SamplingGridProperties::size
276 double end_window[3];
277
278private:
279 friend class MPQCData;
280
281 friend class boost::serialization::access;
282 // serialization
283 template <typename Archive>
284 void serialize(Archive& ar, const unsigned int version)
285 {
286 ar & boost::serialization::base_object<SamplingGridProperties>(*this);
287 ar & const_cast< sampledvalues_t &>(sampled_grid);
288 for(size_t i=0;i<3;++i) {
289 ar & begin_window[i];
290 ar & end_window[i];
291 }
292 }
293
294 //!> static typedef to use in cstor when no initial values are given
295 static const double zeroOffset[3];
296};
297
298/** Output operator for class SamplingGrid.
299 *
300 * \param ost output stream to print to
301 * \param other instance to print
302 * \return ref to stream for concatenation
303 */
304std::ostream & operator<<(std::ostream &ost, const SamplingGrid& other);
305
306template<typename T> T ZeroInstance();
307template<> SamplingGrid ZeroInstance<SamplingGrid>();
308
309// we need to give this class a unique key for serialization
310// its is only serialized through its base class FragmentJob
311BOOST_CLASS_EXPORT_KEY(SamplingGrid)
312
313#endif /* SAMPLINGGRID_HPP_ */
Note: See TracBrowser for help on using the repository browser.