[c74fdb] | 1 | /*
|
---|
| 2 | * Fragment.hpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Aug 8, 2012
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #ifndef FRAGMENT_HPP_
|
---|
| 9 | #define FRAGMENT_HPP_
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 | // include config.h
|
---|
| 13 | #ifdef HAVE_CONFIG_H
|
---|
| 14 | #include <config.h>
|
---|
| 15 | #endif
|
---|
| 16 |
|
---|
[a576eb] | 17 | #include <boost/serialization/export.hpp>
|
---|
| 18 | #include <boost/serialization/vector.hpp>
|
---|
| 19 | #include <boost/serialization/utility.hpp>
|
---|
| 20 |
|
---|
[184943] | 21 | #include <iosfwd>
|
---|
[c74fdb] | 22 | #include <vector>
|
---|
| 23 |
|
---|
[f3bc5f] | 24 | class FragmentTest;
|
---|
| 25 |
|
---|
[c74fdb] | 26 | class Fragment {
|
---|
[184943] | 27 | //!> grant ostream operator access
|
---|
| 28 | friend std::ostream & operator<<(std::ostream &ost, const Fragment &f);
|
---|
[f3bc5f] | 29 | //!> grant unit test access
|
---|
| 30 | friend class FragmentTest;
|
---|
[c74fdb] | 31 | public:
|
---|
[f3bc5f] | 32 | typedef std::vector<double> position_t;
|
---|
| 33 | typedef std::vector< position_t > positions_t;
|
---|
[c74fdb] | 34 | typedef std::vector< double > charges_t;
|
---|
[f3bc5f] | 35 | typedef std::pair< position_t, double> nucleus_t;
|
---|
[c74fdb] | 36 | typedef std::vector< nucleus_t > nuclei_t;
|
---|
| 37 |
|
---|
| 38 | /** Default constructor of class Fragment.
|
---|
| 39 | *
|
---|
| 40 | */
|
---|
| 41 | Fragment();
|
---|
| 42 |
|
---|
| 43 | /** Default constructor of class Fragment.
|
---|
| 44 | *
|
---|
| 45 | */
|
---|
| 46 | Fragment(const nuclei_t &_nuclei) :
|
---|
| 47 | nuclei(_nuclei)
|
---|
| 48 | {}
|
---|
| 49 |
|
---|
| 50 | /** Constructor of class Fragment.
|
---|
| 51 | *
|
---|
| 52 | * @param _positions given positions
|
---|
| 53 | * @param _charges given charges
|
---|
| 54 | */
|
---|
[f3bc5f] | 55 | Fragment(const positions_t &_positions, const charges_t &_charges);
|
---|
[c74fdb] | 56 |
|
---|
| 57 | /** Adding another fragment onto this one.
|
---|
| 58 | *
|
---|
| 59 | * \note The operation is area-conserving, i.e. the new area is the sum of
|
---|
| 60 | * both areas.
|
---|
| 61 | *
|
---|
| 62 | * @param other other fragment
|
---|
| 63 | * @return ref to this instance
|
---|
| 64 | */
|
---|
| 65 | Fragment& operator+=(const Fragment &other);
|
---|
| 66 |
|
---|
| 67 | /** Assignment operator.
|
---|
| 68 | *
|
---|
| 69 | * @param other other fragment to make ourselves equal to
|
---|
| 70 | * @return ref to this instance
|
---|
| 71 | */
|
---|
| 72 | Fragment& operator=(const Fragment &other);
|
---|
| 73 |
|
---|
| 74 | /** Subtracting another fragment from this one.
|
---|
| 75 | *
|
---|
| 76 | * @param other other fragment
|
---|
| 77 | * @return ref to this instance
|
---|
| 78 | */
|
---|
| 79 | Fragment& operator-=(const Fragment &other);
|
---|
| 80 |
|
---|
[184943] | 81 | /** Getter for all stored positions.
|
---|
| 82 | *
|
---|
| 83 | * @return vector of positions
|
---|
| 84 | */
|
---|
| 85 | positions_t getPositions() const;
|
---|
| 86 |
|
---|
| 87 | /** Getter for all stored charges.
|
---|
| 88 | *
|
---|
| 89 | * @return vector of charges
|
---|
| 90 | */
|
---|
| 91 | charges_t getCharges() const;
|
---|
| 92 |
|
---|
[f3bc5f] | 93 | /** Equality operator.
|
---|
| 94 | *
|
---|
| 95 | * @param other other instance to check against
|
---|
| 96 | * @return true - both are equal, false - some nucleus_t differ
|
---|
| 97 | */
|
---|
| 98 | bool operator==(const Fragment& other) const;
|
---|
| 99 |
|
---|
| 100 | bool operator!=(const Fragment& other) const
|
---|
| 101 | {
|
---|
| 102 | return (!(*this == other));
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | /** Creates type nucleus_t from given \a position and \a charge.
|
---|
| 106 | *
|
---|
| 107 | * @param position position of nucleus to create
|
---|
| 108 | * @param charge charge of nucleus to create
|
---|
| 109 | * @return nucleus with given \a position and \a charge
|
---|
| 110 | */
|
---|
| 111 | static nucleus_t createNucleus(const position_t &position, const double charge);
|
---|
| 112 |
|
---|
| 113 | /** Helper function to check whether two positions are equal.
|
---|
| 114 | *
|
---|
| 115 | * @param a first position
|
---|
| 116 | * @param b second position
|
---|
| 117 | * @return a equals b within numerical precision
|
---|
| 118 | */
|
---|
| 119 | static bool isPositionEqual(const position_t &a, const position_t &b);
|
---|
| 120 |
|
---|
[c74fdb] | 121 | private:
|
---|
[f3bc5f] | 122 | /** Helper function that checks whether this nuclei \b position is present.
|
---|
[c74fdb] | 123 | *
|
---|
| 124 | * This operation is \f${\cal O}(n)\f$
|
---|
| 125 | *
|
---|
| 126 | * @param n nuclei to check
|
---|
| 127 | * @return true - is contained, false - is not contained
|
---|
| 128 | */
|
---|
| 129 | bool containsNuclei(const nucleus_t &n) const;
|
---|
| 130 |
|
---|
[f3bc5f] | 131 | /** Seeks through all nuclei and removes one with matching \b position if found.
|
---|
[c74fdb] | 132 | *
|
---|
| 133 | * @param n nuclei to remove
|
---|
| 134 | */
|
---|
| 135 | void removeNuclei(const nucleus_t &n);
|
---|
| 136 |
|
---|
| 137 | private:
|
---|
| 138 | nuclei_t nuclei;
|
---|
[a576eb] | 139 |
|
---|
| 140 | private:
|
---|
| 141 | friend class boost::serialization::access;
|
---|
| 142 | // serialization
|
---|
| 143 | template <typename Archive>
|
---|
| 144 | void serialize(Archive& ar, const unsigned int version)
|
---|
| 145 | {
|
---|
| 146 | ar & nuclei;
|
---|
| 147 | }
|
---|
[c74fdb] | 148 | };
|
---|
| 149 |
|
---|
[a576eb] | 150 | // we need to give this class a unique key for serialization
|
---|
| 151 | BOOST_CLASS_EXPORT_KEY(Fragment)
|
---|
| 152 |
|
---|
[f3bc5f] | 153 | /** Equality operator for two nuclei.
|
---|
| 154 | *
|
---|
| 155 | * @param a first nuclei
|
---|
| 156 | * @param b second nuclei
|
---|
| 157 | * @return true - both have same position and charge, false - either charge or position is different
|
---|
| 158 | */
|
---|
| 159 | bool operator==(const Fragment::nucleus_t &a, const Fragment::nucleus_t &b);
|
---|
| 160 |
|
---|
| 161 | std::ostream & operator<<(std::ostream &ost, const Fragment::nucleus_t &n);
|
---|
| 162 |
|
---|
[184943] | 163 | std::ostream & operator<<(std::ostream &ost, const Fragment &f);
|
---|
| 164 |
|
---|
[c74fdb] | 165 | template<typename T> T ZeroInstance();
|
---|
| 166 | template<> Fragment ZeroInstance<Fragment>();
|
---|
| 167 |
|
---|
| 168 | #endif /* FRAGMENT_HPP_ */
|
---|