| 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 | */
|
|---|
| 30 | class SamplingGrid : public SamplingGridProperties
|
|---|
| 31 | {
|
|---|
| 32 | //!> grant unit test access to private parts
|
|---|
| 33 | friend class SamplingGridTest;
|
|---|
| 34 | //!> grant output operator access
|
|---|
| 35 | friend std::ostream & operator<<(std::ostream &ost, const SamplingGrid& other);
|
|---|
| 36 | public:
|
|---|
| 37 | //!> typedef for sampled values
|
|---|
| 38 | typedef std::vector< double > sampledvalues_t;
|
|---|
| 39 |
|
|---|
| 40 | /** Constructor for class SamplingGrid.
|
|---|
| 41 | *
|
|---|
| 42 | * \param _begin offset for grid
|
|---|
| 43 | * \param _size edge length of grid
|
|---|
| 44 | * \param _level number of grid points in \f$2^{\text{level}}\f$
|
|---|
| 45 | * \param _sampled_grid sample points
|
|---|
| 46 | */
|
|---|
| 47 | SamplingGrid(const double _begin[3],
|
|---|
| 48 | const double _size,
|
|---|
| 49 | const int _level,
|
|---|
| 50 | const sampledvalues_t &_sampled_grid);
|
|---|
| 51 |
|
|---|
| 52 | /** Copy constructor for class SamplingGrid.
|
|---|
| 53 | *
|
|---|
| 54 | * \param _grid grid to copy
|
|---|
| 55 | */
|
|---|
| 56 | SamplingGrid(const SamplingGrid &_grid);
|
|---|
| 57 |
|
|---|
| 58 | /** Copy constructor for class SamplingGrid from SamplingGridProperties.
|
|---|
| 59 | *
|
|---|
| 60 | * \param _props properties to copy
|
|---|
| 61 | */
|
|---|
| 62 | SamplingGrid(const SamplingGridProperties &_props);
|
|---|
| 63 |
|
|---|
| 64 | /** Copy constructor for class SamplingGrid from SamplingGridProperties.
|
|---|
| 65 | *
|
|---|
| 66 | * \param _props properties to copy
|
|---|
| 67 | * \param _sampled_grid sample points
|
|---|
| 68 | */
|
|---|
| 69 | SamplingGrid(
|
|---|
| 70 | const SamplingGridProperties &_props,
|
|---|
| 71 | const sampledvalues_t &_sampled_grid);
|
|---|
| 72 |
|
|---|
| 73 | /** default cstor.
|
|---|
| 74 | */
|
|---|
| 75 | SamplingGrid()
|
|---|
| 76 | {}
|
|---|
| 77 |
|
|---|
| 78 | virtual ~SamplingGrid();
|
|---|
| 79 |
|
|---|
| 80 | /** Assignment operator.
|
|---|
| 81 | *
|
|---|
| 82 | * \param other other instance to assign ourselves to
|
|---|
| 83 | */
|
|---|
| 84 | SamplingGrid& operator=(const SamplingGrid& other);
|
|---|
| 85 |
|
|---|
| 86 | /** Addition operator with another SamplingGrid instance \a other.
|
|---|
| 87 | *
|
|---|
| 88 | * \param other other instance to sum onto this one.
|
|---|
| 89 | * \return ref to this instance
|
|---|
| 90 | */
|
|---|
| 91 | SamplingGrid& operator+=(const SamplingGrid& other)
|
|---|
| 92 | {
|
|---|
| 93 | superposeOtherGrids(other, +1.);
|
|---|
| 94 | return *this;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | /** Element-wise multiplication operator with another SamplingGrid instance \a other.
|
|---|
| 98 | *
|
|---|
| 99 | * \param other other instance to sum onto this one.
|
|---|
| 100 | * \return ref to this instance
|
|---|
| 101 | */
|
|---|
| 102 | SamplingGrid& operator*=(const SamplingGrid& other);
|
|---|
| 103 |
|
|---|
| 104 | /** Subtraction operator with another SamplingGrid instance \a other.
|
|---|
| 105 | *
|
|---|
| 106 | * \param other other instance to subtract from this one.
|
|---|
| 107 | * \return ref to this instance
|
|---|
| 108 | */
|
|---|
| 109 | SamplingGrid& operator-=(const SamplingGrid& other)
|
|---|
| 110 | {
|
|---|
| 111 | superposeOtherGrids(other, -1.);
|
|---|
| 112 | return *this;
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | /** Returns the numeric integral over the grid.
|
|---|
| 116 | *
|
|---|
| 117 | * @return sum of grid values times volume element
|
|---|
| 118 | */
|
|---|
| 119 | double integral() const;
|
|---|
| 120 |
|
|---|
| 121 | /** Returns the numeric integral over the grid where the grid is element-wise multiplied with \a weight.
|
|---|
| 122 | *
|
|---|
| 123 | * @param weight grid of weights
|
|---|
| 124 | * @return sum of grid values weighted by respective element in weight times volume element
|
|---|
| 125 | */
|
|---|
| 126 | double integral(const SamplingGrid &weight) const;
|
|---|
| 127 |
|
|---|
| 128 | private:
|
|---|
| 129 | /** Helper function that contains all the logic of how to superpose two
|
|---|
| 130 | * grids.
|
|---|
| 131 | *
|
|---|
| 132 | * Is called by SamplingGrid::operator+=() and SamplingGrid::operator-=()
|
|---|
| 133 | *
|
|---|
| 134 | * @param other other histogram
|
|---|
| 135 | * @param prefactor +1. is then addition, -1. is subtraction.
|
|---|
| 136 | */
|
|---|
| 137 | void superposeOtherGrids(const SamplingGrid &other, const double prefactor);
|
|---|
| 138 |
|
|---|
| 139 | public:
|
|---|
| 140 | //!> sample points
|
|---|
| 141 | sampledvalues_t sampled_grid;
|
|---|
| 142 |
|
|---|
| 143 | private:
|
|---|
| 144 | friend class MPQCData;
|
|---|
| 145 |
|
|---|
| 146 | friend class boost::serialization::access;
|
|---|
| 147 | // serialization
|
|---|
| 148 | template <typename Archive>
|
|---|
| 149 | void serialize(Archive& ar, const unsigned int version)
|
|---|
| 150 | {
|
|---|
| 151 | ar & boost::serialization::base_object<SamplingGridProperties>(*this);
|
|---|
| 152 | ar & const_cast< sampledvalues_t &>(sampled_grid);
|
|---|
| 153 | }
|
|---|
| 154 | };
|
|---|
| 155 |
|
|---|
| 156 | /** Output operator for class SamplingGrid.
|
|---|
| 157 | *
|
|---|
| 158 | * \param ost output stream to print to
|
|---|
| 159 | * \param other instance to print
|
|---|
| 160 | * \return ref to stream for concatenation
|
|---|
| 161 | */
|
|---|
| 162 | std::ostream & operator<<(std::ostream &ost, const SamplingGrid& other);
|
|---|
| 163 |
|
|---|
| 164 | template<typename T> T ZeroInstance();
|
|---|
| 165 | template<> SamplingGrid ZeroInstance<SamplingGrid>();
|
|---|
| 166 |
|
|---|
| 167 | // we need to give this class a unique key for serialization
|
|---|
| 168 | // its is only serialized through its base class FragmentJob
|
|---|
| 169 | BOOST_CLASS_EXPORT_KEY(SamplingGrid)
|
|---|
| 170 |
|
|---|
| 171 | #endif /* SAMPLINGGRID_HPP_ */
|
|---|