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 |
|
---|
24 | class MPQCData;
|
---|
25 | class 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 | */
|
---|
32 | class 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);
|
---|
38 | public:
|
---|
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 |
|
---|
80 | virtual ~SamplingGrid();
|
---|
81 |
|
---|
82 | /** Assignment operator.
|
---|
83 | *
|
---|
84 | * \param other other instance to assign ourselves to
|
---|
85 | */
|
---|
86 | SamplingGrid& operator=(const SamplingGrid& other);
|
---|
87 |
|
---|
88 | /** Addition operator with another SamplingGrid instance \a other.
|
---|
89 | *
|
---|
90 | * \param other other instance to sum onto this one.
|
---|
91 | * \return ref to this instance
|
---|
92 | */
|
---|
93 | SamplingGrid& operator+=(const SamplingGrid& other)
|
---|
94 | {
|
---|
95 | superposeOtherGrids(other, +1.);
|
---|
96 | return *this;
|
---|
97 | }
|
---|
98 |
|
---|
99 | /** Element-wise multiplication operator with another SamplingGrid instance \a other.
|
---|
100 | *
|
---|
101 | * \param other other instance to sum onto this one.
|
---|
102 | * \return ref to this instance
|
---|
103 | */
|
---|
104 | SamplingGrid& operator*=(const SamplingGrid& other);
|
---|
105 |
|
---|
106 | /** Subtraction operator with another SamplingGrid instance \a other.
|
---|
107 | *
|
---|
108 | * \param other other instance to subtract from this one.
|
---|
109 | * \return ref to this instance
|
---|
110 | */
|
---|
111 | SamplingGrid& operator-=(const SamplingGrid& other)
|
---|
112 | {
|
---|
113 | superposeOtherGrids(other, -1.);
|
---|
114 | return *this;
|
---|
115 | }
|
---|
116 |
|
---|
117 | /** Returns the numeric integral over the grid.
|
---|
118 | *
|
---|
119 | * @return sum of grid values times volume element
|
---|
120 | */
|
---|
121 | double integral() const;
|
---|
122 |
|
---|
123 | /** Returns the numeric integral over the grid where the grid is element-wise multiplied with \a weight.
|
---|
124 | *
|
---|
125 | * @param weight grid of weights
|
---|
126 | * @return sum of grid values weighted by respective element in weight times volume element
|
---|
127 | */
|
---|
128 | double integral(const SamplingGrid &weight) const;
|
---|
129 |
|
---|
130 | private:
|
---|
131 | /** Returns the volume of the domain for this sampled function.
|
---|
132 | *
|
---|
133 | * @return volume
|
---|
134 | */
|
---|
135 | double getVolume() const;
|
---|
136 |
|
---|
137 | /** Helper function that contains all the logic of how to superpose two
|
---|
138 | * grids.
|
---|
139 | *
|
---|
140 | * Is called by SamplingGrid::operator+=() and SamplingGrid::operator-=()
|
---|
141 | *
|
---|
142 | * @param other other histogram
|
---|
143 | * @param prefactor +1. is then addition, -1. is subtraction.
|
---|
144 | */
|
---|
145 | void superposeOtherGrids(const SamplingGrid &other, const double prefactor);
|
---|
146 |
|
---|
147 | public:
|
---|
148 | //!> sample points
|
---|
149 | sampledvalues_t sampled_grid;
|
---|
150 |
|
---|
151 | private:
|
---|
152 | friend class MPQCData;
|
---|
153 |
|
---|
154 | friend class boost::serialization::access;
|
---|
155 | // serialization
|
---|
156 | template <typename Archive>
|
---|
157 | void serialize(Archive& ar, const unsigned int version)
|
---|
158 | {
|
---|
159 | ar & boost::serialization::base_object<SamplingGridProperties>(*this);
|
---|
160 | ar & const_cast< sampledvalues_t &>(sampled_grid);
|
---|
161 | }
|
---|
162 | };
|
---|
163 |
|
---|
164 | /** Output operator for class SamplingGrid.
|
---|
165 | *
|
---|
166 | * \param ost output stream to print to
|
---|
167 | * \param other instance to print
|
---|
168 | * \return ref to stream for concatenation
|
---|
169 | */
|
---|
170 | std::ostream & operator<<(std::ostream &ost, const SamplingGrid& other);
|
---|
171 |
|
---|
172 | template<typename T> T ZeroInstance();
|
---|
173 | template<> SamplingGrid ZeroInstance<SamplingGrid>();
|
---|
174 |
|
---|
175 | // we need to give this class a unique key for serialization
|
---|
176 | // its is only serialized through its base class FragmentJob
|
---|
177 | BOOST_CLASS_EXPORT_KEY(SamplingGrid)
|
---|
178 |
|
---|
179 | #endif /* SAMPLINGGRID_HPP_ */
|
---|