/* * SamplingGrid.hpp * * Created on: 25.07.2012 * Author: heber */ #ifndef SAMPLINGGRID_HPP_ #define SAMPLINGGRID_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include #include "boost/serialization/export.hpp" #include "boost/serialization/vector.hpp" #include "Jobs/Grid/SamplingGridProperties.hpp" class MPQCData; class SamplingGridTest; /** This class stores a sample function on a three-dimensional grid. * */ class SamplingGrid : public SamplingGridProperties { //!> grant unit test access to private parts friend class SamplingGridTest; //!> grant output operator access friend std::ostream & operator<<(std::ostream &ost, const SamplingGrid& other); public: //!> typedef for sampled values typedef std::vector< double > sampledvalues_t; /** Constructor for class SamplingGrid. * * \param _begin offset for grid * \param _size edge length of grid * \param _level number of grid points in \f$2^{\text{level}}\f$ * \param _sampled_grid sample points */ SamplingGrid(const double _begin[3], const double _size, const int _level, const sampledvalues_t &_sampled_grid); /** Copy constructor for class SamplingGrid. * * \param _grid grid to copy */ SamplingGrid(const SamplingGrid &_grid); /** Copy constructor for class SamplingGrid from SamplingGridProperties. * * \param _props properties to copy */ SamplingGrid(const SamplingGridProperties &_props); /** Copy constructor for class SamplingGrid from SamplingGridProperties. * * \param _props properties to copy * \param _sampled_grid sample points */ SamplingGrid( const SamplingGridProperties &_props, const sampledvalues_t &_sampled_grid); /** default cstor. */ SamplingGrid() {} virtual ~SamplingGrid(); /** Assignment operator. * * \param other other instance to assign ourselves to */ SamplingGrid& operator=(const SamplingGrid& other); /** Addition operator with another SamplingGrid instance \a other. * * \param other other instance to sum onto this one. * \return ref to this instance */ SamplingGrid& operator+=(const SamplingGrid& other) { superposeOtherGrids(other, +1.); return *this; } /** Subtraction operator with another SamplingGrid instance \a other. * * \param other other instance to subtract from this one. * \return ref to this instance */ SamplingGrid& operator-=(const SamplingGrid& other) { superposeOtherGrids(other, -1.); return *this; } /** Returns the numeric integral over the grid. * * @return sum of grid values times volume element */ double integral() const; private: /** Helper function that contains all the logic of how to superpose two * grids. * * Is called by SamplingGrid::operator+=() and SamplingGrid::operator-=() * * @param other other histogram * @param prefactor +1. is then addition, -1. is subtraction. */ void superposeOtherGrids(const SamplingGrid &other, const double prefactor); public: //!> sample points sampledvalues_t sampled_grid; private: friend class MPQCData; friend class boost::serialization::access; // serialization template void serialize(Archive& ar, const unsigned int version) { ar & boost::serialization::base_object(*this); ar & const_cast< sampledvalues_t &>(sampled_grid); } }; /** Output operator for class SamplingGrid. * * \param ost output stream to print to * \param other instance to print * \return ref to stream for concatenation */ std::ostream & operator<<(std::ostream &ost, const SamplingGrid& other); // we need to give this class a unique key for serialization // its is only serialized through its base class FragmentJob BOOST_CLASS_EXPORT_KEY(SamplingGrid) #endif /* SAMPLINGGRID_HPP_ */