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

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 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 cb30d9 was 336da8, checked in by Frederik Heber <heber@…>, 9 years ago

WindowGrid_converter's refactored a bit with getDiscreteWindowOffsets().

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