source: src/Fragmentation/Summation/SetValues/SamplingGrid.hpp@ b5f548

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

FIX: Shifted all helper functions from SamplingGrid to ..Properties.

  • these functions just rely on member values of ..Properties and allow for using the properties as replacement to the full grid when its values (and the window) are of no more interest.
  • Property mode set to 100644
File size: 11.8 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 <boost/function.hpp>
17#include <iosfwd>
18#include <vector>
19
20#include "boost/serialization/export.hpp"
21#include "boost/serialization/vector.hpp"
22
23#include "Fragmentation/Summation/SetValues/SamplingGridProperties.hpp"
24
25class MPQCData;
26class SamplingGridTest;
27
28/** This class stores a sample function on a three-dimensional grid.
29 *
30 * \note We do not use boost::multi_array because it is not trivial to serialize.
31 *
32 */
33class SamplingGrid : public SamplingGridProperties
34{
35 //!> grant unit test access to private parts
36 friend class SamplingGridTest;
37 //!> grant output operator access
38 friend std::ostream & operator<<(std::ostream &ost, const SamplingGrid& other);
39public:
40 //!> typedef for sampled values
41 typedef std::vector< double > sampledvalues_t;
42
43 /** Constructor for class SamplingGrid for full window.
44 *
45 * Here, the window of sampled values spans the given domain.
46 *
47 * \param _begin offset for grid per axis
48 * \param _end edge length of grid per axis
49 * \param _level number of grid points in \f$2^{\mathrm{level}}\f$
50 * \param _sampled_grid sample points
51 */
52 SamplingGrid(const double _begin[3],
53 const double _end[3],
54 const int _level,
55 const sampledvalues_t &_sampled_grid);
56
57 /** Constructor for class SamplingGrid for empty window.
58 *
59 * Here, the window is initially of size zero.
60 *
61 * \param _begin offset for grid per axis
62 * \param _end edge length of grid per axis
63 * \param _level number of grid points in \f$2^{\mathrm{level}}\f$
64 */
65 SamplingGrid(const double _begin[3],
66 const double _end[3],
67 const int _level);
68
69 /** Copy constructor for class SamplingGrid with full window from SamplingGridProperties.
70 *
71 * Here, the window is initially empty.
72 *
73 * \param _props properties to copy
74 */
75 SamplingGrid(const SamplingGridProperties &_props);
76
77 /** Copy constructor for class SamplingGrid with empty window from SamplingGridProperties.
78 *
79 * Here, the window must span the whole domain
80 *
81 * \param _props properties to copy
82 * \param _sampled_grid sample points
83 */
84 SamplingGrid(
85 const SamplingGridProperties &_props,
86 const sampledvalues_t &_sampled_grid);
87
88 /** Copy constructor for class SamplingGrid.
89 *
90 * The window of sampled values corresponds to the one on \a _grid.
91 *
92 * \param _grid grid to copy
93 */
94 SamplingGrid(const SamplingGrid &_grid);
95
96 /** default cstor.
97 */
98 SamplingGrid();
99
100 virtual ~SamplingGrid();
101
102 /** Checks whether another instance is consistent with this one.
103 *
104 * \note Conistency is stronger as grids must have the same window.
105 *
106 * \param _props other properties to check against
107 * \return true - are consistent, false - else
108 */
109 bool isCongruent(const SamplingGrid &_props) const;
110
111 /** Assignment operator.
112 *
113 * \param other other instance to assign ourselves to
114 */
115 SamplingGrid& operator=(const SamplingGrid& other);
116
117 /** Addition operator with another SamplingGrid instance \a other.
118 *
119 * \param other other instance to sum onto this one.
120 * \return ref to this instance
121 */
122 SamplingGrid& operator+=(const SamplingGrid& other)
123 {
124 superposeOtherGrids(other, +1.);
125 return *this;
126 }
127
128 /** Element-wise multiplication operator with another SamplingGrid instance \a other.
129 *
130 * With non-zero windows we have to pay some more attention here.
131 * Now, the windows may not be congruent but we have to find the intersection
132 * of the two windows and then construct the new window only of this size and
133 * multiply. The trick then is not to copy&change the other grid but to
134 * access it properly.
135 *
136 * \param other other instance to sum onto this one.
137 * \return ref to this instance
138 */
139 SamplingGrid& operator*=(const SamplingGrid& other);
140
141 /** Subtraction operator with another SamplingGrid instance \a other.
142 *
143 * \param other other instance to subtract from this one.
144 * \return ref to this instance
145 */
146 SamplingGrid& operator-=(const SamplingGrid& other)
147 {
148 superposeOtherGrids(other, -1.);
149 return *this;
150 }
151
152 /** Returns the numeric integral over the grid.
153 *
154 * @return sum of grid values times volume element
155 */
156 double integral() const;
157
158 /** Returns the numeric integral over the grid where the grid is element-wise multiplied with \a weight.
159 *
160 * @param weight grid of weights
161 * @return sum of grid values weighted by respective element in weight times volume element
162 */
163 double integral(const SamplingGrid &weight) const;
164
165 /** Returns the total number of gridpoints of the discrete mesh covering the (window) volume.
166 *
167 * @return number of gridpoints sampled_values should have
168 */
169 const size_t getWindowGridPoints() const;
170
171 /** Returns the number of gridpoints of the discrete mesh for the current
172 * window size for given axis \axis.
173 *
174 * \param axis axis to calculate number of gridpoints for
175 * \return number of gridpoints along this axis
176 */
177 const size_t getWindowGridPointsPerAxis(const size_t axis) const;
178
179 /** Returns the length of the window for the given \a axis.
180 *
181 * \param axis axis for which to get step length
182 * \return window length for the given axis, i.e. end - begin
183 */
184 const double getWindowLengthPerAxis(const size_t axis) const;
185
186 /** Returns the volume of the domain covered by the current window.
187 *
188 * @return volume of window
189 */
190 const double getWindowVolume() const;
191
192 /** Sets the size of the window.
193 *
194 * \note also resets the sampled points so far.
195 *
196 * \param _begin_window start of new window
197 * \param _end_window end of window
198 */
199 void setWindow(const double _begin_window[3], const double _end_window[3]);
200
201private:
202 /** Sets the size of the domain.
203 *
204 * \note also resets the sampled points so far and the window.
205 *
206 * \param _begin start of new window
207 * \param _end end of window
208 */
209 void setDomain(const double _begin[3], const double _end[3]);
210
211 /** Sets the size of the domain.
212 *
213 * \note this is just internally used for easing the array setting.
214 *
215 * \param _begin start of domain
216 * \param _end end of domain
217 */
218 void setDomainSize(const double _begin[3], const double _end[3]);
219
220 /** Extends the window while keeping the values.
221 *
222 * \param _begin_window new start of window
223 * \param _end_window new end of window
224 */
225 void extendWindow(const double _begin_window[3], const double _end_window[3]);
226
227 /** Shrinks the window while keeping the values.
228 *
229 * \param _begin_window new start of window
230 * \param _end_window new end of window
231 */
232 void shrinkWindow(const double _begin_window[3], const double _end_window[3]);
233
234 /** Adds another (smaller) window onto the one in this instance.
235 *
236 * \note We assume here that the given window fits on the this one.
237 *
238 * \param _begin_window start of other window
239 * \param _end_window end of other window
240 * \param _sampled_grid other set of sampled values
241 * @param prefactor +1. is then addition, -1. is subtraction.
242 */
243 void addOntoWindow(
244 const double _begin_window[3],
245 const double _end_window[3],
246 const sampledvalues_t &_sampled_grid,
247 const double prefactor);
248
249 /** Adds another (larger) window into the one in this instance.
250 *
251 * \note We assume here that the given window is larger than this one.
252 *
253 * \param _begin_window start of other window
254 * \param _end_window end of other window
255 * \param _sampled_grid other set of sampled values
256 * @param prefactor +1. is then addition, -1. is subtraction.
257 */
258 void addIntoWindow(
259 const double _begin_window[3],
260 const double _end_window[3],
261 const sampledvalues_t &_sampled_grid,
262 const double prefactor);
263
264 /** Enum to help in addWindowOntoWindow() decide which iterator needs to be
265 * advanced.
266 */
267 enum eLargerWindow {
268 destwindow,
269 sourcewindow
270 };
271
272 /** Helper function to copy one (larger) window into a (smaller) window.
273 *
274 * \note Why do we need the extra \a choice? We need to know which window
275 * tuples is associated with which sampled values that are constrained by
276 * one of them being constant, hence the source values
277 *
278 * \param larger_wbegin start of larger window
279 * \param larger_wend end of larger window
280 * \param smaller_wbegin start of smaller window
281 * \param smaller_wend end of smaller window
282 * \param dest_sampled_grid larger set of sampled values
283 * \param source_sampled_grid smaller set of sampled values
284 * \param op operation to perform with the two elements
285 * \param larger_window indicates which is the larger window
286 */
287 void addWindowOntoWindow(
288 const double larger_wbegin[3],
289 const double larger_wend[3],
290 const double smaller_wbegin[3],
291 const double smaller_wend[3],
292 sampledvalues_t &dest_sampled_grid,
293 const sampledvalues_t &source_sampled_grid,
294 boost::function<void (double &, const double &)> op,
295 enum eLargerWindow larger_window);
296
297 /** Helper function that contains all the logic of how to superpose two
298 * grids.
299 *
300 * Is called by SamplingGrid::operator+=() and SamplingGrid::operator-=()
301 *
302 * @param other other histogram
303 * @param prefactor +1. is then addition, -1. is subtraction.
304 */
305 void superposeOtherGrids(const SamplingGrid &other, const double prefactor);
306
307 /** Sets the size of the window.
308 *
309 * \note also resets the sampled points so far.
310 *
311 * \param _begin_window start of new window
312 * \param _end_window end of window
313 */
314 void setWindowSize(const double _begin_window[3], const double _end_window[3]);
315
316 /** Helper function to get point at grid point for given \a axis and less than value.
317 *
318 * @param value value to find nearest grid point to
319 * @param axis axis of the value
320 * @return nearest lower grid point
321 */
322 double getNearestLowerGridPoint(
323 const double value, const size_t axis) const;
324
325 /** Helper function to get point at grid point for given \a axis and greater than value.
326 *
327 * @param value value to find nearest grid point to
328 * @param axis axis of the value
329 * @return nearest lower grid point
330 */
331 double getNearestHigherGridPoint(
332 const double value, const size_t axis) const;
333
334public:
335 /// We do not store the whole grid if many entries are actually zero
336 /// but only a window wherein the sampled function is non-zero.
337
338 //!> sample points of the window
339 sampledvalues_t sampled_grid;
340
341 //!> start of the window relative to SamplingGridProperties::begin and SamplingGridProperties::size
342 double begin_window[3];
343 //!> end of the window relative to SamplingGridProperties::begin and SamplingGridProperties::size
344 double end_window[3];
345
346private:
347 friend class MPQCData;
348
349 friend class boost::serialization::access;
350 // serialization
351 template <typename Archive>
352 void serialize(Archive& ar, const unsigned int version)
353 {
354 ar & boost::serialization::base_object<SamplingGridProperties>(*this);
355 ar & const_cast< sampledvalues_t &>(sampled_grid);
356 for(size_t i=0;i<3;++i) {
357 ar & begin_window[i];
358 ar & end_window[i];
359 }
360 }
361
362 //!> static typedef to use in cstor when no initial values are given
363 static const double zeroOffset[3];
364};
365
366/** Output operator for class SamplingGrid.
367 *
368 * \param ost output stream to print to
369 * \param other instance to print
370 * \return ref to stream for concatenation
371 */
372std::ostream & operator<<(std::ostream &ost, const SamplingGrid& other);
373
374template<typename T> T ZeroInstance();
375template<> SamplingGrid ZeroInstance<SamplingGrid>();
376
377// we need to give this class a unique key for serialization
378// its is only serialized through its base class FragmentJob
379BOOST_CLASS_EXPORT_KEY(SamplingGrid)
380
381// define inline functions
382#include "SamplingGrid_inline.hpp"
383
384#endif /* SAMPLINGGRID_HPP_ */
Note: See TracBrowser for help on using the repository browser.